debugfs.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. #include <linux/ceph/ceph_debug.h>
  2. #include <linux/device.h>
  3. #include <linux/slab.h>
  4. #include <linux/module.h>
  5. #include <linux/ctype.h>
  6. #include <linux/debugfs.h>
  7. #include <linux/seq_file.h>
  8. #include <linux/ceph/libceph.h>
  9. #include <linux/ceph/mon_client.h>
  10. #include <linux/ceph/auth.h>
  11. #include <linux/ceph/debugfs.h>
  12. #ifdef CONFIG_DEBUG_FS
  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. * .../monmap - current monmap
  19. * .../osdc - active osd requests
  20. * .../monc - mon client state
  21. * .../client_options - libceph-only (i.e. not rbd or cephfs) options
  22. * .../dentry_lru - dump contents of dentry lru
  23. * .../caps - expose cap (reservation) stats
  24. * .../bdi - symlink to ../../bdi/something
  25. */
  26. static struct dentry *ceph_debugfs_dir;
  27. static int monmap_show(struct seq_file *s, void *p)
  28. {
  29. int i;
  30. struct ceph_client *client = s->private;
  31. if (client->monc.monmap == NULL)
  32. return 0;
  33. seq_printf(s, "epoch %d\n", client->monc.monmap->epoch);
  34. for (i = 0; i < client->monc.monmap->num_mon; i++) {
  35. struct ceph_entity_inst *inst =
  36. &client->monc.monmap->mon_inst[i];
  37. seq_printf(s, "\t%s%lld\t%s\n",
  38. ENTITY_NAME(inst->name),
  39. ceph_pr_addr(&inst->addr.in_addr));
  40. }
  41. return 0;
  42. }
  43. static int osdmap_show(struct seq_file *s, void *p)
  44. {
  45. int i;
  46. struct ceph_client *client = s->private;
  47. struct ceph_osdmap *map = client->osdc.osdmap;
  48. struct rb_node *n;
  49. if (map == NULL)
  50. return 0;
  51. seq_printf(s, "epoch %d\n", map->epoch);
  52. seq_printf(s, "flags%s%s\n",
  53. (map->flags & CEPH_OSDMAP_NEARFULL) ? " NEARFULL" : "",
  54. (map->flags & CEPH_OSDMAP_FULL) ? " FULL" : "");
  55. for (n = rb_first(&map->pg_pools); n; n = rb_next(n)) {
  56. struct ceph_pg_pool_info *pi =
  57. rb_entry(n, struct ceph_pg_pool_info, node);
  58. 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",
  59. pi->id, pi->name, pi->type, pi->size, pi->min_size,
  60. pi->pg_num, pi->pg_num_mask, pi->flags,
  61. pi->last_force_request_resend, pi->read_tier,
  62. pi->write_tier);
  63. }
  64. for (i = 0; i < map->max_osd; i++) {
  65. struct ceph_entity_addr *addr = &map->osd_addr[i];
  66. int state = map->osd_state[i];
  67. char sb[64];
  68. seq_printf(s, "osd%d\t%s\t%3d%%\t(%s)\t%3d%%\n",
  69. i, ceph_pr_addr(&addr->in_addr),
  70. ((map->osd_weight[i]*100) >> 16),
  71. ceph_osdmap_state_str(sb, sizeof(sb), state),
  72. ((ceph_get_primary_affinity(map, i)*100) >> 16));
  73. }
  74. for (n = rb_first(&map->pg_temp); n; n = rb_next(n)) {
  75. struct ceph_pg_mapping *pg =
  76. rb_entry(n, struct ceph_pg_mapping, node);
  77. seq_printf(s, "pg_temp %llu.%x [", pg->pgid.pool,
  78. pg->pgid.seed);
  79. for (i = 0; i < pg->pg_temp.len; i++)
  80. seq_printf(s, "%s%d", (i == 0 ? "" : ","),
  81. pg->pg_temp.osds[i]);
  82. seq_printf(s, "]\n");
  83. }
  84. for (n = rb_first(&map->primary_temp); n; n = rb_next(n)) {
  85. struct ceph_pg_mapping *pg =
  86. rb_entry(n, struct ceph_pg_mapping, node);
  87. seq_printf(s, "primary_temp %llu.%x %d\n", pg->pgid.pool,
  88. pg->pgid.seed, pg->primary_temp.osd);
  89. }
  90. return 0;
  91. }
  92. static int monc_show(struct seq_file *s, void *p)
  93. {
  94. struct ceph_client *client = s->private;
  95. struct ceph_mon_generic_request *req;
  96. struct ceph_mon_client *monc = &client->monc;
  97. struct rb_node *rp;
  98. int i;
  99. mutex_lock(&monc->mutex);
  100. for (i = 0; i < ARRAY_SIZE(monc->subs); i++) {
  101. seq_printf(s, "have %s %u", ceph_sub_str[i],
  102. monc->subs[i].have);
  103. if (monc->subs[i].want)
  104. seq_printf(s, " want %llu%s",
  105. le64_to_cpu(monc->subs[i].item.start),
  106. (monc->subs[i].item.flags &
  107. CEPH_SUBSCRIBE_ONETIME ? "" : "+"));
  108. seq_putc(s, '\n');
  109. }
  110. for (rp = rb_first(&monc->generic_request_tree); rp; rp = rb_next(rp)) {
  111. __u16 op;
  112. req = rb_entry(rp, struct ceph_mon_generic_request, node);
  113. op = le16_to_cpu(req->request->hdr.type);
  114. if (op == CEPH_MSG_STATFS)
  115. seq_printf(s, "%llu statfs\n", req->tid);
  116. else if (op == CEPH_MSG_MON_GET_VERSION)
  117. seq_printf(s, "%llu mon_get_version", req->tid);
  118. else
  119. seq_printf(s, "%llu unknown\n", req->tid);
  120. }
  121. mutex_unlock(&monc->mutex);
  122. return 0;
  123. }
  124. static int osdc_show(struct seq_file *s, void *pp)
  125. {
  126. struct ceph_client *client = s->private;
  127. struct ceph_osd_client *osdc = &client->osdc;
  128. struct rb_node *p;
  129. mutex_lock(&osdc->request_mutex);
  130. for (p = rb_first(&osdc->requests); p; p = rb_next(p)) {
  131. struct ceph_osd_request *req;
  132. unsigned int i;
  133. int opcode;
  134. req = rb_entry(p, struct ceph_osd_request, r_node);
  135. seq_printf(s, "%lld\tosd%d\t%lld.%x\t", req->r_tid,
  136. req->r_osd ? req->r_osd->o_osd : -1,
  137. req->r_t.pgid.pool, req->r_t.pgid.seed);
  138. seq_printf(s, "%*pE", req->r_base_oid.name_len,
  139. req->r_base_oid.name);
  140. if (req->r_reassert_version.epoch)
  141. seq_printf(s, "\t%u'%llu",
  142. (unsigned int)le32_to_cpu(req->r_reassert_version.epoch),
  143. le64_to_cpu(req->r_reassert_version.version));
  144. else
  145. seq_printf(s, "\t");
  146. for (i = 0; i < req->r_num_ops; i++) {
  147. opcode = req->r_ops[i].op;
  148. seq_printf(s, "%s%s", (i == 0 ? "\t" : ","),
  149. ceph_osd_op_name(opcode));
  150. }
  151. seq_printf(s, "\n");
  152. }
  153. mutex_unlock(&osdc->request_mutex);
  154. return 0;
  155. }
  156. static int client_options_show(struct seq_file *s, void *p)
  157. {
  158. struct ceph_client *client = s->private;
  159. int ret;
  160. ret = ceph_print_client_options(s, client);
  161. if (ret)
  162. return ret;
  163. seq_putc(s, '\n');
  164. return 0;
  165. }
  166. CEPH_DEFINE_SHOW_FUNC(monmap_show)
  167. CEPH_DEFINE_SHOW_FUNC(osdmap_show)
  168. CEPH_DEFINE_SHOW_FUNC(monc_show)
  169. CEPH_DEFINE_SHOW_FUNC(osdc_show)
  170. CEPH_DEFINE_SHOW_FUNC(client_options_show)
  171. int ceph_debugfs_init(void)
  172. {
  173. ceph_debugfs_dir = debugfs_create_dir("ceph", NULL);
  174. if (!ceph_debugfs_dir)
  175. return -ENOMEM;
  176. return 0;
  177. }
  178. void ceph_debugfs_cleanup(void)
  179. {
  180. debugfs_remove(ceph_debugfs_dir);
  181. }
  182. int ceph_debugfs_client_init(struct ceph_client *client)
  183. {
  184. int ret = -ENOMEM;
  185. char name[80];
  186. snprintf(name, sizeof(name), "%pU.client%lld", &client->fsid,
  187. client->monc.auth->global_id);
  188. dout("ceph_debugfs_client_init %p %s\n", client, name);
  189. BUG_ON(client->debugfs_dir);
  190. client->debugfs_dir = debugfs_create_dir(name, ceph_debugfs_dir);
  191. if (!client->debugfs_dir)
  192. goto out;
  193. client->monc.debugfs_file = debugfs_create_file("monc",
  194. 0600,
  195. client->debugfs_dir,
  196. client,
  197. &monc_show_fops);
  198. if (!client->monc.debugfs_file)
  199. goto out;
  200. client->osdc.debugfs_file = debugfs_create_file("osdc",
  201. 0600,
  202. client->debugfs_dir,
  203. client,
  204. &osdc_show_fops);
  205. if (!client->osdc.debugfs_file)
  206. goto out;
  207. client->debugfs_monmap = debugfs_create_file("monmap",
  208. 0600,
  209. client->debugfs_dir,
  210. client,
  211. &monmap_show_fops);
  212. if (!client->debugfs_monmap)
  213. goto out;
  214. client->debugfs_osdmap = debugfs_create_file("osdmap",
  215. 0600,
  216. client->debugfs_dir,
  217. client,
  218. &osdmap_show_fops);
  219. if (!client->debugfs_osdmap)
  220. goto out;
  221. client->debugfs_options = debugfs_create_file("client_options",
  222. 0600,
  223. client->debugfs_dir,
  224. client,
  225. &client_options_show_fops);
  226. if (!client->debugfs_options)
  227. goto out;
  228. return 0;
  229. out:
  230. ceph_debugfs_client_cleanup(client);
  231. return ret;
  232. }
  233. void ceph_debugfs_client_cleanup(struct ceph_client *client)
  234. {
  235. dout("ceph_debugfs_client_cleanup %p\n", client);
  236. debugfs_remove(client->debugfs_options);
  237. debugfs_remove(client->debugfs_osdmap);
  238. debugfs_remove(client->debugfs_monmap);
  239. debugfs_remove(client->osdc.debugfs_file);
  240. debugfs_remove(client->monc.debugfs_file);
  241. debugfs_remove(client->debugfs_dir);
  242. }
  243. #else /* CONFIG_DEBUG_FS */
  244. int ceph_debugfs_init(void)
  245. {
  246. return 0;
  247. }
  248. void ceph_debugfs_cleanup(void)
  249. {
  250. }
  251. int ceph_debugfs_client_init(struct ceph_client *client)
  252. {
  253. return 0;
  254. }
  255. void ceph_debugfs_client_cleanup(struct ceph_client *client)
  256. {
  257. }
  258. #endif /* CONFIG_DEBUG_FS */
  259. EXPORT_SYMBOL(ceph_debugfs_init);
  260. EXPORT_SYMBOL(ceph_debugfs_cleanup);