drbd_proc.c 7.7 KB

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