]>
Commit | Line | Data |
---|---|---|
76aa844d SW |
1 | #include "ceph_debug.h" |
2 | ||
06edf046 | 3 | #include <linux/device.h> |
76aa844d SW |
4 | #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" | |
0743304d SW |
11 | #include "mon_client.h" |
12 | #include "auth.h" | |
76aa844d | 13 | |
039934b8 SW |
14 | #ifdef CONFIG_DEBUG_FS |
15 | ||
76aa844d SW |
16 | /* |
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 | |
06edf046 | 28 | * .../bdi - symlink to ../../bdi/something |
76aa844d SW |
29 | */ |
30 | ||
31 | static struct dentry *ceph_debugfs_dir; | |
32 | ||
33 | static 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 | ||
53 | static 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 | ||
77 | static 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 | ||
111 | static int monc_show(struct seq_file *s, void *p) | |
112 | { | |
113 | struct ceph_client *client = s->private; | |
114 | struct ceph_mon_statfs_request *req; | |
115 | u64 nexttid = 0; | |
116 | int got; | |
117 | struct ceph_mon_client *monc = &client->monc; | |
118 | ||
119 | mutex_lock(&monc->mutex); | |
120 | ||
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"); | |
127 | ||
128 | while (nexttid < monc->last_tid) { | |
129 | got = radix_tree_gang_lookup(&monc->statfs_request_tree, | |
130 | (void **)&req, nexttid, 1); | |
131 | if (got == 0) | |
132 | break; | |
133 | nexttid = req->tid + 1; | |
134 | ||
135 | seq_printf(s, "%lld statfs\n", req->tid); | |
136 | } | |
137 | mutex_unlock(&monc->mutex); | |
138 | ||
139 | return 0; | |
140 | } | |
141 | ||
142 | static int mdsc_show(struct seq_file *s, void *p) | |
143 | { | |
144 | struct ceph_client *client = s->private; | |
145 | struct ceph_mds_request *req; | |
146 | u64 nexttid = 0; | |
147 | int got; | |
148 | struct ceph_mds_client *mdsc = &client->mdsc; | |
149 | int pathlen; | |
150 | u64 pathbase; | |
151 | char *path; | |
152 | ||
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); | |
157 | if (got == 0) | |
158 | break; | |
159 | nexttid = req->r_tid + 1; | |
160 | ||
161 | if (req->r_request) | |
162 | seq_printf(s, "%lld\tmds%d\t", req->r_tid, req->r_mds); | |
163 | else | |
164 | seq_printf(s, "%lld\t(no request)\t", req->r_tid); | |
165 | ||
166 | seq_printf(s, "%s", ceph_mds_op_name(req->r_op)); | |
167 | ||
168 | if (req->r_got_unsafe) | |
169 | seq_printf(s, "\t(unsafe)"); | |
170 | else | |
171 | seq_printf(s, "\t"); | |
172 | ||
173 | if (req->r_inode) { | |
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, | |
177 | &pathbase, 0); | |
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, | |
183 | path ? path : ""); | |
184 | spin_unlock(&req->r_dentry->d_lock); | |
185 | kfree(path); | |
186 | } else if (req->r_path1) { | |
187 | seq_printf(s, " #%llx/%s", req->r_ino1.ino, | |
188 | req->r_path1); | |
189 | } | |
190 | ||
191 | if (req->r_old_dentry) { | |
192 | path = ceph_mdsc_build_path(req->r_old_dentry, &pathlen, | |
193 | &pathbase, 0); | |
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, | |
199 | path ? path : ""); | |
200 | spin_unlock(&req->r_old_dentry->d_lock); | |
201 | kfree(path); | |
202 | } else if (req->r_path2) { | |
203 | if (req->r_ino2.ino) | |
204 | seq_printf(s, " #%llx/%s", req->r_ino2.ino, | |
205 | req->r_path2); | |
206 | else | |
207 | seq_printf(s, " %s", req->r_path2); | |
208 | } | |
209 | ||
210 | seq_printf(s, "\n"); | |
211 | } | |
212 | mutex_unlock(&mdsc->mutex); | |
213 | ||
214 | return 0; | |
215 | } | |
216 | ||
217 | static int osdc_show(struct seq_file *s, void *pp) | |
218 | { | |
219 | struct ceph_client *client = s->private; | |
220 | struct ceph_osd_client *osdc = &client->osdc; | |
221 | struct rb_node *p; | |
222 | ||
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; | |
228 | int num_ops; | |
229 | int opcode, olen; | |
230 | int i; | |
231 | ||
232 | req = rb_entry(p, struct ceph_osd_request, r_node); | |
233 | ||
7740a42f SW |
234 | seq_printf(s, "%lld\tosd%d\t%d.%x\t", req->r_tid, |
235 | req->r_osd ? req->r_osd->o_osd : -1, | |
236 | le32_to_cpu(req->r_pgid.pool), | |
237 | le16_to_cpu(req->r_pgid.ps)); | |
76aa844d SW |
238 | |
239 | head = req->r_request->front.iov_base; | |
240 | op = (void *)(head + 1); | |
241 | ||
242 | num_ops = le16_to_cpu(head->num_ops); | |
243 | olen = le32_to_cpu(head->object_len); | |
244 | seq_printf(s, "%.*s", olen, | |
245 | (const char *)(head->ops + num_ops)); | |
246 | ||
247 | if (req->r_reassert_version.epoch) | |
248 | seq_printf(s, "\t%u'%llu", | |
249 | (unsigned)le32_to_cpu(req->r_reassert_version.epoch), | |
250 | le64_to_cpu(req->r_reassert_version.version)); | |
251 | else | |
252 | seq_printf(s, "\t"); | |
253 | ||
254 | for (i = 0; i < num_ops; i++) { | |
255 | opcode = le16_to_cpu(op->op); | |
256 | seq_printf(s, "\t%s", ceph_osd_op_name(opcode)); | |
257 | op++; | |
258 | } | |
259 | ||
260 | seq_printf(s, "\n"); | |
261 | } | |
262 | mutex_unlock(&osdc->request_mutex); | |
263 | return 0; | |
264 | } | |
265 | ||
266 | static int caps_show(struct seq_file *s, void *p) | |
267 | { | |
268 | struct ceph_client *client = p; | |
269 | int total, avail, used, reserved; | |
270 | ||
271 | ceph_reservation_status(client, &total, &avail, &used, &reserved); | |
272 | seq_printf(s, "total\t\t%d\n" | |
273 | "avail\t\t%d\n" | |
274 | "used\t\t%d\n" | |
275 | "reserved\t%d\n", | |
276 | total, avail, used, reserved); | |
277 | return 0; | |
278 | } | |
279 | ||
280 | static int dentry_lru_show(struct seq_file *s, void *ptr) | |
281 | { | |
282 | struct ceph_client *client = s->private; | |
283 | struct ceph_mds_client *mdsc = &client->mdsc; | |
284 | struct ceph_dentry_info *di; | |
285 | ||
286 | spin_lock(&mdsc->dentry_lru_lock); | |
287 | list_for_each_entry(di, &mdsc->dentry_lru, lru) { | |
288 | struct dentry *dentry = di->dentry; | |
289 | seq_printf(s, "%p %p\t%.*s\n", | |
290 | di, dentry, dentry->d_name.len, dentry->d_name.name); | |
291 | } | |
292 | spin_unlock(&mdsc->dentry_lru_lock); | |
293 | ||
294 | return 0; | |
295 | } | |
296 | ||
297 | #define DEFINE_SHOW_FUNC(name) \ | |
298 | static int name##_open(struct inode *inode, struct file *file) \ | |
299 | { \ | |
300 | struct seq_file *sf; \ | |
301 | int ret; \ | |
302 | \ | |
303 | ret = single_open(file, name, NULL); \ | |
304 | sf = file->private_data; \ | |
305 | sf->private = inode->i_private; \ | |
306 | return ret; \ | |
307 | } \ | |
308 | \ | |
309 | static const struct file_operations name##_fops = { \ | |
310 | .open = name##_open, \ | |
311 | .read = seq_read, \ | |
312 | .llseek = seq_lseek, \ | |
313 | .release = single_release, \ | |
314 | }; | |
315 | ||
316 | DEFINE_SHOW_FUNC(monmap_show) | |
317 | DEFINE_SHOW_FUNC(mdsmap_show) | |
318 | DEFINE_SHOW_FUNC(osdmap_show) | |
319 | DEFINE_SHOW_FUNC(monc_show) | |
320 | DEFINE_SHOW_FUNC(mdsc_show) | |
321 | DEFINE_SHOW_FUNC(osdc_show) | |
322 | DEFINE_SHOW_FUNC(dentry_lru_show) | |
323 | DEFINE_SHOW_FUNC(caps_show) | |
324 | ||
2baba250 YS |
325 | static int congestion_kb_set(void *data, u64 val) |
326 | { | |
327 | struct ceph_client *client = (struct ceph_client *)data; | |
328 | ||
329 | if (client) | |
330 | client->mount_args->congestion_kb = (int)val; | |
331 | ||
332 | return 0; | |
333 | } | |
334 | ||
335 | static int congestion_kb_get(void *data, u64 *val) | |
336 | { | |
337 | struct ceph_client *client = (struct ceph_client *)data; | |
338 | ||
339 | if (client) | |
340 | *val = (u64)client->mount_args->congestion_kb; | |
341 | ||
342 | return 0; | |
343 | } | |
344 | ||
345 | ||
346 | DEFINE_SIMPLE_ATTRIBUTE(congestion_kb_fops, congestion_kb_get, | |
347 | congestion_kb_set, "%llu\n"); | |
348 | ||
76aa844d SW |
349 | int __init ceph_debugfs_init(void) |
350 | { | |
351 | ceph_debugfs_dir = debugfs_create_dir("ceph", NULL); | |
352 | if (!ceph_debugfs_dir) | |
353 | return -ENOMEM; | |
354 | return 0; | |
355 | } | |
356 | ||
357 | void ceph_debugfs_cleanup(void) | |
358 | { | |
359 | debugfs_remove(ceph_debugfs_dir); | |
360 | } | |
361 | ||
362 | int ceph_debugfs_client_init(struct ceph_client *client) | |
363 | { | |
364 | int ret = 0; | |
365 | char name[80]; | |
366 | ||
367 | snprintf(name, sizeof(name), FSID_FORMAT ".client%lld", | |
0743304d | 368 | PR_FSID(&client->fsid), client->monc.auth->global_id); |
76aa844d SW |
369 | |
370 | client->debugfs_dir = debugfs_create_dir(name, ceph_debugfs_dir); | |
371 | if (!client->debugfs_dir) | |
372 | goto out; | |
373 | ||
374 | client->monc.debugfs_file = debugfs_create_file("monc", | |
375 | 0600, | |
376 | client->debugfs_dir, | |
377 | client, | |
378 | &monc_show_fops); | |
379 | if (!client->monc.debugfs_file) | |
380 | goto out; | |
381 | ||
382 | client->mdsc.debugfs_file = debugfs_create_file("mdsc", | |
383 | 0600, | |
384 | client->debugfs_dir, | |
385 | client, | |
386 | &mdsc_show_fops); | |
387 | if (!client->mdsc.debugfs_file) | |
388 | goto out; | |
389 | ||
390 | client->osdc.debugfs_file = debugfs_create_file("osdc", | |
391 | 0600, | |
392 | client->debugfs_dir, | |
393 | client, | |
394 | &osdc_show_fops); | |
395 | if (!client->osdc.debugfs_file) | |
396 | goto out; | |
397 | ||
398 | client->debugfs_monmap = debugfs_create_file("monmap", | |
399 | 0600, | |
400 | client->debugfs_dir, | |
401 | client, | |
402 | &monmap_show_fops); | |
403 | if (!client->debugfs_monmap) | |
404 | goto out; | |
405 | ||
406 | client->debugfs_mdsmap = debugfs_create_file("mdsmap", | |
407 | 0600, | |
408 | client->debugfs_dir, | |
409 | client, | |
410 | &mdsmap_show_fops); | |
411 | if (!client->debugfs_mdsmap) | |
412 | goto out; | |
413 | ||
414 | client->debugfs_osdmap = debugfs_create_file("osdmap", | |
415 | 0600, | |
416 | client->debugfs_dir, | |
417 | client, | |
418 | &osdmap_show_fops); | |
419 | if (!client->debugfs_osdmap) | |
420 | goto out; | |
421 | ||
422 | client->debugfs_dentry_lru = debugfs_create_file("dentry_lru", | |
423 | 0600, | |
424 | client->debugfs_dir, | |
425 | client, | |
426 | &dentry_lru_show_fops); | |
427 | if (!client->debugfs_dentry_lru) | |
428 | goto out; | |
429 | ||
430 | client->debugfs_caps = debugfs_create_file("caps", | |
431 | 0400, | |
432 | client->debugfs_dir, | |
433 | client, | |
434 | &caps_show_fops); | |
435 | if (!client->debugfs_caps) | |
436 | goto out; | |
437 | ||
2baba250 YS |
438 | client->debugfs_congestion_kb = debugfs_create_file("writeback_congestion_kb", |
439 | 0600, | |
440 | client->debugfs_dir, | |
441 | client, | |
442 | &congestion_kb_fops); | |
443 | if (!client->debugfs_congestion_kb) | |
444 | goto out; | |
445 | ||
06edf046 SW |
446 | sprintf(name, "../../bdi/%s", dev_name(client->sb->s_bdi->dev)); |
447 | client->debugfs_bdi = debugfs_create_symlink("bdi", client->debugfs_dir, | |
448 | name); | |
449 | ||
76aa844d SW |
450 | return 0; |
451 | ||
452 | out: | |
453 | ceph_debugfs_client_cleanup(client); | |
454 | return ret; | |
455 | } | |
456 | ||
457 | void ceph_debugfs_client_cleanup(struct ceph_client *client) | |
458 | { | |
06edf046 | 459 | debugfs_remove(client->debugfs_bdi); |
76aa844d SW |
460 | debugfs_remove(client->debugfs_caps); |
461 | debugfs_remove(client->debugfs_dentry_lru); | |
462 | debugfs_remove(client->debugfs_osdmap); | |
463 | debugfs_remove(client->debugfs_mdsmap); | |
464 | debugfs_remove(client->debugfs_monmap); | |
465 | debugfs_remove(client->osdc.debugfs_file); | |
466 | debugfs_remove(client->mdsc.debugfs_file); | |
467 | debugfs_remove(client->monc.debugfs_file); | |
2baba250 | 468 | debugfs_remove(client->debugfs_congestion_kb); |
76aa844d SW |
469 | debugfs_remove(client->debugfs_dir); |
470 | } | |
471 | ||
039934b8 SW |
472 | #else // CONFIG_DEBUG_FS |
473 | ||
474 | int __init ceph_debugfs_init(void) | |
475 | { | |
476 | return 0; | |
477 | } | |
478 | ||
479 | void ceph_debugfs_cleanup(void) | |
480 | { | |
481 | } | |
482 | ||
483 | int ceph_debugfs_client_init(struct ceph_client *client) | |
484 | { | |
485 | return 0; | |
486 | } | |
487 | ||
488 | void ceph_debugfs_client_cleanup(struct ceph_client *client) | |
489 | { | |
490 | } | |
491 | ||
492 | #endif // CONFIG_DEBUG_FS |