blob: 83cd41fa2b01ad4cdb586b8a8c1a38db53f0b7e3 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07002#include <linux/ceph/ceph_debug.h>
Sage Weil76aa8442009-10-06 11:31:14 -07003
Sage Weil06edf042009-12-15 14:44:32 -08004#include <linux/device.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09005#include <linux/slab.h>
Sage Weil76aa8442009-10-06 11:31:14 -07006#include <linux/module.h>
7#include <linux/ctype.h>
8#include <linux/debugfs.h>
9#include <linux/seq_file.h>
10
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -070011#include <linux/ceph/libceph.h>
12#include <linux/ceph/mon_client.h>
13#include <linux/ceph/auth.h>
14#include <linux/ceph/debugfs.h>
Sage Weil76aa8442009-10-06 11:31:14 -070015
Randy Dunlap6f453ed2010-09-28 09:53:10 -070016#include "super.h"
17
Sage Weil039934b2009-11-12 15:05:52 -080018#ifdef CONFIG_DEBUG_FS
19
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -070020#include "mds_client.h"
Sage Weil76aa8442009-10-06 11:31:14 -070021
22static int mdsmap_show(struct seq_file *s, void *p)
23{
24 int i;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -070025 struct ceph_fs_client *fsc = s->private;
Yan, Zheng76201b62017-03-28 17:04:13 +080026 struct ceph_mdsmap *mdsmap;
Sage Weil76aa8442009-10-06 11:31:14 -070027
Markus Elfringd37b1d92017-08-20 20:22:02 +020028 if (!fsc->mdsc || !fsc->mdsc->mdsmap)
Sage Weil76aa8442009-10-06 11:31:14 -070029 return 0;
Yan, Zheng76201b62017-03-28 17:04:13 +080030 mdsmap = fsc->mdsc->mdsmap;
31 seq_printf(s, "epoch %d\n", mdsmap->m_epoch);
32 seq_printf(s, "root %d\n", mdsmap->m_root);
33 seq_printf(s, "max_mds %d\n", mdsmap->m_max_mds);
34 seq_printf(s, "session_timeout %d\n", mdsmap->m_session_timeout);
35 seq_printf(s, "session_autoclose %d\n", mdsmap->m_session_autoclose);
36 for (i = 0; i < mdsmap->m_num_mds; i++) {
37 struct ceph_entity_addr *addr = &mdsmap->m_info[i].addr;
38 int state = mdsmap->m_info[i].state;
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -070039 seq_printf(s, "\tmds%d\t%s\t(%s)\n", i,
Jeff Laytonb726ec92019-05-06 09:38:47 -040040 ceph_pr_addr(addr),
Sage Weil76aa8442009-10-06 11:31:14 -070041 ceph_mds_state_name(state));
42 }
43 return 0;
44}
45
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -070046/*
47 * mdsc debugfs
48 */
Sage Weil76aa8442009-10-06 11:31:14 -070049static int mdsc_show(struct seq_file *s, void *p)
50{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -070051 struct ceph_fs_client *fsc = s->private;
52 struct ceph_mds_client *mdsc = fsc->mdsc;
Sage Weil44ca18f2010-02-15 12:08:46 -080053 struct ceph_mds_request *req;
54 struct rb_node *rp;
Sage Weil76aa8442009-10-06 11:31:14 -070055 int pathlen;
56 u64 pathbase;
57 char *path;
58
59 mutex_lock(&mdsc->mutex);
Sage Weil44ca18f2010-02-15 12:08:46 -080060 for (rp = rb_first(&mdsc->request_tree); rp; rp = rb_next(rp)) {
61 req = rb_entry(rp, struct ceph_mds_request, r_node);
Sage Weil76aa8442009-10-06 11:31:14 -070062
Sage Weil4af25fd2010-11-02 13:41:47 -070063 if (req->r_request && req->r_session)
64 seq_printf(s, "%lld\tmds%d\t", req->r_tid,
65 req->r_session->s_mds);
66 else if (!req->r_request)
Sage Weil76aa8442009-10-06 11:31:14 -070067 seq_printf(s, "%lld\t(no request)\t", req->r_tid);
Sage Weil4af25fd2010-11-02 13:41:47 -070068 else
69 seq_printf(s, "%lld\t(no session)\t", req->r_tid);
Sage Weil76aa8442009-10-06 11:31:14 -070070
71 seq_printf(s, "%s", ceph_mds_op_name(req->r_op));
72
Jeff Laytonbc2de10d2017-02-01 13:49:09 -050073 if (test_bit(CEPH_MDS_R_GOT_UNSAFE, &req->r_req_flags))
Fabian Frederick3364d112014-06-06 14:35:38 -070074 seq_puts(s, "\t(unsafe)");
Sage Weil76aa8442009-10-06 11:31:14 -070075 else
Fabian Frederick3364d112014-06-06 14:35:38 -070076 seq_puts(s, "\t");
Sage Weil76aa8442009-10-06 11:31:14 -070077
78 if (req->r_inode) {
79 seq_printf(s, " #%llx", ceph_ino(req->r_inode));
80 } else if (req->r_dentry) {
81 path = ceph_mdsc_build_path(req->r_dentry, &pathlen,
82 &pathbase, 0);
Dan Carpenterf44c3892010-08-26 11:07:24 +020083 if (IS_ERR(path))
84 path = NULL;
Sage Weil76aa8442009-10-06 11:31:14 -070085 spin_lock(&req->r_dentry->d_lock);
Al Viroa4555892014-10-21 20:11:25 -040086 seq_printf(s, " #%llx/%pd (%s)",
David Howells2b0143b2015-03-17 22:25:59 +000087 ceph_ino(d_inode(req->r_dentry->d_parent)),
Al Viroa4555892014-10-21 20:11:25 -040088 req->r_dentry,
Sage Weil76aa8442009-10-06 11:31:14 -070089 path ? path : "");
90 spin_unlock(&req->r_dentry->d_lock);
Jeff Laytonf77f21b2019-04-29 12:13:14 -040091 ceph_mdsc_free_path(path, pathlen);
Sage Weil76aa8442009-10-06 11:31:14 -070092 } else if (req->r_path1) {
93 seq_printf(s, " #%llx/%s", req->r_ino1.ino,
94 req->r_path1);
Yan, Zhengc137a322014-03-01 22:22:57 +080095 } else {
96 seq_printf(s, " #%llx", req->r_ino1.ino);
Sage Weil76aa8442009-10-06 11:31:14 -070097 }
98
99 if (req->r_old_dentry) {
100 path = ceph_mdsc_build_path(req->r_old_dentry, &pathlen,
101 &pathbase, 0);
Dan Carpenterf44c3892010-08-26 11:07:24 +0200102 if (IS_ERR(path))
103 path = NULL;
Sage Weil76aa8442009-10-06 11:31:14 -0700104 spin_lock(&req->r_old_dentry->d_lock);
Al Viroa4555892014-10-21 20:11:25 -0400105 seq_printf(s, " #%llx/%pd (%s)",
Sage Weil844d87c2013-02-05 13:40:09 -0800106 req->r_old_dentry_dir ?
107 ceph_ino(req->r_old_dentry_dir) : 0,
Al Viroa4555892014-10-21 20:11:25 -0400108 req->r_old_dentry,
Sage Weil76aa8442009-10-06 11:31:14 -0700109 path ? path : "");
110 spin_unlock(&req->r_old_dentry->d_lock);
Jeff Laytonf77f21b2019-04-29 12:13:14 -0400111 ceph_mdsc_free_path(path, pathlen);
Yan, Zhengaeda0812016-04-18 16:51:37 +0800112 } else if (req->r_path2 && req->r_op != CEPH_MDS_OP_SYMLINK) {
Sage Weil76aa8442009-10-06 11:31:14 -0700113 if (req->r_ino2.ino)
114 seq_printf(s, " #%llx/%s", req->r_ino2.ino,
115 req->r_path2);
116 else
117 seq_printf(s, " %s", req->r_path2);
118 }
119
Fabian Frederick3364d112014-06-06 14:35:38 -0700120 seq_puts(s, "\n");
Sage Weil76aa8442009-10-06 11:31:14 -0700121 }
122 mutex_unlock(&mdsc->mutex);
123
124 return 0;
125}
126
Jeff Laytonff4a80b2019-04-24 12:05:15 -0400127static int caps_show_cb(struct inode *inode, struct ceph_cap *cap, void *p)
128{
129 struct seq_file *s = p;
130
131 seq_printf(s, "0x%-17lx%-17s%-17s\n", inode->i_ino,
132 ceph_cap_string(cap->issued),
133 ceph_cap_string(cap->implemented));
134 return 0;
135}
136
Sage Weil76aa8442009-10-06 11:31:14 -0700137static int caps_show(struct seq_file *s, void *p)
138{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700139 struct ceph_fs_client *fsc = s->private;
Jeff Laytonff4a80b2019-04-24 12:05:15 -0400140 struct ceph_mds_client *mdsc = fsc->mdsc;
141 int total, avail, used, reserved, min, i;
Sage Weil76aa8442009-10-06 11:31:14 -0700142
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700143 ceph_reservation_status(fsc, &total, &avail, &used, &reserved, &min);
Sage Weil76aa8442009-10-06 11:31:14 -0700144 seq_printf(s, "total\t\t%d\n"
Sage Weil85ccce42010-02-17 10:02:43 -0800145 "avail\t\t%d\n"
146 "used\t\t%d\n"
147 "reserved\t%d\n"
Jeff Laytonff4a80b2019-04-24 12:05:15 -0400148 "min\t\t%d\n\n",
Sage Weil85ccce42010-02-17 10:02:43 -0800149 total, avail, used, reserved, min);
Jeff Laytonff4a80b2019-04-24 12:05:15 -0400150 seq_printf(s, "ino issued implemented\n");
151 seq_printf(s, "-----------------------------------------------\n");
152
153 mutex_lock(&mdsc->mutex);
154 for (i = 0; i < mdsc->max_sessions; i++) {
155 struct ceph_mds_session *session;
156
157 session = __ceph_lookup_mds_session(mdsc, i);
158 if (!session)
159 continue;
160 mutex_unlock(&mdsc->mutex);
161 mutex_lock(&session->s_mutex);
162 ceph_iterate_session_caps(session, caps_show_cb, s);
163 mutex_unlock(&session->s_mutex);
164 ceph_put_mds_session(session);
165 mutex_lock(&mdsc->mutex);
166 }
167 mutex_unlock(&mdsc->mutex);
168
Sage Weil76aa8442009-10-06 11:31:14 -0700169 return 0;
170}
171
John Spray14ed9702014-09-12 16:58:49 +0100172static int mds_sessions_show(struct seq_file *s, void *ptr)
173{
174 struct ceph_fs_client *fsc = s->private;
175 struct ceph_mds_client *mdsc = fsc->mdsc;
176 struct ceph_auth_client *ac = fsc->client->monc.auth;
177 struct ceph_options *opt = fsc->client->options;
178 int mds = -1;
179
180 mutex_lock(&mdsc->mutex);
181
182 /* The 'num' portion of an 'entity name' */
183 seq_printf(s, "global_id %llu\n", ac->global_id);
184
185 /* The -o name mount argument */
186 seq_printf(s, "name \"%s\"\n", opt->name ? opt->name : "");
187
188 /* The list of MDS session rank+state */
189 for (mds = 0; mds < mdsc->max_sessions; mds++) {
190 struct ceph_mds_session *session =
191 __ceph_lookup_mds_session(mdsc, mds);
192 if (!session) {
193 continue;
194 }
195 mutex_unlock(&mdsc->mutex);
196 seq_printf(s, "mds.%d %s\n",
197 session->s_mds,
198 ceph_session_state_name(session->s_state));
199
200 ceph_put_mds_session(session);
201 mutex_lock(&mdsc->mutex);
202 }
203 mutex_unlock(&mdsc->mutex);
204
205 return 0;
206}
207
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700208CEPH_DEFINE_SHOW_FUNC(mdsmap_show)
209CEPH_DEFINE_SHOW_FUNC(mdsc_show)
210CEPH_DEFINE_SHOW_FUNC(caps_show)
John Spray14ed9702014-09-12 16:58:49 +0100211CEPH_DEFINE_SHOW_FUNC(mds_sessions_show)
Sage Weil76aa8442009-10-06 11:31:14 -0700212
Sage Weil76aa8442009-10-06 11:31:14 -0700213
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700214/*
215 * debugfs
216 */
Yehuda Sadeh2baba252009-12-18 13:51:57 -0800217static int congestion_kb_set(void *data, u64 val)
218{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700219 struct ceph_fs_client *fsc = (struct ceph_fs_client *)data;
Yehuda Sadeh2baba252009-12-18 13:51:57 -0800220
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700221 fsc->mount_options->congestion_kb = (int)val;
Yehuda Sadeh2baba252009-12-18 13:51:57 -0800222 return 0;
223}
224
225static int congestion_kb_get(void *data, u64 *val)
226{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700227 struct ceph_fs_client *fsc = (struct ceph_fs_client *)data;
Yehuda Sadeh2baba252009-12-18 13:51:57 -0800228
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700229 *val = (u64)fsc->mount_options->congestion_kb;
Yehuda Sadeh2baba252009-12-18 13:51:57 -0800230 return 0;
231}
232
Yehuda Sadeh2baba252009-12-18 13:51:57 -0800233DEFINE_SIMPLE_ATTRIBUTE(congestion_kb_fops, congestion_kb_get,
234 congestion_kb_set, "%llu\n");
235
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700236
237void ceph_fs_debugfs_cleanup(struct ceph_fs_client *fsc)
Sage Weil76aa8442009-10-06 11:31:14 -0700238{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700239 dout("ceph_fs_debugfs_cleanup\n");
240 debugfs_remove(fsc->debugfs_bdi);
241 debugfs_remove(fsc->debugfs_congestion_kb);
242 debugfs_remove(fsc->debugfs_mdsmap);
John Spray14ed9702014-09-12 16:58:49 +0100243 debugfs_remove(fsc->debugfs_mds_sessions);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700244 debugfs_remove(fsc->debugfs_caps);
245 debugfs_remove(fsc->debugfs_mdsc);
Sage Weil76aa8442009-10-06 11:31:14 -0700246}
247
Greg Kroah-Hartman1a829ff2019-06-12 16:55:38 +0200248void ceph_fs_debugfs_init(struct ceph_fs_client *fsc)
Sage Weil76aa8442009-10-06 11:31:14 -0700249{
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700250 char name[100];
Sage Weil76aa8442009-10-06 11:31:14 -0700251
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700252 dout("ceph_fs_debugfs_init\n");
253 fsc->debugfs_congestion_kb =
Sage Weil213c99e2010-08-03 10:25:11 -0700254 debugfs_create_file("writeback_congestion_kb",
255 0600,
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700256 fsc->client->debugfs_dir,
257 fsc,
Sage Weil213c99e2010-08-03 10:25:11 -0700258 &congestion_kb_fops);
Yehuda Sadeh2baba252009-12-18 13:51:57 -0800259
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700260 snprintf(name, sizeof(name), "../../bdi/%s",
Jan Kara09dc9fc2017-04-12 12:24:33 +0200261 dev_name(fsc->sb->s_bdi->dev));
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700262 fsc->debugfs_bdi =
263 debugfs_create_symlink("bdi",
264 fsc->client->debugfs_dir,
265 name);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700266
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700267 fsc->debugfs_mdsmap = debugfs_create_file("mdsmap",
Chengguang Xu11e14782018-02-10 14:18:06 +0800268 0400,
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700269 fsc->client->debugfs_dir,
270 fsc,
271 &mdsmap_show_fops);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700272
John Spray14ed9702014-09-12 16:58:49 +0100273 fsc->debugfs_mds_sessions = debugfs_create_file("mds_sessions",
Chengguang Xu11e14782018-02-10 14:18:06 +0800274 0400,
John Spray14ed9702014-09-12 16:58:49 +0100275 fsc->client->debugfs_dir,
276 fsc,
277 &mds_sessions_show_fops);
John Spray14ed9702014-09-12 16:58:49 +0100278
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700279 fsc->debugfs_mdsc = debugfs_create_file("mdsc",
Chengguang Xu11e14782018-02-10 14:18:06 +0800280 0400,
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700281 fsc->client->debugfs_dir,
282 fsc,
283 &mdsc_show_fops);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700284
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700285 fsc->debugfs_caps = debugfs_create_file("caps",
286 0400,
287 fsc->client->debugfs_dir,
288 fsc,
289 &caps_show_fops);
Sage Weil76aa8442009-10-06 11:31:14 -0700290}
291
Sage Weil76aa8442009-10-06 11:31:14 -0700292
Sage Weil213c99e2010-08-03 10:25:11 -0700293#else /* CONFIG_DEBUG_FS */
Sage Weil039934b2009-11-12 15:05:52 -0800294
Greg Kroah-Hartman1a829ff2019-06-12 16:55:38 +0200295void ceph_fs_debugfs_init(struct ceph_fs_client *fsc)
Sage Weil039934b2009-11-12 15:05:52 -0800296{
297 return 0;
298}
299
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700300void ceph_fs_debugfs_cleanup(struct ceph_fs_client *fsc)
Sage Weil039934b2009-11-12 15:05:52 -0800301{
302}
303
Sage Weil213c99e2010-08-03 10:25:11 -0700304#endif /* CONFIG_DEBUG_FS */