drbd_proc.c 7.3 KB

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