]>
Commit | Line | Data |
---|---|---|
76aa844d SW |
1 | #include "ceph_debug.h" |
2 | ||
3 | #include <linux/module.h> | |
4 | #include <linux/ctype.h> | |
5 | #include <linux/debugfs.h> | |
6 | #include <linux/seq_file.h> | |
7 | ||
8 | #include "super.h" | |
9 | #include "mds_client.h" | |
10 | ||
039934b8 SW |
11 | #ifdef CONFIG_DEBUG_FS |
12 | ||
76aa844d SW |
13 | /* |
14 | * Implement /sys/kernel/debug/ceph fun | |
15 | * | |
16 | * /sys/kernel/debug/ceph/client* - an instance of the ceph client | |
17 | * .../osdmap - current osdmap | |
18 | * .../mdsmap - current mdsmap | |
19 | * .../monmap - current monmap | |
20 | * .../osdc - active osd requests | |
21 | * .../mdsc - active mds requests | |
22 | * .../monc - mon client state | |
23 | * .../dentry_lru - dump contents of dentry lru | |
24 | * .../caps - expose cap (reservation) stats | |
25 | */ | |
26 | ||
27 | static struct dentry *ceph_debugfs_dir; | |
28 | ||
29 | static int monmap_show(struct seq_file *s, void *p) | |
30 | { | |
31 | int i; | |
32 | struct ceph_client *client = s->private; | |
33 | ||
34 | if (client->monc.monmap == NULL) | |
35 | return 0; | |
36 | ||
37 | seq_printf(s, "epoch %d\n", client->monc.monmap->epoch); | |
38 | for (i = 0; i < client->monc.monmap->num_mon; i++) { | |
39 | struct ceph_entity_inst *inst = | |
40 | &client->monc.monmap->mon_inst[i]; | |
41 | ||
42 | seq_printf(s, "\t%s%lld\t%s\n", | |
43 | ENTITY_NAME(inst->name), | |
44 | pr_addr(&inst->addr.in_addr)); | |
45 | } | |
46 | return 0; | |
47 | } | |
48 | ||
49 | static int mdsmap_show(struct seq_file *s, void *p) | |
50 | { | |
51 | int i; | |
52 | struct ceph_client *client = s->private; | |
53 | ||
54 | if (client->mdsc.mdsmap == NULL) | |
55 | return 0; | |
56 | seq_printf(s, "epoch %d\n", client->mdsc.mdsmap->m_epoch); | |
57 | seq_printf(s, "root %d\n", client->mdsc.mdsmap->m_root); | |
58 | seq_printf(s, "session_timeout %d\n", | |
59 | client->mdsc.mdsmap->m_session_timeout); | |
60 | seq_printf(s, "session_autoclose %d\n", | |
61 | client->mdsc.mdsmap->m_session_autoclose); | |
62 | for (i = 0; i < client->mdsc.mdsmap->m_max_mds; i++) { | |
63 | struct ceph_entity_addr *addr = | |
64 | &client->mdsc.mdsmap->m_info[i].addr; | |
65 | int state = client->mdsc.mdsmap->m_info[i].state; | |
66 | ||
67 | seq_printf(s, "\tmds%d\t%s\t(%s)\n", i, pr_addr(&addr->in_addr), | |
68 | ceph_mds_state_name(state)); | |
69 | } | |
70 | return 0; | |
71 | } | |
72 | ||
73 | static int osdmap_show(struct seq_file *s, void *p) | |
74 | { | |
75 | int i; | |
76 | struct ceph_client *client = s->private; | |
77 | ||
78 | if (client->osdc.osdmap == NULL) | |
79 | return 0; | |
80 | seq_printf(s, "epoch %d\n", client->osdc.osdmap->epoch); | |
81 | seq_printf(s, "flags%s%s\n", | |
82 | (client->osdc.osdmap->flags & CEPH_OSDMAP_NEARFULL) ? | |
83 | " NEARFULL" : "", | |
84 | (client->osdc.osdmap->flags & CEPH_OSDMAP_FULL) ? | |
85 | " FULL" : ""); | |
86 | for (i = 0; i < client->osdc.osdmap->num_pools; i++) { | |
87 | struct ceph_pg_pool_info *pool = | |
88 | &client->osdc.osdmap->pg_pool[i]; | |
89 | seq_printf(s, "pg_pool %d pg_num %d / %d, lpg_num %d / %d\n", | |
90 | i, pool->v.pg_num, pool->pg_num_mask, | |
91 | pool->v.lpg_num, pool->lpg_num_mask); | |
92 | } | |
93 | for (i = 0; i < client->osdc.osdmap->max_osd; i++) { | |
94 | struct ceph_entity_addr *addr = | |
95 | &client->osdc.osdmap->osd_addr[i]; | |
96 | int state = client->osdc.osdmap->osd_state[i]; | |
97 | char sb[64]; | |
98 | ||
99 | seq_printf(s, "\tosd%d\t%s\t%3d%%\t(%s)\n", | |
100 | i, pr_addr(&addr->in_addr), | |
101 | ((client->osdc.osdmap->osd_weight[i]*100) >> 16), | |
102 | ceph_osdmap_state_str(sb, sizeof(sb), state)); | |
103 | } | |
104 | return 0; | |
105 | } | |
106 | ||
107 | static int monc_show(struct seq_file *s, void *p) | |
108 | { | |
109 | struct ceph_client *client = s->private; | |
110 | struct ceph_mon_statfs_request *req; | |
111 | u64 nexttid = 0; | |
112 | int got; | |
113 | struct ceph_mon_client *monc = &client->monc; | |
114 | ||
115 | mutex_lock(&monc->mutex); | |
116 | ||
117 | if (monc->have_mdsmap) | |
118 | seq_printf(s, "have mdsmap %u\n", (unsigned)monc->have_mdsmap); | |
119 | if (monc->have_osdmap) | |
120 | seq_printf(s, "have osdmap %u\n", (unsigned)monc->have_osdmap); | |
121 | if (monc->want_next_osdmap) | |
122 | seq_printf(s, "want next osdmap\n"); | |
123 | ||
124 | while (nexttid < monc->last_tid) { | |
125 | got = radix_tree_gang_lookup(&monc->statfs_request_tree, | |
126 | (void **)&req, nexttid, 1); | |
127 | if (got == 0) | |
128 | break; | |
129 | nexttid = req->tid + 1; | |
130 | ||
131 | seq_printf(s, "%lld statfs\n", req->tid); | |
132 | } | |
133 | mutex_unlock(&monc->mutex); | |
134 | ||
135 | return 0; | |
136 | } | |
137 | ||
138 | static int mdsc_show(struct seq_file *s, void *p) | |
139 | { | |
140 | struct ceph_client *client = s->private; | |
141 | struct ceph_mds_request *req; | |
142 | u64 nexttid = 0; | |
143 | int got; | |
144 | struct ceph_mds_client *mdsc = &client->mdsc; | |
145 | int pathlen; | |
146 | u64 pathbase; | |
147 | char *path; | |
148 | ||
149 | mutex_lock(&mdsc->mutex); | |
150 | while (nexttid < mdsc->last_tid) { | |
151 | got = radix_tree_gang_lookup(&mdsc->request_tree, | |
152 | (void **)&req, nexttid, 1); | |
153 | if (got == 0) | |
154 | break; | |
155 | nexttid = req->r_tid + 1; | |
156 | ||
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 | ||
213 | static 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 | ||
230 | seq_printf(s, "%lld\tosd%d\t", req->r_tid, | |
231 | req->r_osd ? req->r_osd->o_osd : -1); | |
232 | ||
233 | head = req->r_request->front.iov_base; | |
234 | op = (void *)(head + 1); | |
235 | ||
236 | num_ops = le16_to_cpu(head->num_ops); | |
237 | olen = le32_to_cpu(head->object_len); | |
238 | seq_printf(s, "%.*s", olen, | |
239 | (const char *)(head->ops + num_ops)); | |
240 | ||
241 | if (req->r_reassert_version.epoch) | |
242 | seq_printf(s, "\t%u'%llu", | |
243 | (unsigned)le32_to_cpu(req->r_reassert_version.epoch), | |
244 | le64_to_cpu(req->r_reassert_version.version)); | |
245 | else | |
246 | seq_printf(s, "\t"); | |
247 | ||
248 | for (i = 0; i < num_ops; i++) { | |
249 | opcode = le16_to_cpu(op->op); | |
250 | seq_printf(s, "\t%s", ceph_osd_op_name(opcode)); | |
251 | op++; | |
252 | } | |
253 | ||
254 | seq_printf(s, "\n"); | |
255 | } | |
256 | mutex_unlock(&osdc->request_mutex); | |
257 | return 0; | |
258 | } | |
259 | ||
260 | static int caps_show(struct seq_file *s, void *p) | |
261 | { | |
262 | struct ceph_client *client = p; | |
263 | int total, avail, used, reserved; | |
264 | ||
265 | ceph_reservation_status(client, &total, &avail, &used, &reserved); | |
266 | seq_printf(s, "total\t\t%d\n" | |
267 | "avail\t\t%d\n" | |
268 | "used\t\t%d\n" | |
269 | "reserved\t%d\n", | |
270 | total, avail, used, reserved); | |
271 | return 0; | |
272 | } | |
273 | ||
274 | static int dentry_lru_show(struct seq_file *s, void *ptr) | |
275 | { | |
276 | struct ceph_client *client = s->private; | |
277 | struct ceph_mds_client *mdsc = &client->mdsc; | |
278 | struct ceph_dentry_info *di; | |
279 | ||
280 | spin_lock(&mdsc->dentry_lru_lock); | |
281 | list_for_each_entry(di, &mdsc->dentry_lru, lru) { | |
282 | struct dentry *dentry = di->dentry; | |
283 | seq_printf(s, "%p %p\t%.*s\n", | |
284 | di, dentry, dentry->d_name.len, dentry->d_name.name); | |
285 | } | |
286 | spin_unlock(&mdsc->dentry_lru_lock); | |
287 | ||
288 | return 0; | |
289 | } | |
290 | ||
291 | #define DEFINE_SHOW_FUNC(name) \ | |
292 | static int name##_open(struct inode *inode, struct file *file) \ | |
293 | { \ | |
294 | struct seq_file *sf; \ | |
295 | int ret; \ | |
296 | \ | |
297 | ret = single_open(file, name, NULL); \ | |
298 | sf = file->private_data; \ | |
299 | sf->private = inode->i_private; \ | |
300 | return ret; \ | |
301 | } \ | |
302 | \ | |
303 | static const struct file_operations name##_fops = { \ | |
304 | .open = name##_open, \ | |
305 | .read = seq_read, \ | |
306 | .llseek = seq_lseek, \ | |
307 | .release = single_release, \ | |
308 | }; | |
309 | ||
310 | DEFINE_SHOW_FUNC(monmap_show) | |
311 | DEFINE_SHOW_FUNC(mdsmap_show) | |
312 | DEFINE_SHOW_FUNC(osdmap_show) | |
313 | DEFINE_SHOW_FUNC(monc_show) | |
314 | DEFINE_SHOW_FUNC(mdsc_show) | |
315 | DEFINE_SHOW_FUNC(osdc_show) | |
316 | DEFINE_SHOW_FUNC(dentry_lru_show) | |
317 | DEFINE_SHOW_FUNC(caps_show) | |
318 | ||
319 | int __init ceph_debugfs_init(void) | |
320 | { | |
321 | ceph_debugfs_dir = debugfs_create_dir("ceph", NULL); | |
322 | if (!ceph_debugfs_dir) | |
323 | return -ENOMEM; | |
324 | return 0; | |
325 | } | |
326 | ||
327 | void ceph_debugfs_cleanup(void) | |
328 | { | |
329 | debugfs_remove(ceph_debugfs_dir); | |
330 | } | |
331 | ||
332 | int ceph_debugfs_client_init(struct ceph_client *client) | |
333 | { | |
334 | int ret = 0; | |
335 | char name[80]; | |
336 | ||
337 | snprintf(name, sizeof(name), FSID_FORMAT ".client%lld", | |
338 | PR_FSID(&client->monc.monmap->fsid), client->whoami); | |
339 | ||
340 | client->debugfs_dir = debugfs_create_dir(name, ceph_debugfs_dir); | |
341 | if (!client->debugfs_dir) | |
342 | goto out; | |
343 | ||
344 | client->monc.debugfs_file = debugfs_create_file("monc", | |
345 | 0600, | |
346 | client->debugfs_dir, | |
347 | client, | |
348 | &monc_show_fops); | |
349 | if (!client->monc.debugfs_file) | |
350 | goto out; | |
351 | ||
352 | client->mdsc.debugfs_file = debugfs_create_file("mdsc", | |
353 | 0600, | |
354 | client->debugfs_dir, | |
355 | client, | |
356 | &mdsc_show_fops); | |
357 | if (!client->mdsc.debugfs_file) | |
358 | goto out; | |
359 | ||
360 | client->osdc.debugfs_file = debugfs_create_file("osdc", | |
361 | 0600, | |
362 | client->debugfs_dir, | |
363 | client, | |
364 | &osdc_show_fops); | |
365 | if (!client->osdc.debugfs_file) | |
366 | goto out; | |
367 | ||
368 | client->debugfs_monmap = debugfs_create_file("monmap", | |
369 | 0600, | |
370 | client->debugfs_dir, | |
371 | client, | |
372 | &monmap_show_fops); | |
373 | if (!client->debugfs_monmap) | |
374 | goto out; | |
375 | ||
376 | client->debugfs_mdsmap = debugfs_create_file("mdsmap", | |
377 | 0600, | |
378 | client->debugfs_dir, | |
379 | client, | |
380 | &mdsmap_show_fops); | |
381 | if (!client->debugfs_mdsmap) | |
382 | goto out; | |
383 | ||
384 | client->debugfs_osdmap = debugfs_create_file("osdmap", | |
385 | 0600, | |
386 | client->debugfs_dir, | |
387 | client, | |
388 | &osdmap_show_fops); | |
389 | if (!client->debugfs_osdmap) | |
390 | goto out; | |
391 | ||
392 | client->debugfs_dentry_lru = debugfs_create_file("dentry_lru", | |
393 | 0600, | |
394 | client->debugfs_dir, | |
395 | client, | |
396 | &dentry_lru_show_fops); | |
397 | if (!client->debugfs_dentry_lru) | |
398 | goto out; | |
399 | ||
400 | client->debugfs_caps = debugfs_create_file("caps", | |
401 | 0400, | |
402 | client->debugfs_dir, | |
403 | client, | |
404 | &caps_show_fops); | |
405 | if (!client->debugfs_caps) | |
406 | goto out; | |
407 | ||
408 | return 0; | |
409 | ||
410 | out: | |
411 | ceph_debugfs_client_cleanup(client); | |
412 | return ret; | |
413 | } | |
414 | ||
415 | void ceph_debugfs_client_cleanup(struct ceph_client *client) | |
416 | { | |
417 | debugfs_remove(client->debugfs_caps); | |
418 | debugfs_remove(client->debugfs_dentry_lru); | |
419 | debugfs_remove(client->debugfs_osdmap); | |
420 | debugfs_remove(client->debugfs_mdsmap); | |
421 | debugfs_remove(client->debugfs_monmap); | |
422 | debugfs_remove(client->osdc.debugfs_file); | |
423 | debugfs_remove(client->mdsc.debugfs_file); | |
424 | debugfs_remove(client->monc.debugfs_file); | |
425 | debugfs_remove(client->debugfs_dir); | |
426 | } | |
427 | ||
039934b8 SW |
428 | #else // CONFIG_DEBUG_FS |
429 | ||
430 | int __init ceph_debugfs_init(void) | |
431 | { | |
432 | return 0; | |
433 | } | |
434 | ||
435 | void ceph_debugfs_cleanup(void) | |
436 | { | |
437 | } | |
438 | ||
439 | int ceph_debugfs_client_init(struct ceph_client *client) | |
440 | { | |
441 | return 0; | |
442 | } | |
443 | ||
444 | void ceph_debugfs_client_cleanup(struct ceph_client *client) | |
445 | { | |
446 | } | |
447 | ||
448 | #endif // CONFIG_DEBUG_FS |