ceph: debugfs
[deliverable/linux.git] / fs / ceph / debugfs.c
CommitLineData
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
11/*
12 * Implement /sys/kernel/debug/ceph fun
13 *
14 * /sys/kernel/debug/ceph/client* - an instance of the ceph client
15 * .../osdmap - current osdmap
16 * .../mdsmap - current mdsmap
17 * .../monmap - current monmap
18 * .../osdc - active osd requests
19 * .../mdsc - active mds requests
20 * .../monc - mon client state
21 * .../dentry_lru - dump contents of dentry lru
22 * .../caps - expose cap (reservation) stats
23 */
24
25static struct dentry *ceph_debugfs_dir;
26
27static int monmap_show(struct seq_file *s, void *p)
28{
29 int i;
30 struct ceph_client *client = s->private;
31
32 if (client->monc.monmap == NULL)
33 return 0;
34
35 seq_printf(s, "epoch %d\n", client->monc.monmap->epoch);
36 for (i = 0; i < client->monc.monmap->num_mon; i++) {
37 struct ceph_entity_inst *inst =
38 &client->monc.monmap->mon_inst[i];
39
40 seq_printf(s, "\t%s%lld\t%s\n",
41 ENTITY_NAME(inst->name),
42 pr_addr(&inst->addr.in_addr));
43 }
44 return 0;
45}
46
47static int mdsmap_show(struct seq_file *s, void *p)
48{
49 int i;
50 struct ceph_client *client = s->private;
51
52 if (client->mdsc.mdsmap == NULL)
53 return 0;
54 seq_printf(s, "epoch %d\n", client->mdsc.mdsmap->m_epoch);
55 seq_printf(s, "root %d\n", client->mdsc.mdsmap->m_root);
56 seq_printf(s, "session_timeout %d\n",
57 client->mdsc.mdsmap->m_session_timeout);
58 seq_printf(s, "session_autoclose %d\n",
59 client->mdsc.mdsmap->m_session_autoclose);
60 for (i = 0; i < client->mdsc.mdsmap->m_max_mds; i++) {
61 struct ceph_entity_addr *addr =
62 &client->mdsc.mdsmap->m_info[i].addr;
63 int state = client->mdsc.mdsmap->m_info[i].state;
64
65 seq_printf(s, "\tmds%d\t%s\t(%s)\n", i, pr_addr(&addr->in_addr),
66 ceph_mds_state_name(state));
67 }
68 return 0;
69}
70
71static int osdmap_show(struct seq_file *s, void *p)
72{
73 int i;
74 struct ceph_client *client = s->private;
75
76 if (client->osdc.osdmap == NULL)
77 return 0;
78 seq_printf(s, "epoch %d\n", client->osdc.osdmap->epoch);
79 seq_printf(s, "flags%s%s\n",
80 (client->osdc.osdmap->flags & CEPH_OSDMAP_NEARFULL) ?
81 " NEARFULL" : "",
82 (client->osdc.osdmap->flags & CEPH_OSDMAP_FULL) ?
83 " FULL" : "");
84 for (i = 0; i < client->osdc.osdmap->num_pools; i++) {
85 struct ceph_pg_pool_info *pool =
86 &client->osdc.osdmap->pg_pool[i];
87 seq_printf(s, "pg_pool %d pg_num %d / %d, lpg_num %d / %d\n",
88 i, pool->v.pg_num, pool->pg_num_mask,
89 pool->v.lpg_num, pool->lpg_num_mask);
90 }
91 for (i = 0; i < client->osdc.osdmap->max_osd; i++) {
92 struct ceph_entity_addr *addr =
93 &client->osdc.osdmap->osd_addr[i];
94 int state = client->osdc.osdmap->osd_state[i];
95 char sb[64];
96
97 seq_printf(s, "\tosd%d\t%s\t%3d%%\t(%s)\n",
98 i, pr_addr(&addr->in_addr),
99 ((client->osdc.osdmap->osd_weight[i]*100) >> 16),
100 ceph_osdmap_state_str(sb, sizeof(sb), state));
101 }
102 return 0;
103}
104
105static int monc_show(struct seq_file *s, void *p)
106{
107 struct ceph_client *client = s->private;
108 struct ceph_mon_statfs_request *req;
109 u64 nexttid = 0;
110 int got;
111 struct ceph_mon_client *monc = &client->monc;
112
113 mutex_lock(&monc->mutex);
114
115 if (monc->have_mdsmap)
116 seq_printf(s, "have mdsmap %u\n", (unsigned)monc->have_mdsmap);
117 if (monc->have_osdmap)
118 seq_printf(s, "have osdmap %u\n", (unsigned)monc->have_osdmap);
119 if (monc->want_next_osdmap)
120 seq_printf(s, "want next osdmap\n");
121
122 while (nexttid < monc->last_tid) {
123 got = radix_tree_gang_lookup(&monc->statfs_request_tree,
124 (void **)&req, nexttid, 1);
125 if (got == 0)
126 break;
127 nexttid = req->tid + 1;
128
129 seq_printf(s, "%lld statfs\n", req->tid);
130 }
131 mutex_unlock(&monc->mutex);
132
133 return 0;
134}
135
136static int mdsc_show(struct seq_file *s, void *p)
137{
138 struct ceph_client *client = s->private;
139 struct ceph_mds_request *req;
140 u64 nexttid = 0;
141 int got;
142 struct ceph_mds_client *mdsc = &client->mdsc;
143 int pathlen;
144 u64 pathbase;
145 char *path;
146
147 mutex_lock(&mdsc->mutex);
148 while (nexttid < mdsc->last_tid) {
149 got = radix_tree_gang_lookup(&mdsc->request_tree,
150 (void **)&req, nexttid, 1);
151 if (got == 0)
152 break;
153 nexttid = req->r_tid + 1;
154
155 if (req->r_request)
156 seq_printf(s, "%lld\tmds%d\t", req->r_tid, req->r_mds);
157 else
158 seq_printf(s, "%lld\t(no request)\t", req->r_tid);
159
160 seq_printf(s, "%s", ceph_mds_op_name(req->r_op));
161
162 if (req->r_got_unsafe)
163 seq_printf(s, "\t(unsafe)");
164 else
165 seq_printf(s, "\t");
166
167 if (req->r_inode) {
168 seq_printf(s, " #%llx", ceph_ino(req->r_inode));
169 } else if (req->r_dentry) {
170 path = ceph_mdsc_build_path(req->r_dentry, &pathlen,
171 &pathbase, 0);
172 spin_lock(&req->r_dentry->d_lock);
173 seq_printf(s, " #%llx/%.*s (%s)",
174 ceph_ino(req->r_dentry->d_parent->d_inode),
175 req->r_dentry->d_name.len,
176 req->r_dentry->d_name.name,
177 path ? path : "");
178 spin_unlock(&req->r_dentry->d_lock);
179 kfree(path);
180 } else if (req->r_path1) {
181 seq_printf(s, " #%llx/%s", req->r_ino1.ino,
182 req->r_path1);
183 }
184
185 if (req->r_old_dentry) {
186 path = ceph_mdsc_build_path(req->r_old_dentry, &pathlen,
187 &pathbase, 0);
188 spin_lock(&req->r_old_dentry->d_lock);
189 seq_printf(s, " #%llx/%.*s (%s)",
190 ceph_ino(req->r_old_dentry->d_parent->d_inode),
191 req->r_old_dentry->d_name.len,
192 req->r_old_dentry->d_name.name,
193 path ? path : "");
194 spin_unlock(&req->r_old_dentry->d_lock);
195 kfree(path);
196 } else if (req->r_path2) {
197 if (req->r_ino2.ino)
198 seq_printf(s, " #%llx/%s", req->r_ino2.ino,
199 req->r_path2);
200 else
201 seq_printf(s, " %s", req->r_path2);
202 }
203
204 seq_printf(s, "\n");
205 }
206 mutex_unlock(&mdsc->mutex);
207
208 return 0;
209}
210
211static int osdc_show(struct seq_file *s, void *pp)
212{
213 struct ceph_client *client = s->private;
214 struct ceph_osd_client *osdc = &client->osdc;
215 struct rb_node *p;
216
217 mutex_lock(&osdc->request_mutex);
218 for (p = rb_first(&osdc->requests); p; p = rb_next(p)) {
219 struct ceph_osd_request *req;
220 struct ceph_osd_request_head *head;
221 struct ceph_osd_op *op;
222 int num_ops;
223 int opcode, olen;
224 int i;
225
226 req = rb_entry(p, struct ceph_osd_request, r_node);
227
228 seq_printf(s, "%lld\tosd%d\t", req->r_tid,
229 req->r_osd ? req->r_osd->o_osd : -1);
230
231 head = req->r_request->front.iov_base;
232 op = (void *)(head + 1);
233
234 num_ops = le16_to_cpu(head->num_ops);
235 olen = le32_to_cpu(head->object_len);
236 seq_printf(s, "%.*s", olen,
237 (const char *)(head->ops + num_ops));
238
239 if (req->r_reassert_version.epoch)
240 seq_printf(s, "\t%u'%llu",
241 (unsigned)le32_to_cpu(req->r_reassert_version.epoch),
242 le64_to_cpu(req->r_reassert_version.version));
243 else
244 seq_printf(s, "\t");
245
246 for (i = 0; i < num_ops; i++) {
247 opcode = le16_to_cpu(op->op);
248 seq_printf(s, "\t%s", ceph_osd_op_name(opcode));
249 op++;
250 }
251
252 seq_printf(s, "\n");
253 }
254 mutex_unlock(&osdc->request_mutex);
255 return 0;
256}
257
258static int caps_show(struct seq_file *s, void *p)
259{
260 struct ceph_client *client = p;
261 int total, avail, used, reserved;
262
263 ceph_reservation_status(client, &total, &avail, &used, &reserved);
264 seq_printf(s, "total\t\t%d\n"
265 "avail\t\t%d\n"
266 "used\t\t%d\n"
267 "reserved\t%d\n",
268 total, avail, used, reserved);
269 return 0;
270}
271
272static int dentry_lru_show(struct seq_file *s, void *ptr)
273{
274 struct ceph_client *client = s->private;
275 struct ceph_mds_client *mdsc = &client->mdsc;
276 struct ceph_dentry_info *di;
277
278 spin_lock(&mdsc->dentry_lru_lock);
279 list_for_each_entry(di, &mdsc->dentry_lru, lru) {
280 struct dentry *dentry = di->dentry;
281 seq_printf(s, "%p %p\t%.*s\n",
282 di, dentry, dentry->d_name.len, dentry->d_name.name);
283 }
284 spin_unlock(&mdsc->dentry_lru_lock);
285
286 return 0;
287}
288
289#define DEFINE_SHOW_FUNC(name) \
290static int name##_open(struct inode *inode, struct file *file) \
291{ \
292 struct seq_file *sf; \
293 int ret; \
294 \
295 ret = single_open(file, name, NULL); \
296 sf = file->private_data; \
297 sf->private = inode->i_private; \
298 return ret; \
299} \
300 \
301static const struct file_operations name##_fops = { \
302 .open = name##_open, \
303 .read = seq_read, \
304 .llseek = seq_lseek, \
305 .release = single_release, \
306};
307
308DEFINE_SHOW_FUNC(monmap_show)
309DEFINE_SHOW_FUNC(mdsmap_show)
310DEFINE_SHOW_FUNC(osdmap_show)
311DEFINE_SHOW_FUNC(monc_show)
312DEFINE_SHOW_FUNC(mdsc_show)
313DEFINE_SHOW_FUNC(osdc_show)
314DEFINE_SHOW_FUNC(dentry_lru_show)
315DEFINE_SHOW_FUNC(caps_show)
316
317int __init ceph_debugfs_init(void)
318{
319 ceph_debugfs_dir = debugfs_create_dir("ceph", NULL);
320 if (!ceph_debugfs_dir)
321 return -ENOMEM;
322 return 0;
323}
324
325void ceph_debugfs_cleanup(void)
326{
327 debugfs_remove(ceph_debugfs_dir);
328}
329
330int ceph_debugfs_client_init(struct ceph_client *client)
331{
332 int ret = 0;
333 char name[80];
334
335 snprintf(name, sizeof(name), FSID_FORMAT ".client%lld",
336 PR_FSID(&client->monc.monmap->fsid), client->whoami);
337
338 client->debugfs_dir = debugfs_create_dir(name, ceph_debugfs_dir);
339 if (!client->debugfs_dir)
340 goto out;
341
342 client->monc.debugfs_file = debugfs_create_file("monc",
343 0600,
344 client->debugfs_dir,
345 client,
346 &monc_show_fops);
347 if (!client->monc.debugfs_file)
348 goto out;
349
350 client->mdsc.debugfs_file = debugfs_create_file("mdsc",
351 0600,
352 client->debugfs_dir,
353 client,
354 &mdsc_show_fops);
355 if (!client->mdsc.debugfs_file)
356 goto out;
357
358 client->osdc.debugfs_file = debugfs_create_file("osdc",
359 0600,
360 client->debugfs_dir,
361 client,
362 &osdc_show_fops);
363 if (!client->osdc.debugfs_file)
364 goto out;
365
366 client->debugfs_monmap = debugfs_create_file("monmap",
367 0600,
368 client->debugfs_dir,
369 client,
370 &monmap_show_fops);
371 if (!client->debugfs_monmap)
372 goto out;
373
374 client->debugfs_mdsmap = debugfs_create_file("mdsmap",
375 0600,
376 client->debugfs_dir,
377 client,
378 &mdsmap_show_fops);
379 if (!client->debugfs_mdsmap)
380 goto out;
381
382 client->debugfs_osdmap = debugfs_create_file("osdmap",
383 0600,
384 client->debugfs_dir,
385 client,
386 &osdmap_show_fops);
387 if (!client->debugfs_osdmap)
388 goto out;
389
390 client->debugfs_dentry_lru = debugfs_create_file("dentry_lru",
391 0600,
392 client->debugfs_dir,
393 client,
394 &dentry_lru_show_fops);
395 if (!client->debugfs_dentry_lru)
396 goto out;
397
398 client->debugfs_caps = debugfs_create_file("caps",
399 0400,
400 client->debugfs_dir,
401 client,
402 &caps_show_fops);
403 if (!client->debugfs_caps)
404 goto out;
405
406 return 0;
407
408out:
409 ceph_debugfs_client_cleanup(client);
410 return ret;
411}
412
413void ceph_debugfs_client_cleanup(struct ceph_client *client)
414{
415 debugfs_remove(client->debugfs_caps);
416 debugfs_remove(client->debugfs_dentry_lru);
417 debugfs_remove(client->debugfs_osdmap);
418 debugfs_remove(client->debugfs_mdsmap);
419 debugfs_remove(client->debugfs_monmap);
420 debugfs_remove(client->osdc.debugfs_file);
421 debugfs_remove(client->mdsc.debugfs_file);
422 debugfs_remove(client->monc.debugfs_file);
423 debugfs_remove(client->debugfs_dir);
424}
425
This page took 0.043739 seconds and 5 git commands to generate.