debugfs.c 11 KB

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