drbd_proc.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /*
  2. drbd_proc.c
  3. This file is part of DRBD by Philipp Reisner and Lars Ellenberg.
  4. Copyright (C) 2001-2008, LINBIT Information Technologies GmbH.
  5. Copyright (C) 1999-2008, Philipp Reisner <philipp.reisner@linbit.com>.
  6. Copyright (C) 2002-2008, Lars Ellenberg <lars.ellenberg@linbit.com>.
  7. drbd is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2, or (at your option)
  10. any later version.
  11. drbd is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with drbd; see the file COPYING. If not, write to
  17. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19. #include <linux/autoconf.h>
  20. #include <linux/module.h>
  21. #include <asm/uaccess.h>
  22. #include <linux/fs.h>
  23. #include <linux/file.h>
  24. #include <linux/slab.h>
  25. #include <linux/proc_fs.h>
  26. #include <linux/seq_file.h>
  27. #include <linux/drbd.h>
  28. #include "drbd_int.h"
  29. static int drbd_proc_open(struct inode *inode, struct file *file);
  30. struct proc_dir_entry *drbd_proc;
  31. struct file_operations drbd_proc_fops = {
  32. .owner = THIS_MODULE,
  33. .open = drbd_proc_open,
  34. .read = seq_read,
  35. .llseek = seq_lseek,
  36. .release = single_release,
  37. };
  38. /*lge
  39. * progress bars shamelessly adapted from driver/md/md.c
  40. * output looks like
  41. * [=====>..............] 33.5% (23456/123456)
  42. * finish: 2:20:20 speed: 6,345 (6,456) K/sec
  43. */
  44. static void drbd_syncer_progress(struct drbd_conf *mdev, struct seq_file *seq)
  45. {
  46. unsigned long db, dt, dbdt, rt, rs_left;
  47. unsigned int res;
  48. int i, x, y;
  49. drbd_get_syncer_progress(mdev, &rs_left, &res);
  50. x = res/50;
  51. y = 20-x;
  52. seq_printf(seq, "\t[");
  53. for (i = 1; i < x; i++)
  54. seq_printf(seq, "=");
  55. seq_printf(seq, ">");
  56. for (i = 0; i < y; i++)
  57. seq_printf(seq, ".");
  58. seq_printf(seq, "] ");
  59. seq_printf(seq, "sync'ed:%3u.%u%% ", res / 10, res % 10);
  60. /* if more than 1 GB display in MB */
  61. if (mdev->rs_total > 0x100000L)
  62. seq_printf(seq, "(%lu/%lu)M\n\t",
  63. (unsigned long) Bit2KB(rs_left >> 10),
  64. (unsigned long) Bit2KB(mdev->rs_total >> 10));
  65. else
  66. seq_printf(seq, "(%lu/%lu)K\n\t",
  67. (unsigned long) Bit2KB(rs_left),
  68. (unsigned long) Bit2KB(mdev->rs_total));
  69. /* see drivers/md/md.c
  70. * We do not want to overflow, so the order of operands and
  71. * the * 100 / 100 trick are important. We do a +1 to be
  72. * safe against division by zero. We only estimate anyway.
  73. *
  74. * dt: time from mark until now
  75. * db: blocks written from mark until now
  76. * rt: remaining time
  77. */
  78. dt = (jiffies - mdev->rs_mark_time) / HZ;
  79. if (dt > 20) {
  80. /* if we made no update to rs_mark_time for too long,
  81. * we are stalled. show that. */
  82. seq_printf(seq, "stalled\n");
  83. return;
  84. }
  85. if (!dt)
  86. dt++;
  87. db = mdev->rs_mark_left - rs_left;
  88. rt = (dt * (rs_left / (db/100+1)))/100; /* seconds */
  89. seq_printf(seq, "finish: %lu:%02lu:%02lu",
  90. rt / 3600, (rt % 3600) / 60, rt % 60);
  91. /* current speed average over (SYNC_MARKS * SYNC_MARK_STEP) jiffies */
  92. dbdt = Bit2KB(db/dt);
  93. if (dbdt > 1000)
  94. seq_printf(seq, " speed: %ld,%03ld",
  95. dbdt/1000, dbdt % 1000);
  96. else
  97. seq_printf(seq, " speed: %ld", dbdt);
  98. /* mean speed since syncer started
  99. * we do account for PausedSync periods */
  100. dt = (jiffies - mdev->rs_start - mdev->rs_paused) / HZ;
  101. if (dt <= 0)
  102. dt = 1;
  103. db = mdev->rs_total - rs_left;
  104. dbdt = Bit2KB(db/dt);
  105. if (dbdt > 1000)
  106. seq_printf(seq, " (%ld,%03ld)",
  107. dbdt/1000, dbdt % 1000);
  108. else
  109. seq_printf(seq, " (%ld)", dbdt);
  110. seq_printf(seq, " K/sec\n");
  111. }
  112. static void resync_dump_detail(struct seq_file *seq, struct lc_element *e)
  113. {
  114. struct bm_extent *bme = lc_entry(e, struct bm_extent, lce);
  115. seq_printf(seq, "%5d %s %s\n", bme->rs_left,
  116. bme->flags & BME_NO_WRITES ? "NO_WRITES" : "---------",
  117. bme->flags & BME_LOCKED ? "LOCKED" : "------"
  118. );
  119. }
  120. static int drbd_seq_show(struct seq_file *seq, void *v)
  121. {
  122. int i, hole = 0;
  123. const char *sn;
  124. struct drbd_conf *mdev;
  125. static char write_ordering_chars[] = {
  126. [WO_none] = 'n',
  127. [WO_drain_io] = 'd',
  128. [WO_bdev_flush] = 'f',
  129. [WO_bio_barrier] = 'b',
  130. };
  131. seq_printf(seq, "version: " REL_VERSION " (api:%d/proto:%d-%d)\n%s\n",
  132. API_VERSION, PRO_VERSION_MIN, PRO_VERSION_MAX, drbd_buildtag());
  133. /*
  134. cs .. connection state
  135. ro .. node role (local/remote)
  136. ds .. disk state (local/remote)
  137. protocol
  138. various flags
  139. ns .. network send
  140. nr .. network receive
  141. dw .. disk write
  142. dr .. disk read
  143. al .. activity log write count
  144. bm .. bitmap update write count
  145. pe .. pending (waiting for ack or data reply)
  146. ua .. unack'd (still need to send ack or data reply)
  147. ap .. application requests accepted, but not yet completed
  148. ep .. number of epochs currently "on the fly", P_BARRIER_ACK pending
  149. wo .. write ordering mode currently in use
  150. oos .. known out-of-sync kB
  151. */
  152. for (i = 0; i < minor_count; i++) {
  153. mdev = minor_to_mdev(i);
  154. if (!mdev) {
  155. hole = 1;
  156. continue;
  157. }
  158. if (hole) {
  159. hole = 0;
  160. seq_printf(seq, "\n");
  161. }
  162. sn = drbd_conn_str(mdev->state.conn);
  163. if (mdev->state.conn == C_STANDALONE &&
  164. mdev->state.disk == D_DISKLESS &&
  165. mdev->state.role == R_SECONDARY) {
  166. seq_printf(seq, "%2d: cs:Unconfigured\n", i);
  167. } else {
  168. seq_printf(seq,
  169. "%2d: cs:%s ro:%s/%s ds:%s/%s %c %c%c%c%c%c\n"
  170. " ns:%u nr:%u dw:%u dr:%u al:%u bm:%u "
  171. "lo:%d pe:%d ua:%d ap:%d ep:%d wo:%c",
  172. i, sn,
  173. drbd_role_str(mdev->state.role),
  174. drbd_role_str(mdev->state.peer),
  175. drbd_disk_str(mdev->state.disk),
  176. drbd_disk_str(mdev->state.pdsk),
  177. (mdev->net_conf == NULL ? ' ' :
  178. (mdev->net_conf->wire_protocol - DRBD_PROT_A+'A')),
  179. mdev->state.susp ? 's' : 'r',
  180. mdev->state.aftr_isp ? 'a' : '-',
  181. mdev->state.peer_isp ? 'p' : '-',
  182. mdev->state.user_isp ? 'u' : '-',
  183. mdev->congestion_reason ?: '-',
  184. mdev->send_cnt/2,
  185. mdev->recv_cnt/2,
  186. mdev->writ_cnt/2,
  187. mdev->read_cnt/2,
  188. mdev->al_writ_cnt,
  189. mdev->bm_writ_cnt,
  190. atomic_read(&mdev->local_cnt),
  191. atomic_read(&mdev->ap_pending_cnt) +
  192. atomic_read(&mdev->rs_pending_cnt),
  193. atomic_read(&mdev->unacked_cnt),
  194. atomic_read(&mdev->ap_bio_cnt),
  195. mdev->epochs,
  196. write_ordering_chars[mdev->write_ordering]
  197. );
  198. seq_printf(seq, " oos:%lu\n",
  199. Bit2KB(drbd_bm_total_weight(mdev)));
  200. }
  201. if (mdev->state.conn == C_SYNC_SOURCE ||
  202. mdev->state.conn == C_SYNC_TARGET)
  203. drbd_syncer_progress(mdev, seq);
  204. if (mdev->state.conn == C_VERIFY_S || mdev->state.conn == C_VERIFY_T)
  205. seq_printf(seq, "\t%3d%% %lu/%lu\n",
  206. (int)((mdev->rs_total-mdev->ov_left) /
  207. (mdev->rs_total/100+1)),
  208. mdev->rs_total - mdev->ov_left,
  209. mdev->rs_total);
  210. if (proc_details >= 1 && get_ldev_if_state(mdev, D_FAILED)) {
  211. lc_seq_printf_stats(seq, mdev->resync);
  212. lc_seq_printf_stats(seq, mdev->act_log);
  213. put_ldev(mdev);
  214. }
  215. if (proc_details >= 2) {
  216. if (mdev->resync) {
  217. lc_seq_dump_details(seq, mdev->resync, "rs_left",
  218. resync_dump_detail);
  219. }
  220. }
  221. }
  222. return 0;
  223. }
  224. static int drbd_proc_open(struct inode *inode, struct file *file)
  225. {
  226. return single_open(file, drbd_seq_show, PDE(inode)->data);
  227. }
  228. /* PROC FS stuff end */