debugfs.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. #include "ceph_debug.h"
  2. #include <linux/module.h>
  3. #include <linux/ctype.h>
  4. #include <linux/debugfs.h>
  5. #include <linux/seq_file.h>
  6. #include "super.h"
  7. #include "mds_client.h"
  8. /*
  9. * Implement /sys/kernel/debug/ceph fun
  10. *
  11. * /sys/kernel/debug/ceph/client* - an instance of the ceph client
  12. * .../osdmap - current osdmap
  13. * .../mdsmap - current mdsmap
  14. * .../monmap - current monmap
  15. * .../osdc - active osd requests
  16. * .../mdsc - active mds requests
  17. * .../monc - mon client state
  18. * .../dentry_lru - dump contents of dentry lru
  19. * .../caps - expose cap (reservation) stats
  20. */
  21. static struct dentry *ceph_debugfs_dir;
  22. static int monmap_show(struct seq_file *s, void *p)
  23. {
  24. int i;
  25. struct ceph_client *client = s->private;
  26. if (client->monc.monmap == NULL)
  27. return 0;
  28. seq_printf(s, "epoch %d\n", client->monc.monmap->epoch);
  29. for (i = 0; i < client->monc.monmap->num_mon; i++) {
  30. struct ceph_entity_inst *inst =
  31. &client->monc.monmap->mon_inst[i];
  32. seq_printf(s, "\t%s%lld\t%s\n",
  33. ENTITY_NAME(inst->name),
  34. pr_addr(&inst->addr.in_addr));
  35. }
  36. return 0;
  37. }
  38. static int mdsmap_show(struct seq_file *s, void *p)
  39. {
  40. int i;
  41. struct ceph_client *client = s->private;
  42. if (client->mdsc.mdsmap == NULL)
  43. return 0;
  44. seq_printf(s, "epoch %d\n", client->mdsc.mdsmap->m_epoch);
  45. seq_printf(s, "root %d\n", client->mdsc.mdsmap->m_root);
  46. seq_printf(s, "session_timeout %d\n",
  47. client->mdsc.mdsmap->m_session_timeout);
  48. seq_printf(s, "session_autoclose %d\n",
  49. client->mdsc.mdsmap->m_session_autoclose);
  50. for (i = 0; i < client->mdsc.mdsmap->m_max_mds; i++) {
  51. struct ceph_entity_addr *addr =
  52. &client->mdsc.mdsmap->m_info[i].addr;
  53. int state = client->mdsc.mdsmap->m_info[i].state;
  54. seq_printf(s, "\tmds%d\t%s\t(%s)\n", i, pr_addr(&addr->in_addr),
  55. ceph_mds_state_name(state));
  56. }
  57. return 0;
  58. }
  59. static int osdmap_show(struct seq_file *s, void *p)
  60. {
  61. int i;
  62. struct ceph_client *client = s->private;
  63. if (client->osdc.osdmap == NULL)
  64. return 0;
  65. seq_printf(s, "epoch %d\n", client->osdc.osdmap->epoch);
  66. seq_printf(s, "flags%s%s\n",
  67. (client->osdc.osdmap->flags & CEPH_OSDMAP_NEARFULL) ?
  68. " NEARFULL" : "",
  69. (client->osdc.osdmap->flags & CEPH_OSDMAP_FULL) ?
  70. " FULL" : "");
  71. for (i = 0; i < client->osdc.osdmap->num_pools; i++) {
  72. struct ceph_pg_pool_info *pool =
  73. &client->osdc.osdmap->pg_pool[i];
  74. seq_printf(s, "pg_pool %d pg_num %d / %d, lpg_num %d / %d\n",
  75. i, pool->v.pg_num, pool->pg_num_mask,
  76. pool->v.lpg_num, pool->lpg_num_mask);
  77. }
  78. for (i = 0; i < client->osdc.osdmap->max_osd; i++) {
  79. struct ceph_entity_addr *addr =
  80. &client->osdc.osdmap->osd_addr[i];
  81. int state = client->osdc.osdmap->osd_state[i];
  82. char sb[64];
  83. seq_printf(s, "\tosd%d\t%s\t%3d%%\t(%s)\n",
  84. i, pr_addr(&addr->in_addr),
  85. ((client->osdc.osdmap->osd_weight[i]*100) >> 16),
  86. ceph_osdmap_state_str(sb, sizeof(sb), state));
  87. }
  88. return 0;
  89. }
  90. static int monc_show(struct seq_file *s, void *p)
  91. {
  92. struct ceph_client *client = s->private;
  93. struct ceph_mon_statfs_request *req;
  94. u64 nexttid = 0;
  95. int got;
  96. struct ceph_mon_client *monc = &client->monc;
  97. mutex_lock(&monc->mutex);
  98. if (monc->have_mdsmap)
  99. seq_printf(s, "have mdsmap %u\n", (unsigned)monc->have_mdsmap);
  100. if (monc->have_osdmap)
  101. seq_printf(s, "have osdmap %u\n", (unsigned)monc->have_osdmap);
  102. if (monc->want_next_osdmap)
  103. seq_printf(s, "want next osdmap\n");
  104. while (nexttid < monc->last_tid) {
  105. got = radix_tree_gang_lookup(&monc->statfs_request_tree,
  106. (void **)&req, nexttid, 1);
  107. if (got == 0)
  108. break;
  109. nexttid = req->tid + 1;
  110. seq_printf(s, "%lld statfs\n", req->tid);
  111. }
  112. mutex_unlock(&monc->mutex);
  113. return 0;
  114. }
  115. static int mdsc_show(struct seq_file *s, void *p)
  116. {
  117. struct ceph_client *client = s->private;
  118. struct ceph_mds_request *req;
  119. u64 nexttid = 0;
  120. int got;
  121. struct ceph_mds_client *mdsc = &client->mdsc;
  122. int pathlen;
  123. u64 pathbase;
  124. char *path;
  125. mutex_lock(&mdsc->mutex);
  126. while (nexttid < mdsc->last_tid) {
  127. got = radix_tree_gang_lookup(&mdsc->request_tree,
  128. (void **)&req, nexttid, 1);
  129. if (got == 0)
  130. break;
  131. nexttid = req->r_tid + 1;
  132. if (req->r_request)
  133. seq_printf(s, "%lld\tmds%d\t", req->r_tid, req->r_mds);
  134. else
  135. seq_printf(s, "%lld\t(no request)\t", req->r_tid);
  136. seq_printf(s, "%s", ceph_mds_op_name(req->r_op));
  137. if (req->r_got_unsafe)
  138. seq_printf(s, "\t(unsafe)");
  139. else
  140. seq_printf(s, "\t");
  141. if (req->r_inode) {
  142. seq_printf(s, " #%llx", ceph_ino(req->r_inode));
  143. } else if (req->r_dentry) {
  144. path = ceph_mdsc_build_path(req->r_dentry, &pathlen,
  145. &pathbase, 0);
  146. spin_lock(&req->r_dentry->d_lock);
  147. seq_printf(s, " #%llx/%.*s (%s)",
  148. ceph_ino(req->r_dentry->d_parent->d_inode),
  149. req->r_dentry->d_name.len,
  150. req->r_dentry->d_name.name,
  151. path ? path : "");
  152. spin_unlock(&req->r_dentry->d_lock);
  153. kfree(path);
  154. } else if (req->r_path1) {
  155. seq_printf(s, " #%llx/%s", req->r_ino1.ino,
  156. req->r_path1);
  157. }
  158. if (req->r_old_dentry) {
  159. path = ceph_mdsc_build_path(req->r_old_dentry, &pathlen,
  160. &pathbase, 0);
  161. spin_lock(&req->r_old_dentry->d_lock);
  162. seq_printf(s, " #%llx/%.*s (%s)",
  163. ceph_ino(req->r_old_dentry->d_parent->d_inode),
  164. req->r_old_dentry->d_name.len,
  165. req->r_old_dentry->d_name.name,
  166. path ? path : "");
  167. spin_unlock(&req->r_old_dentry->d_lock);
  168. kfree(path);
  169. } else if (req->r_path2) {
  170. if (req->r_ino2.ino)
  171. seq_printf(s, " #%llx/%s", req->r_ino2.ino,
  172. req->r_path2);
  173. else
  174. seq_printf(s, " %s", req->r_path2);
  175. }
  176. seq_printf(s, "\n");
  177. }
  178. mutex_unlock(&mdsc->mutex);
  179. return 0;
  180. }
  181. static int osdc_show(struct seq_file *s, void *pp)
  182. {
  183. struct ceph_client *client = s->private;
  184. struct ceph_osd_client *osdc = &client->osdc;
  185. struct rb_node *p;
  186. mutex_lock(&osdc->request_mutex);
  187. for (p = rb_first(&osdc->requests); p; p = rb_next(p)) {
  188. struct ceph_osd_request *req;
  189. struct ceph_osd_request_head *head;
  190. struct ceph_osd_op *op;
  191. int num_ops;
  192. int opcode, olen;
  193. int i;
  194. req = rb_entry(p, struct ceph_osd_request, r_node);
  195. seq_printf(s, "%lld\tosd%d\t", req->r_tid,
  196. req->r_osd ? req->r_osd->o_osd : -1);
  197. head = req->r_request->front.iov_base;
  198. op = (void *)(head + 1);
  199. num_ops = le16_to_cpu(head->num_ops);
  200. olen = le32_to_cpu(head->object_len);
  201. seq_printf(s, "%.*s", olen,
  202. (const char *)(head->ops + num_ops));
  203. if (req->r_reassert_version.epoch)
  204. seq_printf(s, "\t%u'%llu",
  205. (unsigned)le32_to_cpu(req->r_reassert_version.epoch),
  206. le64_to_cpu(req->r_reassert_version.version));
  207. else
  208. seq_printf(s, "\t");
  209. for (i = 0; i < num_ops; i++) {
  210. opcode = le16_to_cpu(op->op);
  211. seq_printf(s, "\t%s", ceph_osd_op_name(opcode));
  212. op++;
  213. }
  214. seq_printf(s, "\n");
  215. }
  216. mutex_unlock(&osdc->request_mutex);
  217. return 0;
  218. }
  219. static int caps_show(struct seq_file *s, void *p)
  220. {
  221. struct ceph_client *client = p;
  222. int total, avail, used, reserved;
  223. ceph_reservation_status(client, &total, &avail, &used, &reserved);
  224. seq_printf(s, "total\t\t%d\n"
  225. "avail\t\t%d\n"
  226. "used\t\t%d\n"
  227. "reserved\t%d\n",
  228. total, avail, used, reserved);
  229. return 0;
  230. }
  231. static int dentry_lru_show(struct seq_file *s, void *ptr)
  232. {
  233. struct ceph_client *client = s->private;
  234. struct ceph_mds_client *mdsc = &client->mdsc;
  235. struct ceph_dentry_info *di;
  236. spin_lock(&mdsc->dentry_lru_lock);
  237. list_for_each_entry(di, &mdsc->dentry_lru, lru) {
  238. struct dentry *dentry = di->dentry;
  239. seq_printf(s, "%p %p\t%.*s\n",
  240. di, dentry, dentry->d_name.len, dentry->d_name.name);
  241. }
  242. spin_unlock(&mdsc->dentry_lru_lock);
  243. return 0;
  244. }
  245. #define DEFINE_SHOW_FUNC(name) \
  246. static int name##_open(struct inode *inode, struct file *file) \
  247. { \
  248. struct seq_file *sf; \
  249. int ret; \
  250. \
  251. ret = single_open(file, name, NULL); \
  252. sf = file->private_data; \
  253. sf->private = inode->i_private; \
  254. return ret; \
  255. } \
  256. \
  257. static const struct file_operations name##_fops = { \
  258. .open = name##_open, \
  259. .read = seq_read, \
  260. .llseek = seq_lseek, \
  261. .release = single_release, \
  262. };
  263. DEFINE_SHOW_FUNC(monmap_show)
  264. DEFINE_SHOW_FUNC(mdsmap_show)
  265. DEFINE_SHOW_FUNC(osdmap_show)
  266. DEFINE_SHOW_FUNC(monc_show)
  267. DEFINE_SHOW_FUNC(mdsc_show)
  268. DEFINE_SHOW_FUNC(osdc_show)
  269. DEFINE_SHOW_FUNC(dentry_lru_show)
  270. DEFINE_SHOW_FUNC(caps_show)
  271. int __init ceph_debugfs_init(void)
  272. {
  273. ceph_debugfs_dir = debugfs_create_dir("ceph", NULL);
  274. if (!ceph_debugfs_dir)
  275. return -ENOMEM;
  276. return 0;
  277. }
  278. void ceph_debugfs_cleanup(void)
  279. {
  280. debugfs_remove(ceph_debugfs_dir);
  281. }
  282. int ceph_debugfs_client_init(struct ceph_client *client)
  283. {
  284. int ret = 0;
  285. char name[80];
  286. snprintf(name, sizeof(name), FSID_FORMAT ".client%lld",
  287. PR_FSID(&client->monc.monmap->fsid), client->whoami);
  288. client->debugfs_dir = debugfs_create_dir(name, ceph_debugfs_dir);
  289. if (!client->debugfs_dir)
  290. goto out;
  291. client->monc.debugfs_file = debugfs_create_file("monc",
  292. 0600,
  293. client->debugfs_dir,
  294. client,
  295. &monc_show_fops);
  296. if (!client->monc.debugfs_file)
  297. goto out;
  298. client->mdsc.debugfs_file = debugfs_create_file("mdsc",
  299. 0600,
  300. client->debugfs_dir,
  301. client,
  302. &mdsc_show_fops);
  303. if (!client->mdsc.debugfs_file)
  304. goto out;
  305. client->osdc.debugfs_file = debugfs_create_file("osdc",
  306. 0600,
  307. client->debugfs_dir,
  308. client,
  309. &osdc_show_fops);
  310. if (!client->osdc.debugfs_file)
  311. goto out;
  312. client->debugfs_monmap = debugfs_create_file("monmap",
  313. 0600,
  314. client->debugfs_dir,
  315. client,
  316. &monmap_show_fops);
  317. if (!client->debugfs_monmap)
  318. goto out;
  319. client->debugfs_mdsmap = debugfs_create_file("mdsmap",
  320. 0600,
  321. client->debugfs_dir,
  322. client,
  323. &mdsmap_show_fops);
  324. if (!client->debugfs_mdsmap)
  325. goto out;
  326. client->debugfs_osdmap = debugfs_create_file("osdmap",
  327. 0600,
  328. client->debugfs_dir,
  329. client,
  330. &osdmap_show_fops);
  331. if (!client->debugfs_osdmap)
  332. goto out;
  333. client->debugfs_dentry_lru = debugfs_create_file("dentry_lru",
  334. 0600,
  335. client->debugfs_dir,
  336. client,
  337. &dentry_lru_show_fops);
  338. if (!client->debugfs_dentry_lru)
  339. goto out;
  340. client->debugfs_caps = debugfs_create_file("caps",
  341. 0400,
  342. client->debugfs_dir,
  343. client,
  344. &caps_show_fops);
  345. if (!client->debugfs_caps)
  346. goto out;
  347. return 0;
  348. out:
  349. ceph_debugfs_client_cleanup(client);
  350. return ret;
  351. }
  352. void ceph_debugfs_client_cleanup(struct ceph_client *client)
  353. {
  354. debugfs_remove(client->debugfs_caps);
  355. debugfs_remove(client->debugfs_dentry_lru);
  356. debugfs_remove(client->debugfs_osdmap);
  357. debugfs_remove(client->debugfs_mdsmap);
  358. debugfs_remove(client->debugfs_monmap);
  359. debugfs_remove(client->osdc.debugfs_file);
  360. debugfs_remove(client->mdsc.debugfs_file);
  361. debugfs_remove(client->monc.debugfs_file);
  362. debugfs_remove(client->debugfs_dir);
  363. }