blob: 1a47b5c25b5fb3707d39696e1dfbe82ec60f9d26 [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>
Sage Weil76aa8442009-10-06 11:31:14 -07004#include <linux/module.h>
5#include <linux/ctype.h>
6#include <linux/debugfs.h>
7#include <linux/seq_file.h>
8
9#include "super.h"
10#include "mds_client.h"
Sage Weil07433042009-11-18 16:50:41 -080011#include "mon_client.h"
12#include "auth.h"
Sage Weil76aa8442009-10-06 11:31:14 -070013
Sage Weil039934b2009-11-12 15:05:52 -080014#ifdef CONFIG_DEBUG_FS
15
Sage Weil76aa8442009-10-06 11:31:14 -070016/*
17 * Implement /sys/kernel/debug/ceph fun
18 *
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
Sage Weil06edf042009-12-15 14:44:32 -080028 * .../bdi - symlink to ../../bdi/something
Sage Weil76aa8442009-10-06 11:31:14 -070029 */
30
31static struct dentry *ceph_debugfs_dir;
32
33static int monmap_show(struct seq_file *s, void *p)
34{
35 int i;
36 struct ceph_client *client = s->private;
37
38 if (client->monc.monmap == NULL)
39 return 0;
40
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];
45
46 seq_printf(s, "\t%s%lld\t%s\n",
47 ENTITY_NAME(inst->name),
48 pr_addr(&inst->addr.in_addr));
49 }
50 return 0;
51}
52
53static int mdsmap_show(struct seq_file *s, void *p)
54{
55 int i;
56 struct ceph_client *client = s->private;
57
58 if (client->mdsc.mdsmap == NULL)
59 return 0;
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;
70
71 seq_printf(s, "\tmds%d\t%s\t(%s)\n", i, pr_addr(&addr->in_addr),
72 ceph_mds_state_name(state));
73 }
74 return 0;
75}
76
77static int osdmap_show(struct seq_file *s, void *p)
78{
79 int i;
80 struct ceph_client *client = s->private;
81
82 if (client->osdc.osdmap == NULL)
83 return 0;
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) ?
87 " NEARFULL" : "",
88 (client->osdc.osdmap->flags & CEPH_OSDMAP_FULL) ?
89 " 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);
96 }
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];
101 char sb[64];
102
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));
107 }
108 return 0;
109}
110
111static int monc_show(struct seq_file *s, void *p)
112{
113 struct ceph_client *client = s->private;
114 struct ceph_mon_statfs_request *req;
Sage Weil76aa8442009-10-06 11:31:14 -0700115 struct ceph_mon_client *monc = &client->monc;
Sage Weil85ff03f2010-02-15 14:47:28 -0800116 struct rb_node *rp;
Sage Weil76aa8442009-10-06 11:31:14 -0700117
118 mutex_lock(&monc->mutex);
119
120 if (monc->have_mdsmap)
121 seq_printf(s, "have mdsmap %u\n", (unsigned)monc->have_mdsmap);
122 if (monc->have_osdmap)
123 seq_printf(s, "have osdmap %u\n", (unsigned)monc->have_osdmap);
124 if (monc->want_next_osdmap)
125 seq_printf(s, "want next osdmap\n");
126
Sage Weil85ff03f2010-02-15 14:47:28 -0800127 for (rp = rb_first(&monc->statfs_request_tree); rp; rp = rb_next(rp)) {
128 req = rb_entry(rp, struct ceph_mon_statfs_request, node);
Sage Weil76aa8442009-10-06 11:31:14 -0700129 seq_printf(s, "%lld statfs\n", req->tid);
130 }
Sage Weil76aa8442009-10-06 11:31:14 -0700131
Sage Weil85ff03f2010-02-15 14:47:28 -0800132 mutex_unlock(&monc->mutex);
Sage Weil76aa8442009-10-06 11:31:14 -0700133 return 0;
134}
135
136static int mdsc_show(struct seq_file *s, void *p)
137{
138 struct ceph_client *client = s->private;
Sage Weil76aa8442009-10-06 11:31:14 -0700139 struct ceph_mds_client *mdsc = &client->mdsc;
Sage Weil44ca18f2010-02-15 12:08:46 -0800140 struct ceph_mds_request *req;
141 struct rb_node *rp;
Sage Weil76aa8442009-10-06 11:31:14 -0700142 int pathlen;
143 u64 pathbase;
144 char *path;
145
146 mutex_lock(&mdsc->mutex);
Sage Weil44ca18f2010-02-15 12:08:46 -0800147 for (rp = rb_first(&mdsc->request_tree); rp; rp = rb_next(rp)) {
148 req = rb_entry(rp, struct ceph_mds_request, r_node);
Sage Weil76aa8442009-10-06 11:31:14 -0700149
150 if (req->r_request)
151 seq_printf(s, "%lld\tmds%d\t", req->r_tid, req->r_mds);
152 else
153 seq_printf(s, "%lld\t(no request)\t", req->r_tid);
154
155 seq_printf(s, "%s", ceph_mds_op_name(req->r_op));
156
157 if (req->r_got_unsafe)
158 seq_printf(s, "\t(unsafe)");
159 else
160 seq_printf(s, "\t");
161
162 if (req->r_inode) {
163 seq_printf(s, " #%llx", ceph_ino(req->r_inode));
164 } else if (req->r_dentry) {
165 path = ceph_mdsc_build_path(req->r_dentry, &pathlen,
166 &pathbase, 0);
167 spin_lock(&req->r_dentry->d_lock);
168 seq_printf(s, " #%llx/%.*s (%s)",
169 ceph_ino(req->r_dentry->d_parent->d_inode),
170 req->r_dentry->d_name.len,
171 req->r_dentry->d_name.name,
172 path ? path : "");
173 spin_unlock(&req->r_dentry->d_lock);
174 kfree(path);
175 } else if (req->r_path1) {
176 seq_printf(s, " #%llx/%s", req->r_ino1.ino,
177 req->r_path1);
178 }
179
180 if (req->r_old_dentry) {
181 path = ceph_mdsc_build_path(req->r_old_dentry, &pathlen,
182 &pathbase, 0);
183 spin_lock(&req->r_old_dentry->d_lock);
184 seq_printf(s, " #%llx/%.*s (%s)",
185 ceph_ino(req->r_old_dentry->d_parent->d_inode),
186 req->r_old_dentry->d_name.len,
187 req->r_old_dentry->d_name.name,
188 path ? path : "");
189 spin_unlock(&req->r_old_dentry->d_lock);
190 kfree(path);
191 } else if (req->r_path2) {
192 if (req->r_ino2.ino)
193 seq_printf(s, " #%llx/%s", req->r_ino2.ino,
194 req->r_path2);
195 else
196 seq_printf(s, " %s", req->r_path2);
197 }
198
199 seq_printf(s, "\n");
200 }
201 mutex_unlock(&mdsc->mutex);
202
203 return 0;
204}
205
206static int osdc_show(struct seq_file *s, void *pp)
207{
208 struct ceph_client *client = s->private;
209 struct ceph_osd_client *osdc = &client->osdc;
210 struct rb_node *p;
211
212 mutex_lock(&osdc->request_mutex);
213 for (p = rb_first(&osdc->requests); p; p = rb_next(p)) {
214 struct ceph_osd_request *req;
215 struct ceph_osd_request_head *head;
216 struct ceph_osd_op *op;
217 int num_ops;
218 int opcode, olen;
219 int i;
220
221 req = rb_entry(p, struct ceph_osd_request, r_node);
222
Sage Weil7740a422010-01-08 15:58:25 -0800223 seq_printf(s, "%lld\tosd%d\t%d.%x\t", req->r_tid,
224 req->r_osd ? req->r_osd->o_osd : -1,
225 le32_to_cpu(req->r_pgid.pool),
226 le16_to_cpu(req->r_pgid.ps));
Sage Weil76aa8442009-10-06 11:31:14 -0700227
228 head = req->r_request->front.iov_base;
229 op = (void *)(head + 1);
230
231 num_ops = le16_to_cpu(head->num_ops);
232 olen = le32_to_cpu(head->object_len);
233 seq_printf(s, "%.*s", olen,
234 (const char *)(head->ops + num_ops));
235
236 if (req->r_reassert_version.epoch)
237 seq_printf(s, "\t%u'%llu",
238 (unsigned)le32_to_cpu(req->r_reassert_version.epoch),
239 le64_to_cpu(req->r_reassert_version.version));
240 else
241 seq_printf(s, "\t");
242
243 for (i = 0; i < num_ops; i++) {
244 opcode = le16_to_cpu(op->op);
245 seq_printf(s, "\t%s", ceph_osd_op_name(opcode));
246 op++;
247 }
248
249 seq_printf(s, "\n");
250 }
251 mutex_unlock(&osdc->request_mutex);
252 return 0;
253}
254
255static int caps_show(struct seq_file *s, void *p)
256{
257 struct ceph_client *client = p;
Sage Weil85ccce42010-02-17 10:02:43 -0800258 int total, avail, used, reserved, min;
Sage Weil76aa8442009-10-06 11:31:14 -0700259
Sage Weil85ccce42010-02-17 10:02:43 -0800260 ceph_reservation_status(client, &total, &avail, &used, &reserved, &min);
Sage Weil76aa8442009-10-06 11:31:14 -0700261 seq_printf(s, "total\t\t%d\n"
Sage Weil85ccce42010-02-17 10:02:43 -0800262 "avail\t\t%d\n"
263 "used\t\t%d\n"
264 "reserved\t%d\n"
265 "min\t%d\n",
266 total, avail, used, reserved, min);
Sage Weil76aa8442009-10-06 11:31:14 -0700267 return 0;
268}
269
270static int dentry_lru_show(struct seq_file *s, void *ptr)
271{
272 struct ceph_client *client = s->private;
273 struct ceph_mds_client *mdsc = &client->mdsc;
274 struct ceph_dentry_info *di;
275
276 spin_lock(&mdsc->dentry_lru_lock);
277 list_for_each_entry(di, &mdsc->dentry_lru, lru) {
278 struct dentry *dentry = di->dentry;
279 seq_printf(s, "%p %p\t%.*s\n",
280 di, dentry, dentry->d_name.len, dentry->d_name.name);
281 }
282 spin_unlock(&mdsc->dentry_lru_lock);
283
284 return 0;
285}
286
287#define DEFINE_SHOW_FUNC(name) \
288static int name##_open(struct inode *inode, struct file *file) \
289{ \
290 struct seq_file *sf; \
291 int ret; \
292 \
293 ret = single_open(file, name, NULL); \
294 sf = file->private_data; \
295 sf->private = inode->i_private; \
296 return ret; \
297} \
298 \
299static const struct file_operations name##_fops = { \
300 .open = name##_open, \
301 .read = seq_read, \
302 .llseek = seq_lseek, \
303 .release = single_release, \
304};
305
306DEFINE_SHOW_FUNC(monmap_show)
307DEFINE_SHOW_FUNC(mdsmap_show)
308DEFINE_SHOW_FUNC(osdmap_show)
309DEFINE_SHOW_FUNC(monc_show)
310DEFINE_SHOW_FUNC(mdsc_show)
311DEFINE_SHOW_FUNC(osdc_show)
312DEFINE_SHOW_FUNC(dentry_lru_show)
313DEFINE_SHOW_FUNC(caps_show)
314
Yehuda Sadeh2baba252009-12-18 13:51:57 -0800315static int congestion_kb_set(void *data, u64 val)
316{
317 struct ceph_client *client = (struct ceph_client *)data;
318
319 if (client)
320 client->mount_args->congestion_kb = (int)val;
321
322 return 0;
323}
324
325static int congestion_kb_get(void *data, u64 *val)
326{
327 struct ceph_client *client = (struct ceph_client *)data;
328
329 if (client)
330 *val = (u64)client->mount_args->congestion_kb;
331
332 return 0;
333}
334
335
336DEFINE_SIMPLE_ATTRIBUTE(congestion_kb_fops, congestion_kb_get,
337 congestion_kb_set, "%llu\n");
338
Sage Weil76aa8442009-10-06 11:31:14 -0700339int __init ceph_debugfs_init(void)
340{
341 ceph_debugfs_dir = debugfs_create_dir("ceph", NULL);
342 if (!ceph_debugfs_dir)
343 return -ENOMEM;
344 return 0;
345}
346
347void ceph_debugfs_cleanup(void)
348{
349 debugfs_remove(ceph_debugfs_dir);
350}
351
352int ceph_debugfs_client_init(struct ceph_client *client)
353{
354 int ret = 0;
355 char name[80];
356
357 snprintf(name, sizeof(name), FSID_FORMAT ".client%lld",
Sage Weil07433042009-11-18 16:50:41 -0800358 PR_FSID(&client->fsid), client->monc.auth->global_id);
Sage Weil76aa8442009-10-06 11:31:14 -0700359
360 client->debugfs_dir = debugfs_create_dir(name, ceph_debugfs_dir);
361 if (!client->debugfs_dir)
362 goto out;
363
364 client->monc.debugfs_file = debugfs_create_file("monc",
365 0600,
366 client->debugfs_dir,
367 client,
368 &monc_show_fops);
369 if (!client->monc.debugfs_file)
370 goto out;
371
372 client->mdsc.debugfs_file = debugfs_create_file("mdsc",
373 0600,
374 client->debugfs_dir,
375 client,
376 &mdsc_show_fops);
377 if (!client->mdsc.debugfs_file)
378 goto out;
379
380 client->osdc.debugfs_file = debugfs_create_file("osdc",
381 0600,
382 client->debugfs_dir,
383 client,
384 &osdc_show_fops);
385 if (!client->osdc.debugfs_file)
386 goto out;
387
388 client->debugfs_monmap = debugfs_create_file("monmap",
389 0600,
390 client->debugfs_dir,
391 client,
392 &monmap_show_fops);
393 if (!client->debugfs_monmap)
394 goto out;
395
396 client->debugfs_mdsmap = debugfs_create_file("mdsmap",
397 0600,
398 client->debugfs_dir,
399 client,
400 &mdsmap_show_fops);
401 if (!client->debugfs_mdsmap)
402 goto out;
403
404 client->debugfs_osdmap = debugfs_create_file("osdmap",
405 0600,
406 client->debugfs_dir,
407 client,
408 &osdmap_show_fops);
409 if (!client->debugfs_osdmap)
410 goto out;
411
412 client->debugfs_dentry_lru = debugfs_create_file("dentry_lru",
413 0600,
414 client->debugfs_dir,
415 client,
416 &dentry_lru_show_fops);
417 if (!client->debugfs_dentry_lru)
418 goto out;
419
420 client->debugfs_caps = debugfs_create_file("caps",
421 0400,
422 client->debugfs_dir,
423 client,
424 &caps_show_fops);
425 if (!client->debugfs_caps)
426 goto out;
427
Yehuda Sadeh2baba252009-12-18 13:51:57 -0800428 client->debugfs_congestion_kb = debugfs_create_file("writeback_congestion_kb",
429 0600,
430 client->debugfs_dir,
431 client,
432 &congestion_kb_fops);
433 if (!client->debugfs_congestion_kb)
434 goto out;
435
Sage Weil06edf042009-12-15 14:44:32 -0800436 sprintf(name, "../../bdi/%s", dev_name(client->sb->s_bdi->dev));
437 client->debugfs_bdi = debugfs_create_symlink("bdi", client->debugfs_dir,
438 name);
439
Sage Weil76aa8442009-10-06 11:31:14 -0700440 return 0;
441
442out:
443 ceph_debugfs_client_cleanup(client);
444 return ret;
445}
446
447void ceph_debugfs_client_cleanup(struct ceph_client *client)
448{
Sage Weil06edf042009-12-15 14:44:32 -0800449 debugfs_remove(client->debugfs_bdi);
Sage Weil76aa8442009-10-06 11:31:14 -0700450 debugfs_remove(client->debugfs_caps);
451 debugfs_remove(client->debugfs_dentry_lru);
452 debugfs_remove(client->debugfs_osdmap);
453 debugfs_remove(client->debugfs_mdsmap);
454 debugfs_remove(client->debugfs_monmap);
455 debugfs_remove(client->osdc.debugfs_file);
456 debugfs_remove(client->mdsc.debugfs_file);
457 debugfs_remove(client->monc.debugfs_file);
Yehuda Sadeh2baba252009-12-18 13:51:57 -0800458 debugfs_remove(client->debugfs_congestion_kb);
Sage Weil76aa8442009-10-06 11:31:14 -0700459 debugfs_remove(client->debugfs_dir);
460}
461
Sage Weil039934b2009-11-12 15:05:52 -0800462#else // CONFIG_DEBUG_FS
463
464int __init ceph_debugfs_init(void)
465{
466 return 0;
467}
468
469void ceph_debugfs_cleanup(void)
470{
471}
472
473int ceph_debugfs_client_init(struct ceph_client *client)
474{
475 return 0;
476}
477
478void ceph_debugfs_client_cleanup(struct ceph_client *client)
479{
480}
481
482#endif // CONFIG_DEBUG_FS