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>
11 #include "mds_client.h"
12 #include "mon_client.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
)
37 struct ceph_client
*client
= s
->private;
39 if (client
->monc
.monmap
== NULL
)
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
));
54 static int mdsmap_show(struct seq_file
*s
, void *p
)
57 struct ceph_client
*client
= s
->private;
59 if (client
->mdsc
.mdsmap
== NULL
)
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
));
78 static int osdmap_show(struct seq_file
*s
, void *p
)
81 struct ceph_client
*client
= s
->private;
84 if (client
->osdc
.osdmap
== NULL
)
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
) ?
90 (client
->osdc
.osdmap
->flags
& CEPH_OSDMAP_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
];
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
));
113 static int monc_show(struct seq_file
*s
, void *p
)
115 struct ceph_client
*client
= s
->private;
116 struct ceph_mon_statfs_request
*req
;
117 struct ceph_mon_client
*monc
= &client
->monc
;
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
->statfs_request_tree
); rp
; rp
= rb_next(rp
)) {
130 req
= rb_entry(rp
, struct ceph_mon_statfs_request
, node
);
131 seq_printf(s
, "%lld statfs\n", req
->tid
);
134 mutex_unlock(&monc
->mutex
);
138 static int mdsc_show(struct seq_file
*s
, void *p
)
140 struct ceph_client
*client
= s
->private;
141 struct ceph_mds_client
*mdsc
= &client
->mdsc
;
142 struct ceph_mds_request
*req
;
148 mutex_lock(&mdsc
->mutex
);
149 for (rp
= rb_first(&mdsc
->request_tree
); rp
; rp
= rb_next(rp
)) {
150 req
= rb_entry(rp
, struct ceph_mds_request
, r_node
);
153 seq_printf(s
, "%lld\tmds%d\t", req
->r_tid
, req
->r_mds
);
155 seq_printf(s
, "%lld\t(no request)\t", req
->r_tid
);
157 seq_printf(s
, "%s", ceph_mds_op_name(req
->r_op
));
159 if (req
->r_got_unsafe
)
160 seq_printf(s
, "\t(unsafe)");
165 seq_printf(s
, " #%llx", ceph_ino(req
->r_inode
));
166 } else if (req
->r_dentry
) {
167 path
= ceph_mdsc_build_path(req
->r_dentry
, &pathlen
,
169 spin_lock(&req
->r_dentry
->d_lock
);
170 seq_printf(s
, " #%llx/%.*s (%s)",
171 ceph_ino(req
->r_dentry
->d_parent
->d_inode
),
172 req
->r_dentry
->d_name
.len
,
173 req
->r_dentry
->d_name
.name
,
175 spin_unlock(&req
->r_dentry
->d_lock
);
177 } else if (req
->r_path1
) {
178 seq_printf(s
, " #%llx/%s", req
->r_ino1
.ino
,
182 if (req
->r_old_dentry
) {
183 path
= ceph_mdsc_build_path(req
->r_old_dentry
, &pathlen
,
185 spin_lock(&req
->r_old_dentry
->d_lock
);
186 seq_printf(s
, " #%llx/%.*s (%s)",
187 ceph_ino(req
->r_old_dentry
->d_parent
->d_inode
),
188 req
->r_old_dentry
->d_name
.len
,
189 req
->r_old_dentry
->d_name
.name
,
191 spin_unlock(&req
->r_old_dentry
->d_lock
);
193 } else if (req
->r_path2
) {
195 seq_printf(s
, " #%llx/%s", req
->r_ino2
.ino
,
198 seq_printf(s
, " %s", req
->r_path2
);
203 mutex_unlock(&mdsc
->mutex
);
208 static int osdc_show(struct seq_file
*s
, void *pp
)
210 struct ceph_client
*client
= s
->private;
211 struct ceph_osd_client
*osdc
= &client
->osdc
;
214 mutex_lock(&osdc
->request_mutex
);
215 for (p
= rb_first(&osdc
->requests
); p
; p
= rb_next(p
)) {
216 struct ceph_osd_request
*req
;
217 struct ceph_osd_request_head
*head
;
218 struct ceph_osd_op
*op
;
223 req
= rb_entry(p
, struct ceph_osd_request
, r_node
);
225 seq_printf(s
, "%lld\tosd%d\t%d.%x\t", req
->r_tid
,
226 req
->r_osd
? req
->r_osd
->o_osd
: -1,
227 le32_to_cpu(req
->r_pgid
.pool
),
228 le16_to_cpu(req
->r_pgid
.ps
));
230 head
= req
->r_request
->front
.iov_base
;
231 op
= (void *)(head
+ 1);
233 num_ops
= le16_to_cpu(head
->num_ops
);
234 olen
= le32_to_cpu(head
->object_len
);
235 seq_printf(s
, "%.*s", olen
,
236 (const char *)(head
->ops
+ num_ops
));
238 if (req
->r_reassert_version
.epoch
)
239 seq_printf(s
, "\t%u'%llu",
240 (unsigned)le32_to_cpu(req
->r_reassert_version
.epoch
),
241 le64_to_cpu(req
->r_reassert_version
.version
));
245 for (i
= 0; i
< num_ops
; i
++) {
246 opcode
= le16_to_cpu(op
->op
);
247 seq_printf(s
, "\t%s", ceph_osd_op_name(opcode
));
253 mutex_unlock(&osdc
->request_mutex
);
257 static int caps_show(struct seq_file
*s
, void *p
)
259 struct ceph_client
*client
= p
;
260 int total
, avail
, used
, reserved
, min
;
262 ceph_reservation_status(client
, &total
, &avail
, &used
, &reserved
, &min
);
263 seq_printf(s
, "total\t\t%d\n"
268 total
, avail
, used
, reserved
, min
);
272 static int dentry_lru_show(struct seq_file
*s
, void *ptr
)
274 struct ceph_client
*client
= s
->private;
275 struct ceph_mds_client
*mdsc
= &client
->mdsc
;
276 struct ceph_dentry_info
*di
;
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
);
284 spin_unlock(&mdsc
->dentry_lru_lock
);
289 #define DEFINE_SHOW_FUNC(name) \
290 static int name##_open(struct inode *inode, struct file *file) \
292 struct seq_file *sf; \
295 ret = single_open(file, name, NULL); \
296 sf = file->private_data; \
297 sf->private = inode->i_private; \
301 static const struct file_operations name##_fops = { \
302 .open = name##_open, \
304 .llseek = seq_lseek, \
305 .release = single_release, \
308 DEFINE_SHOW_FUNC(monmap_show
)
309 DEFINE_SHOW_FUNC(mdsmap_show
)
310 DEFINE_SHOW_FUNC(osdmap_show
)
311 DEFINE_SHOW_FUNC(monc_show
)
312 DEFINE_SHOW_FUNC(mdsc_show
)
313 DEFINE_SHOW_FUNC(osdc_show
)
314 DEFINE_SHOW_FUNC(dentry_lru_show
)
315 DEFINE_SHOW_FUNC(caps_show
)
317 static int congestion_kb_set(void *data
, u64 val
)
319 struct ceph_client
*client
= (struct ceph_client
*)data
;
322 client
->mount_args
->congestion_kb
= (int)val
;
327 static int congestion_kb_get(void *data
, u64
*val
)
329 struct ceph_client
*client
= (struct ceph_client
*)data
;
332 *val
= (u64
)client
->mount_args
->congestion_kb
;
338 DEFINE_SIMPLE_ATTRIBUTE(congestion_kb_fops
, congestion_kb_get
,
339 congestion_kb_set
, "%llu\n");
341 int __init
ceph_debugfs_init(void)
343 ceph_debugfs_dir
= debugfs_create_dir("ceph", NULL
);
344 if (!ceph_debugfs_dir
)
349 void ceph_debugfs_cleanup(void)
351 debugfs_remove(ceph_debugfs_dir
);
354 int ceph_debugfs_client_init(struct ceph_client
*client
)
359 snprintf(name
, sizeof(name
), FSID_FORMAT
".client%lld",
360 PR_FSID(&client
->fsid
), client
->monc
.auth
->global_id
);
362 client
->debugfs_dir
= debugfs_create_dir(name
, ceph_debugfs_dir
);
363 if (!client
->debugfs_dir
)
366 client
->monc
.debugfs_file
= debugfs_create_file("monc",
371 if (!client
->monc
.debugfs_file
)
374 client
->mdsc
.debugfs_file
= debugfs_create_file("mdsc",
379 if (!client
->mdsc
.debugfs_file
)
382 client
->osdc
.debugfs_file
= debugfs_create_file("osdc",
387 if (!client
->osdc
.debugfs_file
)
390 client
->debugfs_monmap
= debugfs_create_file("monmap",
395 if (!client
->debugfs_monmap
)
398 client
->debugfs_mdsmap
= debugfs_create_file("mdsmap",
403 if (!client
->debugfs_mdsmap
)
406 client
->debugfs_osdmap
= debugfs_create_file("osdmap",
411 if (!client
->debugfs_osdmap
)
414 client
->debugfs_dentry_lru
= debugfs_create_file("dentry_lru",
418 &dentry_lru_show_fops
);
419 if (!client
->debugfs_dentry_lru
)
422 client
->debugfs_caps
= debugfs_create_file("caps",
427 if (!client
->debugfs_caps
)
430 client
->debugfs_congestion_kb
= debugfs_create_file("writeback_congestion_kb",
434 &congestion_kb_fops
);
435 if (!client
->debugfs_congestion_kb
)
438 sprintf(name
, "../../bdi/%s", dev_name(client
->sb
->s_bdi
->dev
));
439 client
->debugfs_bdi
= debugfs_create_symlink("bdi", client
->debugfs_dir
,
445 ceph_debugfs_client_cleanup(client
);
449 void ceph_debugfs_client_cleanup(struct ceph_client
*client
)
451 debugfs_remove(client
->debugfs_bdi
);
452 debugfs_remove(client
->debugfs_caps
);
453 debugfs_remove(client
->debugfs_dentry_lru
);
454 debugfs_remove(client
->debugfs_osdmap
);
455 debugfs_remove(client
->debugfs_mdsmap
);
456 debugfs_remove(client
->debugfs_monmap
);
457 debugfs_remove(client
->osdc
.debugfs_file
);
458 debugfs_remove(client
->mdsc
.debugfs_file
);
459 debugfs_remove(client
->monc
.debugfs_file
);
460 debugfs_remove(client
->debugfs_congestion_kb
);
461 debugfs_remove(client
->debugfs_dir
);
464 #else // CONFIG_DEBUG_FS
466 int __init
ceph_debugfs_init(void)
471 void ceph_debugfs_cleanup(void)
475 int ceph_debugfs_client_init(struct ceph_client
*client
)
480 void ceph_debugfs_client_cleanup(struct ceph_client
*client
)
484 #endif // CONFIG_DEBUG_FS
This page took 0.040093 seconds and 5 git commands to generate.