drbd_proc.c 7.8 KB

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