debugfs.c 12 KB

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