drbd_proc.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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/slab.h>
  24. #include <linux/proc_fs.h>
  25. #include <linux/seq_file.h>
  26. #include <linux/drbd.h>
  27. #include "drbd_int.h"
  28. static int drbd_proc_open(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 = single_release,
  36. };
  37. /*lge
  38. * progress bars shamelessly adapted from driver/md/md.c
  39. * output looks like
  40. * [=====>..............] 33.5% (23456/123456)
  41. * finish: 2:20:20 speed: 6,345 (6,456) K/sec
  42. */
  43. static void drbd_syncer_progress(struct drbd_conf *mdev, struct seq_file *seq)
  44. {
  45. unsigned long db, dt, dbdt, rt, rs_left;
  46. unsigned int res;
  47. int i, x, y;
  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. dt = (jiffies - mdev->rs_mark_time) / HZ;
  78. if (dt > 20) {
  79. /* if we made no update to rs_mark_time for too long,
  80. * we are stalled. show that. */
  81. seq_printf(seq, "stalled\n");
  82. return;
  83. }
  84. if (!dt)
  85. dt++;
  86. db = mdev->rs_mark_left - 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. seq_printf(seq, " K/sec\n");
  110. }
  111. static void resync_dump_detail(struct seq_file *seq, struct lc_element *e)
  112. {
  113. struct bm_extent *bme = lc_entry(e, struct bm_extent, lce);
  114. seq_printf(seq, "%5d %s %s\n", bme->rs_left,
  115. bme->flags & BME_NO_WRITES ? "NO_WRITES" : "---------",
  116. bme->flags & BME_LOCKED ? "LOCKED" : "------"
  117. );
  118. }
  119. static int drbd_seq_show(struct seq_file *seq, void *v)
  120. {
  121. int i, hole = 0;
  122. const char *sn;
  123. struct drbd_conf *mdev;
  124. static char write_ordering_chars[] = {
  125. [WO_none] = 'n',
  126. [WO_drain_io] = 'd',
  127. [WO_bdev_flush] = 'f',
  128. [WO_bio_barrier] = 'b',
  129. };
  130. seq_printf(seq, "version: " REL_VERSION " (api:%d/proto:%d-%d)\n%s\n",
  131. API_VERSION, PRO_VERSION_MIN, PRO_VERSION_MAX, drbd_buildtag());
  132. /*
  133. cs .. connection state
  134. ro .. node role (local/remote)
  135. ds .. disk state (local/remote)
  136. protocol
  137. various flags
  138. ns .. network send
  139. nr .. network receive
  140. dw .. disk write
  141. dr .. disk read
  142. al .. activity log write count
  143. bm .. bitmap update write count
  144. pe .. pending (waiting for ack or data reply)
  145. ua .. unack'd (still need to send ack or data reply)
  146. ap .. application requests accepted, but not yet completed
  147. ep .. number of epochs currently "on the fly", P_BARRIER_ACK pending
  148. wo .. write ordering mode currently in use
  149. oos .. known out-of-sync kB
  150. */
  151. for (i = 0; i < minor_count; i++) {
  152. mdev = minor_to_mdev(i);
  153. if (!mdev) {
  154. hole = 1;
  155. continue;
  156. }
  157. if (hole) {
  158. hole = 0;
  159. seq_printf(seq, "\n");
  160. }
  161. sn = drbd_conn_str(mdev->state.conn);
  162. if (mdev->state.conn == C_STANDALONE &&
  163. mdev->state.disk == D_DISKLESS &&
  164. mdev->state.role == R_SECONDARY) {
  165. seq_printf(seq, "%2d: cs:Unconfigured\n", i);
  166. } else {
  167. seq_printf(seq,
  168. "%2d: cs:%s ro:%s/%s ds:%s/%s %c %c%c%c%c%c\n"
  169. " ns:%u nr:%u dw:%u dr:%u al:%u bm:%u "
  170. "lo:%d pe:%d ua:%d ap:%d ep:%d wo:%c",
  171. i, sn,
  172. drbd_role_str(mdev->state.role),
  173. drbd_role_str(mdev->state.peer),
  174. drbd_disk_str(mdev->state.disk),
  175. drbd_disk_str(mdev->state.pdsk),
  176. (mdev->net_conf == NULL ? ' ' :
  177. (mdev->net_conf->wire_protocol - DRBD_PROT_A+'A')),
  178. mdev->state.susp ? 's' : 'r',
  179. mdev->state.aftr_isp ? 'a' : '-',
  180. mdev->state.peer_isp ? 'p' : '-',
  181. mdev->state.user_isp ? 'u' : '-',
  182. mdev->congestion_reason ?: '-',
  183. mdev->send_cnt/2,
  184. mdev->recv_cnt/2,
  185. mdev->writ_cnt/2,
  186. mdev->read_cnt/2,
  187. mdev->al_writ_cnt,
  188. mdev->bm_writ_cnt,
  189. atomic_read(&mdev->local_cnt),
  190. atomic_read(&mdev->ap_pending_cnt) +
  191. atomic_read(&mdev->rs_pending_cnt),
  192. atomic_read(&mdev->unacked_cnt),
  193. atomic_read(&mdev->ap_bio_cnt),
  194. mdev->epochs,
  195. write_ordering_chars[mdev->write_ordering]
  196. );
  197. seq_printf(seq, " oos:%lu\n",
  198. Bit2KB(drbd_bm_total_weight(mdev)));
  199. }
  200. if (mdev->state.conn == C_SYNC_SOURCE ||
  201. mdev->state.conn == C_SYNC_TARGET)
  202. drbd_syncer_progress(mdev, seq);
  203. if (mdev->state.conn == C_VERIFY_S || mdev->state.conn == C_VERIFY_T)
  204. seq_printf(seq, "\t%3d%% %lu/%lu\n",
  205. (int)((mdev->rs_total-mdev->ov_left) /
  206. (mdev->rs_total/100+1)),
  207. mdev->rs_total - mdev->ov_left,
  208. mdev->rs_total);
  209. if (proc_details >= 1 && get_ldev_if_state(mdev, D_FAILED)) {
  210. lc_seq_printf_stats(seq, mdev->resync);
  211. lc_seq_printf_stats(seq, mdev->act_log);
  212. put_ldev(mdev);
  213. }
  214. if (proc_details >= 2) {
  215. if (mdev->resync) {
  216. lc_seq_dump_details(seq, mdev->resync, "rs_left",
  217. resync_dump_detail);
  218. }
  219. }
  220. }
  221. return 0;
  222. }
  223. static int drbd_proc_open(struct inode *inode, struct file *file)
  224. {
  225. return single_open(file, drbd_seq_show, PDE(inode)->data);
  226. }
  227. /* PROC FS stuff end */