debugfs.c 12 KB

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