4 This file is part of DRBD by Philipp Reisner and Lars Ellenberg.
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>.
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)
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.
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.
26 #include <linux/module.h>
28 #include <asm/uaccess.h>
30 #include <linux/file.h>
31 #include <linux/proc_fs.h>
32 #include <linux/seq_file.h>
33 #include <linux/drbd.h>
36 static int drbd_proc_open(struct inode *inode, struct file *file);
37 static int drbd_proc_release(struct inode *inode, struct file *file);
40 struct proc_dir_entry *drbd_proc;
41 const struct file_operations drbd_proc_fops = {
43 .open = drbd_proc_open,
46 .release = drbd_proc_release,
49 void seq_printf_with_thousands_grouping(struct seq_file *seq, long v)
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);
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);
60 seq_printf(seq, "%ld", v);
64 * progress bars shamelessly adapted from driver/md/md.c
66 * [=====>..............] 33.5% (23456/123456)
67 * finish: 2:20:20 speed: 6,345 (6,456) K/sec
69 static void drbd_syncer_progress(struct drbd_conf *mdev, struct seq_file *seq)
71 unsigned long db, dt, dbdt, rt, rs_left;
76 drbd_get_syncer_progress(mdev, &rs_left, &res);
80 seq_printf(seq, "\t[");
81 for (i = 1; i < x; i++)
84 for (i = 0; i < y; i++)
86 seq_printf(seq, "] ");
88 if (mdev->state.conn == C_VERIFY_S || mdev->state.conn == C_VERIFY_T)
89 seq_printf(seq, "verified:");
91 seq_printf(seq, "sync'ed:");
92 seq_printf(seq, "%3u.%u%% ", res / 10, res % 10);
94 /* 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",
97 (unsigned long) Bit2KB(rs_left >> 10),
98 (unsigned long) Bit2KB(mdev->rs_total >> 10));
100 seq_printf(seq, "(%lu/%lu)K\n\t",
101 (unsigned long) Bit2KB(rs_left),
102 (unsigned long) Bit2KB(mdev->rs_total));
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.
109 * dt: time from mark until now
110 * db: blocks written from mark until now
113 /* 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. */
116 /* ------------------------ ~18s average ------------------------ */
117 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))
124 db = mdev->rs_mark_left[i] - rs_left;
125 rt = (dt * (rs_left / (db/100+1)))/100; /* seconds */
127 seq_printf(seq, "finish: %lu:%02lu:%02lu",
128 rt / 3600, (rt % 3600) / 60, rt % 60);
130 dbdt = Bit2KB(db/dt);
131 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;
141 db = mdev->rs_mark_left[i] - rs_left;
142 dbdt = Bit2KB(db/dt);
143 seq_printf_with_thousands_grouping(seq, dbdt);
144 seq_printf(seq, " -- ");
147 /* --------------------- long term average ---------------------- */
148 /* mean speed since syncer started
149 * we do account for PausedSync periods */
150 dt = (jiffies - mdev->rs_start - mdev->rs_paused) / HZ;
153 db = mdev->rs_total - rs_left;
154 dbdt = Bit2KB(db/dt);
155 seq_printf_with_thousands_grouping(seq, dbdt);
156 seq_printf(seq, ")");
158 if (mdev->state.conn == C_SYNC_TARGET ||
159 mdev->state.conn == C_VERIFY_S) {
160 seq_printf(seq, " want: ");
161 seq_printf_with_thousands_grouping(seq, mdev->c_sync_rate);
163 seq_printf(seq, " K/sec%s\n", stalled ? " (stalled)" : "");
165 if (proc_details >= 1) {
167 * we convert to sectors in the display below. */
168 unsigned long bm_bits = drbd_bm_bits(mdev);
169 unsigned long bit_pos;
170 unsigned long long stop_sector = 0;
171 if (mdev->state.conn == C_VERIFY_S ||
172 mdev->state.conn == C_VERIFY_T) {
173 bit_pos = bm_bits - mdev->ov_left;
174 if (mdev->agreed_pro_version >= 97)
175 stop_sector = mdev->ov_stop_sector;
177 bit_pos = mdev->bm_resync_fo;
178 /* Total sectors may be slightly off for oddly
179 * sized devices. So what. */
181 "\t%3d%% sector pos: %llu/%llu",
182 (int)(bit_pos / (bm_bits/100+1)),
183 (unsigned long long)bit_pos * BM_SECT_PER_BIT,
184 (unsigned long long)bm_bits * BM_SECT_PER_BIT);
185 if (stop_sector != 0 && stop_sector != ULLONG_MAX)
186 seq_printf(seq, " stop sector: %llu", stop_sector);
187 seq_printf(seq, "\n");
191 static void resync_dump_detail(struct seq_file *seq, struct lc_element *e)
193 struct bm_extent *bme = lc_entry(e, struct bm_extent, lce);
195 seq_printf(seq, "%5d %s %s\n", bme->rs_left,
196 bme->flags & BME_NO_WRITES ? "NO_WRITES" : "---------",
197 bme->flags & BME_LOCKED ? "LOCKED" : "------"
201 static int drbd_seq_show(struct seq_file *seq, void *v)
205 struct drbd_conf *mdev;
207 static char write_ordering_chars[] = {
210 [WO_bdev_flush] = 'f',
213 seq_printf(seq, "version: " REL_VERSION " (api:%d/proto:%d-%d)\n%s\n",
214 API_VERSION, PRO_VERSION_MIN, PRO_VERSION_MAX, drbd_buildtag());
217 cs .. connection state
218 ro .. node role (local/remote)
219 ds .. disk state (local/remote)
223 nr .. network receive
226 al .. activity log write count
227 bm .. bitmap update write count
228 pe .. pending (waiting for ack or data reply)
229 ua .. unack'd (still need to send ack or data reply)
230 ap .. application requests accepted, but not yet completed
231 ep .. number of epochs currently "on the fly", P_BARRIER_ACK pending
232 wo .. write ordering mode currently in use
233 oos .. known out-of-sync kB
236 for (i = 0; i < minor_count; i++) {
237 mdev = minor_to_mdev(i);
244 seq_printf(seq, "\n");
247 sn = drbd_conn_str(mdev->state.conn);
249 if (mdev->state.conn == C_STANDALONE &&
250 mdev->state.disk == D_DISKLESS &&
251 mdev->state.role == R_SECONDARY) {
252 seq_printf(seq, "%2d: cs:Unconfigured\n", i);
254 /* reset mdev->congestion_reason */
255 bdi_rw_congested(&mdev->rq_queue->backing_dev_info);
258 "%2d: cs:%s ro:%s/%s ds:%s/%s %c %c%c%c%c%c%c\n"
259 " ns:%u nr:%u dw:%u dr:%u al:%u bm:%u "
260 "lo:%d pe:%d ua:%d ap:%d ep:%d wo:%c",
262 drbd_role_str(mdev->state.role),
263 drbd_role_str(mdev->state.peer),
264 drbd_disk_str(mdev->state.disk),
265 drbd_disk_str(mdev->state.pdsk),
266 (mdev->net_conf == NULL ? ' ' :
267 (mdev->net_conf->wire_protocol - DRBD_PROT_A+'A')),
268 is_susp(mdev->state) ? 's' : 'r',
269 mdev->state.aftr_isp ? 'a' : '-',
270 mdev->state.peer_isp ? 'p' : '-',
271 mdev->state.user_isp ? 'u' : '-',
272 mdev->congestion_reason ?: '-',
273 drbd_test_flag(mdev, AL_SUSPENDED) ? 's' : '-',
280 atomic_read(&mdev->local_cnt),
281 atomic_read(&mdev->ap_pending_cnt) +
282 atomic_read(&mdev->rs_pending_cnt),
283 atomic_read(&mdev->unacked_cnt),
284 atomic_read(&mdev->ap_bio_cnt),
286 write_ordering_chars[mdev->write_ordering]
288 seq_printf(seq, " oos:%llu\n",
289 Bit2KB((unsigned long long)
290 drbd_bm_total_weight(mdev)));
292 if (mdev->state.conn == C_SYNC_SOURCE ||
293 mdev->state.conn == C_SYNC_TARGET ||
294 mdev->state.conn == C_VERIFY_S ||
295 mdev->state.conn == C_VERIFY_T)
296 drbd_syncer_progress(mdev, seq);
298 if (proc_details >= 1 && get_ldev_if_state(mdev, D_FAILED)) {
299 lc_seq_printf_stats(seq, mdev->resync);
300 lc_seq_printf_stats(seq, mdev->act_log);
304 if (proc_details >= 2) {
306 lc_seq_dump_details(seq, mdev->resync, "rs_left",
315 static int drbd_proc_open(struct inode *inode, struct file *file)
317 if (try_module_get(THIS_MODULE))
318 return single_open(file, drbd_seq_show, PDE(inode)->data);
322 static int drbd_proc_release(struct inode *inode, struct file *file)
324 module_put(THIS_MODULE);
325 return single_release(inode, file);
328 /* PROC FS stuff end */