debugfs.c 12 KB

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