debugfs.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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 ceph_osdmap *map = client->osdc.osdmap;
  47. struct rb_node *n;
  48. if (map == NULL)
  49. return 0;
  50. seq_printf(s, "epoch %d\n", map->epoch);
  51. seq_printf(s, "flags%s%s\n",
  52. (map->flags & CEPH_OSDMAP_NEARFULL) ? " NEARFULL" : "",
  53. (map->flags & CEPH_OSDMAP_FULL) ? " FULL" : "");
  54. for (n = rb_first(&map->pg_pools); n; n = rb_next(n)) {
  55. struct ceph_pg_pool_info *pool =
  56. rb_entry(n, struct ceph_pg_pool_info, node);
  57. seq_printf(s, "pool %lld pg_num %u (%d) read_tier %lld write_tier %lld\n",
  58. pool->id, pool->pg_num, pool->pg_num_mask,
  59. pool->read_tier, pool->write_tier);
  60. }
  61. for (i = 0; i < map->max_osd; i++) {
  62. struct ceph_entity_addr *addr = &map->osd_addr[i];
  63. int state = map->osd_state[i];
  64. char sb[64];
  65. seq_printf(s, "osd%d\t%s\t%3d%%\t(%s)\t%3d%%\n",
  66. i, ceph_pr_addr(&addr->in_addr),
  67. ((map->osd_weight[i]*100) >> 16),
  68. ceph_osdmap_state_str(sb, sizeof(sb), state),
  69. ((ceph_get_primary_affinity(map, i)*100) >> 16));
  70. }
  71. for (n = rb_first(&map->pg_temp); n; n = rb_next(n)) {
  72. struct ceph_pg_mapping *pg =
  73. rb_entry(n, struct ceph_pg_mapping, node);
  74. seq_printf(s, "pg_temp %llu.%x [", pg->pgid.pool,
  75. pg->pgid.seed);
  76. for (i = 0; i < pg->pg_temp.len; i++)
  77. seq_printf(s, "%s%d", (i == 0 ? "" : ","),
  78. pg->pg_temp.osds[i]);
  79. seq_printf(s, "]\n");
  80. }
  81. for (n = rb_first(&map->primary_temp); n; n = rb_next(n)) {
  82. struct ceph_pg_mapping *pg =
  83. rb_entry(n, struct ceph_pg_mapping, node);
  84. seq_printf(s, "primary_temp %llu.%x %d\n", pg->pgid.pool,
  85. pg->pgid.seed, pg->primary_temp.osd);
  86. }
  87. return 0;
  88. }
  89. static int monc_show(struct seq_file *s, void *p)
  90. {
  91. struct ceph_client *client = s->private;
  92. struct ceph_mon_generic_request *req;
  93. struct ceph_mon_client *monc = &client->monc;
  94. struct rb_node *rp;
  95. mutex_lock(&monc->mutex);
  96. if (monc->have_mdsmap)
  97. seq_printf(s, "have mdsmap %u\n", (unsigned int)monc->have_mdsmap);
  98. if (monc->have_osdmap)
  99. seq_printf(s, "have osdmap %u\n", (unsigned int)monc->have_osdmap);
  100. if (monc->want_next_osdmap)
  101. seq_printf(s, "want next osdmap\n");
  102. for (rp = rb_first(&monc->generic_request_tree); rp; rp = rb_next(rp)) {
  103. __u16 op;
  104. req = rb_entry(rp, struct ceph_mon_generic_request, node);
  105. op = le16_to_cpu(req->request->hdr.type);
  106. if (op == CEPH_MSG_STATFS)
  107. seq_printf(s, "%llu statfs\n", req->tid);
  108. else if (op == CEPH_MSG_MON_GET_VERSION)
  109. seq_printf(s, "%llu mon_get_version", req->tid);
  110. else
  111. seq_printf(s, "%llu unknown\n", req->tid);
  112. }
  113. mutex_unlock(&monc->mutex);
  114. return 0;
  115. }
  116. static int osdc_show(struct seq_file *s, void *pp)
  117. {
  118. struct ceph_client *client = s->private;
  119. struct ceph_osd_client *osdc = &client->osdc;
  120. struct rb_node *p;
  121. mutex_lock(&osdc->request_mutex);
  122. for (p = rb_first(&osdc->requests); p; p = rb_next(p)) {
  123. struct ceph_osd_request *req;
  124. unsigned int i;
  125. int opcode;
  126. req = rb_entry(p, struct ceph_osd_request, r_node);
  127. seq_printf(s, "%lld\tosd%d\t%lld.%x\t", req->r_tid,
  128. req->r_osd ? req->r_osd->o_osd : -1,
  129. req->r_pgid.pool, req->r_pgid.seed);
  130. seq_printf(s, "%.*s", req->r_base_oid.name_len,
  131. req->r_base_oid.name);
  132. if (req->r_reassert_version.epoch)
  133. seq_printf(s, "\t%u'%llu",
  134. (unsigned int)le32_to_cpu(req->r_reassert_version.epoch),
  135. le64_to_cpu(req->r_reassert_version.version));
  136. else
  137. seq_printf(s, "\t");
  138. for (i = 0; i < req->r_num_ops; i++) {
  139. opcode = req->r_ops[i].op;
  140. seq_printf(s, "%s%s", (i == 0 ? "\t" : ","),
  141. ceph_osd_op_name(opcode));
  142. }
  143. seq_printf(s, "\n");
  144. }
  145. mutex_unlock(&osdc->request_mutex);
  146. return 0;
  147. }
  148. CEPH_DEFINE_SHOW_FUNC(monmap_show)
  149. CEPH_DEFINE_SHOW_FUNC(osdmap_show)
  150. CEPH_DEFINE_SHOW_FUNC(monc_show)
  151. CEPH_DEFINE_SHOW_FUNC(osdc_show)
  152. int ceph_debugfs_init(void)
  153. {
  154. ceph_debugfs_dir = debugfs_create_dir("ceph", NULL);
  155. if (!ceph_debugfs_dir)
  156. return -ENOMEM;
  157. return 0;
  158. }
  159. void ceph_debugfs_cleanup(void)
  160. {
  161. debugfs_remove(ceph_debugfs_dir);
  162. }
  163. int ceph_debugfs_client_init(struct ceph_client *client)
  164. {
  165. int ret = -ENOMEM;
  166. char name[80];
  167. snprintf(name, sizeof(name), "%pU.client%lld", &client->fsid,
  168. client->monc.auth->global_id);
  169. dout("ceph_debugfs_client_init %p %s\n", client, name);
  170. BUG_ON(client->debugfs_dir);
  171. client->debugfs_dir = debugfs_create_dir(name, ceph_debugfs_dir);
  172. if (!client->debugfs_dir)
  173. goto out;
  174. client->monc.debugfs_file = debugfs_create_file("monc",
  175. 0600,
  176. client->debugfs_dir,
  177. client,
  178. &monc_show_fops);
  179. if (!client->monc.debugfs_file)
  180. goto out;
  181. client->osdc.debugfs_file = debugfs_create_file("osdc",
  182. 0600,
  183. client->debugfs_dir,
  184. client,
  185. &osdc_show_fops);
  186. if (!client->osdc.debugfs_file)
  187. goto out;
  188. client->debugfs_monmap = debugfs_create_file("monmap",
  189. 0600,
  190. client->debugfs_dir,
  191. client,
  192. &monmap_show_fops);
  193. if (!client->debugfs_monmap)
  194. goto out;
  195. client->debugfs_osdmap = debugfs_create_file("osdmap",
  196. 0600,
  197. client->debugfs_dir,
  198. client,
  199. &osdmap_show_fops);
  200. if (!client->debugfs_osdmap)
  201. goto out;
  202. return 0;
  203. out:
  204. ceph_debugfs_client_cleanup(client);
  205. return ret;
  206. }
  207. void ceph_debugfs_client_cleanup(struct ceph_client *client)
  208. {
  209. dout("ceph_debugfs_client_cleanup %p\n", client);
  210. debugfs_remove(client->debugfs_osdmap);
  211. debugfs_remove(client->debugfs_monmap);
  212. debugfs_remove(client->osdc.debugfs_file);
  213. debugfs_remove(client->monc.debugfs_file);
  214. debugfs_remove(client->debugfs_dir);
  215. }
  216. #else /* CONFIG_DEBUG_FS */
  217. int ceph_debugfs_init(void)
  218. {
  219. return 0;
  220. }
  221. void ceph_debugfs_cleanup(void)
  222. {
  223. }
  224. int ceph_debugfs_client_init(struct ceph_client *client)
  225. {
  226. return 0;
  227. }
  228. void ceph_debugfs_client_cleanup(struct ceph_client *client)
  229. {
  230. }
  231. #endif /* CONFIG_DEBUG_FS */
  232. EXPORT_SYMBOL(ceph_debugfs_init);
  233. EXPORT_SYMBOL(ceph_debugfs_cleanup);