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