drbd_proc.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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 <linux/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. struct proc_dir_entry *drbd_proc;
  28. static void seq_printf_with_thousands_grouping(struct seq_file *seq, long v)
  29. {
  30. /* v is in kB/sec. We don't expect TiByte/sec yet. */
  31. if (unlikely(v >= 1000000)) {
  32. /* cool: > GiByte/s */
  33. seq_printf(seq, "%ld,", v / 1000000);
  34. v %= 1000000;
  35. seq_printf(seq, "%03ld,%03ld", v/1000, v % 1000);
  36. } else if (likely(v >= 1000))
  37. seq_printf(seq, "%ld,%03ld", v/1000, v % 1000);
  38. else
  39. seq_printf(seq, "%ld", v);
  40. }
  41. static void drbd_get_syncer_progress(struct drbd_device *device,
  42. union drbd_dev_state state, unsigned long *rs_total,
  43. unsigned long *bits_left, unsigned int *per_mil_done)
  44. {
  45. /* this is to break it at compile time when we change that, in case we
  46. * want to support more than (1<<32) bits on a 32bit arch. */
  47. typecheck(unsigned long, device->rs_total);
  48. *rs_total = device->rs_total;
  49. /* note: both rs_total and rs_left are in bits, i.e. in
  50. * units of BM_BLOCK_SIZE.
  51. * for the percentage, we don't care. */
  52. if (state.conn == C_VERIFY_S || state.conn == C_VERIFY_T)
  53. *bits_left = device->ov_left;
  54. else
  55. *bits_left = drbd_bm_total_weight(device) - device->rs_failed;
  56. /* >> 10 to prevent overflow,
  57. * +1 to prevent division by zero */
  58. if (*bits_left > *rs_total) {
  59. /* D'oh. Maybe a logic bug somewhere. More likely just a race
  60. * between state change and reset of rs_total.
  61. */
  62. *bits_left = *rs_total;
  63. *per_mil_done = *rs_total ? 0 : 1000;
  64. } else {
  65. /* Make sure the division happens in long context.
  66. * We allow up to one petabyte storage right now,
  67. * at a granularity of 4k per bit that is 2**38 bits.
  68. * After shift right and multiplication by 1000,
  69. * this should still fit easily into a 32bit long,
  70. * so we don't need a 64bit division on 32bit arch.
  71. * Note: currently we don't support such large bitmaps on 32bit
  72. * arch anyways, but no harm done to be prepared for it here.
  73. */
  74. unsigned int shift = *rs_total > UINT_MAX ? 16 : 10;
  75. unsigned long left = *bits_left >> shift;
  76. unsigned long total = 1UL + (*rs_total >> shift);
  77. unsigned long tmp = 1000UL - left * 1000UL/total;
  78. *per_mil_done = tmp;
  79. }
  80. }
  81. /*lge
  82. * progress bars shamelessly adapted from driver/md/md.c
  83. * output looks like
  84. * [=====>..............] 33.5% (23456/123456)
  85. * finish: 2:20:20 speed: 6,345 (6,456) K/sec
  86. */
  87. static void drbd_syncer_progress(struct drbd_device *device, struct seq_file *seq,
  88. union drbd_dev_state state)
  89. {
  90. unsigned long db, dt, dbdt, rt, rs_total, rs_left;
  91. unsigned int res;
  92. int i, x, y;
  93. int stalled = 0;
  94. drbd_get_syncer_progress(device, state, &rs_total, &rs_left, &res);
  95. x = res/50;
  96. y = 20-x;
  97. seq_puts(seq, "\t[");
  98. for (i = 1; i < x; i++)
  99. seq_putc(seq, '=');
  100. seq_putc(seq, '>');
  101. for (i = 0; i < y; i++)
  102. seq_putc(seq, '.');
  103. seq_puts(seq, "] ");
  104. if (state.conn == C_VERIFY_S || state.conn == C_VERIFY_T)
  105. seq_puts(seq, "verified:");
  106. else
  107. seq_puts(seq, "sync'ed:");
  108. seq_printf(seq, "%3u.%u%% ", res / 10, res % 10);
  109. /* if more than a few GB, display in MB */
  110. if (rs_total > (4UL << (30 - BM_BLOCK_SHIFT)))
  111. seq_printf(seq, "(%lu/%lu)M",
  112. (unsigned long) Bit2KB(rs_left >> 10),
  113. (unsigned long) Bit2KB(rs_total >> 10));
  114. else
  115. seq_printf(seq, "(%lu/%lu)K",
  116. (unsigned long) Bit2KB(rs_left),
  117. (unsigned long) Bit2KB(rs_total));
  118. seq_puts(seq, "\n\t");
  119. /* see drivers/md/md.c
  120. * We do not want to overflow, so the order of operands and
  121. * the * 100 / 100 trick are important. We do a +1 to be
  122. * safe against division by zero. We only estimate anyway.
  123. *
  124. * dt: time from mark until now
  125. * db: blocks written from mark until now
  126. * rt: remaining time
  127. */
  128. /* Rolling marks. last_mark+1 may just now be modified. last_mark+2 is
  129. * at least (DRBD_SYNC_MARKS-2)*DRBD_SYNC_MARK_STEP old, and has at
  130. * least DRBD_SYNC_MARK_STEP time before it will be modified. */
  131. /* ------------------------ ~18s average ------------------------ */
  132. i = (device->rs_last_mark + 2) % DRBD_SYNC_MARKS;
  133. dt = (jiffies - device->rs_mark_time[i]) / HZ;
  134. if (dt > 180)
  135. stalled = 1;
  136. if (!dt)
  137. dt++;
  138. db = device->rs_mark_left[i] - rs_left;
  139. rt = (dt * (rs_left / (db/100+1)))/100; /* seconds */
  140. seq_printf(seq, "finish: %lu:%02lu:%02lu",
  141. rt / 3600, (rt % 3600) / 60, rt % 60);
  142. dbdt = Bit2KB(db/dt);
  143. seq_puts(seq, " speed: ");
  144. seq_printf_with_thousands_grouping(seq, dbdt);
  145. seq_puts(seq, " (");
  146. /* ------------------------- ~3s average ------------------------ */
  147. if (drbd_proc_details >= 1) {
  148. /* this is what drbd_rs_should_slow_down() uses */
  149. i = (device->rs_last_mark + DRBD_SYNC_MARKS-1) % DRBD_SYNC_MARKS;
  150. dt = (jiffies - device->rs_mark_time[i]) / HZ;
  151. if (!dt)
  152. dt++;
  153. db = device->rs_mark_left[i] - rs_left;
  154. dbdt = Bit2KB(db/dt);
  155. seq_printf_with_thousands_grouping(seq, dbdt);
  156. seq_puts(seq, " -- ");
  157. }
  158. /* --------------------- long term average ---------------------- */
  159. /* mean speed since syncer started
  160. * we do account for PausedSync periods */
  161. dt = (jiffies - device->rs_start - device->rs_paused) / HZ;
  162. if (dt == 0)
  163. dt = 1;
  164. db = rs_total - rs_left;
  165. dbdt = Bit2KB(db/dt);
  166. seq_printf_with_thousands_grouping(seq, dbdt);
  167. seq_putc(seq, ')');
  168. if (state.conn == C_SYNC_TARGET ||
  169. state.conn == C_VERIFY_S) {
  170. seq_puts(seq, " want: ");
  171. seq_printf_with_thousands_grouping(seq, device->c_sync_rate);
  172. }
  173. seq_printf(seq, " K/sec%s\n", stalled ? " (stalled)" : "");
  174. if (drbd_proc_details >= 1) {
  175. /* 64 bit:
  176. * we convert to sectors in the display below. */
  177. unsigned long bm_bits = drbd_bm_bits(device);
  178. unsigned long bit_pos;
  179. unsigned long long stop_sector = 0;
  180. if (state.conn == C_VERIFY_S ||
  181. state.conn == C_VERIFY_T) {
  182. bit_pos = bm_bits - device->ov_left;
  183. if (verify_can_do_stop_sector(device))
  184. stop_sector = device->ov_stop_sector;
  185. } else
  186. bit_pos = device->bm_resync_fo;
  187. /* Total sectors may be slightly off for oddly
  188. * sized devices. So what. */
  189. seq_printf(seq,
  190. "\t%3d%% sector pos: %llu/%llu",
  191. (int)(bit_pos / (bm_bits/100+1)),
  192. (unsigned long long)bit_pos * BM_SECT_PER_BIT,
  193. (unsigned long long)bm_bits * BM_SECT_PER_BIT);
  194. if (stop_sector != 0 && stop_sector != ULLONG_MAX)
  195. seq_printf(seq, " stop sector: %llu", stop_sector);
  196. seq_putc(seq, '\n');
  197. }
  198. }
  199. int drbd_seq_show(struct seq_file *seq, void *v)
  200. {
  201. int i, prev_i = -1;
  202. const char *sn;
  203. struct drbd_device *device;
  204. struct net_conf *nc;
  205. union drbd_dev_state state;
  206. char wp;
  207. static char write_ordering_chars[] = {
  208. [WO_NONE] = 'n',
  209. [WO_DRAIN_IO] = 'd',
  210. [WO_BDEV_FLUSH] = 'f',
  211. };
  212. seq_printf(seq, "version: " REL_VERSION " (api:%d/proto:%d-%d)\n%s\n",
  213. API_VERSION, PRO_VERSION_MIN, PRO_VERSION_MAX, drbd_buildtag());
  214. /*
  215. cs .. connection state
  216. ro .. node role (local/remote)
  217. ds .. disk state (local/remote)
  218. protocol
  219. various flags
  220. ns .. network send
  221. nr .. network receive
  222. dw .. disk write
  223. dr .. disk read
  224. al .. activity log write count
  225. bm .. bitmap update write count
  226. pe .. pending (waiting for ack or data reply)
  227. ua .. unack'd (still need to send ack or data reply)
  228. ap .. application requests accepted, but not yet completed
  229. ep .. number of epochs currently "on the fly", P_BARRIER_ACK pending
  230. wo .. write ordering mode currently in use
  231. oos .. known out-of-sync kB
  232. */
  233. rcu_read_lock();
  234. idr_for_each_entry(&drbd_devices, device, i) {
  235. if (prev_i != i - 1)
  236. seq_putc(seq, '\n');
  237. prev_i = i;
  238. state = device->state;
  239. sn = drbd_conn_str(state.conn);
  240. if (state.conn == C_STANDALONE &&
  241. state.disk == D_DISKLESS &&
  242. state.role == R_SECONDARY) {
  243. seq_printf(seq, "%2d: cs:Unconfigured\n", i);
  244. } else {
  245. /* reset device->congestion_reason */
  246. bdi_rw_congested(device->rq_queue->backing_dev_info);
  247. nc = rcu_dereference(first_peer_device(device)->connection->net_conf);
  248. wp = nc ? nc->wire_protocol - DRBD_PROT_A + 'A' : ' ';
  249. seq_printf(seq,
  250. "%2d: cs:%s ro:%s/%s ds:%s/%s %c %c%c%c%c%c%c\n"
  251. " ns:%u nr:%u dw:%u dr:%u al:%u bm:%u "
  252. "lo:%d pe:%d ua:%d ap:%d ep:%d wo:%c",
  253. i, sn,
  254. drbd_role_str(state.role),
  255. drbd_role_str(state.peer),
  256. drbd_disk_str(state.disk),
  257. drbd_disk_str(state.pdsk),
  258. wp,
  259. drbd_suspended(device) ? 's' : 'r',
  260. state.aftr_isp ? 'a' : '-',
  261. state.peer_isp ? 'p' : '-',
  262. state.user_isp ? 'u' : '-',
  263. device->congestion_reason ?: '-',
  264. test_bit(AL_SUSPENDED, &device->flags) ? 's' : '-',
  265. device->send_cnt/2,
  266. device->recv_cnt/2,
  267. device->writ_cnt/2,
  268. device->read_cnt/2,
  269. device->al_writ_cnt,
  270. device->bm_writ_cnt,
  271. atomic_read(&device->local_cnt),
  272. atomic_read(&device->ap_pending_cnt) +
  273. atomic_read(&device->rs_pending_cnt),
  274. atomic_read(&device->unacked_cnt),
  275. atomic_read(&device->ap_bio_cnt),
  276. first_peer_device(device)->connection->epochs,
  277. write_ordering_chars[device->resource->write_ordering]
  278. );
  279. seq_printf(seq, " oos:%llu\n",
  280. Bit2KB((unsigned long long)
  281. drbd_bm_total_weight(device)));
  282. }
  283. if (state.conn == C_SYNC_SOURCE ||
  284. state.conn == C_SYNC_TARGET ||
  285. state.conn == C_VERIFY_S ||
  286. state.conn == C_VERIFY_T)
  287. drbd_syncer_progress(device, seq, state);
  288. if (drbd_proc_details >= 1 && get_ldev_if_state(device, D_FAILED)) {
  289. lc_seq_printf_stats(seq, device->resync);
  290. lc_seq_printf_stats(seq, device->act_log);
  291. put_ldev(device);
  292. }
  293. if (drbd_proc_details >= 2)
  294. seq_printf(seq, "\tblocked on activity log: %d\n", atomic_read(&device->ap_actlog_cnt));
  295. }
  296. rcu_read_unlock();
  297. return 0;
  298. }