drbd_debugfs.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891
  1. // SPDX-License-Identifier: GPL-2.0
  2. #define pr_fmt(fmt) "drbd debugfs: " fmt
  3. #include <linux/kernel.h>
  4. #include <linux/module.h>
  5. #include <linux/debugfs.h>
  6. #include <linux/seq_file.h>
  7. #include <linux/stat.h>
  8. #include <linux/jiffies.h>
  9. #include <linux/list.h>
  10. #include "drbd_int.h"
  11. #include "drbd_req.h"
  12. #include "drbd_debugfs.h"
  13. /**********************************************************************
  14. * Whenever you change the file format, remember to bump the version. *
  15. **********************************************************************/
  16. static struct dentry *drbd_debugfs_root;
  17. static struct dentry *drbd_debugfs_version;
  18. static struct dentry *drbd_debugfs_resources;
  19. static struct dentry *drbd_debugfs_minors;
  20. static void seq_print_age_or_dash(struct seq_file *m, bool valid, unsigned long dt)
  21. {
  22. if (valid)
  23. seq_printf(m, "\t%d", jiffies_to_msecs(dt));
  24. else
  25. seq_printf(m, "\t-");
  26. }
  27. static void __seq_print_rq_state_bit(struct seq_file *m,
  28. bool is_set, char *sep, const char *set_name, const char *unset_name)
  29. {
  30. if (is_set && set_name) {
  31. seq_putc(m, *sep);
  32. seq_puts(m, set_name);
  33. *sep = '|';
  34. } else if (!is_set && unset_name) {
  35. seq_putc(m, *sep);
  36. seq_puts(m, unset_name);
  37. *sep = '|';
  38. }
  39. }
  40. static void seq_print_rq_state_bit(struct seq_file *m,
  41. bool is_set, char *sep, const char *set_name)
  42. {
  43. __seq_print_rq_state_bit(m, is_set, sep, set_name, NULL);
  44. }
  45. /* pretty print enum drbd_req_state_bits req->rq_state */
  46. static void seq_print_request_state(struct seq_file *m, struct drbd_request *req)
  47. {
  48. unsigned int s = req->rq_state;
  49. char sep = ' ';
  50. seq_printf(m, "\t0x%08x", s);
  51. seq_printf(m, "\tmaster: %s", req->master_bio ? "pending" : "completed");
  52. /* RQ_WRITE ignored, already reported */
  53. seq_puts(m, "\tlocal:");
  54. seq_print_rq_state_bit(m, s & RQ_IN_ACT_LOG, &sep, "in-AL");
  55. seq_print_rq_state_bit(m, s & RQ_POSTPONED, &sep, "postponed");
  56. seq_print_rq_state_bit(m, s & RQ_COMPLETION_SUSP, &sep, "suspended");
  57. sep = ' ';
  58. seq_print_rq_state_bit(m, s & RQ_LOCAL_PENDING, &sep, "pending");
  59. seq_print_rq_state_bit(m, s & RQ_LOCAL_COMPLETED, &sep, "completed");
  60. seq_print_rq_state_bit(m, s & RQ_LOCAL_ABORTED, &sep, "aborted");
  61. seq_print_rq_state_bit(m, s & RQ_LOCAL_OK, &sep, "ok");
  62. if (sep == ' ')
  63. seq_puts(m, " -");
  64. /* for_each_connection ... */
  65. seq_printf(m, "\tnet:");
  66. sep = ' ';
  67. seq_print_rq_state_bit(m, s & RQ_NET_PENDING, &sep, "pending");
  68. seq_print_rq_state_bit(m, s & RQ_NET_QUEUED, &sep, "queued");
  69. seq_print_rq_state_bit(m, s & RQ_NET_SENT, &sep, "sent");
  70. seq_print_rq_state_bit(m, s & RQ_NET_DONE, &sep, "done");
  71. seq_print_rq_state_bit(m, s & RQ_NET_SIS, &sep, "sis");
  72. seq_print_rq_state_bit(m, s & RQ_NET_OK, &sep, "ok");
  73. if (sep == ' ')
  74. seq_puts(m, " -");
  75. seq_printf(m, " :");
  76. sep = ' ';
  77. seq_print_rq_state_bit(m, s & RQ_EXP_RECEIVE_ACK, &sep, "B");
  78. seq_print_rq_state_bit(m, s & RQ_EXP_WRITE_ACK, &sep, "C");
  79. seq_print_rq_state_bit(m, s & RQ_EXP_BARR_ACK, &sep, "barr");
  80. if (sep == ' ')
  81. seq_puts(m, " -");
  82. seq_printf(m, "\n");
  83. }
  84. static void seq_print_one_request(struct seq_file *m, struct drbd_request *req, unsigned long now)
  85. {
  86. /* change anything here, fixup header below! */
  87. unsigned int s = req->rq_state;
  88. #define RQ_HDR_1 "epoch\tsector\tsize\trw"
  89. seq_printf(m, "0x%x\t%llu\t%u\t%s",
  90. req->epoch,
  91. (unsigned long long)req->i.sector, req->i.size >> 9,
  92. (s & RQ_WRITE) ? "W" : "R");
  93. #define RQ_HDR_2 "\tstart\tin AL\tsubmit"
  94. seq_printf(m, "\t%d", jiffies_to_msecs(now - req->start_jif));
  95. seq_print_age_or_dash(m, s & RQ_IN_ACT_LOG, now - req->in_actlog_jif);
  96. seq_print_age_or_dash(m, s & RQ_LOCAL_PENDING, now - req->pre_submit_jif);
  97. #define RQ_HDR_3 "\tsent\tacked\tdone"
  98. seq_print_age_or_dash(m, s & RQ_NET_SENT, now - req->pre_send_jif);
  99. seq_print_age_or_dash(m, (s & RQ_NET_SENT) && !(s & RQ_NET_PENDING), now - req->acked_jif);
  100. seq_print_age_or_dash(m, s & RQ_NET_DONE, now - req->net_done_jif);
  101. #define RQ_HDR_4 "\tstate\n"
  102. seq_print_request_state(m, req);
  103. }
  104. #define RQ_HDR RQ_HDR_1 RQ_HDR_2 RQ_HDR_3 RQ_HDR_4
  105. static void seq_print_minor_vnr_req(struct seq_file *m, struct drbd_request *req, unsigned long now)
  106. {
  107. seq_printf(m, "%u\t%u\t", req->device->minor, req->device->vnr);
  108. seq_print_one_request(m, req, now);
  109. }
  110. static void seq_print_resource_pending_meta_io(struct seq_file *m, struct drbd_resource *resource, unsigned long now)
  111. {
  112. struct drbd_device *device;
  113. unsigned int i;
  114. seq_puts(m, "minor\tvnr\tstart\tsubmit\tintent\n");
  115. rcu_read_lock();
  116. idr_for_each_entry(&resource->devices, device, i) {
  117. struct drbd_md_io tmp;
  118. /* In theory this is racy,
  119. * in the sense that there could have been a
  120. * drbd_md_put_buffer(); drbd_md_get_buffer();
  121. * between accessing these members here. */
  122. tmp = device->md_io;
  123. if (atomic_read(&tmp.in_use)) {
  124. seq_printf(m, "%u\t%u\t%d\t",
  125. device->minor, device->vnr,
  126. jiffies_to_msecs(now - tmp.start_jif));
  127. if (time_before(tmp.submit_jif, tmp.start_jif))
  128. seq_puts(m, "-\t");
  129. else
  130. seq_printf(m, "%d\t", jiffies_to_msecs(now - tmp.submit_jif));
  131. seq_printf(m, "%s\n", tmp.current_use);
  132. }
  133. }
  134. rcu_read_unlock();
  135. }
  136. static void seq_print_waiting_for_AL(struct seq_file *m, struct drbd_resource *resource, unsigned long now)
  137. {
  138. struct drbd_device *device;
  139. unsigned int i;
  140. seq_puts(m, "minor\tvnr\tage\t#waiting\n");
  141. rcu_read_lock();
  142. idr_for_each_entry(&resource->devices, device, i) {
  143. unsigned long jif;
  144. struct drbd_request *req;
  145. int n = atomic_read(&device->ap_actlog_cnt);
  146. if (n) {
  147. spin_lock_irq(&device->resource->req_lock);
  148. req = list_first_entry_or_null(&device->pending_master_completion[1],
  149. struct drbd_request, req_pending_master_completion);
  150. /* if the oldest request does not wait for the activity log
  151. * it is not interesting for us here */
  152. if (req && !(req->rq_state & RQ_IN_ACT_LOG))
  153. jif = req->start_jif;
  154. else
  155. req = NULL;
  156. spin_unlock_irq(&device->resource->req_lock);
  157. }
  158. if (n) {
  159. seq_printf(m, "%u\t%u\t", device->minor, device->vnr);
  160. if (req)
  161. seq_printf(m, "%u\t", jiffies_to_msecs(now - jif));
  162. else
  163. seq_puts(m, "-\t");
  164. seq_printf(m, "%u\n", n);
  165. }
  166. }
  167. rcu_read_unlock();
  168. }
  169. static void seq_print_device_bitmap_io(struct seq_file *m, struct drbd_device *device, unsigned long now)
  170. {
  171. struct drbd_bm_aio_ctx *ctx;
  172. unsigned long start_jif;
  173. unsigned int in_flight;
  174. unsigned int flags;
  175. spin_lock_irq(&device->resource->req_lock);
  176. ctx = list_first_entry_or_null(&device->pending_bitmap_io, struct drbd_bm_aio_ctx, list);
  177. if (ctx && ctx->done)
  178. ctx = NULL;
  179. if (ctx) {
  180. start_jif = ctx->start_jif;
  181. in_flight = atomic_read(&ctx->in_flight);
  182. flags = ctx->flags;
  183. }
  184. spin_unlock_irq(&device->resource->req_lock);
  185. if (ctx) {
  186. seq_printf(m, "%u\t%u\t%c\t%u\t%u\n",
  187. device->minor, device->vnr,
  188. (flags & BM_AIO_READ) ? 'R' : 'W',
  189. jiffies_to_msecs(now - start_jif),
  190. in_flight);
  191. }
  192. }
  193. static void seq_print_resource_pending_bitmap_io(struct seq_file *m, struct drbd_resource *resource, unsigned long now)
  194. {
  195. struct drbd_device *device;
  196. unsigned int i;
  197. seq_puts(m, "minor\tvnr\trw\tage\t#in-flight\n");
  198. rcu_read_lock();
  199. idr_for_each_entry(&resource->devices, device, i) {
  200. seq_print_device_bitmap_io(m, device, now);
  201. }
  202. rcu_read_unlock();
  203. }
  204. /* pretty print enum peer_req->flags */
  205. static void seq_print_peer_request_flags(struct seq_file *m, struct drbd_peer_request *peer_req)
  206. {
  207. unsigned long f = peer_req->flags;
  208. char sep = ' ';
  209. __seq_print_rq_state_bit(m, f & EE_SUBMITTED, &sep, "submitted", "preparing");
  210. __seq_print_rq_state_bit(m, f & EE_APPLICATION, &sep, "application", "internal");
  211. seq_print_rq_state_bit(m, f & EE_CALL_AL_COMPLETE_IO, &sep, "in-AL");
  212. seq_print_rq_state_bit(m, f & EE_SEND_WRITE_ACK, &sep, "C");
  213. seq_print_rq_state_bit(m, f & EE_MAY_SET_IN_SYNC, &sep, "set-in-sync");
  214. seq_print_rq_state_bit(m, f & EE_TRIM, &sep, "trim");
  215. seq_print_rq_state_bit(m, f & EE_ZEROOUT, &sep, "zero-out");
  216. seq_print_rq_state_bit(m, f & EE_WRITE_SAME, &sep, "write-same");
  217. seq_putc(m, '\n');
  218. }
  219. static void seq_print_peer_request(struct seq_file *m,
  220. struct drbd_device *device, struct list_head *lh,
  221. unsigned long now)
  222. {
  223. bool reported_preparing = false;
  224. struct drbd_peer_request *peer_req;
  225. list_for_each_entry(peer_req, lh, w.list) {
  226. if (reported_preparing && !(peer_req->flags & EE_SUBMITTED))
  227. continue;
  228. if (device)
  229. seq_printf(m, "%u\t%u\t", device->minor, device->vnr);
  230. seq_printf(m, "%llu\t%u\t%c\t%u\t",
  231. (unsigned long long)peer_req->i.sector, peer_req->i.size >> 9,
  232. (peer_req->flags & EE_WRITE) ? 'W' : 'R',
  233. jiffies_to_msecs(now - peer_req->submit_jif));
  234. seq_print_peer_request_flags(m, peer_req);
  235. if (peer_req->flags & EE_SUBMITTED)
  236. break;
  237. else
  238. reported_preparing = true;
  239. }
  240. }
  241. static void seq_print_device_peer_requests(struct seq_file *m,
  242. struct drbd_device *device, unsigned long now)
  243. {
  244. seq_puts(m, "minor\tvnr\tsector\tsize\trw\tage\tflags\n");
  245. spin_lock_irq(&device->resource->req_lock);
  246. seq_print_peer_request(m, device, &device->active_ee, now);
  247. seq_print_peer_request(m, device, &device->read_ee, now);
  248. seq_print_peer_request(m, device, &device->sync_ee, now);
  249. spin_unlock_irq(&device->resource->req_lock);
  250. if (test_bit(FLUSH_PENDING, &device->flags)) {
  251. seq_printf(m, "%u\t%u\t-\t-\tF\t%u\tflush\n",
  252. device->minor, device->vnr,
  253. jiffies_to_msecs(now - device->flush_jif));
  254. }
  255. }
  256. static void seq_print_resource_pending_peer_requests(struct seq_file *m,
  257. struct drbd_resource *resource, unsigned long now)
  258. {
  259. struct drbd_device *device;
  260. unsigned int i;
  261. rcu_read_lock();
  262. idr_for_each_entry(&resource->devices, device, i) {
  263. seq_print_device_peer_requests(m, device, now);
  264. }
  265. rcu_read_unlock();
  266. }
  267. static void seq_print_resource_transfer_log_summary(struct seq_file *m,
  268. struct drbd_resource *resource,
  269. struct drbd_connection *connection,
  270. unsigned long now)
  271. {
  272. struct drbd_request *req;
  273. unsigned int count = 0;
  274. unsigned int show_state = 0;
  275. seq_puts(m, "n\tdevice\tvnr\t" RQ_HDR);
  276. spin_lock_irq(&resource->req_lock);
  277. list_for_each_entry(req, &connection->transfer_log, tl_requests) {
  278. unsigned int tmp = 0;
  279. unsigned int s;
  280. ++count;
  281. /* don't disable irq "forever" */
  282. if (!(count & 0x1ff)) {
  283. struct drbd_request *req_next;
  284. kref_get(&req->kref);
  285. spin_unlock_irq(&resource->req_lock);
  286. cond_resched();
  287. spin_lock_irq(&resource->req_lock);
  288. req_next = list_next_entry(req, tl_requests);
  289. if (kref_put(&req->kref, drbd_req_destroy))
  290. req = req_next;
  291. if (&req->tl_requests == &connection->transfer_log)
  292. break;
  293. }
  294. s = req->rq_state;
  295. /* This is meant to summarize timing issues, to be able to tell
  296. * local disk problems from network problems.
  297. * Skip requests, if we have shown an even older request with
  298. * similar aspects already. */
  299. if (req->master_bio == NULL)
  300. tmp |= 1;
  301. if ((s & RQ_LOCAL_MASK) && (s & RQ_LOCAL_PENDING))
  302. tmp |= 2;
  303. if (s & RQ_NET_MASK) {
  304. if (!(s & RQ_NET_SENT))
  305. tmp |= 4;
  306. if (s & RQ_NET_PENDING)
  307. tmp |= 8;
  308. if (!(s & RQ_NET_DONE))
  309. tmp |= 16;
  310. }
  311. if ((tmp & show_state) == tmp)
  312. continue;
  313. show_state |= tmp;
  314. seq_printf(m, "%u\t", count);
  315. seq_print_minor_vnr_req(m, req, now);
  316. if (show_state == 0x1f)
  317. break;
  318. }
  319. spin_unlock_irq(&resource->req_lock);
  320. }
  321. /* TODO: transfer_log and friends should be moved to resource */
  322. static int in_flight_summary_show(struct seq_file *m, void *pos)
  323. {
  324. struct drbd_resource *resource = m->private;
  325. struct drbd_connection *connection;
  326. unsigned long jif = jiffies;
  327. connection = first_connection(resource);
  328. /* This does not happen, actually.
  329. * But be robust and prepare for future code changes. */
  330. if (!connection || !kref_get_unless_zero(&connection->kref))
  331. return -ESTALE;
  332. /* BUMP me if you change the file format/content/presentation */
  333. seq_printf(m, "v: %u\n\n", 0);
  334. seq_puts(m, "oldest bitmap IO\n");
  335. seq_print_resource_pending_bitmap_io(m, resource, jif);
  336. seq_putc(m, '\n');
  337. seq_puts(m, "meta data IO\n");
  338. seq_print_resource_pending_meta_io(m, resource, jif);
  339. seq_putc(m, '\n');
  340. seq_puts(m, "socket buffer stats\n");
  341. /* for each connection ... once we have more than one */
  342. rcu_read_lock();
  343. if (connection->data.socket) {
  344. /* open coded SIOCINQ, the "relevant" part */
  345. struct tcp_sock *tp = tcp_sk(connection->data.socket->sk);
  346. int answ = tp->rcv_nxt - tp->copied_seq;
  347. seq_printf(m, "unread receive buffer: %u Byte\n", answ);
  348. /* open coded SIOCOUTQ, the "relevant" part */
  349. answ = tp->write_seq - tp->snd_una;
  350. seq_printf(m, "unacked send buffer: %u Byte\n", answ);
  351. }
  352. rcu_read_unlock();
  353. seq_putc(m, '\n');
  354. seq_puts(m, "oldest peer requests\n");
  355. seq_print_resource_pending_peer_requests(m, resource, jif);
  356. seq_putc(m, '\n');
  357. seq_puts(m, "application requests waiting for activity log\n");
  358. seq_print_waiting_for_AL(m, resource, jif);
  359. seq_putc(m, '\n');
  360. seq_puts(m, "oldest application requests\n");
  361. seq_print_resource_transfer_log_summary(m, resource, connection, jif);
  362. seq_putc(m, '\n');
  363. jif = jiffies - jif;
  364. if (jif)
  365. seq_printf(m, "generated in %d ms\n", jiffies_to_msecs(jif));
  366. kref_put(&connection->kref, drbd_destroy_connection);
  367. return 0;
  368. }
  369. /* make sure at *open* time that the respective object won't go away. */
  370. static int drbd_single_open(struct file *file, int (*show)(struct seq_file *, void *),
  371. void *data, struct kref *kref,
  372. void (*release)(struct kref *))
  373. {
  374. struct dentry *parent;
  375. int ret = -ESTALE;
  376. /* Are we still linked,
  377. * or has debugfs_remove() already been called? */
  378. parent = file->f_path.dentry->d_parent;
  379. /* serialize with d_delete() */
  380. inode_lock(d_inode(parent));
  381. /* Make sure the object is still alive */
  382. if (simple_positive(file->f_path.dentry)
  383. && kref_get_unless_zero(kref))
  384. ret = 0;
  385. inode_unlock(d_inode(parent));
  386. if (!ret) {
  387. ret = single_open(file, show, data);
  388. if (ret)
  389. kref_put(kref, release);
  390. }
  391. return ret;
  392. }
  393. static int in_flight_summary_open(struct inode *inode, struct file *file)
  394. {
  395. struct drbd_resource *resource = inode->i_private;
  396. return drbd_single_open(file, in_flight_summary_show, resource,
  397. &resource->kref, drbd_destroy_resource);
  398. }
  399. static int in_flight_summary_release(struct inode *inode, struct file *file)
  400. {
  401. struct drbd_resource *resource = inode->i_private;
  402. kref_put(&resource->kref, drbd_destroy_resource);
  403. return single_release(inode, file);
  404. }
  405. static const struct file_operations in_flight_summary_fops = {
  406. .owner = THIS_MODULE,
  407. .open = in_flight_summary_open,
  408. .read = seq_read,
  409. .llseek = seq_lseek,
  410. .release = in_flight_summary_release,
  411. };
  412. void drbd_debugfs_resource_add(struct drbd_resource *resource)
  413. {
  414. struct dentry *dentry;
  415. dentry = debugfs_create_dir(resource->name, drbd_debugfs_resources);
  416. resource->debugfs_res = dentry;
  417. dentry = debugfs_create_dir("volumes", resource->debugfs_res);
  418. resource->debugfs_res_volumes = dentry;
  419. dentry = debugfs_create_dir("connections", resource->debugfs_res);
  420. resource->debugfs_res_connections = dentry;
  421. dentry = debugfs_create_file("in_flight_summary", 0440,
  422. resource->debugfs_res, resource,
  423. &in_flight_summary_fops);
  424. resource->debugfs_res_in_flight_summary = dentry;
  425. }
  426. static void drbd_debugfs_remove(struct dentry **dp)
  427. {
  428. debugfs_remove(*dp);
  429. *dp = NULL;
  430. }
  431. void drbd_debugfs_resource_cleanup(struct drbd_resource *resource)
  432. {
  433. /* it is ok to call debugfs_remove(NULL) */
  434. drbd_debugfs_remove(&resource->debugfs_res_in_flight_summary);
  435. drbd_debugfs_remove(&resource->debugfs_res_connections);
  436. drbd_debugfs_remove(&resource->debugfs_res_volumes);
  437. drbd_debugfs_remove(&resource->debugfs_res);
  438. }
  439. static void seq_print_one_timing_detail(struct seq_file *m,
  440. const struct drbd_thread_timing_details *tdp,
  441. unsigned long now)
  442. {
  443. struct drbd_thread_timing_details td;
  444. /* No locking...
  445. * use temporary assignment to get at consistent data. */
  446. do {
  447. td = *tdp;
  448. } while (td.cb_nr != tdp->cb_nr);
  449. if (!td.cb_addr)
  450. return;
  451. seq_printf(m, "%u\t%d\t%s:%u\t%ps\n",
  452. td.cb_nr,
  453. jiffies_to_msecs(now - td.start_jif),
  454. td.caller_fn, td.line,
  455. td.cb_addr);
  456. }
  457. static void seq_print_timing_details(struct seq_file *m,
  458. const char *title,
  459. unsigned int cb_nr, struct drbd_thread_timing_details *tdp, unsigned long now)
  460. {
  461. unsigned int start_idx;
  462. unsigned int i;
  463. seq_printf(m, "%s\n", title);
  464. /* If not much is going on, this will result in natural ordering.
  465. * If it is very busy, we will possibly skip events, or even see wrap
  466. * arounds, which could only be avoided with locking.
  467. */
  468. start_idx = cb_nr % DRBD_THREAD_DETAILS_HIST;
  469. for (i = start_idx; i < DRBD_THREAD_DETAILS_HIST; i++)
  470. seq_print_one_timing_detail(m, tdp+i, now);
  471. for (i = 0; i < start_idx; i++)
  472. seq_print_one_timing_detail(m, tdp+i, now);
  473. }
  474. static int callback_history_show(struct seq_file *m, void *ignored)
  475. {
  476. struct drbd_connection *connection = m->private;
  477. unsigned long jif = jiffies;
  478. /* BUMP me if you change the file format/content/presentation */
  479. seq_printf(m, "v: %u\n\n", 0);
  480. seq_puts(m, "n\tage\tcallsite\tfn\n");
  481. seq_print_timing_details(m, "worker", connection->w_cb_nr, connection->w_timing_details, jif);
  482. seq_print_timing_details(m, "receiver", connection->r_cb_nr, connection->r_timing_details, jif);
  483. return 0;
  484. }
  485. static int callback_history_open(struct inode *inode, struct file *file)
  486. {
  487. struct drbd_connection *connection = inode->i_private;
  488. return drbd_single_open(file, callback_history_show, connection,
  489. &connection->kref, drbd_destroy_connection);
  490. }
  491. static int callback_history_release(struct inode *inode, struct file *file)
  492. {
  493. struct drbd_connection *connection = inode->i_private;
  494. kref_put(&connection->kref, drbd_destroy_connection);
  495. return single_release(inode, file);
  496. }
  497. static const struct file_operations connection_callback_history_fops = {
  498. .owner = THIS_MODULE,
  499. .open = callback_history_open,
  500. .read = seq_read,
  501. .llseek = seq_lseek,
  502. .release = callback_history_release,
  503. };
  504. static int connection_oldest_requests_show(struct seq_file *m, void *ignored)
  505. {
  506. struct drbd_connection *connection = m->private;
  507. unsigned long now = jiffies;
  508. struct drbd_request *r1, *r2;
  509. /* BUMP me if you change the file format/content/presentation */
  510. seq_printf(m, "v: %u\n\n", 0);
  511. spin_lock_irq(&connection->resource->req_lock);
  512. r1 = connection->req_next;
  513. if (r1)
  514. seq_print_minor_vnr_req(m, r1, now);
  515. r2 = connection->req_ack_pending;
  516. if (r2 && r2 != r1) {
  517. r1 = r2;
  518. seq_print_minor_vnr_req(m, r1, now);
  519. }
  520. r2 = connection->req_not_net_done;
  521. if (r2 && r2 != r1)
  522. seq_print_minor_vnr_req(m, r2, now);
  523. spin_unlock_irq(&connection->resource->req_lock);
  524. return 0;
  525. }
  526. static int connection_oldest_requests_open(struct inode *inode, struct file *file)
  527. {
  528. struct drbd_connection *connection = inode->i_private;
  529. return drbd_single_open(file, connection_oldest_requests_show, connection,
  530. &connection->kref, drbd_destroy_connection);
  531. }
  532. static int connection_oldest_requests_release(struct inode *inode, struct file *file)
  533. {
  534. struct drbd_connection *connection = inode->i_private;
  535. kref_put(&connection->kref, drbd_destroy_connection);
  536. return single_release(inode, file);
  537. }
  538. static const struct file_operations connection_oldest_requests_fops = {
  539. .owner = THIS_MODULE,
  540. .open = connection_oldest_requests_open,
  541. .read = seq_read,
  542. .llseek = seq_lseek,
  543. .release = connection_oldest_requests_release,
  544. };
  545. void drbd_debugfs_connection_add(struct drbd_connection *connection)
  546. {
  547. struct dentry *conns_dir = connection->resource->debugfs_res_connections;
  548. struct dentry *dentry;
  549. /* Once we enable mutliple peers,
  550. * these connections will have descriptive names.
  551. * For now, it is just the one connection to the (only) "peer". */
  552. dentry = debugfs_create_dir("peer", conns_dir);
  553. connection->debugfs_conn = dentry;
  554. dentry = debugfs_create_file("callback_history", 0440,
  555. connection->debugfs_conn, connection,
  556. &connection_callback_history_fops);
  557. connection->debugfs_conn_callback_history = dentry;
  558. dentry = debugfs_create_file("oldest_requests", 0440,
  559. connection->debugfs_conn, connection,
  560. &connection_oldest_requests_fops);
  561. connection->debugfs_conn_oldest_requests = dentry;
  562. }
  563. void drbd_debugfs_connection_cleanup(struct drbd_connection *connection)
  564. {
  565. drbd_debugfs_remove(&connection->debugfs_conn_callback_history);
  566. drbd_debugfs_remove(&connection->debugfs_conn_oldest_requests);
  567. drbd_debugfs_remove(&connection->debugfs_conn);
  568. }
  569. static void resync_dump_detail(struct seq_file *m, struct lc_element *e)
  570. {
  571. struct bm_extent *bme = lc_entry(e, struct bm_extent, lce);
  572. seq_printf(m, "%5d %s %s %s", bme->rs_left,
  573. test_bit(BME_NO_WRITES, &bme->flags) ? "NO_WRITES" : "---------",
  574. test_bit(BME_LOCKED, &bme->flags) ? "LOCKED" : "------",
  575. test_bit(BME_PRIORITY, &bme->flags) ? "PRIORITY" : "--------"
  576. );
  577. }
  578. static int device_resync_extents_show(struct seq_file *m, void *ignored)
  579. {
  580. struct drbd_device *device = m->private;
  581. /* BUMP me if you change the file format/content/presentation */
  582. seq_printf(m, "v: %u\n\n", 0);
  583. if (get_ldev_if_state(device, D_FAILED)) {
  584. lc_seq_printf_stats(m, device->resync);
  585. lc_seq_dump_details(m, device->resync, "rs_left flags", resync_dump_detail);
  586. put_ldev(device);
  587. }
  588. return 0;
  589. }
  590. static int device_act_log_extents_show(struct seq_file *m, void *ignored)
  591. {
  592. struct drbd_device *device = m->private;
  593. /* BUMP me if you change the file format/content/presentation */
  594. seq_printf(m, "v: %u\n\n", 0);
  595. if (get_ldev_if_state(device, D_FAILED)) {
  596. lc_seq_printf_stats(m, device->act_log);
  597. lc_seq_dump_details(m, device->act_log, "", NULL);
  598. put_ldev(device);
  599. }
  600. return 0;
  601. }
  602. static int device_oldest_requests_show(struct seq_file *m, void *ignored)
  603. {
  604. struct drbd_device *device = m->private;
  605. struct drbd_resource *resource = device->resource;
  606. unsigned long now = jiffies;
  607. struct drbd_request *r1, *r2;
  608. int i;
  609. /* BUMP me if you change the file format/content/presentation */
  610. seq_printf(m, "v: %u\n\n", 0);
  611. seq_puts(m, RQ_HDR);
  612. spin_lock_irq(&resource->req_lock);
  613. /* WRITE, then READ */
  614. for (i = 1; i >= 0; --i) {
  615. r1 = list_first_entry_or_null(&device->pending_master_completion[i],
  616. struct drbd_request, req_pending_master_completion);
  617. r2 = list_first_entry_or_null(&device->pending_completion[i],
  618. struct drbd_request, req_pending_local);
  619. if (r1)
  620. seq_print_one_request(m, r1, now);
  621. if (r2 && r2 != r1)
  622. seq_print_one_request(m, r2, now);
  623. }
  624. spin_unlock_irq(&resource->req_lock);
  625. return 0;
  626. }
  627. static int device_data_gen_id_show(struct seq_file *m, void *ignored)
  628. {
  629. struct drbd_device *device = m->private;
  630. struct drbd_md *md;
  631. enum drbd_uuid_index idx;
  632. if (!get_ldev_if_state(device, D_FAILED))
  633. return -ENODEV;
  634. md = &device->ldev->md;
  635. spin_lock_irq(&md->uuid_lock);
  636. for (idx = UI_CURRENT; idx <= UI_HISTORY_END; idx++) {
  637. seq_printf(m, "0x%016llX\n", md->uuid[idx]);
  638. }
  639. spin_unlock_irq(&md->uuid_lock);
  640. put_ldev(device);
  641. return 0;
  642. }
  643. static int device_ed_gen_id_show(struct seq_file *m, void *ignored)
  644. {
  645. struct drbd_device *device = m->private;
  646. seq_printf(m, "0x%016llX\n", (unsigned long long)device->ed_uuid);
  647. return 0;
  648. }
  649. #define drbd_debugfs_device_attr(name) \
  650. static int device_ ## name ## _open(struct inode *inode, struct file *file) \
  651. { \
  652. struct drbd_device *device = inode->i_private; \
  653. return drbd_single_open(file, device_ ## name ## _show, device, \
  654. &device->kref, drbd_destroy_device); \
  655. } \
  656. static int device_ ## name ## _release(struct inode *inode, struct file *file) \
  657. { \
  658. struct drbd_device *device = inode->i_private; \
  659. kref_put(&device->kref, drbd_destroy_device); \
  660. return single_release(inode, file); \
  661. } \
  662. static const struct file_operations device_ ## name ## _fops = { \
  663. .owner = THIS_MODULE, \
  664. .open = device_ ## name ## _open, \
  665. .read = seq_read, \
  666. .llseek = seq_lseek, \
  667. .release = device_ ## name ## _release, \
  668. };
  669. drbd_debugfs_device_attr(oldest_requests)
  670. drbd_debugfs_device_attr(act_log_extents)
  671. drbd_debugfs_device_attr(resync_extents)
  672. drbd_debugfs_device_attr(data_gen_id)
  673. drbd_debugfs_device_attr(ed_gen_id)
  674. void drbd_debugfs_device_add(struct drbd_device *device)
  675. {
  676. struct dentry *vols_dir = device->resource->debugfs_res_volumes;
  677. char minor_buf[8]; /* MINORMASK, MINORBITS == 20; */
  678. char vnr_buf[8]; /* volume number vnr is even 16 bit only; */
  679. char *slink_name = NULL;
  680. struct dentry *dentry;
  681. if (!vols_dir || !drbd_debugfs_minors)
  682. return;
  683. snprintf(vnr_buf, sizeof(vnr_buf), "%u", device->vnr);
  684. dentry = debugfs_create_dir(vnr_buf, vols_dir);
  685. device->debugfs_vol = dentry;
  686. snprintf(minor_buf, sizeof(minor_buf), "%u", device->minor);
  687. slink_name = kasprintf(GFP_KERNEL, "../resources/%s/volumes/%u",
  688. device->resource->name, device->vnr);
  689. if (!slink_name)
  690. goto fail;
  691. dentry = debugfs_create_symlink(minor_buf, drbd_debugfs_minors, slink_name);
  692. device->debugfs_minor = dentry;
  693. kfree(slink_name);
  694. slink_name = NULL;
  695. #define DCF(name) do { \
  696. dentry = debugfs_create_file(#name, 0440, \
  697. device->debugfs_vol, device, \
  698. &device_ ## name ## _fops); \
  699. device->debugfs_vol_ ## name = dentry; \
  700. } while (0)
  701. DCF(oldest_requests);
  702. DCF(act_log_extents);
  703. DCF(resync_extents);
  704. DCF(data_gen_id);
  705. DCF(ed_gen_id);
  706. #undef DCF
  707. return;
  708. fail:
  709. drbd_debugfs_device_cleanup(device);
  710. drbd_err(device, "failed to create debugfs entries\n");
  711. }
  712. void drbd_debugfs_device_cleanup(struct drbd_device *device)
  713. {
  714. drbd_debugfs_remove(&device->debugfs_minor);
  715. drbd_debugfs_remove(&device->debugfs_vol_oldest_requests);
  716. drbd_debugfs_remove(&device->debugfs_vol_act_log_extents);
  717. drbd_debugfs_remove(&device->debugfs_vol_resync_extents);
  718. drbd_debugfs_remove(&device->debugfs_vol_data_gen_id);
  719. drbd_debugfs_remove(&device->debugfs_vol_ed_gen_id);
  720. drbd_debugfs_remove(&device->debugfs_vol);
  721. }
  722. void drbd_debugfs_peer_device_add(struct drbd_peer_device *peer_device)
  723. {
  724. struct dentry *conn_dir = peer_device->connection->debugfs_conn;
  725. struct dentry *dentry;
  726. char vnr_buf[8];
  727. snprintf(vnr_buf, sizeof(vnr_buf), "%u", peer_device->device->vnr);
  728. dentry = debugfs_create_dir(vnr_buf, conn_dir);
  729. peer_device->debugfs_peer_dev = dentry;
  730. }
  731. void drbd_debugfs_peer_device_cleanup(struct drbd_peer_device *peer_device)
  732. {
  733. drbd_debugfs_remove(&peer_device->debugfs_peer_dev);
  734. }
  735. static int drbd_version_show(struct seq_file *m, void *ignored)
  736. {
  737. seq_printf(m, "# %s\n", drbd_buildtag());
  738. seq_printf(m, "VERSION=%s\n", REL_VERSION);
  739. seq_printf(m, "API_VERSION=%u\n", API_VERSION);
  740. seq_printf(m, "PRO_VERSION_MIN=%u\n", PRO_VERSION_MIN);
  741. seq_printf(m, "PRO_VERSION_MAX=%u\n", PRO_VERSION_MAX);
  742. return 0;
  743. }
  744. static int drbd_version_open(struct inode *inode, struct file *file)
  745. {
  746. return single_open(file, drbd_version_show, NULL);
  747. }
  748. static const struct file_operations drbd_version_fops = {
  749. .owner = THIS_MODULE,
  750. .open = drbd_version_open,
  751. .llseek = seq_lseek,
  752. .read = seq_read,
  753. .release = single_release,
  754. };
  755. /* not __exit, may be indirectly called
  756. * from the module-load-failure path as well. */
  757. void drbd_debugfs_cleanup(void)
  758. {
  759. drbd_debugfs_remove(&drbd_debugfs_resources);
  760. drbd_debugfs_remove(&drbd_debugfs_minors);
  761. drbd_debugfs_remove(&drbd_debugfs_version);
  762. drbd_debugfs_remove(&drbd_debugfs_root);
  763. }
  764. void __init drbd_debugfs_init(void)
  765. {
  766. struct dentry *dentry;
  767. dentry = debugfs_create_dir("drbd", NULL);
  768. drbd_debugfs_root = dentry;
  769. dentry = debugfs_create_file("version", 0444, drbd_debugfs_root, NULL, &drbd_version_fops);
  770. drbd_debugfs_version = dentry;
  771. dentry = debugfs_create_dir("resources", drbd_debugfs_root);
  772. drbd_debugfs_resources = dentry;
  773. dentry = debugfs_create_dir("minors", drbd_debugfs_root);
  774. drbd_debugfs_minors = dentry;
  775. }