drbd_proc.c 9.98 KB
Newer Older
Philipp Reisner's avatar
Philipp Reisner committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
/*
   drbd_proc.c

   This file is part of DRBD by Philipp Reisner and Lars Ellenberg.

   Copyright (C) 2001-2008, LINBIT Information Technologies GmbH.
   Copyright (C) 1999-2008, Philipp Reisner <philipp.reisner@linbit.com>.
   Copyright (C) 2002-2008, Lars Ellenberg <lars.ellenberg@linbit.com>.

   drbd is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2, or (at your option)
   any later version.

   drbd is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with drbd; see the file COPYING.  If not, write to
   the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.

 */

#include <linux/module.h>

#include <asm/uaccess.h>
#include <linux/fs.h>
#include <linux/file.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <linux/drbd.h>
#include "drbd_int.h"

static int drbd_proc_open(struct inode *inode, struct file *file);
37
static int drbd_proc_release(struct inode *inode, struct file *file);
Philipp Reisner's avatar
Philipp Reisner committed
38 39 40


struct proc_dir_entry *drbd_proc;
41
const struct file_operations drbd_proc_fops = {
Philipp Reisner's avatar
Philipp Reisner committed
42 43 44 45
	.owner		= THIS_MODULE,
	.open		= drbd_proc_open,
	.read		= seq_read,
	.llseek		= seq_lseek,
46
	.release	= drbd_proc_release,
Philipp Reisner's avatar
Philipp Reisner committed
47 48
};

49
static void seq_printf_with_thousands_grouping(struct seq_file *seq, long v)
50 51 52 53 54
{
	/* v is in kB/sec. We don't expect TiByte/sec yet. */
	if (unlikely(v >= 1000000)) {
		/* cool: > GiByte/s */
		seq_printf(seq, "%ld,", v / 1000000);
55
		v %= 1000000;
56 57 58 59 60 61
		seq_printf(seq, "%03ld,%03ld", v/1000, v % 1000);
	} else if (likely(v >= 1000))
		seq_printf(seq, "%ld,%03ld", v/1000, v % 1000);
	else
		seq_printf(seq, "%ld", v);
}
Philipp Reisner's avatar
Philipp Reisner committed
62 63 64 65 66 67 68

/*lge
 * progress bars shamelessly adapted from driver/md/md.c
 * output looks like
 *	[=====>..............] 33.5% (23456/123456)
 *	finish: 2:20:20 speed: 6,345 (6,456) K/sec
 */
69
static void drbd_syncer_progress(struct drbd_device *device, struct seq_file *seq)
Philipp Reisner's avatar
Philipp Reisner committed
70 71 72 73
{
	unsigned long db, dt, dbdt, rt, rs_left;
	unsigned int res;
	int i, x, y;
74
	int stalled = 0;
Philipp Reisner's avatar
Philipp Reisner committed
75

76
	drbd_get_syncer_progress(device, &rs_left, &res);
Philipp Reisner's avatar
Philipp Reisner committed
77 78 79 80 81 82 83 84 85 86 87

	x = res/50;
	y = 20-x;
	seq_printf(seq, "\t[");
	for (i = 1; i < x; i++)
		seq_printf(seq, "=");
	seq_printf(seq, ">");
	for (i = 0; i < y; i++)
		seq_printf(seq, ".");
	seq_printf(seq, "] ");

88
	if (device->state.conn == C_VERIFY_S || device->state.conn == C_VERIFY_T)
89 90 91 92 93
		seq_printf(seq, "verified:");
	else
		seq_printf(seq, "sync'ed:");
	seq_printf(seq, "%3u.%u%% ", res / 10, res % 10);

94
	/* if more than a few GB, display in MB */
95
	if (device->rs_total > (4UL << (30 - BM_BLOCK_SHIFT)))
96
		seq_printf(seq, "(%lu/%lu)M",
Philipp Reisner's avatar
Philipp Reisner committed
97
			    (unsigned long) Bit2KB(rs_left >> 10),
98
			    (unsigned long) Bit2KB(device->rs_total >> 10));
Philipp Reisner's avatar
Philipp Reisner committed
99
	else
100
		seq_printf(seq, "(%lu/%lu)K\n\t",
Philipp Reisner's avatar
Philipp Reisner committed
101
			    (unsigned long) Bit2KB(rs_left),
102
			    (unsigned long) Bit2KB(device->rs_total));
Philipp Reisner's avatar
Philipp Reisner committed
103 104 105 106 107 108 109 110 111 112

	/* see drivers/md/md.c
	 * We do not want to overflow, so the order of operands and
	 * the * 100 / 100 trick are important. We do a +1 to be
	 * safe against division by zero. We only estimate anyway.
	 *
	 * dt: time from mark until now
	 * db: blocks written from mark until now
	 * rt: remaining time
	 */
113 114 115
	/* Rolling marks. last_mark+1 may just now be modified.  last_mark+2 is
	 * at least (DRBD_SYNC_MARKS-2)*DRBD_SYNC_MARK_STEP old, and has at
	 * least DRBD_SYNC_MARK_STEP time before it will be modified. */
116
	/* ------------------------ ~18s average ------------------------ */
117 118
	i = (device->rs_last_mark + 2) % DRBD_SYNC_MARKS;
	dt = (jiffies - device->rs_mark_time[i]) / HZ;
119
	if (dt > 180)
120
		stalled = 1;
Philipp Reisner's avatar
Philipp Reisner committed
121 122 123

	if (!dt)
		dt++;
124
	db = device->rs_mark_left[i] - rs_left;
Philipp Reisner's avatar
Philipp Reisner committed
125 126 127 128 129 130
	rt = (dt * (rs_left / (db/100+1)))/100; /* seconds */

	seq_printf(seq, "finish: %lu:%02lu:%02lu",
		rt / 3600, (rt % 3600) / 60, rt % 60);

	dbdt = Bit2KB(db/dt);
131 132 133 134 135 136
	seq_printf(seq, " speed: ");
	seq_printf_with_thousands_grouping(seq, dbdt);
	seq_printf(seq, " (");
	/* ------------------------- ~3s average ------------------------ */
	if (proc_details >= 1) {
		/* this is what drbd_rs_should_slow_down() uses */
137 138
		i = (device->rs_last_mark + DRBD_SYNC_MARKS-1) % DRBD_SYNC_MARKS;
		dt = (jiffies - device->rs_mark_time[i]) / HZ;
139 140
		if (!dt)
			dt++;
141
		db = device->rs_mark_left[i] - rs_left;
142 143 144 145
		dbdt = Bit2KB(db/dt);
		seq_printf_with_thousands_grouping(seq, dbdt);
		seq_printf(seq, " -- ");
	}
Philipp Reisner's avatar
Philipp Reisner committed
146

147
	/* --------------------- long term average ---------------------- */
Philipp Reisner's avatar
Philipp Reisner committed
148 149
	/* mean speed since syncer started
	 * we do account for PausedSync periods */
150
	dt = (jiffies - device->rs_start - device->rs_paused) / HZ;
151
	if (dt == 0)
Philipp Reisner's avatar
Philipp Reisner committed
152
		dt = 1;
153
	db = device->rs_total - rs_left;
Philipp Reisner's avatar
Philipp Reisner committed
154
	dbdt = Bit2KB(db/dt);
155 156
	seq_printf_with_thousands_grouping(seq, dbdt);
	seq_printf(seq, ")");
Philipp Reisner's avatar
Philipp Reisner committed
157

158 159
	if (device->state.conn == C_SYNC_TARGET ||
	    device->state.conn == C_VERIFY_S) {
160
		seq_printf(seq, " want: ");
161
		seq_printf_with_thousands_grouping(seq, device->c_sync_rate);
162 163
	}
	seq_printf(seq, " K/sec%s\n", stalled ? " (stalled)" : "");
164 165 166 167

	if (proc_details >= 1) {
		/* 64 bit:
		 * we convert to sectors in the display below. */
168
		unsigned long bm_bits = drbd_bm_bits(device);
169
		unsigned long bit_pos;
170
		unsigned long long stop_sector = 0;
171 172 173 174 175
		if (device->state.conn == C_VERIFY_S ||
		    device->state.conn == C_VERIFY_T) {
			bit_pos = bm_bits - device->ov_left;
			if (verify_can_do_stop_sector(device))
				stop_sector = device->ov_stop_sector;
176
		} else
177
			bit_pos = device->bm_resync_fo;
178 179 180
		/* Total sectors may be slightly off for oddly
		 * sized devices. So what. */
		seq_printf(seq,
181
			"\t%3d%% sector pos: %llu/%llu",
182
			(int)(bit_pos / (bm_bits/100+1)),
183 184
			(unsigned long long)bit_pos * BM_SECT_PER_BIT,
			(unsigned long long)bm_bits * BM_SECT_PER_BIT);
185 186 187
		if (stop_sector != 0 && stop_sector != ULLONG_MAX)
			seq_printf(seq, " stop sector: %llu", stop_sector);
		seq_printf(seq, "\n");
188
	}
Philipp Reisner's avatar
Philipp Reisner committed
189 190 191 192 193 194 195 196 197 198 199 200 201 202
}

static void resync_dump_detail(struct seq_file *seq, struct lc_element *e)
{
	struct bm_extent *bme = lc_entry(e, struct bm_extent, lce);

	seq_printf(seq, "%5d %s %s\n", bme->rs_left,
		   bme->flags & BME_NO_WRITES ? "NO_WRITES" : "---------",
		   bme->flags & BME_LOCKED ? "LOCKED" : "------"
		   );
}

static int drbd_seq_show(struct seq_file *seq, void *v)
{
203
	int i, prev_i = -1;
Philipp Reisner's avatar
Philipp Reisner committed
204
	const char *sn;
205
	struct drbd_device *device;
206 207
	struct net_conf *nc;
	char wp;
Philipp Reisner's avatar
Philipp Reisner committed
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237

	static char write_ordering_chars[] = {
		[WO_none] = 'n',
		[WO_drain_io] = 'd',
		[WO_bdev_flush] = 'f',
	};

	seq_printf(seq, "version: " REL_VERSION " (api:%d/proto:%d-%d)\n%s\n",
		   API_VERSION, PRO_VERSION_MIN, PRO_VERSION_MAX, drbd_buildtag());

	/*
	  cs .. connection state
	  ro .. node role (local/remote)
	  ds .. disk state (local/remote)
	     protocol
	     various flags
	  ns .. network send
	  nr .. network receive
	  dw .. disk write
	  dr .. disk read
	  al .. activity log write count
	  bm .. bitmap update write count
	  pe .. pending (waiting for ack or data reply)
	  ua .. unack'd (still need to send ack or data reply)
	  ap .. application requests accepted, but not yet completed
	  ep .. number of epochs currently "on the fly", P_BARRIER_ACK pending
	  wo .. write ordering mode currently in use
	 oos .. known out-of-sync kB
	*/

238
	rcu_read_lock();
239
	idr_for_each_entry(&drbd_devices, device, i) {
240
		if (prev_i != i - 1)
Philipp Reisner's avatar
Philipp Reisner committed
241
			seq_printf(seq, "\n");
242
		prev_i = i;
Philipp Reisner's avatar
Philipp Reisner committed
243

244
		sn = drbd_conn_str(device->state.conn);
Philipp Reisner's avatar
Philipp Reisner committed
245

246 247 248
		if (device->state.conn == C_STANDALONE &&
		    device->state.disk == D_DISKLESS &&
		    device->state.role == R_SECONDARY) {
Philipp Reisner's avatar
Philipp Reisner committed
249 250
			seq_printf(seq, "%2d: cs:Unconfigured\n", i);
		} else {
251 252
			/* reset device->congestion_reason */
			bdi_rw_congested(&device->rq_queue->backing_dev_info);
253

254
			nc = rcu_dereference(first_peer_device(device)->connection->net_conf);
255
			wp = nc ? nc->wire_protocol - DRBD_PROT_A + 'A' : ' ';
Philipp Reisner's avatar
Philipp Reisner committed
256
			seq_printf(seq,
257
			   "%2d: cs:%s ro:%s/%s ds:%s/%s %c %c%c%c%c%c%c\n"
Philipp Reisner's avatar
Philipp Reisner committed
258 259 260
			   "    ns:%u nr:%u dw:%u dr:%u al:%u bm:%u "
			   "lo:%d pe:%d ua:%d ap:%d ep:%d wo:%c",
			   i, sn,
261 262 263 264
			   drbd_role_str(device->state.role),
			   drbd_role_str(device->state.peer),
			   drbd_disk_str(device->state.disk),
			   drbd_disk_str(device->state.pdsk),
265
			   wp,
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
			   drbd_suspended(device) ? 's' : 'r',
			   device->state.aftr_isp ? 'a' : '-',
			   device->state.peer_isp ? 'p' : '-',
			   device->state.user_isp ? 'u' : '-',
			   device->congestion_reason ?: '-',
			   test_bit(AL_SUSPENDED, &device->flags) ? 's' : '-',
			   device->send_cnt/2,
			   device->recv_cnt/2,
			   device->writ_cnt/2,
			   device->read_cnt/2,
			   device->al_writ_cnt,
			   device->bm_writ_cnt,
			   atomic_read(&device->local_cnt),
			   atomic_read(&device->ap_pending_cnt) +
			   atomic_read(&device->rs_pending_cnt),
			   atomic_read(&device->unacked_cnt),
			   atomic_read(&device->ap_bio_cnt),
283 284
			   first_peer_device(device)->connection->epochs,
			   write_ordering_chars[first_peer_device(device)->connection->write_ordering]
Philipp Reisner's avatar
Philipp Reisner committed
285
			);
286 287
			seq_printf(seq, " oos:%llu\n",
				   Bit2KB((unsigned long long)
288
					   drbd_bm_total_weight(device)));
Philipp Reisner's avatar
Philipp Reisner committed
289
		}
290 291 292 293 294 295 296 297 298 299
		if (device->state.conn == C_SYNC_SOURCE ||
		    device->state.conn == C_SYNC_TARGET ||
		    device->state.conn == C_VERIFY_S ||
		    device->state.conn == C_VERIFY_T)
			drbd_syncer_progress(device, seq);

		if (proc_details >= 1 && get_ldev_if_state(device, D_FAILED)) {
			lc_seq_printf_stats(seq, device->resync);
			lc_seq_printf_stats(seq, device->act_log);
			put_ldev(device);
Philipp Reisner's avatar
Philipp Reisner committed
300 301 302
		}

		if (proc_details >= 2) {
303 304
			if (device->resync) {
				lc_seq_dump_details(seq, device->resync, "rs_left",
Philipp Reisner's avatar
Philipp Reisner committed
305 306 307 308
					resync_dump_detail);
			}
		}
	}
309
	rcu_read_unlock();
Philipp Reisner's avatar
Philipp Reisner committed
310 311 312 313 314 315

	return 0;
}

static int drbd_proc_open(struct inode *inode, struct file *file)
{
316 317 318
	int err;

	if (try_module_get(THIS_MODULE)) {
319
		err = single_open(file, drbd_seq_show, PDE_DATA(inode));
320 321 322 323
		if (err)
			module_put(THIS_MODULE);
		return err;
	}
324 325 326 327 328 329 330
	return -ENODEV;
}

static int drbd_proc_release(struct inode *inode, struct file *file)
{
	module_put(THIS_MODULE);
	return single_release(inode, file);
Philipp Reisner's avatar
Philipp Reisner committed
331 332 333
}

/* PROC FS stuff end */