net/mlx4_core: drop useless LIST_HEAD
[linux-2.6-block.git] / drivers / block / drbd / drbd_proc.c
CommitLineData
b411b363
PR
1/*
2 drbd_proc.c
3
4 This file is part of DRBD by Philipp Reisner and Lars Ellenberg.
5
6 Copyright (C) 2001-2008, LINBIT Information Technologies GmbH.
7 Copyright (C) 1999-2008, Philipp Reisner <philipp.reisner@linbit.com>.
8 Copyright (C) 2002-2008, Lars Ellenberg <lars.ellenberg@linbit.com>.
9
10 drbd is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
13 any later version.
14
15 drbd is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with drbd; see the file COPYING. If not, write to
22 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23
24 */
25
b411b363
PR
26#include <linux/module.h>
27
7e5fec31 28#include <linux/uaccess.h>
b411b363
PR
29#include <linux/fs.h>
30#include <linux/file.h>
b411b363
PR
31#include <linux/proc_fs.h>
32#include <linux/seq_file.h>
33#include <linux/drbd.h>
34#include "drbd_int.h"
35
b411b363 36struct proc_dir_entry *drbd_proc;
b411b363 37
fbe0d91c 38static void seq_printf_with_thousands_grouping(struct seq_file *seq, long v)
439d5953
LE
39{
40 /* v is in kB/sec. We don't expect TiByte/sec yet. */
41 if (unlikely(v >= 1000000)) {
42 /* cool: > GiByte/s */
43 seq_printf(seq, "%ld,", v / 1000000);
fc251d5c 44 v %= 1000000;
439d5953
LE
45 seq_printf(seq, "%03ld,%03ld", v/1000, v % 1000);
46 } else if (likely(v >= 1000))
47 seq_printf(seq, "%ld,%03ld", v/1000, v % 1000);
48 else
49 seq_printf(seq, "%ld", v);
50}
b411b363 51
a5655dac
LE
52static void drbd_get_syncer_progress(struct drbd_device *device,
53 union drbd_dev_state state, unsigned long *rs_total,
54 unsigned long *bits_left, unsigned int *per_mil_done)
55{
56 /* this is to break it at compile time when we change that, in case we
57 * want to support more than (1<<32) bits on a 32bit arch. */
58 typecheck(unsigned long, device->rs_total);
59 *rs_total = device->rs_total;
60
61 /* note: both rs_total and rs_left are in bits, i.e. in
62 * units of BM_BLOCK_SIZE.
63 * for the percentage, we don't care. */
64
65 if (state.conn == C_VERIFY_S || state.conn == C_VERIFY_T)
66 *bits_left = device->ov_left;
67 else
68 *bits_left = drbd_bm_total_weight(device) - device->rs_failed;
69 /* >> 10 to prevent overflow,
70 * +1 to prevent division by zero */
71 if (*bits_left > *rs_total) {
72 /* D'oh. Maybe a logic bug somewhere. More likely just a race
73 * between state change and reset of rs_total.
74 */
75 *bits_left = *rs_total;
76 *per_mil_done = *rs_total ? 0 : 1000;
77 } else {
78 /* Make sure the division happens in long context.
79 * We allow up to one petabyte storage right now,
80 * at a granularity of 4k per bit that is 2**38 bits.
81 * After shift right and multiplication by 1000,
82 * this should still fit easily into a 32bit long,
83 * so we don't need a 64bit division on 32bit arch.
84 * Note: currently we don't support such large bitmaps on 32bit
85 * arch anyways, but no harm done to be prepared for it here.
86 */
87 unsigned int shift = *rs_total > UINT_MAX ? 16 : 10;
88 unsigned long left = *bits_left >> shift;
89 unsigned long total = 1UL + (*rs_total >> shift);
90 unsigned long tmp = 1000UL - left * 1000UL/total;
91 *per_mil_done = tmp;
92 }
93}
94
95
b411b363
PR
96/*lge
97 * progress bars shamelessly adapted from driver/md/md.c
98 * output looks like
99 * [=====>..............] 33.5% (23456/123456)
100 * finish: 2:20:20 speed: 6,345 (6,456) K/sec
101 */
a5655dac
LE
102static void drbd_syncer_progress(struct drbd_device *device, struct seq_file *seq,
103 union drbd_dev_state state)
b411b363 104{
a5655dac 105 unsigned long db, dt, dbdt, rt, rs_total, rs_left;
b411b363
PR
106 unsigned int res;
107 int i, x, y;
1d7734a0 108 int stalled = 0;
b411b363 109
a5655dac 110 drbd_get_syncer_progress(device, state, &rs_total, &rs_left, &res);
b411b363
PR
111
112 x = res/50;
113 y = 20-x;
7e5fec31 114 seq_puts(seq, "\t[");
b411b363 115 for (i = 1; i < x; i++)
7e5fec31
FF
116 seq_putc(seq, '=');
117 seq_putc(seq, '>');
b411b363 118 for (i = 0; i < y; i++)
427fd2be 119 seq_putc(seq, '.');
7e5fec31 120 seq_puts(seq, "] ");
b411b363 121
a5655dac 122 if (state.conn == C_VERIFY_S || state.conn == C_VERIFY_T)
7e5fec31 123 seq_puts(seq, "verified:");
5f9915bb 124 else
7e5fec31 125 seq_puts(seq, "sync'ed:");
5f9915bb
LE
126 seq_printf(seq, "%3u.%u%% ", res / 10, res % 10);
127
4b0715f0 128 /* if more than a few GB, display in MB */
a5655dac 129 if (rs_total > (4UL << (30 - BM_BLOCK_SHIFT)))
4b0715f0 130 seq_printf(seq, "(%lu/%lu)M",
b411b363 131 (unsigned long) Bit2KB(rs_left >> 10),
a5655dac 132 (unsigned long) Bit2KB(rs_total >> 10));
b411b363 133 else
590001c2 134 seq_printf(seq, "(%lu/%lu)K",
b411b363 135 (unsigned long) Bit2KB(rs_left),
a5655dac 136 (unsigned long) Bit2KB(rs_total));
b411b363 137
7e5fec31 138 seq_puts(seq, "\n\t");
590001c2 139
b411b363
PR
140 /* see drivers/md/md.c
141 * We do not want to overflow, so the order of operands and
142 * the * 100 / 100 trick are important. We do a +1 to be
143 * safe against division by zero. We only estimate anyway.
144 *
145 * dt: time from mark until now
146 * db: blocks written from mark until now
147 * rt: remaining time
148 */
1d7734a0
LE
149 /* Rolling marks. last_mark+1 may just now be modified. last_mark+2 is
150 * at least (DRBD_SYNC_MARKS-2)*DRBD_SYNC_MARK_STEP old, and has at
151 * least DRBD_SYNC_MARK_STEP time before it will be modified. */
439d5953 152 /* ------------------------ ~18s average ------------------------ */
b30ab791
AG
153 i = (device->rs_last_mark + 2) % DRBD_SYNC_MARKS;
154 dt = (jiffies - device->rs_mark_time[i]) / HZ;
9ae47260 155 if (dt > 180)
1d7734a0 156 stalled = 1;
b411b363
PR
157
158 if (!dt)
159 dt++;
b30ab791 160 db = device->rs_mark_left[i] - rs_left;
b411b363
PR
161 rt = (dt * (rs_left / (db/100+1)))/100; /* seconds */
162
163 seq_printf(seq, "finish: %lu:%02lu:%02lu",
164 rt / 3600, (rt % 3600) / 60, rt % 60);
165
b411b363 166 dbdt = Bit2KB(db/dt);
7e5fec31 167 seq_puts(seq, " speed: ");
439d5953 168 seq_printf_with_thousands_grouping(seq, dbdt);
7e5fec31 169 seq_puts(seq, " (");
439d5953 170 /* ------------------------- ~3s average ------------------------ */
183ece30 171 if (drbd_proc_details >= 1) {
439d5953 172 /* this is what drbd_rs_should_slow_down() uses */
b30ab791
AG
173 i = (device->rs_last_mark + DRBD_SYNC_MARKS-1) % DRBD_SYNC_MARKS;
174 dt = (jiffies - device->rs_mark_time[i]) / HZ;
439d5953
LE
175 if (!dt)
176 dt++;
b30ab791 177 db = device->rs_mark_left[i] - rs_left;
439d5953
LE
178 dbdt = Bit2KB(db/dt);
179 seq_printf_with_thousands_grouping(seq, dbdt);
7e5fec31 180 seq_puts(seq, " -- ");
439d5953 181 }
b411b363 182
439d5953 183 /* --------------------- long term average ---------------------- */
b411b363
PR
184 /* mean speed since syncer started
185 * we do account for PausedSync periods */
b30ab791 186 dt = (jiffies - device->rs_start - device->rs_paused) / HZ;
22657695 187 if (dt == 0)
b411b363 188 dt = 1;
a5655dac 189 db = rs_total - rs_left;
b411b363 190 dbdt = Bit2KB(db/dt);
439d5953 191 seq_printf_with_thousands_grouping(seq, dbdt);
7e5fec31 192 seq_putc(seq, ')');
b411b363 193
a5655dac
LE
194 if (state.conn == C_SYNC_TARGET ||
195 state.conn == C_VERIFY_S) {
7e5fec31 196 seq_puts(seq, " want: ");
b30ab791 197 seq_printf_with_thousands_grouping(seq, device->c_sync_rate);
1d7734a0
LE
198 }
199 seq_printf(seq, " K/sec%s\n", stalled ? " (stalled)" : "");
5f9915bb 200
183ece30 201 if (drbd_proc_details >= 1) {
5f9915bb
LE
202 /* 64 bit:
203 * we convert to sectors in the display below. */
b30ab791 204 unsigned long bm_bits = drbd_bm_bits(device);
4896e8c1 205 unsigned long bit_pos;
58ffa580 206 unsigned long long stop_sector = 0;
a5655dac
LE
207 if (state.conn == C_VERIFY_S ||
208 state.conn == C_VERIFY_T) {
b30ab791
AG
209 bit_pos = bm_bits - device->ov_left;
210 if (verify_can_do_stop_sector(device))
211 stop_sector = device->ov_stop_sector;
58ffa580 212 } else
b30ab791 213 bit_pos = device->bm_resync_fo;
5f9915bb
LE
214 /* Total sectors may be slightly off for oddly
215 * sized devices. So what. */
216 seq_printf(seq,
58ffa580 217 "\t%3d%% sector pos: %llu/%llu",
5f9915bb 218 (int)(bit_pos / (bm_bits/100+1)),
4896e8c1
LE
219 (unsigned long long)bit_pos * BM_SECT_PER_BIT,
220 (unsigned long long)bm_bits * BM_SECT_PER_BIT);
58ffa580
LE
221 if (stop_sector != 0 && stop_sector != ULLONG_MAX)
222 seq_printf(seq, " stop sector: %llu", stop_sector);
7e5fec31 223 seq_putc(seq, '\n');
5f9915bb 224 }
b411b363
PR
225}
226
004fd11d 227int drbd_seq_show(struct seq_file *seq, void *v)
b411b363 228{
81a5d60e 229 int i, prev_i = -1;
b411b363 230 const char *sn;
b30ab791 231 struct drbd_device *device;
44ed167d 232 struct net_conf *nc;
a5655dac 233 union drbd_dev_state state;
44ed167d 234 char wp;
b411b363
PR
235
236 static char write_ordering_chars[] = {
f6ba8636
AG
237 [WO_NONE] = 'n',
238 [WO_DRAIN_IO] = 'd',
239 [WO_BDEV_FLUSH] = 'f',
b411b363
PR
240 };
241
242 seq_printf(seq, "version: " REL_VERSION " (api:%d/proto:%d-%d)\n%s\n",
243 API_VERSION, PRO_VERSION_MIN, PRO_VERSION_MAX, drbd_buildtag());
244
245 /*
246 cs .. connection state
247 ro .. node role (local/remote)
248 ds .. disk state (local/remote)
249 protocol
250 various flags
251 ns .. network send
252 nr .. network receive
253 dw .. disk write
254 dr .. disk read
255 al .. activity log write count
256 bm .. bitmap update write count
257 pe .. pending (waiting for ack or data reply)
258 ua .. unack'd (still need to send ack or data reply)
259 ap .. application requests accepted, but not yet completed
260 ep .. number of epochs currently "on the fly", P_BARRIER_ACK pending
261 wo .. write ordering mode currently in use
262 oos .. known out-of-sync kB
263 */
264
c141ebda 265 rcu_read_lock();
05a10ec7 266 idr_for_each_entry(&drbd_devices, device, i) {
81a5d60e 267 if (prev_i != i - 1)
7e5fec31 268 seq_putc(seq, '\n');
81a5d60e 269 prev_i = i;
b411b363 270
a5655dac
LE
271 state = device->state;
272 sn = drbd_conn_str(state.conn);
b411b363 273
a5655dac
LE
274 if (state.conn == C_STANDALONE &&
275 state.disk == D_DISKLESS &&
276 state.role == R_SECONDARY) {
b411b363
PR
277 seq_printf(seq, "%2d: cs:Unconfigured\n", i);
278 } else {
b30ab791 279 /* reset device->congestion_reason */
dc3b17cc 280 bdi_rw_congested(device->rq_queue->backing_dev_info);
8a943170 281
a6b32bc3 282 nc = rcu_dereference(first_peer_device(device)->connection->net_conf);
44ed167d 283 wp = nc ? nc->wire_protocol - DRBD_PROT_A + 'A' : ' ';
b411b363 284 seq_printf(seq,
0778286a 285 "%2d: cs:%s ro:%s/%s ds:%s/%s %c %c%c%c%c%c%c\n"
b411b363
PR
286 " ns:%u nr:%u dw:%u dr:%u al:%u bm:%u "
287 "lo:%d pe:%d ua:%d ap:%d ep:%d wo:%c",
288 i, sn,
a5655dac
LE
289 drbd_role_str(state.role),
290 drbd_role_str(state.peer),
291 drbd_disk_str(state.disk),
292 drbd_disk_str(state.pdsk),
44ed167d 293 wp,
b30ab791 294 drbd_suspended(device) ? 's' : 'r',
a5655dac
LE
295 state.aftr_isp ? 'a' : '-',
296 state.peer_isp ? 'p' : '-',
297 state.user_isp ? 'u' : '-',
b30ab791
AG
298 device->congestion_reason ?: '-',
299 test_bit(AL_SUSPENDED, &device->flags) ? 's' : '-',
300 device->send_cnt/2,
301 device->recv_cnt/2,
302 device->writ_cnt/2,
303 device->read_cnt/2,
304 device->al_writ_cnt,
305 device->bm_writ_cnt,
306 atomic_read(&device->local_cnt),
307 atomic_read(&device->ap_pending_cnt) +
308 atomic_read(&device->rs_pending_cnt),
309 atomic_read(&device->unacked_cnt),
310 atomic_read(&device->ap_bio_cnt),
a6b32bc3 311 first_peer_device(device)->connection->epochs,
e9526580 312 write_ordering_chars[device->resource->write_ordering]
b411b363 313 );
18edc0b9
LE
314 seq_printf(seq, " oos:%llu\n",
315 Bit2KB((unsigned long long)
b30ab791 316 drbd_bm_total_weight(device)));
b411b363 317 }
a5655dac
LE
318 if (state.conn == C_SYNC_SOURCE ||
319 state.conn == C_SYNC_TARGET ||
320 state.conn == C_VERIFY_S ||
321 state.conn == C_VERIFY_T)
322 drbd_syncer_progress(device, seq, state);
b30ab791 323
183ece30 324 if (drbd_proc_details >= 1 && get_ldev_if_state(device, D_FAILED)) {
b30ab791
AG
325 lc_seq_printf_stats(seq, device->resync);
326 lc_seq_printf_stats(seq, device->act_log);
327 put_ldev(device);
b411b363 328 }
ad3fee79 329
183ece30 330 if (drbd_proc_details >= 2)
ad3fee79 331 seq_printf(seq, "\tblocked on activity log: %d\n", atomic_read(&device->ap_actlog_cnt));
b411b363 332 }
c141ebda 333 rcu_read_unlock();
b411b363
PR
334
335 return 0;
336}