blob: f2f5332ddbba3ca340b3ea4ba5a75a317d18053f [file] [log] [blame]
Sage Weil76aa8442009-10-06 11:31:14 -07001#include "ceph_debug.h"
2
Sage Weil06edf042009-12-15 14:44:32 -08003#include <linux/device.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09004#include <linux/slab.h>
Sage Weil76aa8442009-10-06 11:31:14 -07005#include <linux/module.h>
6#include <linux/ctype.h>
7#include <linux/debugfs.h>
8#include <linux/seq_file.h>
9
10#include "super.h"
11#include "mds_client.h"
Sage Weil07433042009-11-18 16:50:41 -080012#include "mon_client.h"
13#include "auth.h"
Sage Weil76aa8442009-10-06 11:31:14 -070014
Sage Weil039934b2009-11-12 15:05:52 -080015#ifdef CONFIG_DEBUG_FS
16
Sage Weil76aa8442009-10-06 11:31:14 -070017/*
18 * Implement /sys/kernel/debug/ceph fun
19 *
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
Sage Weil06edf042009-12-15 14:44:32 -080029 * .../bdi - symlink to ../../bdi/something
Sage Weil76aa8442009-10-06 11:31:14 -070030 */
31
32static struct dentry *ceph_debugfs_dir;
33
34static int monmap_show(struct seq_file *s, void *p)
35{
36 int i;
37 struct ceph_client *client = s->private;
38
39 if (client->monc.monmap == NULL)
40 return 0;
41
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];
46
47 seq_printf(s, "\t%s%lld\t%s\n",
48 ENTITY_NAME(inst->name),
49 pr_addr(&inst->addr.in_addr));
50 }
51 return 0;
52}
53
54static int mdsmap_show(struct seq_file *s, void *p)
55{
56 int i;
57 struct ceph_client *client = s->private;
58
59 if (client->mdsc.mdsmap == NULL)
60 return 0;
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;
71
72 seq_printf(s, "\tmds%d\t%s\t(%s)\n", i, pr_addr(&addr->in_addr),
73 ceph_mds_state_name(state));
74 }
75 return 0;
76}
77
78static int osdmap_show(struct seq_file *s, void *p)
79{
80 int i;
81 struct ceph_client *client = s->private;
Sage Weil4fc51be2010-02-16 15:55:03 -080082 struct rb_node *n;
Sage Weil76aa8442009-10-06 11:31:14 -070083
84 if (client->osdc.osdmap == NULL)
85 return 0;
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) ?
89 " NEARFULL" : "",
90 (client->osdc.osdmap->flags & CEPH_OSDMAP_FULL) ?
91 " FULL" : "");
Sage Weil4fc51be2010-02-16 15:55:03 -080092 for (n = rb_first(&client->osdc.osdmap->pg_pools); n; n = rb_next(n)) {
Sage Weil76aa8442009-10-06 11:31:14 -070093 struct ceph_pg_pool_info *pool =
Sage Weil4fc51be2010-02-16 15:55:03 -080094 rb_entry(n, struct ceph_pg_pool_info, node);
Sage Weil76aa8442009-10-06 11:31:14 -070095 seq_printf(s, "pg_pool %d pg_num %d / %d, lpg_num %d / %d\n",
Sage Weil4fc51be2010-02-16 15:55:03 -080096 pool->id, pool->v.pg_num, pool->pg_num_mask,
Sage Weil76aa8442009-10-06 11:31:14 -070097 pool->v.lpg_num, pool->lpg_num_mask);
98 }
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];
103 char sb[64];
104
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));
109 }
110 return 0;
111}
112
113static int monc_show(struct seq_file *s, void *p)
114{
115 struct ceph_client *client = s->private;
Yehuda Sadehf8c76f62010-04-22 15:40:37 -0700116 struct ceph_mon_generic_request *req;
Sage Weil76aa8442009-10-06 11:31:14 -0700117 struct ceph_mon_client *monc = &client->monc;
Sage Weil85ff03f2010-02-15 14:47:28 -0800118 struct rb_node *rp;
Sage Weil76aa8442009-10-06 11:31:14 -0700119
120 mutex_lock(&monc->mutex);
121
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");
128
Yehuda Sadehf8c76f62010-04-22 15:40:37 -0700129 for (rp = rb_first(&monc->generic_request_tree); rp; rp = rb_next(rp)) {
130 __u16 op;
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);
135 else
136 seq_printf(s, "%lld unknown\n", req->tid);
Sage Weil76aa8442009-10-06 11:31:14 -0700137 }
Sage Weil76aa8442009-10-06 11:31:14 -0700138
Sage Weil85ff03f2010-02-15 14:47:28 -0800139 mutex_unlock(&monc->mutex);
Sage Weil76aa8442009-10-06 11:31:14 -0700140 return 0;
141}
142
143static int mdsc_show(struct seq_file *s, void *p)
144{
145 struct ceph_client *client = s->private;
Sage Weil76aa8442009-10-06 11:31:14 -0700146 struct ceph_mds_client *mdsc = &client->mdsc;
Sage Weil44ca18f2010-02-15 12:08:46 -0800147 struct ceph_mds_request *req;
148 struct rb_node *rp;
Sage Weil76aa8442009-10-06 11:31:14 -0700149 int pathlen;
150 u64 pathbase;
151 char *path;
152
153 mutex_lock(&mdsc->mutex);
Sage Weil44ca18f2010-02-15 12:08:46 -0800154 for (rp = rb_first(&mdsc->request_tree); rp; rp = rb_next(rp)) {
155 req = rb_entry(rp, struct ceph_mds_request, r_node);
Sage Weil76aa8442009-10-06 11:31:14 -0700156
157 if (req->r_request)
158 seq_printf(s, "%lld\tmds%d\t", req->r_tid, req->r_mds);
159 else
160 seq_printf(s, "%lld\t(no request)\t", req->r_tid);
161
162 seq_printf(s, "%s", ceph_mds_op_name(req->r_op));
163
164 if (req->r_got_unsafe)
165 seq_printf(s, "\t(unsafe)");
166 else
167 seq_printf(s, "\t");
168
169 if (req->r_inode) {
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,
173 &pathbase, 0);
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,
179 path ? path : "");
180 spin_unlock(&req->r_dentry->d_lock);
181 kfree(path);
182 } else if (req->r_path1) {
183 seq_printf(s, " #%llx/%s", req->r_ino1.ino,
184 req->r_path1);
185 }
186
187 if (req->r_old_dentry) {
188 path = ceph_mdsc_build_path(req->r_old_dentry, &pathlen,
189 &pathbase, 0);
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,
195 path ? path : "");
196 spin_unlock(&req->r_old_dentry->d_lock);
197 kfree(path);
198 } else if (req->r_path2) {
199 if (req->r_ino2.ino)
200 seq_printf(s, " #%llx/%s", req->r_ino2.ino,
201 req->r_path2);
202 else
203 seq_printf(s, " %s", req->r_path2);
204 }
205
206 seq_printf(s, "\n");
207 }
208 mutex_unlock(&mdsc->mutex);
209
210 return 0;
211}
212
213static int osdc_show(struct seq_file *s, void *pp)
214{
215 struct ceph_client *client = s->private;
216 struct ceph_osd_client *osdc = &client->osdc;
217 struct rb_node *p;
218
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;
224 int num_ops;
225 int opcode, olen;
226 int i;
227
228 req = rb_entry(p, struct ceph_osd_request, r_node);
229
Sage Weil7740a422010-01-08 15:58:25 -0800230 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));
Sage Weil76aa8442009-10-06 11:31:14 -0700234
235 head = req->r_request->front.iov_base;
236 op = (void *)(head + 1);
237
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));
242
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));
247 else
248 seq_printf(s, "\t");
249
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));
253 op++;
254 }
255
256 seq_printf(s, "\n");
257 }
258 mutex_unlock(&osdc->request_mutex);
259 return 0;
260}
261
262static int caps_show(struct seq_file *s, void *p)
263{
Yehuda Sadehbfaf1482010-06-23 15:52:27 -0700264 struct ceph_client *client = s->private;
Sage Weil85ccce42010-02-17 10:02:43 -0800265 int total, avail, used, reserved, min;
Sage Weil76aa8442009-10-06 11:31:14 -0700266
Sage Weil85ccce42010-02-17 10:02:43 -0800267 ceph_reservation_status(client, &total, &avail, &used, &reserved, &min);
Sage Weil76aa8442009-10-06 11:31:14 -0700268 seq_printf(s, "total\t\t%d\n"
Sage Weil85ccce42010-02-17 10:02:43 -0800269 "avail\t\t%d\n"
270 "used\t\t%d\n"
271 "reserved\t%d\n"
272 "min\t%d\n",
273 total, avail, used, reserved, min);
Sage Weil76aa8442009-10-06 11:31:14 -0700274 return 0;
275}
276
277static int dentry_lru_show(struct seq_file *s, void *ptr)
278{
279 struct ceph_client *client = s->private;
280 struct ceph_mds_client *mdsc = &client->mdsc;
281 struct ceph_dentry_info *di;
282
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);
288 }
289 spin_unlock(&mdsc->dentry_lru_lock);
290
291 return 0;
292}
293
294#define DEFINE_SHOW_FUNC(name) \
295static int name##_open(struct inode *inode, struct file *file) \
296{ \
297 struct seq_file *sf; \
298 int ret; \
299 \
300 ret = single_open(file, name, NULL); \
301 sf = file->private_data; \
302 sf->private = inode->i_private; \
303 return ret; \
304} \
305 \
306static const struct file_operations name##_fops = { \
307 .open = name##_open, \
308 .read = seq_read, \
309 .llseek = seq_lseek, \
310 .release = single_release, \
311};
312
313DEFINE_SHOW_FUNC(monmap_show)
314DEFINE_SHOW_FUNC(mdsmap_show)
315DEFINE_SHOW_FUNC(osdmap_show)
316DEFINE_SHOW_FUNC(monc_show)
317DEFINE_SHOW_FUNC(mdsc_show)
318DEFINE_SHOW_FUNC(osdc_show)
319DEFINE_SHOW_FUNC(dentry_lru_show)
320DEFINE_SHOW_FUNC(caps_show)
321
Yehuda Sadeh2baba252009-12-18 13:51:57 -0800322static int congestion_kb_set(void *data, u64 val)
323{
324 struct ceph_client *client = (struct ceph_client *)data;
325
326 if (client)
327 client->mount_args->congestion_kb = (int)val;
328
329 return 0;
330}
331
332static int congestion_kb_get(void *data, u64 *val)
333{
334 struct ceph_client *client = (struct ceph_client *)data;
335
336 if (client)
337 *val = (u64)client->mount_args->congestion_kb;
338
339 return 0;
340}
341
342
343DEFINE_SIMPLE_ATTRIBUTE(congestion_kb_fops, congestion_kb_get,
344 congestion_kb_set, "%llu\n");
345
Sage Weil76aa8442009-10-06 11:31:14 -0700346int __init ceph_debugfs_init(void)
347{
348 ceph_debugfs_dir = debugfs_create_dir("ceph", NULL);
349 if (!ceph_debugfs_dir)
350 return -ENOMEM;
351 return 0;
352}
353
354void ceph_debugfs_cleanup(void)
355{
356 debugfs_remove(ceph_debugfs_dir);
357}
358
359int ceph_debugfs_client_init(struct ceph_client *client)
360{
361 int ret = 0;
362 char name[80];
363
364 snprintf(name, sizeof(name), FSID_FORMAT ".client%lld",
Sage Weil07433042009-11-18 16:50:41 -0800365 PR_FSID(&client->fsid), client->monc.auth->global_id);
Sage Weil76aa8442009-10-06 11:31:14 -0700366
367 client->debugfs_dir = debugfs_create_dir(name, ceph_debugfs_dir);
368 if (!client->debugfs_dir)
369 goto out;
370
371 client->monc.debugfs_file = debugfs_create_file("monc",
372 0600,
373 client->debugfs_dir,
374 client,
375 &monc_show_fops);
376 if (!client->monc.debugfs_file)
377 goto out;
378
379 client->mdsc.debugfs_file = debugfs_create_file("mdsc",
380 0600,
381 client->debugfs_dir,
382 client,
383 &mdsc_show_fops);
384 if (!client->mdsc.debugfs_file)
385 goto out;
386
387 client->osdc.debugfs_file = debugfs_create_file("osdc",
388 0600,
389 client->debugfs_dir,
390 client,
391 &osdc_show_fops);
392 if (!client->osdc.debugfs_file)
393 goto out;
394
395 client->debugfs_monmap = debugfs_create_file("monmap",
396 0600,
397 client->debugfs_dir,
398 client,
399 &monmap_show_fops);
400 if (!client->debugfs_monmap)
401 goto out;
402
403 client->debugfs_mdsmap = debugfs_create_file("mdsmap",
404 0600,
405 client->debugfs_dir,
406 client,
407 &mdsmap_show_fops);
408 if (!client->debugfs_mdsmap)
409 goto out;
410
411 client->debugfs_osdmap = debugfs_create_file("osdmap",
412 0600,
413 client->debugfs_dir,
414 client,
415 &osdmap_show_fops);
416 if (!client->debugfs_osdmap)
417 goto out;
418
419 client->debugfs_dentry_lru = debugfs_create_file("dentry_lru",
420 0600,
421 client->debugfs_dir,
422 client,
423 &dentry_lru_show_fops);
424 if (!client->debugfs_dentry_lru)
425 goto out;
426
427 client->debugfs_caps = debugfs_create_file("caps",
428 0400,
429 client->debugfs_dir,
430 client,
431 &caps_show_fops);
432 if (!client->debugfs_caps)
433 goto out;
434
Yehuda Sadeh2baba252009-12-18 13:51:57 -0800435 client->debugfs_congestion_kb = debugfs_create_file("writeback_congestion_kb",
436 0600,
437 client->debugfs_dir,
438 client,
439 &congestion_kb_fops);
440 if (!client->debugfs_congestion_kb)
441 goto out;
442
Sage Weil06edf042009-12-15 14:44:32 -0800443 sprintf(name, "../../bdi/%s", dev_name(client->sb->s_bdi->dev));
444 client->debugfs_bdi = debugfs_create_symlink("bdi", client->debugfs_dir,
445 name);
446
Sage Weil76aa8442009-10-06 11:31:14 -0700447 return 0;
448
449out:
450 ceph_debugfs_client_cleanup(client);
451 return ret;
452}
453
454void ceph_debugfs_client_cleanup(struct ceph_client *client)
455{
Sage Weil06edf042009-12-15 14:44:32 -0800456 debugfs_remove(client->debugfs_bdi);
Sage Weil76aa8442009-10-06 11:31:14 -0700457 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);
Yehuda Sadeh2baba252009-12-18 13:51:57 -0800465 debugfs_remove(client->debugfs_congestion_kb);
Sage Weil76aa8442009-10-06 11:31:14 -0700466 debugfs_remove(client->debugfs_dir);
467}
468
Sage Weil039934b2009-11-12 15:05:52 -0800469#else // CONFIG_DEBUG_FS
470
471int __init ceph_debugfs_init(void)
472{
473 return 0;
474}
475
476void ceph_debugfs_cleanup(void)
477{
478}
479
480int ceph_debugfs_client_init(struct ceph_client *client)
481{
482 return 0;
483}
484
485void ceph_debugfs_client_cleanup(struct ceph_client *client)
486{
487}
488
489#endif // CONFIG_DEBUG_FS