debugfs.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  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. spin_lock(&req->r_dentry->d_lock);
  149. seq_printf(s, " #%llx/%.*s (%s)",
  150. ceph_ino(req->r_dentry->d_parent->d_inode),
  151. req->r_dentry->d_name.len,
  152. req->r_dentry->d_name.name,
  153. path ? path : "");
  154. spin_unlock(&req->r_dentry->d_lock);
  155. kfree(path);
  156. } else if (req->r_path1) {
  157. seq_printf(s, " #%llx/%s", req->r_ino1.ino,
  158. req->r_path1);
  159. }
  160. if (req->r_old_dentry) {
  161. path = ceph_mdsc_build_path(req->r_old_dentry, &pathlen,
  162. &pathbase, 0);
  163. spin_lock(&req->r_old_dentry->d_lock);
  164. seq_printf(s, " #%llx/%.*s (%s)",
  165. ceph_ino(req->r_old_dentry->d_parent->d_inode),
  166. req->r_old_dentry->d_name.len,
  167. req->r_old_dentry->d_name.name,
  168. path ? path : "");
  169. spin_unlock(&req->r_old_dentry->d_lock);
  170. kfree(path);
  171. } else if (req->r_path2) {
  172. if (req->r_ino2.ino)
  173. seq_printf(s, " #%llx/%s", req->r_ino2.ino,
  174. req->r_path2);
  175. else
  176. seq_printf(s, " %s", req->r_path2);
  177. }
  178. seq_printf(s, "\n");
  179. }
  180. mutex_unlock(&mdsc->mutex);
  181. return 0;
  182. }
  183. static int osdc_show(struct seq_file *s, void *pp)
  184. {
  185. struct ceph_client *client = s->private;
  186. struct ceph_osd_client *osdc = &client->osdc;
  187. struct rb_node *p;
  188. mutex_lock(&osdc->request_mutex);
  189. for (p = rb_first(&osdc->requests); p; p = rb_next(p)) {
  190. struct ceph_osd_request *req;
  191. struct ceph_osd_request_head *head;
  192. struct ceph_osd_op *op;
  193. int num_ops;
  194. int opcode, olen;
  195. int i;
  196. req = rb_entry(p, struct ceph_osd_request, r_node);
  197. seq_printf(s, "%lld\tosd%d\t%d.%x\t", req->r_tid,
  198. req->r_osd ? req->r_osd->o_osd : -1,
  199. le32_to_cpu(req->r_pgid.pool),
  200. le16_to_cpu(req->r_pgid.ps));
  201. head = req->r_request->front.iov_base;
  202. op = (void *)(head + 1);
  203. num_ops = le16_to_cpu(head->num_ops);
  204. olen = le32_to_cpu(head->object_len);
  205. seq_printf(s, "%.*s", olen,
  206. (const char *)(head->ops + num_ops));
  207. if (req->r_reassert_version.epoch)
  208. seq_printf(s, "\t%u'%llu",
  209. (unsigned)le32_to_cpu(req->r_reassert_version.epoch),
  210. le64_to_cpu(req->r_reassert_version.version));
  211. else
  212. seq_printf(s, "\t");
  213. for (i = 0; i < num_ops; i++) {
  214. opcode = le16_to_cpu(op->op);
  215. seq_printf(s, "\t%s", ceph_osd_op_name(opcode));
  216. op++;
  217. }
  218. seq_printf(s, "\n");
  219. }
  220. mutex_unlock(&osdc->request_mutex);
  221. return 0;
  222. }
  223. static int caps_show(struct seq_file *s, void *p)
  224. {
  225. struct ceph_client *client = s->private;
  226. int total, avail, used, reserved, min;
  227. ceph_reservation_status(client, &total, &avail, &used, &reserved, &min);
  228. seq_printf(s, "total\t\t%d\n"
  229. "avail\t\t%d\n"
  230. "used\t\t%d\n"
  231. "reserved\t%d\n"
  232. "min\t%d\n",
  233. total, avail, used, reserved, min);
  234. return 0;
  235. }
  236. static int dentry_lru_show(struct seq_file *s, void *ptr)
  237. {
  238. struct ceph_client *client = s->private;
  239. struct ceph_mds_client *mdsc = &client->mdsc;
  240. struct ceph_dentry_info *di;
  241. spin_lock(&mdsc->dentry_lru_lock);
  242. list_for_each_entry(di, &mdsc->dentry_lru, lru) {
  243. struct dentry *dentry = di->dentry;
  244. seq_printf(s, "%p %p\t%.*s\n",
  245. di, dentry, dentry->d_name.len, dentry->d_name.name);
  246. }
  247. spin_unlock(&mdsc->dentry_lru_lock);
  248. return 0;
  249. }
  250. #define DEFINE_SHOW_FUNC(name) \
  251. static int name##_open(struct inode *inode, struct file *file) \
  252. { \
  253. struct seq_file *sf; \
  254. int ret; \
  255. \
  256. ret = single_open(file, name, NULL); \
  257. sf = file->private_data; \
  258. sf->private = inode->i_private; \
  259. return ret; \
  260. } \
  261. \
  262. static const struct file_operations name##_fops = { \
  263. .open = name##_open, \
  264. .read = seq_read, \
  265. .llseek = seq_lseek, \
  266. .release = single_release, \
  267. };
  268. DEFINE_SHOW_FUNC(monmap_show)
  269. DEFINE_SHOW_FUNC(mdsmap_show)
  270. DEFINE_SHOW_FUNC(osdmap_show)
  271. DEFINE_SHOW_FUNC(monc_show)
  272. DEFINE_SHOW_FUNC(mdsc_show)
  273. DEFINE_SHOW_FUNC(osdc_show)
  274. DEFINE_SHOW_FUNC(dentry_lru_show)
  275. DEFINE_SHOW_FUNC(caps_show)
  276. static int congestion_kb_set(void *data, u64 val)
  277. {
  278. struct ceph_client *client = (struct ceph_client *)data;
  279. if (client)
  280. client->mount_args->congestion_kb = (int)val;
  281. return 0;
  282. }
  283. static int congestion_kb_get(void *data, u64 *val)
  284. {
  285. struct ceph_client *client = (struct ceph_client *)data;
  286. if (client)
  287. *val = (u64)client->mount_args->congestion_kb;
  288. return 0;
  289. }
  290. DEFINE_SIMPLE_ATTRIBUTE(congestion_kb_fops, congestion_kb_get,
  291. congestion_kb_set, "%llu\n");
  292. int __init ceph_debugfs_init(void)
  293. {
  294. ceph_debugfs_dir = debugfs_create_dir("ceph", NULL);
  295. if (!ceph_debugfs_dir)
  296. return -ENOMEM;
  297. return 0;
  298. }
  299. void ceph_debugfs_cleanup(void)
  300. {
  301. debugfs_remove(ceph_debugfs_dir);
  302. }
  303. int ceph_debugfs_client_init(struct ceph_client *client)
  304. {
  305. int ret = 0;
  306. char name[80];
  307. snprintf(name, sizeof(name), FSID_FORMAT ".client%lld",
  308. PR_FSID(&client->fsid), client->monc.auth->global_id);
  309. client->debugfs_dir = debugfs_create_dir(name, ceph_debugfs_dir);
  310. if (!client->debugfs_dir)
  311. goto out;
  312. client->monc.debugfs_file = debugfs_create_file("monc",
  313. 0600,
  314. client->debugfs_dir,
  315. client,
  316. &monc_show_fops);
  317. if (!client->monc.debugfs_file)
  318. goto out;
  319. client->mdsc.debugfs_file = debugfs_create_file("mdsc",
  320. 0600,
  321. client->debugfs_dir,
  322. client,
  323. &mdsc_show_fops);
  324. if (!client->mdsc.debugfs_file)
  325. goto out;
  326. client->osdc.debugfs_file = debugfs_create_file("osdc",
  327. 0600,
  328. client->debugfs_dir,
  329. client,
  330. &osdc_show_fops);
  331. if (!client->osdc.debugfs_file)
  332. goto out;
  333. client->debugfs_monmap = debugfs_create_file("monmap",
  334. 0600,
  335. client->debugfs_dir,
  336. client,
  337. &monmap_show_fops);
  338. if (!client->debugfs_monmap)
  339. goto out;
  340. client->debugfs_mdsmap = debugfs_create_file("mdsmap",
  341. 0600,
  342. client->debugfs_dir,
  343. client,
  344. &mdsmap_show_fops);
  345. if (!client->debugfs_mdsmap)
  346. goto out;
  347. client->debugfs_osdmap = debugfs_create_file("osdmap",
  348. 0600,
  349. client->debugfs_dir,
  350. client,
  351. &osdmap_show_fops);
  352. if (!client->debugfs_osdmap)
  353. goto out;
  354. client->debugfs_dentry_lru = debugfs_create_file("dentry_lru",
  355. 0600,
  356. client->debugfs_dir,
  357. client,
  358. &dentry_lru_show_fops);
  359. if (!client->debugfs_dentry_lru)
  360. goto out;
  361. client->debugfs_caps = debugfs_create_file("caps",
  362. 0400,
  363. client->debugfs_dir,
  364. client,
  365. &caps_show_fops);
  366. if (!client->debugfs_caps)
  367. goto out;
  368. client->debugfs_congestion_kb = debugfs_create_file("writeback_congestion_kb",
  369. 0600,
  370. client->debugfs_dir,
  371. client,
  372. &congestion_kb_fops);
  373. if (!client->debugfs_congestion_kb)
  374. goto out;
  375. sprintf(name, "../../bdi/%s", dev_name(client->sb->s_bdi->dev));
  376. client->debugfs_bdi = debugfs_create_symlink("bdi", client->debugfs_dir,
  377. name);
  378. return 0;
  379. out:
  380. ceph_debugfs_client_cleanup(client);
  381. return ret;
  382. }
  383. void ceph_debugfs_client_cleanup(struct ceph_client *client)
  384. {
  385. debugfs_remove(client->debugfs_bdi);
  386. debugfs_remove(client->debugfs_caps);
  387. debugfs_remove(client->debugfs_dentry_lru);
  388. debugfs_remove(client->debugfs_osdmap);
  389. debugfs_remove(client->debugfs_mdsmap);
  390. debugfs_remove(client->debugfs_monmap);
  391. debugfs_remove(client->osdc.debugfs_file);
  392. debugfs_remove(client->mdsc.debugfs_file);
  393. debugfs_remove(client->monc.debugfs_file);
  394. debugfs_remove(client->debugfs_congestion_kb);
  395. debugfs_remove(client->debugfs_dir);
  396. }
  397. #else // CONFIG_DEBUG_FS
  398. int __init ceph_debugfs_init(void)
  399. {
  400. return 0;
  401. }
  402. void ceph_debugfs_cleanup(void)
  403. {
  404. }
  405. int ceph_debugfs_client_init(struct ceph_client *client)
  406. {
  407. return 0;
  408. }
  409. void ceph_debugfs_client_cleanup(struct ceph_client *client)
  410. {
  411. }
  412. #endif // CONFIG_DEBUG_FS