1 #include "ceph_debug.h"
3 #include <linux/device.h>
4 #include <linux/slab.h>
5 #include <linux/module.h>
6 #include <linux/ctype.h>
7 #include <linux/debugfs.h>
8 #include <linux/seq_file.h>
11 #include "mds_client.h"
12 #include "mon_client.h"
15 #ifdef CONFIG_DEBUG_FS
18 * Implement /sys/kernel/debug/ceph fun
20 * /sys/kernel/debug/ceph/client* - an instance of the ceph client
21 * .../osdmap - current osdmap
22 * .../mdsmap - current mdsmap
23 * .../monmap - current monmap
24 * .../osdc - active osd requests
25 * .../mdsc - active mds requests
26 * .../monc - mon client state
27 * .../dentry_lru - dump contents of dentry lru
28 * .../caps - expose cap (reservation) stats
29 * .../bdi - symlink to ../../bdi/something
32 static struct dentry *ceph_debugfs_dir;
34 static int monmap_show(struct seq_file *s, void *p)
37 struct ceph_client *client = s->private;
39 if (client->monc.monmap == NULL)
42 seq_printf(s, "epoch %d\n", client->monc.monmap->epoch);
43 for (i = 0; i < client->monc.monmap->num_mon; i++) {
44 struct ceph_entity_inst *inst =
45 &client->monc.monmap->mon_inst[i];
47 seq_printf(s, "\t%s%lld\t%s\n",
48 ENTITY_NAME(inst->name),
49 pr_addr(&inst->addr.in_addr));
54 static int mdsmap_show(struct seq_file *s, void *p)
57 struct ceph_client *client = s->private;
59 if (client->mdsc.mdsmap == NULL)
61 seq_printf(s, "epoch %d\n", client->mdsc.mdsmap->m_epoch);
62 seq_printf(s, "root %d\n", client->mdsc.mdsmap->m_root);
63 seq_printf(s, "session_timeout %d\n",
64 client->mdsc.mdsmap->m_session_timeout);
65 seq_printf(s, "session_autoclose %d\n",
66 client->mdsc.mdsmap->m_session_autoclose);
67 for (i = 0; i < client->mdsc.mdsmap->m_max_mds; i++) {
68 struct ceph_entity_addr *addr =
69 &client->mdsc.mdsmap->m_info[i].addr;
70 int state = client->mdsc.mdsmap->m_info[i].state;
72 seq_printf(s, "\tmds%d\t%s\t(%s)\n", i, pr_addr(&addr->in_addr),
73 ceph_mds_state_name(state));
78 static int osdmap_show(struct seq_file *s, void *p)
81 struct ceph_client *client = s->private;
84 if (client->osdc.osdmap == NULL)
86 seq_printf(s, "epoch %d\n", client->osdc.osdmap->epoch);
87 seq_printf(s, "flags%s%s\n",
88 (client->osdc.osdmap->flags & CEPH_OSDMAP_NEARFULL) ?
90 (client->osdc.osdmap->flags & CEPH_OSDMAP_FULL) ?
92 for (n = rb_first(&client->osdc.osdmap->pg_pools); n; n = rb_next(n)) {
93 struct ceph_pg_pool_info *pool =
94 rb_entry(n, struct ceph_pg_pool_info, node);
95 seq_printf(s, "pg_pool %d pg_num %d / %d, lpg_num %d / %d\n",
96 pool->id, pool->v.pg_num, pool->pg_num_mask,
97 pool->v.lpg_num, pool->lpg_num_mask);
99 for (i = 0; i < client->osdc.osdmap->max_osd; i++) {
100 struct ceph_entity_addr *addr =
101 &client->osdc.osdmap->osd_addr[i];
102 int state = client->osdc.osdmap->osd_state[i];
105 seq_printf(s, "\tosd%d\t%s\t%3d%%\t(%s)\n",
106 i, pr_addr(&addr->in_addr),
107 ((client->osdc.osdmap->osd_weight[i]*100) >> 16),
108 ceph_osdmap_state_str(sb, sizeof(sb), state));
113 static int monc_show(struct seq_file *s, void *p)
115 struct ceph_client *client = s->private;
116 struct ceph_mon_generic_request *req;
117 struct ceph_mon_client *monc = &client->monc;
120 mutex_lock(&monc->mutex);
122 if (monc->have_mdsmap)
123 seq_printf(s, "have mdsmap %u\n", (unsigned)monc->have_mdsmap);
124 if (monc->have_osdmap)
125 seq_printf(s, "have osdmap %u\n", (unsigned)monc->have_osdmap);
126 if (monc->want_next_osdmap)
127 seq_printf(s, "want next osdmap\n");
129 for (rp = rb_first(&monc->generic_request_tree); rp; rp = rb_next(rp)) {
131 req = rb_entry(rp, struct ceph_mon_generic_request, node);
132 op = le16_to_cpu(req->request->hdr.type);
133 if (op == CEPH_MSG_STATFS)
134 seq_printf(s, "%lld statfs\n", req->tid);
136 seq_printf(s, "%lld unknown\n", req->tid);
139 mutex_unlock(&monc->mutex);
143 static int mdsc_show(struct seq_file *s, void *p)
145 struct ceph_client *client = s->private;
146 struct ceph_mds_client *mdsc = &client->mdsc;
147 struct ceph_mds_request *req;
153 mutex_lock(&mdsc->mutex);
154 for (rp = rb_first(&mdsc->request_tree); rp; rp = rb_next(rp)) {
155 req = rb_entry(rp, struct ceph_mds_request, r_node);
158 seq_printf(s, "%lld\tmds%d\t", req->r_tid, req->r_mds);
160 seq_printf(s, "%lld\t(no request)\t", req->r_tid);
162 seq_printf(s, "%s", ceph_mds_op_name(req->r_op));
164 if (req->r_got_unsafe)
165 seq_printf(s, "\t(unsafe)");
170 seq_printf(s, " #%llx", ceph_ino(req->r_inode));
171 } else if (req->r_dentry) {
172 path = ceph_mdsc_build_path(req->r_dentry, &pathlen,
174 spin_lock(&req->r_dentry->d_lock);
175 seq_printf(s, " #%llx/%.*s (%s)",
176 ceph_ino(req->r_dentry->d_parent->d_inode),
177 req->r_dentry->d_name.len,
178 req->r_dentry->d_name.name,
180 spin_unlock(&req->r_dentry->d_lock);
182 } else if (req->r_path1) {
183 seq_printf(s, " #%llx/%s", req->r_ino1.ino,
187 if (req->r_old_dentry) {
188 path = ceph_mdsc_build_path(req->r_old_dentry, &pathlen,
190 spin_lock(&req->r_old_dentry->d_lock);
191 seq_printf(s, " #%llx/%.*s (%s)",
192 ceph_ino(req->r_old_dentry->d_parent->d_inode),
193 req->r_old_dentry->d_name.len,
194 req->r_old_dentry->d_name.name,
196 spin_unlock(&req->r_old_dentry->d_lock);
198 } else if (req->r_path2) {
200 seq_printf(s, " #%llx/%s", req->r_ino2.ino,
203 seq_printf(s, " %s", req->r_path2);
208 mutex_unlock(&mdsc->mutex);
213 static int osdc_show(struct seq_file *s, void *pp)
215 struct ceph_client *client = s->private;
216 struct ceph_osd_client *osdc = &client->osdc;
219 mutex_lock(&osdc->request_mutex);
220 for (p = rb_first(&osdc->requests); p; p = rb_next(p)) {
221 struct ceph_osd_request *req;
222 struct ceph_osd_request_head *head;
223 struct ceph_osd_op *op;
228 req = rb_entry(p, struct ceph_osd_request, r_node);
230 seq_printf(s, "%lld\tosd%d\t%d.%x\t", req->r_tid,
231 req->r_osd ? req->r_osd->o_osd : -1,
232 le32_to_cpu(req->r_pgid.pool),
233 le16_to_cpu(req->r_pgid.ps));
235 head = req->r_request->front.iov_base;
236 op = (void *)(head + 1);
238 num_ops = le16_to_cpu(head->num_ops);
239 olen = le32_to_cpu(head->object_len);
240 seq_printf(s, "%.*s", olen,
241 (const char *)(head->ops + num_ops));
243 if (req->r_reassert_version.epoch)
244 seq_printf(s, "\t%u'%llu",
245 (unsigned)le32_to_cpu(req->r_reassert_version.epoch),
246 le64_to_cpu(req->r_reassert_version.version));
250 for (i = 0; i < num_ops; i++) {
251 opcode = le16_to_cpu(op->op);
252 seq_printf(s, "\t%s", ceph_osd_op_name(opcode));
258 mutex_unlock(&osdc->request_mutex);
262 static int caps_show(struct seq_file *s, void *p)
264 struct ceph_client *client = p;
265 int total, avail, used, reserved, min;
267 ceph_reservation_status(client, &total, &avail, &used, &reserved, &min);
268 seq_printf(s, "total\t\t%d\n"
273 total, avail, used, reserved, min);
277 static int dentry_lru_show(struct seq_file *s, void *ptr)
279 struct ceph_client *client = s->private;
280 struct ceph_mds_client *mdsc = &client->mdsc;
281 struct ceph_dentry_info *di;
283 spin_lock(&mdsc->dentry_lru_lock);
284 list_for_each_entry(di, &mdsc->dentry_lru, lru) {
285 struct dentry *dentry = di->dentry;
286 seq_printf(s, "%p %p\t%.*s\n",
287 di, dentry, dentry->d_name.len, dentry->d_name.name);
289 spin_unlock(&mdsc->dentry_lru_lock);
294 #define DEFINE_SHOW_FUNC(name) \
295 static int name##_open(struct inode *inode, struct file *file) \
297 struct seq_file *sf; \
300 ret = single_open(file, name, NULL); \
301 sf = file->private_data; \
302 sf->private = inode->i_private; \
306 static const struct file_operations name##_fops = { \
307 .open = name##_open, \
309 .llseek = seq_lseek, \
310 .release = single_release, \
313 DEFINE_SHOW_FUNC(monmap_show)
314 DEFINE_SHOW_FUNC(mdsmap_show)
315 DEFINE_SHOW_FUNC(osdmap_show)
316 DEFINE_SHOW_FUNC(monc_show)
317 DEFINE_SHOW_FUNC(mdsc_show)
318 DEFINE_SHOW_FUNC(osdc_show)
319 DEFINE_SHOW_FUNC(dentry_lru_show)
320 DEFINE_SHOW_FUNC(caps_show)
322 static int congestion_kb_set(void *data, u64 val)
324 struct ceph_client *client = (struct ceph_client *)data;
327 client->mount_args->congestion_kb = (int)val;
332 static int congestion_kb_get(void *data, u64 *val)
334 struct ceph_client *client = (struct ceph_client *)data;
337 *val = (u64)client->mount_args->congestion_kb;
343 DEFINE_SIMPLE_ATTRIBUTE(congestion_kb_fops, congestion_kb_get,
344 congestion_kb_set, "%llu\n");
346 int __init ceph_debugfs_init(void)
348 ceph_debugfs_dir = debugfs_create_dir("ceph", NULL);
349 if (!ceph_debugfs_dir)
354 void ceph_debugfs_cleanup(void)
356 debugfs_remove(ceph_debugfs_dir);
359 int ceph_debugfs_client_init(struct ceph_client *client)
364 snprintf(name, sizeof(name), FSID_FORMAT ".client%lld",
365 PR_FSID(&client->fsid), client->monc.auth->global_id);
367 client->debugfs_dir = debugfs_create_dir(name, ceph_debugfs_dir);
368 if (!client->debugfs_dir)
371 client->monc.debugfs_file = debugfs_create_file("monc",
376 if (!client->monc.debugfs_file)
379 client->mdsc.debugfs_file = debugfs_create_file("mdsc",
384 if (!client->mdsc.debugfs_file)
387 client->osdc.debugfs_file = debugfs_create_file("osdc",
392 if (!client->osdc.debugfs_file)
395 client->debugfs_monmap = debugfs_create_file("monmap",
400 if (!client->debugfs_monmap)
403 client->debugfs_mdsmap = debugfs_create_file("mdsmap",
408 if (!client->debugfs_mdsmap)
411 client->debugfs_osdmap = debugfs_create_file("osdmap",
416 if (!client->debugfs_osdmap)
419 client->debugfs_dentry_lru = debugfs_create_file("dentry_lru",
423 &dentry_lru_show_fops);
424 if (!client->debugfs_dentry_lru)
427 client->debugfs_caps = debugfs_create_file("caps",
432 if (!client->debugfs_caps)
435 client->debugfs_congestion_kb = debugfs_create_file("writeback_congestion_kb",
439 &congestion_kb_fops);
440 if (!client->debugfs_congestion_kb)
443 sprintf(name, "../../bdi/%s", dev_name(client->sb->s_bdi->dev));
444 client->debugfs_bdi = debugfs_create_symlink("bdi", client->debugfs_dir,
450 ceph_debugfs_client_cleanup(client);
454 void ceph_debugfs_client_cleanup(struct ceph_client *client)
456 debugfs_remove(client->debugfs_bdi);
457 debugfs_remove(client->debugfs_caps);
458 debugfs_remove(client->debugfs_dentry_lru);
459 debugfs_remove(client->debugfs_osdmap);
460 debugfs_remove(client->debugfs_mdsmap);
461 debugfs_remove(client->debugfs_monmap);
462 debugfs_remove(client->osdc.debugfs_file);
463 debugfs_remove(client->mdsc.debugfs_file);
464 debugfs_remove(client->monc.debugfs_file);
465 debugfs_remove(client->debugfs_congestion_kb);
466 debugfs_remove(client->debugfs_dir);
469 #else // CONFIG_DEBUG_FS
471 int __init ceph_debugfs_init(void)
476 void ceph_debugfs_cleanup(void)
480 int ceph_debugfs_client_init(struct ceph_client *client)
485 void ceph_debugfs_client_cleanup(struct ceph_client *client)
489 #endif // CONFIG_DEBUG_FS