agp/intel: Use the correct mask to detect i830 aperture size.
[linux/fpc-iii.git] / fs / ceph / debugfs.c
blob3be33fb066cc5f1ada8be5ebb50115c5dc9c9a7e
1 #include "ceph_debug.h"
3 #include <linux/device.h>
4 #include <linux/slab.h>
5 #include <linux/module.h>
6 #include <linux/ctype.h>
7 #include <linux/debugfs.h>
8 #include <linux/seq_file.h>
10 #include "super.h"
11 #include "mds_client.h"
12 #include "mon_client.h"
13 #include "auth.h"
15 #ifdef CONFIG_DEBUG_FS
18 * Implement /sys/kernel/debug/ceph fun
20 * /sys/kernel/debug/ceph/client* - an instance of the ceph client
21 * .../osdmap - current osdmap
22 * .../mdsmap - current mdsmap
23 * .../monmap - current monmap
24 * .../osdc - active osd requests
25 * .../mdsc - active mds requests
26 * .../monc - mon client state
27 * .../dentry_lru - dump contents of dentry lru
28 * .../caps - expose cap (reservation) stats
29 * .../bdi - symlink to ../../bdi/something
32 static struct dentry *ceph_debugfs_dir;
34 static int monmap_show(struct seq_file *s, void *p)
36 int i;
37 struct ceph_client *client = s->private;
39 if (client->monc.monmap == NULL)
40 return 0;
42 seq_printf(s, "epoch %d\n", client->monc.monmap->epoch);
43 for (i = 0; i < client->monc.monmap->num_mon; i++) {
44 struct ceph_entity_inst *inst =
45 &client->monc.monmap->mon_inst[i];
47 seq_printf(s, "\t%s%lld\t%s\n",
48 ENTITY_NAME(inst->name),
49 pr_addr(&inst->addr.in_addr));
51 return 0;
54 static int mdsmap_show(struct seq_file *s, void *p)
56 int i;
57 struct ceph_client *client = s->private;
59 if (client->mdsc.mdsmap == NULL)
60 return 0;
61 seq_printf(s, "epoch %d\n", client->mdsc.mdsmap->m_epoch);
62 seq_printf(s, "root %d\n", client->mdsc.mdsmap->m_root);
63 seq_printf(s, "session_timeout %d\n",
64 client->mdsc.mdsmap->m_session_timeout);
65 seq_printf(s, "session_autoclose %d\n",
66 client->mdsc.mdsmap->m_session_autoclose);
67 for (i = 0; i < client->mdsc.mdsmap->m_max_mds; i++) {
68 struct ceph_entity_addr *addr =
69 &client->mdsc.mdsmap->m_info[i].addr;
70 int state = client->mdsc.mdsmap->m_info[i].state;
72 seq_printf(s, "\tmds%d\t%s\t(%s)\n", i, pr_addr(&addr->in_addr),
73 ceph_mds_state_name(state));
75 return 0;
78 static int osdmap_show(struct seq_file *s, void *p)
80 int i;
81 struct ceph_client *client = s->private;
82 struct rb_node *n;
84 if (client->osdc.osdmap == NULL)
85 return 0;
86 seq_printf(s, "epoch %d\n", client->osdc.osdmap->epoch);
87 seq_printf(s, "flags%s%s\n",
88 (client->osdc.osdmap->flags & CEPH_OSDMAP_NEARFULL) ?
89 " NEARFULL" : "",
90 (client->osdc.osdmap->flags & CEPH_OSDMAP_FULL) ?
91 " FULL" : "");
92 for (n = rb_first(&client->osdc.osdmap->pg_pools); n; n = rb_next(n)) {
93 struct ceph_pg_pool_info *pool =
94 rb_entry(n, struct ceph_pg_pool_info, node);
95 seq_printf(s, "pg_pool %d pg_num %d / %d, lpg_num %d / %d\n",
96 pool->id, pool->v.pg_num, pool->pg_num_mask,
97 pool->v.lpg_num, pool->lpg_num_mask);
99 for (i = 0; i < client->osdc.osdmap->max_osd; i++) {
100 struct ceph_entity_addr *addr =
101 &client->osdc.osdmap->osd_addr[i];
102 int state = client->osdc.osdmap->osd_state[i];
103 char sb[64];
105 seq_printf(s, "\tosd%d\t%s\t%3d%%\t(%s)\n",
106 i, pr_addr(&addr->in_addr),
107 ((client->osdc.osdmap->osd_weight[i]*100) >> 16),
108 ceph_osdmap_state_str(sb, sizeof(sb), state));
110 return 0;
113 static int monc_show(struct seq_file *s, void *p)
115 struct ceph_client *client = s->private;
116 struct ceph_mon_generic_request *req;
117 struct ceph_mon_client *monc = &client->monc;
118 struct rb_node *rp;
120 mutex_lock(&monc->mutex);
122 if (monc->have_mdsmap)
123 seq_printf(s, "have mdsmap %u\n", (unsigned)monc->have_mdsmap);
124 if (monc->have_osdmap)
125 seq_printf(s, "have osdmap %u\n", (unsigned)monc->have_osdmap);
126 if (monc->want_next_osdmap)
127 seq_printf(s, "want next osdmap\n");
129 for (rp = rb_first(&monc->generic_request_tree); rp; rp = rb_next(rp)) {
130 __u16 op;
131 req = rb_entry(rp, struct ceph_mon_generic_request, node);
132 op = le16_to_cpu(req->request->hdr.type);
133 if (op == CEPH_MSG_STATFS)
134 seq_printf(s, "%lld statfs\n", req->tid);
135 else
136 seq_printf(s, "%lld unknown\n", req->tid);
139 mutex_unlock(&monc->mutex);
140 return 0;
143 static int mdsc_show(struct seq_file *s, void *p)
145 struct ceph_client *client = s->private;
146 struct ceph_mds_client *mdsc = &client->mdsc;
147 struct ceph_mds_request *req;
148 struct rb_node *rp;
149 int pathlen;
150 u64 pathbase;
151 char *path;
153 mutex_lock(&mdsc->mutex);
154 for (rp = rb_first(&mdsc->request_tree); rp; rp = rb_next(rp)) {
155 req = rb_entry(rp, struct ceph_mds_request, r_node);
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);
162 seq_printf(s, "%s", ceph_mds_op_name(req->r_op));
164 if (req->r_got_unsafe)
165 seq_printf(s, "\t(unsafe)");
166 else
167 seq_printf(s, "\t");
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);
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);
206 seq_printf(s, "\n");
208 mutex_unlock(&mdsc->mutex);
210 return 0;
213 static int osdc_show(struct seq_file *s, void *pp)
215 struct ceph_client *client = s->private;
216 struct ceph_osd_client *osdc = &client->osdc;
217 struct rb_node *p;
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;
228 req = rb_entry(p, struct ceph_osd_request, r_node);
230 seq_printf(s, "%lld\tosd%d\t%d.%x\t", req->r_tid,
231 req->r_osd ? req->r_osd->o_osd : -1,
232 le32_to_cpu(req->r_pgid.pool),
233 le16_to_cpu(req->r_pgid.ps));
235 head = req->r_request->front.iov_base;
236 op = (void *)(head + 1);
238 num_ops = le16_to_cpu(head->num_ops);
239 olen = le32_to_cpu(head->object_len);
240 seq_printf(s, "%.*s", olen,
241 (const char *)(head->ops + num_ops));
243 if (req->r_reassert_version.epoch)
244 seq_printf(s, "\t%u'%llu",
245 (unsigned)le32_to_cpu(req->r_reassert_version.epoch),
246 le64_to_cpu(req->r_reassert_version.version));
247 else
248 seq_printf(s, "\t");
250 for (i = 0; i < num_ops; i++) {
251 opcode = le16_to_cpu(op->op);
252 seq_printf(s, "\t%s", ceph_osd_op_name(opcode));
253 op++;
256 seq_printf(s, "\n");
258 mutex_unlock(&osdc->request_mutex);
259 return 0;
262 static int caps_show(struct seq_file *s, void *p)
264 struct ceph_client *client = p;
265 int total, avail, used, reserved, min;
267 ceph_reservation_status(client, &total, &avail, &used, &reserved, &min);
268 seq_printf(s, "total\t\t%d\n"
269 "avail\t\t%d\n"
270 "used\t\t%d\n"
271 "reserved\t%d\n"
272 "min\t%d\n",
273 total, avail, used, reserved, min);
274 return 0;
277 static int dentry_lru_show(struct seq_file *s, void *ptr)
279 struct ceph_client *client = s->private;
280 struct ceph_mds_client *mdsc = &client->mdsc;
281 struct ceph_dentry_info *di;
283 spin_lock(&mdsc->dentry_lru_lock);
284 list_for_each_entry(di, &mdsc->dentry_lru, lru) {
285 struct dentry *dentry = di->dentry;
286 seq_printf(s, "%p %p\t%.*s\n",
287 di, dentry, dentry->d_name.len, dentry->d_name.name);
289 spin_unlock(&mdsc->dentry_lru_lock);
291 return 0;
294 #define DEFINE_SHOW_FUNC(name) \
295 static int name##_open(struct inode *inode, struct file *file) \
297 struct seq_file *sf; \
298 int ret; \
300 ret = single_open(file, name, NULL); \
301 sf = file->private_data; \
302 sf->private = inode->i_private; \
303 return ret; \
306 static const struct file_operations name##_fops = { \
307 .open = name##_open, \
308 .read = seq_read, \
309 .llseek = seq_lseek, \
310 .release = single_release, \
313 DEFINE_SHOW_FUNC(monmap_show)
314 DEFINE_SHOW_FUNC(mdsmap_show)
315 DEFINE_SHOW_FUNC(osdmap_show)
316 DEFINE_SHOW_FUNC(monc_show)
317 DEFINE_SHOW_FUNC(mdsc_show)
318 DEFINE_SHOW_FUNC(osdc_show)
319 DEFINE_SHOW_FUNC(dentry_lru_show)
320 DEFINE_SHOW_FUNC(caps_show)
322 static int congestion_kb_set(void *data, u64 val)
324 struct ceph_client *client = (struct ceph_client *)data;
326 if (client)
327 client->mount_args->congestion_kb = (int)val;
329 return 0;
332 static int congestion_kb_get(void *data, u64 *val)
334 struct ceph_client *client = (struct ceph_client *)data;
336 if (client)
337 *val = (u64)client->mount_args->congestion_kb;
339 return 0;
343 DEFINE_SIMPLE_ATTRIBUTE(congestion_kb_fops, congestion_kb_get,
344 congestion_kb_set, "%llu\n");
346 int __init ceph_debugfs_init(void)
348 ceph_debugfs_dir = debugfs_create_dir("ceph", NULL);
349 if (!ceph_debugfs_dir)
350 return -ENOMEM;
351 return 0;
354 void ceph_debugfs_cleanup(void)
356 debugfs_remove(ceph_debugfs_dir);
359 int ceph_debugfs_client_init(struct ceph_client *client)
361 int ret = 0;
362 char name[80];
364 snprintf(name, sizeof(name), FSID_FORMAT ".client%lld",
365 PR_FSID(&client->fsid), client->monc.auth->global_id);
367 client->debugfs_dir = debugfs_create_dir(name, ceph_debugfs_dir);
368 if (!client->debugfs_dir)
369 goto out;
371 client->monc.debugfs_file = debugfs_create_file("monc",
372 0600,
373 client->debugfs_dir,
374 client,
375 &monc_show_fops);
376 if (!client->monc.debugfs_file)
377 goto out;
379 client->mdsc.debugfs_file = debugfs_create_file("mdsc",
380 0600,
381 client->debugfs_dir,
382 client,
383 &mdsc_show_fops);
384 if (!client->mdsc.debugfs_file)
385 goto out;
387 client->osdc.debugfs_file = debugfs_create_file("osdc",
388 0600,
389 client->debugfs_dir,
390 client,
391 &osdc_show_fops);
392 if (!client->osdc.debugfs_file)
393 goto out;
395 client->debugfs_monmap = debugfs_create_file("monmap",
396 0600,
397 client->debugfs_dir,
398 client,
399 &monmap_show_fops);
400 if (!client->debugfs_monmap)
401 goto out;
403 client->debugfs_mdsmap = debugfs_create_file("mdsmap",
404 0600,
405 client->debugfs_dir,
406 client,
407 &mdsmap_show_fops);
408 if (!client->debugfs_mdsmap)
409 goto out;
411 client->debugfs_osdmap = debugfs_create_file("osdmap",
412 0600,
413 client->debugfs_dir,
414 client,
415 &osdmap_show_fops);
416 if (!client->debugfs_osdmap)
417 goto out;
419 client->debugfs_dentry_lru = debugfs_create_file("dentry_lru",
420 0600,
421 client->debugfs_dir,
422 client,
423 &dentry_lru_show_fops);
424 if (!client->debugfs_dentry_lru)
425 goto out;
427 client->debugfs_caps = debugfs_create_file("caps",
428 0400,
429 client->debugfs_dir,
430 client,
431 &caps_show_fops);
432 if (!client->debugfs_caps)
433 goto out;
435 client->debugfs_congestion_kb = debugfs_create_file("writeback_congestion_kb",
436 0600,
437 client->debugfs_dir,
438 client,
439 &congestion_kb_fops);
440 if (!client->debugfs_congestion_kb)
441 goto out;
443 sprintf(name, "../../bdi/%s", dev_name(client->sb->s_bdi->dev));
444 client->debugfs_bdi = debugfs_create_symlink("bdi", client->debugfs_dir,
445 name);
447 return 0;
449 out:
450 ceph_debugfs_client_cleanup(client);
451 return ret;
454 void ceph_debugfs_client_cleanup(struct ceph_client *client)
456 debugfs_remove(client->debugfs_bdi);
457 debugfs_remove(client->debugfs_caps);
458 debugfs_remove(client->debugfs_dentry_lru);
459 debugfs_remove(client->debugfs_osdmap);
460 debugfs_remove(client->debugfs_mdsmap);
461 debugfs_remove(client->debugfs_monmap);
462 debugfs_remove(client->osdc.debugfs_file);
463 debugfs_remove(client->mdsc.debugfs_file);
464 debugfs_remove(client->monc.debugfs_file);
465 debugfs_remove(client->debugfs_congestion_kb);
466 debugfs_remove(client->debugfs_dir);
469 #else // CONFIG_DEBUG_FS
471 int __init ceph_debugfs_init(void)
473 return 0;
476 void ceph_debugfs_cleanup(void)
480 int ceph_debugfs_client_init(struct ceph_client *client)
482 return 0;
485 void ceph_debugfs_client_cleanup(struct ceph_client *client)
489 #endif // CONFIG_DEBUG_FS