blob: 49d817cfe865bbdedbb8d0381739c26ce45cd7bc [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);
37
38
39struct proc_dir_entry *drbd_proc;
Emese Revfy7d4e9d02009-12-14 00:59:30 +010040const struct file_operations drbd_proc_fops = {
Philipp Reisnerb411b362009-09-25 16:07:19 -070041 .owner = THIS_MODULE,
42 .open = drbd_proc_open,
43 .read = seq_read,
44 .llseek = seq_lseek,
45 .release = single_release,
46};
47
Lars Ellenberg439d5952010-11-05 09:52:46 +010048void seq_printf_with_thousands_grouping(struct seq_file *seq, long v)
49{
50 /* v is in kB/sec. We don't expect TiByte/sec yet. */
51 if (unlikely(v >= 1000000)) {
52 /* cool: > GiByte/s */
53 seq_printf(seq, "%ld,", v / 1000000);
54 v /= 1000000;
55 seq_printf(seq, "%03ld,%03ld", v/1000, v % 1000);
56 } else if (likely(v >= 1000))
57 seq_printf(seq, "%ld,%03ld", v/1000, v % 1000);
58 else
59 seq_printf(seq, "%ld", v);
60}
Philipp Reisnerb411b362009-09-25 16:07:19 -070061
62/*lge
63 * progress bars shamelessly adapted from driver/md/md.c
64 * output looks like
65 * [=====>..............] 33.5% (23456/123456)
66 * finish: 2:20:20 speed: 6,345 (6,456) K/sec
67 */
68static void drbd_syncer_progress(struct drbd_conf *mdev, struct seq_file *seq)
69{
70 unsigned long db, dt, dbdt, rt, rs_left;
71 unsigned int res;
72 int i, x, y;
Lars Ellenberg1d7734a2010-08-11 21:21:50 +020073 int stalled = 0;
Philipp Reisnerb411b362009-09-25 16:07:19 -070074
75 drbd_get_syncer_progress(mdev, &rs_left, &res);
76
77 x = res/50;
78 y = 20-x;
79 seq_printf(seq, "\t[");
80 for (i = 1; i < x; i++)
81 seq_printf(seq, "=");
82 seq_printf(seq, ">");
83 for (i = 0; i < y; i++)
84 seq_printf(seq, ".");
85 seq_printf(seq, "] ");
86
Lars Ellenberg5f9915b2010-11-09 14:15:24 +010087 if (mdev->state.conn == C_VERIFY_S || mdev->state.conn == C_VERIFY_T)
88 seq_printf(seq, "verified:");
89 else
90 seq_printf(seq, "sync'ed:");
91 seq_printf(seq, "%3u.%u%% ", res / 10, res % 10);
92
Philipp Reisnerb411b362009-09-25 16:07:19 -070093 /* if more than 1 GB display in MB */
94 if (mdev->rs_total > 0x100000L)
Lars Ellenberge7f52df2010-08-03 20:20:20 +020095 seq_printf(seq, "(%lu/%lu)M\n\t",
Philipp Reisnerb411b362009-09-25 16:07:19 -070096 (unsigned long) Bit2KB(rs_left >> 10),
97 (unsigned long) Bit2KB(mdev->rs_total >> 10));
98 else
Lars Ellenberge7f52df2010-08-03 20:20:20 +020099 seq_printf(seq, "(%lu/%lu)K\n\t",
Philipp Reisnerb411b362009-09-25 16:07:19 -0700100 (unsigned long) Bit2KB(rs_left),
101 (unsigned long) Bit2KB(mdev->rs_total));
102
103 /* see drivers/md/md.c
104 * We do not want to overflow, so the order of operands and
105 * the * 100 / 100 trick are important. We do a +1 to be
106 * safe against division by zero. We only estimate anyway.
107 *
108 * dt: time from mark until now
109 * db: blocks written from mark until now
110 * rt: remaining time
111 */
Lars Ellenberg1d7734a2010-08-11 21:21:50 +0200112 /* Rolling marks. last_mark+1 may just now be modified. last_mark+2 is
113 * at least (DRBD_SYNC_MARKS-2)*DRBD_SYNC_MARK_STEP old, and has at
114 * least DRBD_SYNC_MARK_STEP time before it will be modified. */
Lars Ellenberg439d5952010-11-05 09:52:46 +0100115 /* ------------------------ ~18s average ------------------------ */
Lars Ellenberg1d7734a2010-08-11 21:21:50 +0200116 i = (mdev->rs_last_mark + 2) % DRBD_SYNC_MARKS;
117 dt = (jiffies - mdev->rs_mark_time[i]) / HZ;
118 if (dt > (DRBD_SYNC_MARK_STEP * DRBD_SYNC_MARKS))
119 stalled = 1;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700120
121 if (!dt)
122 dt++;
Lars Ellenberg1d7734a2010-08-11 21:21:50 +0200123 db = mdev->rs_mark_left[i] - rs_left;
Philipp Reisnerb411b362009-09-25 16:07:19 -0700124 rt = (dt * (rs_left / (db/100+1)))/100; /* seconds */
125
126 seq_printf(seq, "finish: %lu:%02lu:%02lu",
127 rt / 3600, (rt % 3600) / 60, rt % 60);
128
Philipp Reisnerb411b362009-09-25 16:07:19 -0700129 dbdt = Bit2KB(db/dt);
Lars Ellenberg439d5952010-11-05 09:52:46 +0100130 seq_printf(seq, " speed: ");
131 seq_printf_with_thousands_grouping(seq, dbdt);
132 seq_printf(seq, " (");
133 /* ------------------------- ~3s average ------------------------ */
134 if (proc_details >= 1) {
135 /* this is what drbd_rs_should_slow_down() uses */
136 i = (mdev->rs_last_mark + DRBD_SYNC_MARKS-1) % DRBD_SYNC_MARKS;
137 dt = (jiffies - mdev->rs_mark_time[i]) / HZ;
Lars Ellenberg439d5952010-11-05 09:52:46 +0100138 if (!dt)
139 dt++;
140 db = mdev->rs_mark_left[i] - rs_left;
Lars Ellenberg439d5952010-11-05 09:52:46 +0100141 dbdt = Bit2KB(db/dt);
142 seq_printf_with_thousands_grouping(seq, dbdt);
143 seq_printf(seq, " -- ");
144 }
145
146 /* --------------------- long term average ---------------------- */
Philipp Reisnerb411b362009-09-25 16:07:19 -0700147 /* mean speed since syncer started
148 * we do account for PausedSync periods */
149 dt = (jiffies - mdev->rs_start - mdev->rs_paused) / HZ;
Dan Carpenter22657692010-08-12 00:38:45 +0200150 if (dt == 0)
Philipp Reisnerb411b362009-09-25 16:07:19 -0700151 dt = 1;
152 db = mdev->rs_total - rs_left;
153 dbdt = Bit2KB(db/dt);
Lars Ellenberg439d5952010-11-05 09:52:46 +0100154 seq_printf_with_thousands_grouping(seq, dbdt);
155 seq_printf(seq, ")");
Philipp Reisnerb411b362009-09-25 16:07:19 -0700156
Lars Ellenberg2649f082010-11-05 10:05:47 +0100157 if (mdev->state.conn == C_SYNC_TARGET ||
158 mdev->state.conn == C_VERIFY_S) {
Lars Ellenberg5f9915b2010-11-09 14:15:24 +0100159 seq_printf(seq, " want: ");
160 seq_printf_with_thousands_grouping(seq, mdev->c_sync_rate);
Lars Ellenberg1d7734a2010-08-11 21:21:50 +0200161 }
162 seq_printf(seq, " K/sec%s\n", stalled ? " (stalled)" : "");
Lars Ellenberg5f9915b2010-11-09 14:15:24 +0100163
164 if (proc_details >= 1) {
165 /* 64 bit:
166 * we convert to sectors in the display below. */
Lars Ellenberg4896e8c2010-11-11 22:41:04 +0100167 unsigned long bm_bits = drbd_bm_bits(mdev);
168 unsigned long bit_pos;
Lars Ellenberg5f9915b2010-11-09 14:15:24 +0100169 if (mdev->state.conn == C_VERIFY_S ||
170 mdev->state.conn == C_VERIFY_T)
171 bit_pos = bm_bits - mdev->ov_left;
172 else
173 bit_pos = mdev->bm_resync_fo;
174 /* Total sectors may be slightly off for oddly
175 * sized devices. So what. */
176 seq_printf(seq,
177 "\t%3d%% sector pos: %llu/%llu\n",
178 (int)(bit_pos / (bm_bits/100+1)),
Lars Ellenberg4896e8c2010-11-11 22:41:04 +0100179 (unsigned long long)bit_pos * BM_SECT_PER_BIT,
180 (unsigned long long)bm_bits * BM_SECT_PER_BIT);
Lars Ellenberg5f9915b2010-11-09 14:15:24 +0100181 }
Philipp Reisnerb411b362009-09-25 16:07:19 -0700182}
183
184static void resync_dump_detail(struct seq_file *seq, struct lc_element *e)
185{
186 struct bm_extent *bme = lc_entry(e, struct bm_extent, lce);
187
188 seq_printf(seq, "%5d %s %s\n", bme->rs_left,
189 bme->flags & BME_NO_WRITES ? "NO_WRITES" : "---------",
190 bme->flags & BME_LOCKED ? "LOCKED" : "------"
191 );
192}
193
194static int drbd_seq_show(struct seq_file *seq, void *v)
195{
196 int i, hole = 0;
197 const char *sn;
198 struct drbd_conf *mdev;
199
200 static char write_ordering_chars[] = {
201 [WO_none] = 'n',
202 [WO_drain_io] = 'd',
203 [WO_bdev_flush] = 'f',
Philipp Reisnerb411b362009-09-25 16:07:19 -0700204 };
205
206 seq_printf(seq, "version: " REL_VERSION " (api:%d/proto:%d-%d)\n%s\n",
207 API_VERSION, PRO_VERSION_MIN, PRO_VERSION_MAX, drbd_buildtag());
208
209 /*
210 cs .. connection state
211 ro .. node role (local/remote)
212 ds .. disk state (local/remote)
213 protocol
214 various flags
215 ns .. network send
216 nr .. network receive
217 dw .. disk write
218 dr .. disk read
219 al .. activity log write count
220 bm .. bitmap update write count
221 pe .. pending (waiting for ack or data reply)
222 ua .. unack'd (still need to send ack or data reply)
223 ap .. application requests accepted, but not yet completed
224 ep .. number of epochs currently "on the fly", P_BARRIER_ACK pending
225 wo .. write ordering mode currently in use
226 oos .. known out-of-sync kB
227 */
228
229 for (i = 0; i < minor_count; i++) {
230 mdev = minor_to_mdev(i);
231 if (!mdev) {
232 hole = 1;
233 continue;
234 }
235 if (hole) {
236 hole = 0;
237 seq_printf(seq, "\n");
238 }
239
240 sn = drbd_conn_str(mdev->state.conn);
241
242 if (mdev->state.conn == C_STANDALONE &&
243 mdev->state.disk == D_DISKLESS &&
244 mdev->state.role == R_SECONDARY) {
245 seq_printf(seq, "%2d: cs:Unconfigured\n", i);
246 } else {
247 seq_printf(seq,
Philipp Reisner07782862010-08-31 12:00:50 +0200248 "%2d: cs:%s ro:%s/%s ds:%s/%s %c %c%c%c%c%c%c\n"
Philipp Reisnerb411b362009-09-25 16:07:19 -0700249 " ns:%u nr:%u dw:%u dr:%u al:%u bm:%u "
250 "lo:%d pe:%d ua:%d ap:%d ep:%d wo:%c",
251 i, sn,
252 drbd_role_str(mdev->state.role),
253 drbd_role_str(mdev->state.peer),
254 drbd_disk_str(mdev->state.disk),
255 drbd_disk_str(mdev->state.pdsk),
256 (mdev->net_conf == NULL ? ' ' :
257 (mdev->net_conf->wire_protocol - DRBD_PROT_A+'A')),
Philipp Reisnerfb22c402010-09-08 23:20:21 +0200258 is_susp(mdev->state) ? 's' : 'r',
Philipp Reisnerb411b362009-09-25 16:07:19 -0700259 mdev->state.aftr_isp ? 'a' : '-',
260 mdev->state.peer_isp ? 'p' : '-',
261 mdev->state.user_isp ? 'u' : '-',
262 mdev->congestion_reason ?: '-',
Philipp Reisner07782862010-08-31 12:00:50 +0200263 test_bit(AL_SUSPENDED, &mdev->flags) ? 's' : '-',
Philipp Reisnerb411b362009-09-25 16:07:19 -0700264 mdev->send_cnt/2,
265 mdev->recv_cnt/2,
266 mdev->writ_cnt/2,
267 mdev->read_cnt/2,
268 mdev->al_writ_cnt,
269 mdev->bm_writ_cnt,
270 atomic_read(&mdev->local_cnt),
271 atomic_read(&mdev->ap_pending_cnt) +
272 atomic_read(&mdev->rs_pending_cnt),
273 atomic_read(&mdev->unacked_cnt),
274 atomic_read(&mdev->ap_bio_cnt),
275 mdev->epochs,
276 write_ordering_chars[mdev->write_ordering]
277 );
Lars Ellenberg18edc0b2010-11-09 14:12:10 +0100278 seq_printf(seq, " oos:%llu\n",
279 Bit2KB((unsigned long long)
280 drbd_bm_total_weight(mdev)));
Philipp Reisnerb411b362009-09-25 16:07:19 -0700281 }
282 if (mdev->state.conn == C_SYNC_SOURCE ||
Lars Ellenberg439d5952010-11-05 09:52:46 +0100283 mdev->state.conn == C_SYNC_TARGET ||
284 mdev->state.conn == C_VERIFY_S ||
285 mdev->state.conn == C_VERIFY_T)
Philipp Reisnerb411b362009-09-25 16:07:19 -0700286 drbd_syncer_progress(mdev, seq);
287
Philipp Reisnerb411b362009-09-25 16:07:19 -0700288 if (proc_details >= 1 && get_ldev_if_state(mdev, D_FAILED)) {
289 lc_seq_printf_stats(seq, mdev->resync);
290 lc_seq_printf_stats(seq, mdev->act_log);
291 put_ldev(mdev);
292 }
293
294 if (proc_details >= 2) {
295 if (mdev->resync) {
296 lc_seq_dump_details(seq, mdev->resync, "rs_left",
297 resync_dump_detail);
298 }
299 }
300 }
301
302 return 0;
303}
304
305static int drbd_proc_open(struct inode *inode, struct file *file)
306{
307 return single_open(file, drbd_seq_show, PDE(inode)->data);
308}
309
310/* PROC FS stuff end */