drbd_proc.c 9.3 KB

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