1 #include "ceph_debug.h"
3 #include <linux/device.h>
4 #include <linux/module.h>
5 #include <linux/ctype.h>
6 #include <linux/debugfs.h>
7 #include <linux/seq_file.h>
10 #include "mds_client.h"
11 #include "mon_client.h"
14 #ifdef CONFIG_DEBUG_FS
17 * Implement /sys/kernel/debug/ceph fun
19 * /sys/kernel/debug/ceph/client* - an instance of the ceph client
20 * .../osdmap - current osdmap
21 * .../mdsmap - current mdsmap
22 * .../monmap - current monmap
23 * .../osdc - active osd requests
24 * .../mdsc - active mds requests
25 * .../monc - mon client state
26 * .../dentry_lru - dump contents of dentry lru
27 * .../caps - expose cap (reservation) stats
28 * .../bdi - symlink to ../../bdi/something
31 static struct dentry *ceph_debugfs_dir;
33 static int monmap_show(struct seq_file *s, void *p)
36 struct ceph_client *client = s->private;
38 if (client->monc.monmap == NULL)
41 seq_printf(s, "epoch %d\n", client->monc.monmap->epoch);
42 for (i = 0; i < client->monc.monmap->num_mon; i++) {
43 struct ceph_entity_inst *inst =
44 &client->monc.monmap->mon_inst[i];
46 seq_printf(s, "\t%s%lld\t%s\n",
47 ENTITY_NAME(inst->name),
48 pr_addr(&inst->addr.in_addr));
53 static int mdsmap_show(struct seq_file *s, void *p)
56 struct ceph_client *client = s->private;
58 if (client->mdsc.mdsmap == NULL)
60 seq_printf(s, "epoch %d\n", client->mdsc.mdsmap->m_epoch);
61 seq_printf(s, "root %d\n", client->mdsc.mdsmap->m_root);
62 seq_printf(s, "session_timeout %d\n",
63 client->mdsc.mdsmap->m_session_timeout);
64 seq_printf(s, "session_autoclose %d\n",
65 client->mdsc.mdsmap->m_session_autoclose);
66 for (i = 0; i < client->mdsc.mdsmap->m_max_mds; i++) {
67 struct ceph_entity_addr *addr =
68 &client->mdsc.mdsmap->m_info[i].addr;
69 int state = client->mdsc.mdsmap->m_info[i].state;
71 seq_printf(s, "\tmds%d\t%s\t(%s)\n", i, pr_addr(&addr->in_addr),
72 ceph_mds_state_name(state));
77 static int osdmap_show(struct seq_file *s, void *p)
80 struct ceph_client *client = s->private;
82 if (client->osdc.osdmap == NULL)
84 seq_printf(s, "epoch %d\n", client->osdc.osdmap->epoch);
85 seq_printf(s, "flags%s%s\n",
86 (client->osdc.osdmap->flags & CEPH_OSDMAP_NEARFULL) ?
88 (client->osdc.osdmap->flags & CEPH_OSDMAP_FULL) ?
90 for (i = 0; i < client->osdc.osdmap->num_pools; i++) {
91 struct ceph_pg_pool_info *pool =
92 &client->osdc.osdmap->pg_pool[i];
93 seq_printf(s, "pg_pool %d pg_num %d / %d, lpg_num %d / %d\n",
94 i, pool->v.pg_num, pool->pg_num_mask,
95 pool->v.lpg_num, pool->lpg_num_mask);
97 for (i = 0; i < client->osdc.osdmap->max_osd; i++) {
98 struct ceph_entity_addr *addr =
99 &client->osdc.osdmap->osd_addr[i];
100 int state = client->osdc.osdmap->osd_state[i];
103 seq_printf(s, "\tosd%d\t%s\t%3d%%\t(%s)\n",
104 i, pr_addr(&addr->in_addr),
105 ((client->osdc.osdmap->osd_weight[i]*100) >> 16),
106 ceph_osdmap_state_str(sb, sizeof(sb), state));
111 static int monc_show(struct seq_file *s, void *p)
113 struct ceph_client *client = s->private;
114 struct ceph_mon_statfs_request *req;
117 struct ceph_mon_client *monc = &client->monc;
119 mutex_lock(&monc->mutex);
121 if (monc->have_mdsmap)
122 seq_printf(s, "have mdsmap %u\n", (unsigned)monc->have_mdsmap);
123 if (monc->have_osdmap)
124 seq_printf(s, "have osdmap %u\n", (unsigned)monc->have_osdmap);
125 if (monc->want_next_osdmap)
126 seq_printf(s, "want next osdmap\n");
128 while (nexttid < monc->last_tid) {
129 got = radix_tree_gang_lookup(&monc->statfs_request_tree,
130 (void **)&req, nexttid, 1);
133 nexttid = req->tid + 1;
135 seq_printf(s, "%lld statfs\n", req->tid);
137 mutex_unlock(&monc->mutex);
142 static int mdsc_show(struct seq_file *s, void *p)
144 struct ceph_client *client = s->private;
145 struct ceph_mds_request *req;
148 struct ceph_mds_client *mdsc = &client->mdsc;
153 mutex_lock(&mdsc->mutex);
154 while (nexttid < mdsc->last_tid) {
155 got = radix_tree_gang_lookup(&mdsc->request_tree,
156 (void **)&req, nexttid, 1);
159 nexttid = req->r_tid + 1;
162 seq_printf(s, "%lld\tmds%d\t", req->r_tid, req->r_mds);
164 seq_printf(s, "%lld\t(no request)\t", req->r_tid);
166 seq_printf(s, "%s", ceph_mds_op_name(req->r_op));
168 if (req->r_got_unsafe)
169 seq_printf(s, "\t(unsafe)");
174 seq_printf(s, " #%llx", ceph_ino(req->r_inode));
175 } else if (req->r_dentry) {
176 path = ceph_mdsc_build_path(req->r_dentry, &pathlen,
178 spin_lock(&req->r_dentry->d_lock);
179 seq_printf(s, " #%llx/%.*s (%s)",
180 ceph_ino(req->r_dentry->d_parent->d_inode),
181 req->r_dentry->d_name.len,
182 req->r_dentry->d_name.name,
184 spin_unlock(&req->r_dentry->d_lock);
186 } else if (req->r_path1) {
187 seq_printf(s, " #%llx/%s", req->r_ino1.ino,
191 if (req->r_old_dentry) {
192 path = ceph_mdsc_build_path(req->r_old_dentry, &pathlen,
194 spin_lock(&req->r_old_dentry->d_lock);
195 seq_printf(s, " #%llx/%.*s (%s)",
196 ceph_ino(req->r_old_dentry->d_parent->d_inode),
197 req->r_old_dentry->d_name.len,
198 req->r_old_dentry->d_name.name,
200 spin_unlock(&req->r_old_dentry->d_lock);
202 } else if (req->r_path2) {
204 seq_printf(s, " #%llx/%s", req->r_ino2.ino,
207 seq_printf(s, " %s", req->r_path2);
212 mutex_unlock(&mdsc->mutex);
217 static int osdc_show(struct seq_file *s, void *pp)
219 struct ceph_client *client = s->private;
220 struct ceph_osd_client *osdc = &client->osdc;
223 mutex_lock(&osdc->request_mutex);
224 for (p = rb_first(&osdc->requests); p; p = rb_next(p)) {
225 struct ceph_osd_request *req;
226 struct ceph_osd_request_head *head;
227 struct ceph_osd_op *op;
232 req = rb_entry(p, struct ceph_osd_request, r_node);
234 seq_printf(s, "%lld\tosd%d\t", req->r_tid,
235 req->r_osd ? req->r_osd->o_osd : -1);
237 head = req->r_request->front.iov_base;
238 op = (void *)(head + 1);
240 num_ops = le16_to_cpu(head->num_ops);
241 olen = le32_to_cpu(head->object_len);
242 seq_printf(s, "%.*s", olen,
243 (const char *)(head->ops + num_ops));
245 if (req->r_reassert_version.epoch)
246 seq_printf(s, "\t%u'%llu",
247 (unsigned)le32_to_cpu(req->r_reassert_version.epoch),
248 le64_to_cpu(req->r_reassert_version.version));
252 for (i = 0; i < num_ops; i++) {
253 opcode = le16_to_cpu(op->op);
254 seq_printf(s, "\t%s", ceph_osd_op_name(opcode));
260 mutex_unlock(&osdc->request_mutex);
264 static int caps_show(struct seq_file *s, void *p)
266 struct ceph_client *client = p;
267 int total, avail, used, reserved;
269 ceph_reservation_status(client, &total, &avail, &used, &reserved);
270 seq_printf(s, "total\t\t%d\n"
274 total, avail, used, reserved);
278 static int dentry_lru_show(struct seq_file *s, void *ptr)
280 struct ceph_client *client = s->private;
281 struct ceph_mds_client *mdsc = &client->mdsc;
282 struct ceph_dentry_info *di;
284 spin_lock(&mdsc->dentry_lru_lock);
285 list_for_each_entry(di, &mdsc->dentry_lru, lru) {
286 struct dentry *dentry = di->dentry;
287 seq_printf(s, "%p %p\t%.*s\n",
288 di, dentry, dentry->d_name.len, dentry->d_name.name);
290 spin_unlock(&mdsc->dentry_lru_lock);
295 #define DEFINE_SHOW_FUNC(name) \
296 static int name##_open(struct inode *inode, struct file *file) \
298 struct seq_file *sf; \
301 ret = single_open(file, name, NULL); \
302 sf = file->private_data; \
303 sf->private = inode->i_private; \
307 static const struct file_operations name##_fops = { \
308 .open = name##_open, \
310 .llseek = seq_lseek, \
311 .release = single_release, \
314 DEFINE_SHOW_FUNC(monmap_show)
315 DEFINE_SHOW_FUNC(mdsmap_show)
316 DEFINE_SHOW_FUNC(osdmap_show)
317 DEFINE_SHOW_FUNC(monc_show)
318 DEFINE_SHOW_FUNC(mdsc_show)
319 DEFINE_SHOW_FUNC(osdc_show)
320 DEFINE_SHOW_FUNC(dentry_lru_show)
321 DEFINE_SHOW_FUNC(caps_show)
323 static int congestion_kb_set(void *data, u64 val)
325 struct ceph_client *client = (struct ceph_client *)data;
328 client->mount_args->congestion_kb = (int)val;
333 static int congestion_kb_get(void *data, u64 *val)
335 struct ceph_client *client = (struct ceph_client *)data;
338 *val = (u64)client->mount_args->congestion_kb;
344 DEFINE_SIMPLE_ATTRIBUTE(congestion_kb_fops, congestion_kb_get,
345 congestion_kb_set, "%llu\n");
347 int __init ceph_debugfs_init(void)
349 ceph_debugfs_dir = debugfs_create_dir("ceph", NULL);
350 if (!ceph_debugfs_dir)
355 void ceph_debugfs_cleanup(void)
357 debugfs_remove(ceph_debugfs_dir);
360 int ceph_debugfs_client_init(struct ceph_client *client)
365 snprintf(name, sizeof(name), FSID_FORMAT ".client%lld",
366 PR_FSID(&client->fsid), client->monc.auth->global_id);
368 client->debugfs_dir = debugfs_create_dir(name, ceph_debugfs_dir);
369 if (!client->debugfs_dir)
372 client->monc.debugfs_file = debugfs_create_file("monc",
377 if (!client->monc.debugfs_file)
380 client->mdsc.debugfs_file = debugfs_create_file("mdsc",
385 if (!client->mdsc.debugfs_file)
388 client->osdc.debugfs_file = debugfs_create_file("osdc",
393 if (!client->osdc.debugfs_file)
396 client->debugfs_monmap = debugfs_create_file("monmap",
401 if (!client->debugfs_monmap)
404 client->debugfs_mdsmap = debugfs_create_file("mdsmap",
409 if (!client->debugfs_mdsmap)
412 client->debugfs_osdmap = debugfs_create_file("osdmap",
417 if (!client->debugfs_osdmap)
420 client->debugfs_dentry_lru = debugfs_create_file("dentry_lru",
424 &dentry_lru_show_fops);
425 if (!client->debugfs_dentry_lru)
428 client->debugfs_caps = debugfs_create_file("caps",
433 if (!client->debugfs_caps)
436 client->debugfs_congestion_kb = debugfs_create_file("writeback_congestion_kb",
440 &congestion_kb_fops);
441 if (!client->debugfs_congestion_kb)
444 sprintf(name, "../../bdi/%s", dev_name(client->sb->s_bdi->dev));
445 client->debugfs_bdi = debugfs_create_symlink("bdi", client->debugfs_dir,
451 ceph_debugfs_client_cleanup(client);
455 void ceph_debugfs_client_cleanup(struct ceph_client *client)
457 debugfs_remove(client->debugfs_bdi);
458 debugfs_remove(client->debugfs_caps);
459 debugfs_remove(client->debugfs_dentry_lru);
460 debugfs_remove(client->debugfs_osdmap);
461 debugfs_remove(client->debugfs_mdsmap);
462 debugfs_remove(client->debugfs_monmap);
463 debugfs_remove(client->osdc.debugfs_file);
464 debugfs_remove(client->mdsc.debugfs_file);
465 debugfs_remove(client->monc.debugfs_file);
466 debugfs_remove(client->debugfs_congestion_kb);
467 debugfs_remove(client->debugfs_dir);
470 #else // CONFIG_DEBUG_FS
472 int __init ceph_debugfs_init(void)
477 void ceph_debugfs_cleanup(void)
481 int ceph_debugfs_client_init(struct ceph_client *client)
486 void ceph_debugfs_client_cleanup(struct ceph_client *client)
490 #endif // CONFIG_DEBUG_FS