]>
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; | |
76aa844d | 115 | struct ceph_mon_client *monc = &client->monc; |
85ff03f6 | 116 | struct rb_node *rp; |
76aa844d SW |
117 | |
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 | ||
85ff03f6 SW |
127 | for (rp = rb_first(&monc->statfs_request_tree); rp; rp = rb_next(rp)) { |
128 | req = rb_entry(rp, struct ceph_mon_statfs_request, node); | |
76aa844d SW |
129 | seq_printf(s, "%lld statfs\n", req->tid); |
130 | } | |
76aa844d | 131 | |
85ff03f6 | 132 | mutex_unlock(&monc->mutex); |
76aa844d SW |
133 | return 0; |
134 | } | |
135 | ||
136 | static int mdsc_show(struct seq_file *s, void *p) | |
137 | { | |
138 | struct ceph_client *client = s->private; | |
76aa844d | 139 | struct ceph_mds_client *mdsc = &client->mdsc; |
44ca18f2 SW |
140 | struct ceph_mds_request *req; |
141 | struct rb_node *rp; | |
76aa844d SW |
142 | int pathlen; |
143 | u64 pathbase; | |
144 | char *path; | |
145 | ||
146 | mutex_lock(&mdsc->mutex); | |
44ca18f2 SW |
147 | for (rp = rb_first(&mdsc->request_tree); rp; rp = rb_next(rp)) { |
148 | req = rb_entry(rp, struct ceph_mds_request, r_node); | |
76aa844d SW |
149 | |
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 | ||
206 | static 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 | ||
7740a42f SW |
223 | 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)); | |
76aa844d SW |
227 | |
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 | ||
255 | static int caps_show(struct seq_file *s, void *p) | |
256 | { | |
257 | struct ceph_client *client = p; | |
258 | int total, avail, used, reserved; | |
259 | ||
260 | ceph_reservation_status(client, &total, &avail, &used, &reserved); | |
261 | seq_printf(s, "total\t\t%d\n" | |
262 | "avail\t\t%d\n" | |
263 | "used\t\t%d\n" | |
264 | "reserved\t%d\n", | |
265 | total, avail, used, reserved); | |
266 | return 0; | |
267 | } | |
268 | ||
269 | static int dentry_lru_show(struct seq_file *s, void *ptr) | |
270 | { | |
271 | struct ceph_client *client = s->private; | |
272 | struct ceph_mds_client *mdsc = &client->mdsc; | |
273 | struct ceph_dentry_info *di; | |
274 | ||
275 | spin_lock(&mdsc->dentry_lru_lock); | |
276 | list_for_each_entry(di, &mdsc->dentry_lru, lru) { | |
277 | struct dentry *dentry = di->dentry; | |
278 | seq_printf(s, "%p %p\t%.*s\n", | |
279 | di, dentry, dentry->d_name.len, dentry->d_name.name); | |
280 | } | |
281 | spin_unlock(&mdsc->dentry_lru_lock); | |
282 | ||
283 | return 0; | |
284 | } | |
285 | ||
286 | #define DEFINE_SHOW_FUNC(name) \ | |
287 | static int name##_open(struct inode *inode, struct file *file) \ | |
288 | { \ | |
289 | struct seq_file *sf; \ | |
290 | int ret; \ | |
291 | \ | |
292 | ret = single_open(file, name, NULL); \ | |
293 | sf = file->private_data; \ | |
294 | sf->private = inode->i_private; \ | |
295 | return ret; \ | |
296 | } \ | |
297 | \ | |
298 | static const struct file_operations name##_fops = { \ | |
299 | .open = name##_open, \ | |
300 | .read = seq_read, \ | |
301 | .llseek = seq_lseek, \ | |
302 | .release = single_release, \ | |
303 | }; | |
304 | ||
305 | DEFINE_SHOW_FUNC(monmap_show) | |
306 | DEFINE_SHOW_FUNC(mdsmap_show) | |
307 | DEFINE_SHOW_FUNC(osdmap_show) | |
308 | DEFINE_SHOW_FUNC(monc_show) | |
309 | DEFINE_SHOW_FUNC(mdsc_show) | |
310 | DEFINE_SHOW_FUNC(osdc_show) | |
311 | DEFINE_SHOW_FUNC(dentry_lru_show) | |
312 | DEFINE_SHOW_FUNC(caps_show) | |
313 | ||
2baba250 YS |
314 | static int congestion_kb_set(void *data, u64 val) |
315 | { | |
316 | struct ceph_client *client = (struct ceph_client *)data; | |
317 | ||
318 | if (client) | |
319 | client->mount_args->congestion_kb = (int)val; | |
320 | ||
321 | return 0; | |
322 | } | |
323 | ||
324 | static int congestion_kb_get(void *data, u64 *val) | |
325 | { | |
326 | struct ceph_client *client = (struct ceph_client *)data; | |
327 | ||
328 | if (client) | |
329 | *val = (u64)client->mount_args->congestion_kb; | |
330 | ||
331 | return 0; | |
332 | } | |
333 | ||
334 | ||
335 | DEFINE_SIMPLE_ATTRIBUTE(congestion_kb_fops, congestion_kb_get, | |
336 | congestion_kb_set, "%llu\n"); | |
337 | ||
76aa844d SW |
338 | int __init ceph_debugfs_init(void) |
339 | { | |
340 | ceph_debugfs_dir = debugfs_create_dir("ceph", NULL); | |
341 | if (!ceph_debugfs_dir) | |
342 | return -ENOMEM; | |
343 | return 0; | |
344 | } | |
345 | ||
346 | void ceph_debugfs_cleanup(void) | |
347 | { | |
348 | debugfs_remove(ceph_debugfs_dir); | |
349 | } | |
350 | ||
351 | int ceph_debugfs_client_init(struct ceph_client *client) | |
352 | { | |
353 | int ret = 0; | |
354 | char name[80]; | |
355 | ||
356 | snprintf(name, sizeof(name), FSID_FORMAT ".client%lld", | |
0743304d | 357 | PR_FSID(&client->fsid), client->monc.auth->global_id); |
76aa844d SW |
358 | |
359 | client->debugfs_dir = debugfs_create_dir(name, ceph_debugfs_dir); | |
360 | if (!client->debugfs_dir) | |
361 | goto out; | |
362 | ||
363 | client->monc.debugfs_file = debugfs_create_file("monc", | |
364 | 0600, | |
365 | client->debugfs_dir, | |
366 | client, | |
367 | &monc_show_fops); | |
368 | if (!client->monc.debugfs_file) | |
369 | goto out; | |
370 | ||
371 | client->mdsc.debugfs_file = debugfs_create_file("mdsc", | |
372 | 0600, | |
373 | client->debugfs_dir, | |
374 | client, | |
375 | &mdsc_show_fops); | |
376 | if (!client->mdsc.debugfs_file) | |
377 | goto out; | |
378 | ||
379 | client->osdc.debugfs_file = debugfs_create_file("osdc", | |
380 | 0600, | |
381 | client->debugfs_dir, | |
382 | client, | |
383 | &osdc_show_fops); | |
384 | if (!client->osdc.debugfs_file) | |
385 | goto out; | |
386 | ||
387 | client->debugfs_monmap = debugfs_create_file("monmap", | |
388 | 0600, | |
389 | client->debugfs_dir, | |
390 | client, | |
391 | &monmap_show_fops); | |
392 | if (!client->debugfs_monmap) | |
393 | goto out; | |
394 | ||
395 | client->debugfs_mdsmap = debugfs_create_file("mdsmap", | |
396 | 0600, | |
397 | client->debugfs_dir, | |
398 | client, | |
399 | &mdsmap_show_fops); | |
400 | if (!client->debugfs_mdsmap) | |
401 | goto out; | |
402 | ||
403 | client->debugfs_osdmap = debugfs_create_file("osdmap", | |
404 | 0600, | |
405 | client->debugfs_dir, | |
406 | client, | |
407 | &osdmap_show_fops); | |
408 | if (!client->debugfs_osdmap) | |
409 | goto out; | |
410 | ||
411 | client->debugfs_dentry_lru = debugfs_create_file("dentry_lru", | |
412 | 0600, | |
413 | client->debugfs_dir, | |
414 | client, | |
415 | &dentry_lru_show_fops); | |
416 | if (!client->debugfs_dentry_lru) | |
417 | goto out; | |
418 | ||
419 | client->debugfs_caps = debugfs_create_file("caps", | |
420 | 0400, | |
421 | client->debugfs_dir, | |
422 | client, | |
423 | &caps_show_fops); | |
424 | if (!client->debugfs_caps) | |
425 | goto out; | |
426 | ||
2baba250 YS |
427 | client->debugfs_congestion_kb = debugfs_create_file("writeback_congestion_kb", |
428 | 0600, | |
429 | client->debugfs_dir, | |
430 | client, | |
431 | &congestion_kb_fops); | |
432 | if (!client->debugfs_congestion_kb) | |
433 | goto out; | |
434 | ||
06edf046 SW |
435 | sprintf(name, "../../bdi/%s", dev_name(client->sb->s_bdi->dev)); |
436 | client->debugfs_bdi = debugfs_create_symlink("bdi", client->debugfs_dir, | |
437 | name); | |
438 | ||
76aa844d SW |
439 | return 0; |
440 | ||
441 | out: | |
442 | ceph_debugfs_client_cleanup(client); | |
443 | return ret; | |
444 | } | |
445 | ||
446 | void ceph_debugfs_client_cleanup(struct ceph_client *client) | |
447 | { | |
06edf046 | 448 | debugfs_remove(client->debugfs_bdi); |
76aa844d SW |
449 | debugfs_remove(client->debugfs_caps); |
450 | debugfs_remove(client->debugfs_dentry_lru); | |
451 | debugfs_remove(client->debugfs_osdmap); | |
452 | debugfs_remove(client->debugfs_mdsmap); | |
453 | debugfs_remove(client->debugfs_monmap); | |
454 | debugfs_remove(client->osdc.debugfs_file); | |
455 | debugfs_remove(client->mdsc.debugfs_file); | |
456 | debugfs_remove(client->monc.debugfs_file); | |
2baba250 | 457 | debugfs_remove(client->debugfs_congestion_kb); |
76aa844d SW |
458 | debugfs_remove(client->debugfs_dir); |
459 | } | |
460 | ||
039934b8 SW |
461 | #else // CONFIG_DEBUG_FS |
462 | ||
463 | int __init ceph_debugfs_init(void) | |
464 | { | |
465 | return 0; | |
466 | } | |
467 | ||
468 | void ceph_debugfs_cleanup(void) | |
469 | { | |
470 | } | |
471 | ||
472 | int ceph_debugfs_client_init(struct ceph_client *client) | |
473 | { | |
474 | return 0; | |
475 | } | |
476 | ||
477 | void ceph_debugfs_client_cleanup(struct ceph_client *client) | |
478 | { | |
479 | } | |
480 | ||
481 | #endif // CONFIG_DEBUG_FS |