Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)    drbd_proc.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)    This file is part of DRBD by Philipp Reisner and Lars Ellenberg.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)    Copyright (C) 2001-2008, LINBIT Information Technologies GmbH.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)    Copyright (C) 1999-2008, Philipp Reisner <philipp.reisner@linbit.com>.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)    Copyright (C) 2002-2008, Lars Ellenberg <lars.ellenberg@linbit.com>.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/drbd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include "drbd_int.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) struct proc_dir_entry *drbd_proc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) static void seq_printf_with_thousands_grouping(struct seq_file *seq, long v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	/* v is in kB/sec. We don't expect TiByte/sec yet. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	if (unlikely(v >= 1000000)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 		/* cool: > GiByte/s */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 		seq_printf(seq, "%ld,", v / 1000000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 		v %= 1000000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 		seq_printf(seq, "%03ld,%03ld", v/1000, v % 1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	} else if (likely(v >= 1000))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 		seq_printf(seq, "%ld,%03ld", v/1000, v % 1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 		seq_printf(seq, "%ld", v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) static void drbd_get_syncer_progress(struct drbd_device *device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		union drbd_dev_state state, unsigned long *rs_total,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		unsigned long *bits_left, unsigned int *per_mil_done)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	/* this is to break it at compile time when we change that, in case we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	 * want to support more than (1<<32) bits on a 32bit arch. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	typecheck(unsigned long, device->rs_total);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	*rs_total = device->rs_total;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	/* note: both rs_total and rs_left are in bits, i.e. in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	 * units of BM_BLOCK_SIZE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	 * for the percentage, we don't care. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	if (state.conn == C_VERIFY_S || state.conn == C_VERIFY_T)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		*bits_left = device->ov_left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		*bits_left = drbd_bm_total_weight(device) - device->rs_failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	/* >> 10 to prevent overflow,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	 * +1 to prevent division by zero */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	if (*bits_left > *rs_total) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		/* D'oh. Maybe a logic bug somewhere.  More likely just a race
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		 * between state change and reset of rs_total.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		*bits_left = *rs_total;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		*per_mil_done = *rs_total ? 0 : 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		/* Make sure the division happens in long context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		 * We allow up to one petabyte storage right now,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		 * at a granularity of 4k per bit that is 2**38 bits.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		 * After shift right and multiplication by 1000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		 * this should still fit easily into a 32bit long,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		 * so we don't need a 64bit division on 32bit arch.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		 * Note: currently we don't support such large bitmaps on 32bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		 * arch anyways, but no harm done to be prepared for it here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		unsigned int shift = *rs_total > UINT_MAX ? 16 : 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		unsigned long left = *bits_left >> shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		unsigned long total = 1UL + (*rs_total >> shift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		unsigned long tmp = 1000UL - left * 1000UL/total;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		*per_mil_done = tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) /*lge
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85)  * progress bars shamelessly adapted from driver/md/md.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86)  * output looks like
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87)  *	[=====>..............] 33.5% (23456/123456)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88)  *	finish: 2:20:20 speed: 6,345 (6,456) K/sec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) static void drbd_syncer_progress(struct drbd_device *device, struct seq_file *seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		union drbd_dev_state state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	unsigned long db, dt, dbdt, rt, rs_total, rs_left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	unsigned int res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	int i, x, y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	int stalled = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	drbd_get_syncer_progress(device, state, &rs_total, &rs_left, &res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	x = res/50;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	y = 20-x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	seq_puts(seq, "\t[");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	for (i = 1; i < x; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		seq_putc(seq, '=');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	seq_putc(seq, '>');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	for (i = 0; i < y; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		seq_putc(seq, '.');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	seq_puts(seq, "] ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	if (state.conn == C_VERIFY_S || state.conn == C_VERIFY_T)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		seq_puts(seq, "verified:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		seq_puts(seq, "sync'ed:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	seq_printf(seq, "%3u.%u%% ", res / 10, res % 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	/* if more than a few GB, display in MB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	if (rs_total > (4UL << (30 - BM_BLOCK_SHIFT)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		seq_printf(seq, "(%lu/%lu)M",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 			    (unsigned long) Bit2KB(rs_left >> 10),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 			    (unsigned long) Bit2KB(rs_total >> 10));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		seq_printf(seq, "(%lu/%lu)K",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 			    (unsigned long) Bit2KB(rs_left),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 			    (unsigned long) Bit2KB(rs_total));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	seq_puts(seq, "\n\t");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	/* see drivers/md/md.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	 * We do not want to overflow, so the order of operands and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	 * the * 100 / 100 trick are important. We do a +1 to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	 * safe against division by zero. We only estimate anyway.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	 * dt: time from mark until now
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	 * db: blocks written from mark until now
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	 * rt: remaining time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	/* Rolling marks. last_mark+1 may just now be modified.  last_mark+2 is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	 * at least (DRBD_SYNC_MARKS-2)*DRBD_SYNC_MARK_STEP old, and has at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	 * least DRBD_SYNC_MARK_STEP time before it will be modified. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	/* ------------------------ ~18s average ------------------------ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	i = (device->rs_last_mark + 2) % DRBD_SYNC_MARKS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	dt = (jiffies - device->rs_mark_time[i]) / HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	if (dt > 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		stalled = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	if (!dt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		dt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	db = device->rs_mark_left[i] - rs_left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	rt = (dt * (rs_left / (db/100+1)))/100; /* seconds */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	seq_printf(seq, "finish: %lu:%02lu:%02lu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		rt / 3600, (rt % 3600) / 60, rt % 60);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	dbdt = Bit2KB(db/dt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	seq_puts(seq, " speed: ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	seq_printf_with_thousands_grouping(seq, dbdt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	seq_puts(seq, " (");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	/* ------------------------- ~3s average ------------------------ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	if (drbd_proc_details >= 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		/* this is what drbd_rs_should_slow_down() uses */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		i = (device->rs_last_mark + DRBD_SYNC_MARKS-1) % DRBD_SYNC_MARKS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		dt = (jiffies - device->rs_mark_time[i]) / HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		if (!dt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 			dt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		db = device->rs_mark_left[i] - rs_left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		dbdt = Bit2KB(db/dt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		seq_printf_with_thousands_grouping(seq, dbdt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		seq_puts(seq, " -- ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	/* --------------------- long term average ---------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	/* mean speed since syncer started
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	 * we do account for PausedSync periods */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	dt = (jiffies - device->rs_start - device->rs_paused) / HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	if (dt == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		dt = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	db = rs_total - rs_left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	dbdt = Bit2KB(db/dt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	seq_printf_with_thousands_grouping(seq, dbdt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	seq_putc(seq, ')');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	if (state.conn == C_SYNC_TARGET ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	    state.conn == C_VERIFY_S) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		seq_puts(seq, " want: ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		seq_printf_with_thousands_grouping(seq, device->c_sync_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	seq_printf(seq, " K/sec%s\n", stalled ? " (stalled)" : "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	if (drbd_proc_details >= 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		/* 64 bit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		 * we convert to sectors in the display below. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		unsigned long bm_bits = drbd_bm_bits(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		unsigned long bit_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		unsigned long long stop_sector = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		if (state.conn == C_VERIFY_S ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		    state.conn == C_VERIFY_T) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 			bit_pos = bm_bits - device->ov_left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 			if (verify_can_do_stop_sector(device))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 				stop_sector = device->ov_stop_sector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 			bit_pos = device->bm_resync_fo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		/* Total sectors may be slightly off for oddly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		 * sized devices. So what. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		seq_printf(seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 			"\t%3d%% sector pos: %llu/%llu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 			(int)(bit_pos / (bm_bits/100+1)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 			(unsigned long long)bit_pos * BM_SECT_PER_BIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 			(unsigned long long)bm_bits * BM_SECT_PER_BIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		if (stop_sector != 0 && stop_sector != ULLONG_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 			seq_printf(seq, " stop sector: %llu", stop_sector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		seq_putc(seq, '\n');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) int drbd_seq_show(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	int i, prev_i = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	const char *sn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	struct drbd_device *device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	struct net_conf *nc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	union drbd_dev_state state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	char wp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	static char write_ordering_chars[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		[WO_NONE] = 'n',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		[WO_DRAIN_IO] = 'd',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		[WO_BDEV_FLUSH] = 'f',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	seq_printf(seq, "version: " REL_VERSION " (api:%d/proto:%d-%d)\n%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		   API_VERSION, PRO_VERSION_MIN, PRO_VERSION_MAX, drbd_buildtag());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	  cs .. connection state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	  ro .. node role (local/remote)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	  ds .. disk state (local/remote)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	     protocol
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	     various flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	  ns .. network send
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	  nr .. network receive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	  dw .. disk write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	  dr .. disk read
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	  al .. activity log write count
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	  bm .. bitmap update write count
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	  pe .. pending (waiting for ack or data reply)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	  ua .. unack'd (still need to send ack or data reply)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	  ap .. application requests accepted, but not yet completed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	  ep .. number of epochs currently "on the fly", P_BARRIER_ACK pending
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	  wo .. write ordering mode currently in use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	 oos .. known out-of-sync kB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	idr_for_each_entry(&drbd_devices, device, i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		if (prev_i != i - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 			seq_putc(seq, '\n');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		prev_i = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		state = device->state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		sn = drbd_conn_str(state.conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		if (state.conn == C_STANDALONE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		    state.disk == D_DISKLESS &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		    state.role == R_SECONDARY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 			seq_printf(seq, "%2d: cs:Unconfigured\n", i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 			/* reset device->congestion_reason */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 			nc = rcu_dereference(first_peer_device(device)->connection->net_conf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 			wp = nc ? nc->wire_protocol - DRBD_PROT_A + 'A' : ' ';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 			seq_printf(seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 			   "%2d: cs:%s ro:%s/%s ds:%s/%s %c %c%c%c%c%c%c\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 			   "    ns:%u nr:%u dw:%u dr:%u al:%u bm:%u "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 			   "lo:%d pe:%d ua:%d ap:%d ep:%d wo:%c",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 			   i, sn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 			   drbd_role_str(state.role),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 			   drbd_role_str(state.peer),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 			   drbd_disk_str(state.disk),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 			   drbd_disk_str(state.pdsk),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 			   wp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 			   drbd_suspended(device) ? 's' : 'r',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 			   state.aftr_isp ? 'a' : '-',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 			   state.peer_isp ? 'p' : '-',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 			   state.user_isp ? 'u' : '-',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 			   device->congestion_reason ?: '-',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 			   test_bit(AL_SUSPENDED, &device->flags) ? 's' : '-',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 			   device->send_cnt/2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 			   device->recv_cnt/2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 			   device->writ_cnt/2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 			   device->read_cnt/2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 			   device->al_writ_cnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 			   device->bm_writ_cnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 			   atomic_read(&device->local_cnt),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 			   atomic_read(&device->ap_pending_cnt) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 			   atomic_read(&device->rs_pending_cnt),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 			   atomic_read(&device->unacked_cnt),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 			   atomic_read(&device->ap_bio_cnt),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 			   first_peer_device(device)->connection->epochs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 			   write_ordering_chars[device->resource->write_ordering]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 			);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 			seq_printf(seq, " oos:%llu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 				   Bit2KB((unsigned long long)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 					   drbd_bm_total_weight(device)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		if (state.conn == C_SYNC_SOURCE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 		    state.conn == C_SYNC_TARGET ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		    state.conn == C_VERIFY_S ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 		    state.conn == C_VERIFY_T)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 			drbd_syncer_progress(device, seq, state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 		if (drbd_proc_details >= 1 && get_ldev_if_state(device, D_FAILED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 			lc_seq_printf_stats(seq, device->resync);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 			lc_seq_printf_stats(seq, device->act_log);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 			put_ldev(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		if (drbd_proc_details >= 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 			seq_printf(seq, "\tblocked on activity log: %d\n", atomic_read(&device->ap_actlog_cnt));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) }