debugfs.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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. * .../dentry_lru - dump contents of dentry lru
  22. * .../caps - expose cap (reservation) stats
  23. * .../bdi - symlink to ../../bdi/something
  24. */
  25. static struct dentry *ceph_debugfs_dir;
  26. static int monmap_show(struct seq_file *s, void *p)
  27. {
  28. int i;
  29. struct ceph_client *client = s->private;
  30. if (client->monc.monmap == NULL)
  31. return 0;
  32. seq_printf(s, "epoch %d\n", client->monc.monmap->epoch);
  33. for (i = 0; i < client->monc.monmap->num_mon; i++) {
  34. struct ceph_entity_inst *inst =
  35. &client->monc.monmap->mon_inst[i];
  36. seq_printf(s, "\t%s%lld\t%s\n",
  37. ENTITY_NAME(inst->name),
  38. ceph_pr_addr(&inst->addr.in_addr));
  39. }
  40. return 0;
  41. }
  42. static int osdmap_show(struct seq_file *s, void *p)
  43. {
  44. int i;
  45. struct ceph_client *client = s->private;
  46. struct rb_node *n;
  47. if (client->osdc.osdmap == NULL)
  48. return 0;
  49. seq_printf(s, "epoch %d\n", client->osdc.osdmap->epoch);
  50. seq_printf(s, "flags%s%s\n",
  51. (client->osdc.osdmap->flags & CEPH_OSDMAP_NEARFULL) ?
  52. " NEARFULL" : "",
  53. (client->osdc.osdmap->flags & CEPH_OSDMAP_FULL) ?
  54. " FULL" : "");
  55. for (n = rb_first(&client->osdc.osdmap->pg_pools); n; n = rb_next(n)) {
  56. struct ceph_pg_pool_info *pool =
  57. rb_entry(n, struct ceph_pg_pool_info, node);
  58. seq_printf(s, "pg_pool %d pg_num %d / %d, lpg_num %d / %d\n",
  59. pool->id, pool->v.pg_num, pool->pg_num_mask,
  60. pool->v.lpg_num, pool->lpg_num_mask);
  61. }
  62. for (i = 0; i < client->osdc.osdmap->max_osd; i++) {
  63. struct ceph_entity_addr *addr =
  64. &client->osdc.osdmap->osd_addr[i];
  65. int state = client->osdc.osdmap->osd_state[i];
  66. char sb[64];
  67. seq_printf(s, "\tosd%d\t%s\t%3d%%\t(%s)\n",
  68. i, ceph_pr_addr(&addr->in_addr),
  69. ((client->osdc.osdmap->osd_weight[i]*100) >> 16),
  70. ceph_osdmap_state_str(sb, sizeof(sb), state));
  71. }
  72. return 0;
  73. }
  74. static int monc_show(struct seq_file *s, void *p)
  75. {
  76. struct ceph_client *client = s->private;
  77. struct ceph_mon_generic_request *req;
  78. struct ceph_mon_client *monc = &client->monc;
  79. struct rb_node *rp;
  80. mutex_lock(&monc->mutex);
  81. if (monc->have_mdsmap)
  82. seq_printf(s, "have mdsmap %u\n", (unsigned)monc->have_mdsmap);
  83. if (monc->have_osdmap)
  84. seq_printf(s, "have osdmap %u\n", (unsigned)monc->have_osdmap);
  85. if (monc->want_next_osdmap)
  86. seq_printf(s, "want next osdmap\n");
  87. for (rp = rb_first(&monc->generic_request_tree); rp; rp = rb_next(rp)) {
  88. __u16 op;
  89. req = rb_entry(rp, struct ceph_mon_generic_request, node);
  90. op = le16_to_cpu(req->request->hdr.type);
  91. if (op == CEPH_MSG_STATFS)
  92. seq_printf(s, "%lld statfs\n", req->tid);
  93. else
  94. seq_printf(s, "%lld unknown\n", req->tid);
  95. }
  96. mutex_unlock(&monc->mutex);
  97. return 0;
  98. }
  99. static int osdc_show(struct seq_file *s, void *pp)
  100. {
  101. struct ceph_client *client = s->private;
  102. struct ceph_osd_client *osdc = &client->osdc;
  103. struct rb_node *p;
  104. mutex_lock(&osdc->request_mutex);
  105. for (p = rb_first(&osdc->requests); p; p = rb_next(p)) {
  106. struct ceph_osd_request *req;
  107. struct ceph_osd_request_head *head;
  108. struct ceph_osd_op *op;
  109. int num_ops;
  110. int opcode, olen;
  111. int i;
  112. req = rb_entry(p, struct ceph_osd_request, r_node);
  113. seq_printf(s, "%lld\tosd%d\t%d.%x\t", req->r_tid,
  114. req->r_osd ? req->r_osd->o_osd : -1,
  115. le32_to_cpu(req->r_pgid.pool),
  116. le16_to_cpu(req->r_pgid.ps));
  117. head = req->r_request->front.iov_base;
  118. op = (void *)(head + 1);
  119. num_ops = le16_to_cpu(head->num_ops);
  120. olen = le32_to_cpu(head->object_len);
  121. seq_printf(s, "%.*s", olen,
  122. (const char *)(head->ops + num_ops));
  123. if (req->r_reassert_version.epoch)
  124. seq_printf(s, "\t%u'%llu",
  125. (unsigned)le32_to_cpu(req->r_reassert_version.epoch),
  126. le64_to_cpu(req->r_reassert_version.version));
  127. else
  128. seq_printf(s, "\t");
  129. for (i = 0; i < num_ops; i++) {
  130. opcode = le16_to_cpu(op->op);
  131. seq_printf(s, "\t%s", ceph_osd_op_name(opcode));
  132. op++;
  133. }
  134. seq_printf(s, "\n");
  135. }
  136. mutex_unlock(&osdc->request_mutex);
  137. return 0;
  138. }
  139. CEPH_DEFINE_SHOW_FUNC(monmap_show)
  140. CEPH_DEFINE_SHOW_FUNC(osdmap_show)
  141. CEPH_DEFINE_SHOW_FUNC(monc_show)
  142. CEPH_DEFINE_SHOW_FUNC(osdc_show)
  143. int ceph_debugfs_init(void)
  144. {
  145. ceph_debugfs_dir = debugfs_create_dir("ceph", NULL);
  146. if (!ceph_debugfs_dir)
  147. return -ENOMEM;
  148. return 0;
  149. }
  150. void ceph_debugfs_cleanup(void)
  151. {
  152. debugfs_remove(ceph_debugfs_dir);
  153. }
  154. int ceph_debugfs_client_init(struct ceph_client *client)
  155. {
  156. int ret = -ENOMEM;
  157. char name[80];
  158. snprintf(name, sizeof(name), "%pU.client%lld", &client->fsid,
  159. client->monc.auth->global_id);
  160. client->debugfs_dir = debugfs_create_dir(name, ceph_debugfs_dir);
  161. if (!client->debugfs_dir)
  162. goto out;
  163. client->monc.debugfs_file = debugfs_create_file("monc",
  164. 0600,
  165. client->debugfs_dir,
  166. client,
  167. &monc_show_fops);
  168. if (!client->monc.debugfs_file)
  169. goto out;
  170. client->osdc.debugfs_file = debugfs_create_file("osdc",
  171. 0600,
  172. client->debugfs_dir,
  173. client,
  174. &osdc_show_fops);
  175. if (!client->osdc.debugfs_file)
  176. goto out;
  177. client->debugfs_monmap = debugfs_create_file("monmap",
  178. 0600,
  179. client->debugfs_dir,
  180. client,
  181. &monmap_show_fops);
  182. if (!client->debugfs_monmap)
  183. goto out;
  184. client->debugfs_osdmap = debugfs_create_file("osdmap",
  185. 0600,
  186. client->debugfs_dir,
  187. client,
  188. &osdmap_show_fops);
  189. if (!client->debugfs_osdmap)
  190. goto out;
  191. return 0;
  192. out:
  193. ceph_debugfs_client_cleanup(client);
  194. return ret;
  195. }
  196. void ceph_debugfs_client_cleanup(struct ceph_client *client)
  197. {
  198. debugfs_remove(client->debugfs_osdmap);
  199. debugfs_remove(client->debugfs_monmap);
  200. debugfs_remove(client->osdc.debugfs_file);
  201. debugfs_remove(client->monc.debugfs_file);
  202. debugfs_remove(client->debugfs_dir);
  203. }
  204. #else /* CONFIG_DEBUG_FS */
  205. int ceph_debugfs_init(void)
  206. {
  207. return 0;
  208. }
  209. void ceph_debugfs_cleanup(void)
  210. {
  211. }
  212. int ceph_debugfs_client_init(struct ceph_client *client)
  213. {
  214. return 0;
  215. }
  216. void ceph_debugfs_client_cleanup(struct ceph_client *client)
  217. {
  218. }
  219. #endif /* CONFIG_DEBUG_FS */
  220. EXPORT_SYMBOL(ceph_debugfs_init);
  221. EXPORT_SYMBOL(ceph_debugfs_cleanup);