debugfs.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  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_statfs_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->statfs_request_tree); rp; rp = rb_next(rp)) {
  111. req = rb_entry(rp, struct ceph_mon_statfs_request, node);
  112. seq_printf(s, "%lld statfs\n", req->tid);
  113. }
  114. mutex_unlock(&monc->mutex);
  115. return 0;
  116. }
  117. static int mdsc_show(struct seq_file *s, void *p)
  118. {
  119. struct ceph_client *client = s->private;
  120. struct ceph_mds_client *mdsc = &client->mdsc;
  121. struct ceph_mds_request *req;
  122. struct rb_node *rp;
  123. int pathlen;
  124. u64 pathbase;
  125. char *path;
  126. mutex_lock(&mdsc->mutex);
  127. for (rp = rb_first(&mdsc->request_tree); rp; rp = rb_next(rp)) {
  128. req = rb_entry(rp, struct ceph_mds_request, r_node);
  129. if (req->r_request)
  130. seq_printf(s, "%lld\tmds%d\t", req->r_tid, req->r_mds);
  131. else
  132. seq_printf(s, "%lld\t(no request)\t", req->r_tid);
  133. seq_printf(s, "%s", ceph_mds_op_name(req->r_op));
  134. if (req->r_got_unsafe)
  135. seq_printf(s, "\t(unsafe)");
  136. else
  137. seq_printf(s, "\t");
  138. if (req->r_inode) {
  139. seq_printf(s, " #%llx", ceph_ino(req->r_inode));
  140. } else if (req->r_dentry) {
  141. path = ceph_mdsc_build_path(req->r_dentry, &pathlen,
  142. &pathbase, 0);
  143. spin_lock(&req->r_dentry->d_lock);
  144. seq_printf(s, " #%llx/%.*s (%s)",
  145. ceph_ino(req->r_dentry->d_parent->d_inode),
  146. req->r_dentry->d_name.len,
  147. req->r_dentry->d_name.name,
  148. path ? path : "");
  149. spin_unlock(&req->r_dentry->d_lock);
  150. kfree(path);
  151. } else if (req->r_path1) {
  152. seq_printf(s, " #%llx/%s", req->r_ino1.ino,
  153. req->r_path1);
  154. }
  155. if (req->r_old_dentry) {
  156. path = ceph_mdsc_build_path(req->r_old_dentry, &pathlen,
  157. &pathbase, 0);
  158. spin_lock(&req->r_old_dentry->d_lock);
  159. seq_printf(s, " #%llx/%.*s (%s)",
  160. ceph_ino(req->r_old_dentry->d_parent->d_inode),
  161. req->r_old_dentry->d_name.len,
  162. req->r_old_dentry->d_name.name,
  163. path ? path : "");
  164. spin_unlock(&req->r_old_dentry->d_lock);
  165. kfree(path);
  166. } else if (req->r_path2) {
  167. if (req->r_ino2.ino)
  168. seq_printf(s, " #%llx/%s", req->r_ino2.ino,
  169. req->r_path2);
  170. else
  171. seq_printf(s, " %s", req->r_path2);
  172. }
  173. seq_printf(s, "\n");
  174. }
  175. mutex_unlock(&mdsc->mutex);
  176. return 0;
  177. }
  178. static int osdc_show(struct seq_file *s, void *pp)
  179. {
  180. struct ceph_client *client = s->private;
  181. struct ceph_osd_client *osdc = &client->osdc;
  182. struct rb_node *p;
  183. mutex_lock(&osdc->request_mutex);
  184. for (p = rb_first(&osdc->requests); p; p = rb_next(p)) {
  185. struct ceph_osd_request *req;
  186. struct ceph_osd_request_head *head;
  187. struct ceph_osd_op *op;
  188. int num_ops;
  189. int opcode, olen;
  190. int i;
  191. req = rb_entry(p, struct ceph_osd_request, r_node);
  192. seq_printf(s, "%lld\tosd%d\t%d.%x\t", req->r_tid,
  193. req->r_osd ? req->r_osd->o_osd : -1,
  194. le32_to_cpu(req->r_pgid.pool),
  195. le16_to_cpu(req->r_pgid.ps));
  196. head = req->r_request->front.iov_base;
  197. op = (void *)(head + 1);
  198. num_ops = le16_to_cpu(head->num_ops);
  199. olen = le32_to_cpu(head->object_len);
  200. seq_printf(s, "%.*s", olen,
  201. (const char *)(head->ops + num_ops));
  202. if (req->r_reassert_version.epoch)
  203. seq_printf(s, "\t%u'%llu",
  204. (unsigned)le32_to_cpu(req->r_reassert_version.epoch),
  205. le64_to_cpu(req->r_reassert_version.version));
  206. else
  207. seq_printf(s, "\t");
  208. for (i = 0; i < num_ops; i++) {
  209. opcode = le16_to_cpu(op->op);
  210. seq_printf(s, "\t%s", ceph_osd_op_name(opcode));
  211. op++;
  212. }
  213. seq_printf(s, "\n");
  214. }
  215. mutex_unlock(&osdc->request_mutex);
  216. return 0;
  217. }
  218. static int caps_show(struct seq_file *s, void *p)
  219. {
  220. struct ceph_client *client = p;
  221. int total, avail, used, reserved, min;
  222. ceph_reservation_status(client, &total, &avail, &used, &reserved, &min);
  223. seq_printf(s, "total\t\t%d\n"
  224. "avail\t\t%d\n"
  225. "used\t\t%d\n"
  226. "reserved\t%d\n"
  227. "min\t%d\n",
  228. total, avail, used, reserved, min);
  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. static int congestion_kb_set(void *data, u64 val)
  272. {
  273. struct ceph_client *client = (struct ceph_client *)data;
  274. if (client)
  275. client->mount_args->congestion_kb = (int)val;
  276. return 0;
  277. }
  278. static int congestion_kb_get(void *data, u64 *val)
  279. {
  280. struct ceph_client *client = (struct ceph_client *)data;
  281. if (client)
  282. *val = (u64)client->mount_args->congestion_kb;
  283. return 0;
  284. }
  285. DEFINE_SIMPLE_ATTRIBUTE(congestion_kb_fops, congestion_kb_get,
  286. congestion_kb_set, "%llu\n");
  287. int __init ceph_debugfs_init(void)
  288. {
  289. ceph_debugfs_dir = debugfs_create_dir("ceph", NULL);
  290. if (!ceph_debugfs_dir)
  291. return -ENOMEM;
  292. return 0;
  293. }
  294. void ceph_debugfs_cleanup(void)
  295. {
  296. debugfs_remove(ceph_debugfs_dir);
  297. }
  298. int ceph_debugfs_client_init(struct ceph_client *client)
  299. {
  300. int ret = 0;
  301. char name[80];
  302. snprintf(name, sizeof(name), FSID_FORMAT ".client%lld",
  303. PR_FSID(&client->fsid), client->monc.auth->global_id);
  304. client->debugfs_dir = debugfs_create_dir(name, ceph_debugfs_dir);
  305. if (!client->debugfs_dir)
  306. goto out;
  307. client->monc.debugfs_file = debugfs_create_file("monc",
  308. 0600,
  309. client->debugfs_dir,
  310. client,
  311. &monc_show_fops);
  312. if (!client->monc.debugfs_file)
  313. goto out;
  314. client->mdsc.debugfs_file = debugfs_create_file("mdsc",
  315. 0600,
  316. client->debugfs_dir,
  317. client,
  318. &mdsc_show_fops);
  319. if (!client->mdsc.debugfs_file)
  320. goto out;
  321. client->osdc.debugfs_file = debugfs_create_file("osdc",
  322. 0600,
  323. client->debugfs_dir,
  324. client,
  325. &osdc_show_fops);
  326. if (!client->osdc.debugfs_file)
  327. goto out;
  328. client->debugfs_monmap = debugfs_create_file("monmap",
  329. 0600,
  330. client->debugfs_dir,
  331. client,
  332. &monmap_show_fops);
  333. if (!client->debugfs_monmap)
  334. goto out;
  335. client->debugfs_mdsmap = debugfs_create_file("mdsmap",
  336. 0600,
  337. client->debugfs_dir,
  338. client,
  339. &mdsmap_show_fops);
  340. if (!client->debugfs_mdsmap)
  341. goto out;
  342. client->debugfs_osdmap = debugfs_create_file("osdmap",
  343. 0600,
  344. client->debugfs_dir,
  345. client,
  346. &osdmap_show_fops);
  347. if (!client->debugfs_osdmap)
  348. goto out;
  349. client->debugfs_dentry_lru = debugfs_create_file("dentry_lru",
  350. 0600,
  351. client->debugfs_dir,
  352. client,
  353. &dentry_lru_show_fops);
  354. if (!client->debugfs_dentry_lru)
  355. goto out;
  356. client->debugfs_caps = debugfs_create_file("caps",
  357. 0400,
  358. client->debugfs_dir,
  359. client,
  360. &caps_show_fops);
  361. if (!client->debugfs_caps)
  362. goto out;
  363. client->debugfs_congestion_kb = debugfs_create_file("writeback_congestion_kb",
  364. 0600,
  365. client->debugfs_dir,
  366. client,
  367. &congestion_kb_fops);
  368. if (!client->debugfs_congestion_kb)
  369. goto out;
  370. sprintf(name, "../../bdi/%s", dev_name(client->sb->s_bdi->dev));
  371. client->debugfs_bdi = debugfs_create_symlink("bdi", client->debugfs_dir,
  372. name);
  373. return 0;
  374. out:
  375. ceph_debugfs_client_cleanup(client);
  376. return ret;
  377. }
  378. void ceph_debugfs_client_cleanup(struct ceph_client *client)
  379. {
  380. debugfs_remove(client->debugfs_bdi);
  381. debugfs_remove(client->debugfs_caps);
  382. debugfs_remove(client->debugfs_dentry_lru);
  383. debugfs_remove(client->debugfs_osdmap);
  384. debugfs_remove(client->debugfs_mdsmap);
  385. debugfs_remove(client->debugfs_monmap);
  386. debugfs_remove(client->osdc.debugfs_file);
  387. debugfs_remove(client->mdsc.debugfs_file);
  388. debugfs_remove(client->monc.debugfs_file);
  389. debugfs_remove(client->debugfs_congestion_kb);
  390. debugfs_remove(client->debugfs_dir);
  391. }
  392. #else // CONFIG_DEBUG_FS
  393. int __init ceph_debugfs_init(void)
  394. {
  395. return 0;
  396. }
  397. void ceph_debugfs_cleanup(void)
  398. {
  399. }
  400. int ceph_debugfs_client_init(struct ceph_client *client)
  401. {
  402. return 0;
  403. }
  404. void ceph_debugfs_client_cleanup(struct ceph_client *client)
  405. {
  406. }
  407. #endif // CONFIG_DEBUG_FS