blob: e0f0d2a6d538bf708c13d3311c6f32e32cfa8929 [file] [log] [blame]
Philipp Reisnerb411b362009-09-25 16:07:19 -07001/*
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
Philipp Reisnerb411b362009-09-25 16:07:19 -070026#include <linux/module.h>
27
28#include <asm/uaccess.h>
29#include <linux/fs.h>
30#include <linux/file.h>
Philipp Reisnerb411b362009-09-25 16:07:19 -070031#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);
Lars Ellenberg3da127f2010-11-24 10:33:02 +010037static int drbd_proc_release(struct inode *inode, struct file *file);
Philipp Reisnerb411b362009-09-25 16:07:19 -070038
39
40struct proc_dir_entry *drbd_proc;
Emese Revfy7d4e9d02009-12-14 00:59:30 +010041const struct file_operations drbd_proc_fops = {
Philipp Reisnerb411b362009-09-25 16:07:19 -070042 .owner = THIS_MODULE,
43 .open = drbd_proc_open,
44 .read = seq_read,
45 .llseek = seq_lseek,
Lars Ellenberg3da127f2010-11-24 10:33:02 +010046 .release = drbd_proc_release,
Philipp Reisnerb411b362009-09-25 16:07:19 -070047};
48
Lars Ellenberg439d5952010-11-05 09:52:46 +010049void seq_printf_with_thousands_grouping(struct seq_file *seq, long v)
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);
Lars Ellenbergfc251d52011-06-03 21:13:17 +020055 v %= 1000000;
Lars Ellenberg439d5952010-11-05 09:52:46 +010056 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}
Philipp Reisnerb411b362009-09-25 16:07:19 -070062
63/*lge
64 * progress bars shamelessly adapted from driver/md/md.c
65 * output looks like
66 * [=====>..............] 33.5% (23456/123456)
67 * finish: 2:20:20 speed: 6,345 (6,456) K/sec
68 */
69static void drbd_syncer_progress(struct drbd_conf *mdev, struct seq_file *seq)
70{
71 unsigned long db, dt, dbdt, rt, rs_left;
72 unsigned int res;
73 int i, x, y;
Lars Ellenberg1d7734a2010-08-11 21:21:50 +020074 int stalled = 0;
Philipp Reisnerb411b362009-09-25 16:07:19 -070075
76 drbd_get_syncer_progress(mdev, &rs_left, &res);
77
78 x = res/50;
79 y = 20-x;
80 seq_printf(seq, "\t[");
81 for (i = 1; i < x; i++)
82 seq_printf(seq, "=");
83 seq_printf(seq, ">");
84 for (i = 0; i < y; i++)
85 seq_printf(seq, ".");
86 seq_printf(seq, "] ");
87
Lars Ellenberg5f9915b2010-11-09 14:15:24 +010088 if (mdev->state.conn == C_VERIFY_S || mdev->state.conn == C_VERIFY_T)
89 seq_printf(seq, "verified:");
90 else
91 seq_printf(seq, "sync'ed:");
92 seq_printf(seq, "%3u.%u%% ", res / 10, res % 10);
93
Lars Ellenberg4b0715f2010-12-14 15:13:04 +010094 /* if more than a few GB, display in MB */
95 if (mdev->rs_total > (4UL << (30 - BM_BLOCK_SHIFT)))
96 seq_printf(seq, "(%lu/%lu)M",
Philipp Reisnerb411b362009-09-25 16:07:19 -070097 (unsigned long) Bit2KB(rs_left >> 10),
98 (unsigned long) Bit2KB(mdev->rs_total >> 10));
99 else
Lars Ellenberge7f52df2010-08-03 20:20:20 +0200100 seq_printf(seq, "(%lu/%lu)K\n\t",
Philipp Reisnerb411b362009-09-25 16:07:19 -0700101 (unsigned long) Bit2KB(rs_left),
102 (unsigned long) Bit2KB(mdev->rs_total));
103
104 /* see drivers/md/md.c
105 * We do not want to overflow, so the order of operands and
106 * the * 100 / 100 trick are important. We do a +1 to be
107 * safe against division by zero. We only estimate anyway.
108 *
109 * dt: time from mark until now
110 * db: blocks written from mark until now
111 * rt: remaining time
112 */
Lars Ellenberg1d7734a2010-08-11 21:21:50 +0200113 /* Rolling marks. last_mark+1 may just now be modified. last_mark+2 is
114 * at least (DRBD_SYNC_MARKS-2)*DRBD_SYNC_MARK_STEP old, and has at
115 * least DRBD_SYNC_MARK_STEP time before it will be modified. */
Lars Ellenberg439d5952010-11-05 09:52:46 +0100116 /* ------------------------ ~18s average ------------------------ */
Lars Ellenberg1d7734a2010-08-11 21:21:50 +0200117 i = (mdev->rs_last_mark + 2) % DRBD_SYNC_MARKS;
118 dt = (jiffies - mdev->rs_mark_time[i]) / HZ;
119 if (dt > (DRBD_SYNC_MARK_STEP * DRBD_SYNC_MARKS))
120 stalled = 1;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700121
122 if (!dt)
123 dt++;
Lars Ellenberg1d7734a2010-08-11 21:21:50 +0200124 db = mdev->rs_mark_left[i] - rs_left;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700125 rt = (dt * (rs_left / (db/100+1)))/100; /* seconds */
126
127 seq_printf(seq, "finish: %lu:%02lu:%02lu",
128 rt / 3600, (rt % 3600) / 60, rt % 60);
129
Philipp Reisnerb411b362009-09-25 16:07:19 -0700130 dbdt = Bit2KB(db/dt);
Lars Ellenberg439d5952010-11-05 09:52:46 +0100131 seq_printf(seq, " speed: ");
132 seq_printf_with_thousands_grouping(seq, dbdt);
133 seq_printf(seq, " (");
134 /* ------------------------- ~3s average ------------------------ */
135 if (proc_details >= 1) {
136 /* this is what drbd_rs_should_slow_down() uses */
137 i = (mdev->rs_last_mark + DRBD_SYNC_MARKS-1) % DRBD_SYNC_MARKS;
138 dt = (jiffies - mdev->rs_mark_time[i]) / HZ;
Lars Ellenberg439d5952010-11-05 09:52:46 +0100139 if (!dt)
140 dt++;
141 db = mdev->rs_mark_left[i] - rs_left;
Lars Ellenberg439d5952010-11-05 09:52:46 +0100142 dbdt = Bit2KB(db/dt);
143 seq_printf_with_thousands_grouping(seq, dbdt);
144 seq_printf(seq, " -- ");
145 }
146
147 /* --------------------- long term average ---------------------- */
Philipp Reisnerb411b362009-09-25 16:07:19 -0700148 /* mean speed since syncer started
149 * we do account for PausedSync periods */
150 dt = (jiffies - mdev->rs_start - mdev->rs_paused) / HZ;
Dan Carpenter22657692010-08-12 00:38:45 +0200151 if (dt == 0)
Philipp Reisnerb411b362009-09-25 16:07:19 -0700152 dt = 1;
153 db = mdev->rs_total - rs_left;
154 dbdt = Bit2KB(db/dt);
Lars Ellenberg439d5952010-11-05 09:52:46 +0100155 seq_printf_with_thousands_grouping(seq, dbdt);
156 seq_printf(seq, ")");
Philipp Reisnerb411b362009-09-25 16:07:19 -0700157
Lars Ellenberg2649f082010-11-05 10:05:47 +0100158 if (mdev->state.conn == C_SYNC_TARGET ||
159 mdev->state.conn == C_VERIFY_S) {
Lars Ellenberg5f9915b2010-11-09 14:15:24 +0100160 seq_printf(seq, " want: ");
161 seq_printf_with_thousands_grouping(seq, mdev->c_sync_rate);
Lars Ellenberg1d7734a2010-08-11 21:21:50 +0200162 }
163 seq_printf(seq, " K/sec%s\n", stalled ? " (stalled)" : "");
Lars Ellenberg5f9915b2010-11-09 14:15:24 +0100164
165 if (proc_details >= 1) {
166 /* 64 bit:
167 * we convert to sectors in the display below. */
Lars Ellenberg4896e8c2010-11-11 22:41:04 +0100168 unsigned long bm_bits = drbd_bm_bits(mdev);
169 unsigned long bit_pos;
Lars Ellenberg5f9915b2010-11-09 14:15:24 +0100170 if (mdev->state.conn == C_VERIFY_S ||
171 mdev->state.conn == C_VERIFY_T)
172 bit_pos = bm_bits - mdev->ov_left;
173 else
174 bit_pos = mdev->bm_resync_fo;
175 /* Total sectors may be slightly off for oddly
176 * sized devices. So what. */
177 seq_printf(seq,
178 "\t%3d%% sector pos: %llu/%llu\n",
179 (int)(bit_pos / (bm_bits/100+1)),
Lars Ellenberg4896e8c2010-11-11 22:41:04 +0100180 (unsigned long long)bit_pos * BM_SECT_PER_BIT,
181 (unsigned long long)bm_bits * BM_SECT_PER_BIT);
Lars Ellenberg5f9915b2010-11-09 14:15:24 +0100182 }
Philipp Reisnerb411b362009-09-25 16:07:19 -0700183}
184
185static void resync_dump_detail(struct seq_file *seq, struct lc_element *e)
186{
187 struct bm_extent *bme = lc_entry(e, struct bm_extent, lce);
188
189 seq_printf(seq, "%5d %s %s\n", bme->rs_left,
190 bme->flags & BME_NO_WRITES ? "NO_WRITES" : "---------",
191 bme->flags & BME_LOCKED ? "LOCKED" : "------"
192 );
193}
194
195static int drbd_seq_show(struct seq_file *seq, void *v)
196{
Philipp Reisner81a5d602011-02-22 19:53:16 -0500197 int i, prev_i = -1;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700198 const char *sn;
199 struct drbd_conf *mdev;
Philipp Reisner44ed1672011-04-19 17:10:19 +0200200 struct net_conf *nc;
201 char wp;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700202
203 static char write_ordering_chars[] = {
204 [WO_none] = 'n',
205 [WO_drain_io] = 'd',
206 [WO_bdev_flush] = 'f',
Philipp Reisnerb411b362009-09-25 16:07:19 -0700207 };
208
209 seq_printf(seq, "version: " REL_VERSION " (api:%d/proto:%d-%d)\n%s\n",
210 API_VERSION, PRO_VERSION_MIN, PRO_VERSION_MAX, drbd_buildtag());
211
212 /*
213 cs .. connection state
214 ro .. node role (local/remote)
215 ds .. disk state (local/remote)
216 protocol
217 various flags
218 ns .. network send
219 nr .. network receive
220 dw .. disk write
221 dr .. disk read
222 al .. activity log write count
223 bm .. bitmap update write count
224 pe .. pending (waiting for ack or data reply)
225 ua .. unack'd (still need to send ack or data reply)
226 ap .. application requests accepted, but not yet completed
227 ep .. number of epochs currently "on the fly", P_BARRIER_ACK pending
228 wo .. write ordering mode currently in use
229 oos .. known out-of-sync kB
230 */
231
Philipp Reisnerc141ebd2011-05-05 16:13:10 +0200232 rcu_read_lock();
Philipp Reisner81a5d602011-02-22 19:53:16 -0500233 idr_for_each_entry(&minors, mdev, i) {
234 if (prev_i != i - 1)
Philipp Reisnerb411b362009-09-25 16:07:19 -0700235 seq_printf(seq, "\n");
Philipp Reisner81a5d602011-02-22 19:53:16 -0500236 prev_i = i;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700237
238 sn = drbd_conn_str(mdev->state.conn);
239
240 if (mdev->state.conn == C_STANDALONE &&
241 mdev->state.disk == D_DISKLESS &&
242 mdev->state.role == R_SECONDARY) {
243 seq_printf(seq, "%2d: cs:Unconfigured\n", i);
244 } else {
Lars Ellenberg8a943172012-07-30 09:09:36 +0200245 /* reset mdev->congestion_reason */
246 bdi_rw_congested(&mdev->rq_queue->backing_dev_info);
247
Philipp Reisner44ed1672011-04-19 17:10:19 +0200248 nc = rcu_dereference(mdev->tconn->net_conf);
249 wp = nc ? nc->wire_protocol - DRBD_PROT_A + 'A' : ' ';
Philipp Reisnerb411b362009-09-25 16:07:19 -0700250 seq_printf(seq,
Philipp Reisner07782862010-08-31 12:00:50 +0200251 "%2d: cs:%s ro:%s/%s ds:%s/%s %c %c%c%c%c%c%c\n"
Philipp Reisnerb411b362009-09-25 16:07:19 -0700252 " ns:%u nr:%u dw:%u dr:%u al:%u bm:%u "
253 "lo:%d pe:%d ua:%d ap:%d ep:%d wo:%c",
254 i, sn,
255 drbd_role_str(mdev->state.role),
256 drbd_role_str(mdev->state.peer),
257 drbd_disk_str(mdev->state.disk),
258 drbd_disk_str(mdev->state.pdsk),
Philipp Reisner44ed1672011-04-19 17:10:19 +0200259 wp,
Philipp Reisner2aebfab2011-03-28 16:48:11 +0200260 drbd_suspended(mdev) ? 's' : 'r',
Philipp Reisnerb411b362009-09-25 16:07:19 -0700261 mdev->state.aftr_isp ? 'a' : '-',
262 mdev->state.peer_isp ? 'p' : '-',
263 mdev->state.user_isp ? 'u' : '-',
264 mdev->congestion_reason ?: '-',
Philipp Reisner07782862010-08-31 12:00:50 +0200265 test_bit(AL_SUSPENDED, &mdev->flags) ? 's' : '-',
Philipp Reisnerb411b362009-09-25 16:07:19 -0700266 mdev->send_cnt/2,
267 mdev->recv_cnt/2,
268 mdev->writ_cnt/2,
269 mdev->read_cnt/2,
270 mdev->al_writ_cnt,
271 mdev->bm_writ_cnt,
272 atomic_read(&mdev->local_cnt),
273 atomic_read(&mdev->ap_pending_cnt) +
274 atomic_read(&mdev->rs_pending_cnt),
275 atomic_read(&mdev->unacked_cnt),
276 atomic_read(&mdev->ap_bio_cnt),
Philipp Reisner12038a32011-11-09 19:18:00 +0100277 mdev->tconn->epochs,
Philipp Reisner4b0007c2011-11-09 20:12:34 +0100278 write_ordering_chars[mdev->tconn->write_ordering]
Philipp Reisnerb411b362009-09-25 16:07:19 -0700279 );
Lars Ellenberg18edc0b2010-11-09 14:12:10 +0100280 seq_printf(seq, " oos:%llu\n",
281 Bit2KB((unsigned long long)
282 drbd_bm_total_weight(mdev)));
Philipp Reisnerb411b362009-09-25 16:07:19 -0700283 }
284 if (mdev->state.conn == C_SYNC_SOURCE ||
Lars Ellenberg439d5952010-11-05 09:52:46 +0100285 mdev->state.conn == C_SYNC_TARGET ||
286 mdev->state.conn == C_VERIFY_S ||
287 mdev->state.conn == C_VERIFY_T)
Philipp Reisnerb411b362009-09-25 16:07:19 -0700288 drbd_syncer_progress(mdev, seq);
289
Philipp Reisnerb411b362009-09-25 16:07:19 -0700290 if (proc_details >= 1 && get_ldev_if_state(mdev, D_FAILED)) {
291 lc_seq_printf_stats(seq, mdev->resync);
292 lc_seq_printf_stats(seq, mdev->act_log);
293 put_ldev(mdev);
294 }
295
296 if (proc_details >= 2) {
297 if (mdev->resync) {
298 lc_seq_dump_details(seq, mdev->resync, "rs_left",
299 resync_dump_detail);
300 }
301 }
302 }
Philipp Reisnerc141ebd2011-05-05 16:13:10 +0200303 rcu_read_unlock();
Philipp Reisnerb411b362009-09-25 16:07:19 -0700304
305 return 0;
306}
307
308static int drbd_proc_open(struct inode *inode, struct file *file)
309{
Lars Ellenberg3da127f2010-11-24 10:33:02 +0100310 if (try_module_get(THIS_MODULE))
311 return single_open(file, drbd_seq_show, PDE(inode)->data);
312 return -ENODEV;
313}
314
315static int drbd_proc_release(struct inode *inode, struct file *file)
316{
317 module_put(THIS_MODULE);
318 return single_release(inode, file);
Philipp Reisnerb411b362009-09-25 16:07:19 -0700319}
320
321/* PROC FS stuff end */