0001
0002 #include <linux/ceph/ceph_debug.h>
0003
0004 #include <linux/device.h>
0005 #include <linux/slab.h>
0006 #include <linux/module.h>
0007 #include <linux/ctype.h>
0008 #include <linux/debugfs.h>
0009 #include <linux/seq_file.h>
0010
0011 #include <linux/ceph/libceph.h>
0012 #include <linux/ceph/mon_client.h>
0013 #include <linux/ceph/auth.h>
0014 #include <linux/ceph/debugfs.h>
0015
0016 #ifdef CONFIG_DEBUG_FS
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032 static struct dentry *ceph_debugfs_dir;
0033
0034 static int monmap_show(struct seq_file *s, void *p)
0035 {
0036 int i;
0037 struct ceph_client *client = s->private;
0038
0039 if (client->monc.monmap == NULL)
0040 return 0;
0041
0042 seq_printf(s, "epoch %d\n", client->monc.monmap->epoch);
0043 for (i = 0; i < client->monc.monmap->num_mon; i++) {
0044 struct ceph_entity_inst *inst =
0045 &client->monc.monmap->mon_inst[i];
0046
0047 seq_printf(s, "\t%s%lld\t%s\n",
0048 ENTITY_NAME(inst->name),
0049 ceph_pr_addr(&inst->addr));
0050 }
0051 return 0;
0052 }
0053
0054 static int osdmap_show(struct seq_file *s, void *p)
0055 {
0056 int i;
0057 struct ceph_client *client = s->private;
0058 struct ceph_osd_client *osdc = &client->osdc;
0059 struct ceph_osdmap *map = osdc->osdmap;
0060 struct rb_node *n;
0061
0062 if (map == NULL)
0063 return 0;
0064
0065 down_read(&osdc->lock);
0066 seq_printf(s, "epoch %u barrier %u flags 0x%x\n", map->epoch,
0067 osdc->epoch_barrier, map->flags);
0068
0069 for (n = rb_first(&map->pg_pools); n; n = rb_next(n)) {
0070 struct ceph_pg_pool_info *pi =
0071 rb_entry(n, struct ceph_pg_pool_info, node);
0072
0073 seq_printf(s, "pool %lld '%s' type %d size %d min_size %d pg_num %u pg_num_mask %d flags 0x%llx lfor %u read_tier %lld write_tier %lld\n",
0074 pi->id, pi->name, pi->type, pi->size, pi->min_size,
0075 pi->pg_num, pi->pg_num_mask, pi->flags,
0076 pi->last_force_request_resend, pi->read_tier,
0077 pi->write_tier);
0078 }
0079 for (i = 0; i < map->max_osd; i++) {
0080 struct ceph_entity_addr *addr = &map->osd_addr[i];
0081 u32 state = map->osd_state[i];
0082 char sb[64];
0083
0084 seq_printf(s, "osd%d\t%s\t%3d%%\t(%s)\t%3d%%\t%2d\n",
0085 i, ceph_pr_addr(addr),
0086 ((map->osd_weight[i]*100) >> 16),
0087 ceph_osdmap_state_str(sb, sizeof(sb), state),
0088 ((ceph_get_primary_affinity(map, i)*100) >> 16),
0089 ceph_get_crush_locality(map, i,
0090 &client->options->crush_locs));
0091 }
0092 for (n = rb_first(&map->pg_temp); n; n = rb_next(n)) {
0093 struct ceph_pg_mapping *pg =
0094 rb_entry(n, struct ceph_pg_mapping, node);
0095
0096 seq_printf(s, "pg_temp %llu.%x [", pg->pgid.pool,
0097 pg->pgid.seed);
0098 for (i = 0; i < pg->pg_temp.len; i++)
0099 seq_printf(s, "%s%d", (i == 0 ? "" : ","),
0100 pg->pg_temp.osds[i]);
0101 seq_printf(s, "]\n");
0102 }
0103 for (n = rb_first(&map->primary_temp); n; n = rb_next(n)) {
0104 struct ceph_pg_mapping *pg =
0105 rb_entry(n, struct ceph_pg_mapping, node);
0106
0107 seq_printf(s, "primary_temp %llu.%x %d\n", pg->pgid.pool,
0108 pg->pgid.seed, pg->primary_temp.osd);
0109 }
0110 for (n = rb_first(&map->pg_upmap); n; n = rb_next(n)) {
0111 struct ceph_pg_mapping *pg =
0112 rb_entry(n, struct ceph_pg_mapping, node);
0113
0114 seq_printf(s, "pg_upmap %llu.%x [", pg->pgid.pool,
0115 pg->pgid.seed);
0116 for (i = 0; i < pg->pg_upmap.len; i++)
0117 seq_printf(s, "%s%d", (i == 0 ? "" : ","),
0118 pg->pg_upmap.osds[i]);
0119 seq_printf(s, "]\n");
0120 }
0121 for (n = rb_first(&map->pg_upmap_items); n; n = rb_next(n)) {
0122 struct ceph_pg_mapping *pg =
0123 rb_entry(n, struct ceph_pg_mapping, node);
0124
0125 seq_printf(s, "pg_upmap_items %llu.%x [", pg->pgid.pool,
0126 pg->pgid.seed);
0127 for (i = 0; i < pg->pg_upmap_items.len; i++)
0128 seq_printf(s, "%s%d->%d", (i == 0 ? "" : ","),
0129 pg->pg_upmap_items.from_to[i][0],
0130 pg->pg_upmap_items.from_to[i][1]);
0131 seq_printf(s, "]\n");
0132 }
0133
0134 up_read(&osdc->lock);
0135 return 0;
0136 }
0137
0138 static int monc_show(struct seq_file *s, void *p)
0139 {
0140 struct ceph_client *client = s->private;
0141 struct ceph_mon_generic_request *req;
0142 struct ceph_mon_client *monc = &client->monc;
0143 struct rb_node *rp;
0144 int i;
0145
0146 mutex_lock(&monc->mutex);
0147
0148 for (i = 0; i < ARRAY_SIZE(monc->subs); i++) {
0149 seq_printf(s, "have %s %u", ceph_sub_str[i],
0150 monc->subs[i].have);
0151 if (monc->subs[i].want)
0152 seq_printf(s, " want %llu%s",
0153 le64_to_cpu(monc->subs[i].item.start),
0154 (monc->subs[i].item.flags &
0155 CEPH_SUBSCRIBE_ONETIME ? "" : "+"));
0156 seq_putc(s, '\n');
0157 }
0158 seq_printf(s, "fs_cluster_id %d\n", monc->fs_cluster_id);
0159
0160 for (rp = rb_first(&monc->generic_request_tree); rp; rp = rb_next(rp)) {
0161 __u16 op;
0162 req = rb_entry(rp, struct ceph_mon_generic_request, node);
0163 op = le16_to_cpu(req->request->hdr.type);
0164 if (op == CEPH_MSG_STATFS)
0165 seq_printf(s, "%llu statfs\n", req->tid);
0166 else if (op == CEPH_MSG_MON_GET_VERSION)
0167 seq_printf(s, "%llu mon_get_version", req->tid);
0168 else
0169 seq_printf(s, "%llu unknown\n", req->tid);
0170 }
0171
0172 mutex_unlock(&monc->mutex);
0173 return 0;
0174 }
0175
0176 static void dump_spgid(struct seq_file *s, const struct ceph_spg *spgid)
0177 {
0178 seq_printf(s, "%llu.%x", spgid->pgid.pool, spgid->pgid.seed);
0179 if (spgid->shard != CEPH_SPG_NOSHARD)
0180 seq_printf(s, "s%d", spgid->shard);
0181 }
0182
0183 static void dump_target(struct seq_file *s, struct ceph_osd_request_target *t)
0184 {
0185 int i;
0186
0187 seq_printf(s, "osd%d\t%llu.%x\t", t->osd, t->pgid.pool, t->pgid.seed);
0188 dump_spgid(s, &t->spgid);
0189 seq_puts(s, "\t[");
0190 for (i = 0; i < t->up.size; i++)
0191 seq_printf(s, "%s%d", (!i ? "" : ","), t->up.osds[i]);
0192 seq_printf(s, "]/%d\t[", t->up.primary);
0193 for (i = 0; i < t->acting.size; i++)
0194 seq_printf(s, "%s%d", (!i ? "" : ","), t->acting.osds[i]);
0195 seq_printf(s, "]/%d\te%u\t", t->acting.primary, t->epoch);
0196 if (t->target_oloc.pool_ns) {
0197 seq_printf(s, "%*pE/%*pE\t0x%x",
0198 (int)t->target_oloc.pool_ns->len,
0199 t->target_oloc.pool_ns->str,
0200 t->target_oid.name_len, t->target_oid.name, t->flags);
0201 } else {
0202 seq_printf(s, "%*pE\t0x%x", t->target_oid.name_len,
0203 t->target_oid.name, t->flags);
0204 }
0205 if (t->paused)
0206 seq_puts(s, "\tP");
0207 }
0208
0209 static void dump_request(struct seq_file *s, struct ceph_osd_request *req)
0210 {
0211 int i;
0212
0213 seq_printf(s, "%llu\t", req->r_tid);
0214 dump_target(s, &req->r_t);
0215
0216 seq_printf(s, "\t%d", req->r_attempts);
0217
0218 for (i = 0; i < req->r_num_ops; i++) {
0219 struct ceph_osd_req_op *op = &req->r_ops[i];
0220
0221 seq_printf(s, "%s%s", (i == 0 ? "\t" : ","),
0222 ceph_osd_op_name(op->op));
0223 if (op->op == CEPH_OSD_OP_WATCH)
0224 seq_printf(s, "-%s",
0225 ceph_osd_watch_op_name(op->watch.op));
0226 else if (op->op == CEPH_OSD_OP_CALL)
0227 seq_printf(s, "-%s/%s", op->cls.class_name,
0228 op->cls.method_name);
0229 }
0230
0231 seq_putc(s, '\n');
0232 }
0233
0234 static void dump_requests(struct seq_file *s, struct ceph_osd *osd)
0235 {
0236 struct rb_node *n;
0237
0238 mutex_lock(&osd->lock);
0239 for (n = rb_first(&osd->o_requests); n; n = rb_next(n)) {
0240 struct ceph_osd_request *req =
0241 rb_entry(n, struct ceph_osd_request, r_node);
0242
0243 dump_request(s, req);
0244 }
0245
0246 mutex_unlock(&osd->lock);
0247 }
0248
0249 static void dump_linger_request(struct seq_file *s,
0250 struct ceph_osd_linger_request *lreq)
0251 {
0252 seq_printf(s, "%llu\t", lreq->linger_id);
0253 dump_target(s, &lreq->t);
0254
0255 seq_printf(s, "\t%u\t%s%s/%d\n", lreq->register_gen,
0256 lreq->is_watch ? "W" : "N", lreq->committed ? "C" : "",
0257 lreq->last_error);
0258 }
0259
0260 static void dump_linger_requests(struct seq_file *s, struct ceph_osd *osd)
0261 {
0262 struct rb_node *n;
0263
0264 mutex_lock(&osd->lock);
0265 for (n = rb_first(&osd->o_linger_requests); n; n = rb_next(n)) {
0266 struct ceph_osd_linger_request *lreq =
0267 rb_entry(n, struct ceph_osd_linger_request, node);
0268
0269 dump_linger_request(s, lreq);
0270 }
0271
0272 mutex_unlock(&osd->lock);
0273 }
0274
0275 static void dump_snapid(struct seq_file *s, u64 snapid)
0276 {
0277 if (snapid == CEPH_NOSNAP)
0278 seq_puts(s, "head");
0279 else if (snapid == CEPH_SNAPDIR)
0280 seq_puts(s, "snapdir");
0281 else
0282 seq_printf(s, "%llx", snapid);
0283 }
0284
0285 static void dump_name_escaped(struct seq_file *s, unsigned char *name,
0286 size_t len)
0287 {
0288 size_t i;
0289
0290 for (i = 0; i < len; i++) {
0291 if (name[i] == '%' || name[i] == ':' || name[i] == '/' ||
0292 name[i] < 32 || name[i] >= 127) {
0293 seq_printf(s, "%%%02x", name[i]);
0294 } else {
0295 seq_putc(s, name[i]);
0296 }
0297 }
0298 }
0299
0300 static void dump_hoid(struct seq_file *s, const struct ceph_hobject_id *hoid)
0301 {
0302 if (hoid->snapid == 0 && hoid->hash == 0 && !hoid->is_max &&
0303 hoid->pool == S64_MIN) {
0304 seq_puts(s, "MIN");
0305 return;
0306 }
0307 if (hoid->is_max) {
0308 seq_puts(s, "MAX");
0309 return;
0310 }
0311 seq_printf(s, "%lld:%08x:", hoid->pool, hoid->hash_reverse_bits);
0312 dump_name_escaped(s, hoid->nspace, hoid->nspace_len);
0313 seq_putc(s, ':');
0314 dump_name_escaped(s, hoid->key, hoid->key_len);
0315 seq_putc(s, ':');
0316 dump_name_escaped(s, hoid->oid, hoid->oid_len);
0317 seq_putc(s, ':');
0318 dump_snapid(s, hoid->snapid);
0319 }
0320
0321 static void dump_backoffs(struct seq_file *s, struct ceph_osd *osd)
0322 {
0323 struct rb_node *n;
0324
0325 mutex_lock(&osd->lock);
0326 for (n = rb_first(&osd->o_backoffs_by_id); n; n = rb_next(n)) {
0327 struct ceph_osd_backoff *backoff =
0328 rb_entry(n, struct ceph_osd_backoff, id_node);
0329
0330 seq_printf(s, "osd%d\t", osd->o_osd);
0331 dump_spgid(s, &backoff->spgid);
0332 seq_printf(s, "\t%llu\t", backoff->id);
0333 dump_hoid(s, backoff->begin);
0334 seq_putc(s, '\t');
0335 dump_hoid(s, backoff->end);
0336 seq_putc(s, '\n');
0337 }
0338
0339 mutex_unlock(&osd->lock);
0340 }
0341
0342 static int osdc_show(struct seq_file *s, void *pp)
0343 {
0344 struct ceph_client *client = s->private;
0345 struct ceph_osd_client *osdc = &client->osdc;
0346 struct rb_node *n;
0347
0348 down_read(&osdc->lock);
0349 seq_printf(s, "REQUESTS %d homeless %d\n",
0350 atomic_read(&osdc->num_requests),
0351 atomic_read(&osdc->num_homeless));
0352 for (n = rb_first(&osdc->osds); n; n = rb_next(n)) {
0353 struct ceph_osd *osd = rb_entry(n, struct ceph_osd, o_node);
0354
0355 dump_requests(s, osd);
0356 }
0357 dump_requests(s, &osdc->homeless_osd);
0358
0359 seq_puts(s, "LINGER REQUESTS\n");
0360 for (n = rb_first(&osdc->osds); n; n = rb_next(n)) {
0361 struct ceph_osd *osd = rb_entry(n, struct ceph_osd, o_node);
0362
0363 dump_linger_requests(s, osd);
0364 }
0365 dump_linger_requests(s, &osdc->homeless_osd);
0366
0367 seq_puts(s, "BACKOFFS\n");
0368 for (n = rb_first(&osdc->osds); n; n = rb_next(n)) {
0369 struct ceph_osd *osd = rb_entry(n, struct ceph_osd, o_node);
0370
0371 dump_backoffs(s, osd);
0372 }
0373
0374 up_read(&osdc->lock);
0375 return 0;
0376 }
0377
0378 static int client_options_show(struct seq_file *s, void *p)
0379 {
0380 struct ceph_client *client = s->private;
0381 int ret;
0382
0383 ret = ceph_print_client_options(s, client, true);
0384 if (ret)
0385 return ret;
0386
0387 seq_putc(s, '\n');
0388 return 0;
0389 }
0390
0391 DEFINE_SHOW_ATTRIBUTE(monmap);
0392 DEFINE_SHOW_ATTRIBUTE(osdmap);
0393 DEFINE_SHOW_ATTRIBUTE(monc);
0394 DEFINE_SHOW_ATTRIBUTE(osdc);
0395 DEFINE_SHOW_ATTRIBUTE(client_options);
0396
0397 void __init ceph_debugfs_init(void)
0398 {
0399 ceph_debugfs_dir = debugfs_create_dir("ceph", NULL);
0400 }
0401
0402 void ceph_debugfs_cleanup(void)
0403 {
0404 debugfs_remove(ceph_debugfs_dir);
0405 }
0406
0407 void ceph_debugfs_client_init(struct ceph_client *client)
0408 {
0409 char name[80];
0410
0411 snprintf(name, sizeof(name), "%pU.client%lld", &client->fsid,
0412 client->monc.auth->global_id);
0413
0414 dout("ceph_debugfs_client_init %p %s\n", client, name);
0415
0416 client->debugfs_dir = debugfs_create_dir(name, ceph_debugfs_dir);
0417
0418 client->monc.debugfs_file = debugfs_create_file("monc",
0419 0400,
0420 client->debugfs_dir,
0421 client,
0422 &monc_fops);
0423
0424 client->osdc.debugfs_file = debugfs_create_file("osdc",
0425 0400,
0426 client->debugfs_dir,
0427 client,
0428 &osdc_fops);
0429
0430 client->debugfs_monmap = debugfs_create_file("monmap",
0431 0400,
0432 client->debugfs_dir,
0433 client,
0434 &monmap_fops);
0435
0436 client->debugfs_osdmap = debugfs_create_file("osdmap",
0437 0400,
0438 client->debugfs_dir,
0439 client,
0440 &osdmap_fops);
0441
0442 client->debugfs_options = debugfs_create_file("client_options",
0443 0400,
0444 client->debugfs_dir,
0445 client,
0446 &client_options_fops);
0447 }
0448
0449 void ceph_debugfs_client_cleanup(struct ceph_client *client)
0450 {
0451 dout("ceph_debugfs_client_cleanup %p\n", client);
0452 debugfs_remove(client->debugfs_options);
0453 debugfs_remove(client->debugfs_osdmap);
0454 debugfs_remove(client->debugfs_monmap);
0455 debugfs_remove(client->osdc.debugfs_file);
0456 debugfs_remove(client->monc.debugfs_file);
0457 debugfs_remove(client->debugfs_dir);
0458 }
0459
0460 #else
0461
0462 void __init ceph_debugfs_init(void)
0463 {
0464 }
0465
0466 void ceph_debugfs_cleanup(void)
0467 {
0468 }
0469
0470 void ceph_debugfs_client_init(struct ceph_client *client)
0471 {
0472 }
0473
0474 void ceph_debugfs_client_cleanup(struct ceph_client *client)
0475 {
0476 }
0477
0478 #endif