Commit | Line | Data |
---|---|---|
b411b363 PR |
1 | /* |
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 | ||
b411b363 PR |
26 | #include <linux/module.h> |
27 | ||
28 | #include <asm/uaccess.h> | |
29 | #include <linux/fs.h> | |
30 | #include <linux/file.h> | |
b411b363 PR |
31 | #include <linux/proc_fs.h> |
32 | #include <linux/seq_file.h> | |
33 | #include <linux/drbd.h> | |
34 | #include "drbd_int.h" | |
35 | ||
36 | static int drbd_proc_open(struct inode *inode, struct file *file); | |
3da127fa | 37 | static int drbd_proc_release(struct inode *inode, struct file *file); |
b411b363 PR |
38 | |
39 | ||
40 | struct proc_dir_entry *drbd_proc; | |
7d4e9d09 | 41 | const struct file_operations drbd_proc_fops = { |
b411b363 PR |
42 | .owner = THIS_MODULE, |
43 | .open = drbd_proc_open, | |
44 | .read = seq_read, | |
45 | .llseek = seq_lseek, | |
3da127fa | 46 | .release = drbd_proc_release, |
b411b363 PR |
47 | }; |
48 | ||
fbe0d91c | 49 | static void seq_printf_with_thousands_grouping(struct seq_file *seq, long v) |
439d5953 LE |
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); | |
fc251d5c | 55 | v %= 1000000; |
439d5953 LE |
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); | |
59 | else | |
60 | seq_printf(seq, "%ld", v); | |
61 | } | |
b411b363 PR |
62 | |
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 | */ | |
b30ab791 | 69 | static void drbd_syncer_progress(struct drbd_device *device, struct seq_file *seq) |
b411b363 PR |
70 | { |
71 | unsigned long db, dt, dbdt, rt, rs_left; | |
72 | unsigned int res; | |
73 | int i, x, y; | |
1d7734a0 | 74 | int stalled = 0; |
b411b363 | 75 | |
b30ab791 | 76 | drbd_get_syncer_progress(device, &rs_left, &res); |
b411b363 PR |
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 | ||
b30ab791 | 88 | if (device->state.conn == C_VERIFY_S || device->state.conn == C_VERIFY_T) |
5f9915bb LE |
89 | seq_printf(seq, "verified:"); |
90 | else | |
91 | seq_printf(seq, "sync'ed:"); | |
92 | seq_printf(seq, "%3u.%u%% ", res / 10, res % 10); | |
93 | ||
4b0715f0 | 94 | /* if more than a few GB, display in MB */ |
b30ab791 | 95 | if (device->rs_total > (4UL << (30 - BM_BLOCK_SHIFT))) |
4b0715f0 | 96 | seq_printf(seq, "(%lu/%lu)M", |
b411b363 | 97 | (unsigned long) Bit2KB(rs_left >> 10), |
b30ab791 | 98 | (unsigned long) Bit2KB(device->rs_total >> 10)); |
b411b363 | 99 | else |
e7f52dfb | 100 | seq_printf(seq, "(%lu/%lu)K\n\t", |
b411b363 | 101 | (unsigned long) Bit2KB(rs_left), |
b30ab791 | 102 | (unsigned long) Bit2KB(device->rs_total)); |
b411b363 PR |
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 | */ | |
1d7734a0 LE |
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. */ | |
439d5953 | 116 | /* ------------------------ ~18s average ------------------------ */ |
b30ab791 AG |
117 | i = (device->rs_last_mark + 2) % DRBD_SYNC_MARKS; |
118 | dt = (jiffies - device->rs_mark_time[i]) / HZ; | |
9ae47260 | 119 | if (dt > 180) |
1d7734a0 | 120 | stalled = 1; |
b411b363 PR |
121 | |
122 | if (!dt) | |
123 | dt++; | |
b30ab791 | 124 | db = device->rs_mark_left[i] - rs_left; |
b411b363 PR |
125 | 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 | ||
b411b363 | 130 | dbdt = Bit2KB(db/dt); |
439d5953 LE |
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 */ | |
b30ab791 AG |
137 | i = (device->rs_last_mark + DRBD_SYNC_MARKS-1) % DRBD_SYNC_MARKS; |
138 | dt = (jiffies - device->rs_mark_time[i]) / HZ; | |
439d5953 LE |
139 | if (!dt) |
140 | dt++; | |
b30ab791 | 141 | db = device->rs_mark_left[i] - rs_left; |
439d5953 LE |
142 | dbdt = Bit2KB(db/dt); |
143 | seq_printf_with_thousands_grouping(seq, dbdt); | |
144 | seq_printf(seq, " -- "); | |
145 | } | |
b411b363 | 146 | |
439d5953 | 147 | /* --------------------- long term average ---------------------- */ |
b411b363 PR |
148 | /* mean speed since syncer started |
149 | * we do account for PausedSync periods */ | |
b30ab791 | 150 | dt = (jiffies - device->rs_start - device->rs_paused) / HZ; |
22657695 | 151 | if (dt == 0) |
b411b363 | 152 | dt = 1; |
b30ab791 | 153 | db = device->rs_total - rs_left; |
b411b363 | 154 | dbdt = Bit2KB(db/dt); |
439d5953 LE |
155 | seq_printf_with_thousands_grouping(seq, dbdt); |
156 | seq_printf(seq, ")"); | |
b411b363 | 157 | |
b30ab791 AG |
158 | if (device->state.conn == C_SYNC_TARGET || |
159 | device->state.conn == C_VERIFY_S) { | |
5f9915bb | 160 | seq_printf(seq, " want: "); |
b30ab791 | 161 | seq_printf_with_thousands_grouping(seq, device->c_sync_rate); |
1d7734a0 LE |
162 | } |
163 | seq_printf(seq, " K/sec%s\n", stalled ? " (stalled)" : ""); | |
5f9915bb LE |
164 | |
165 | if (proc_details >= 1) { | |
166 | /* 64 bit: | |
167 | * we convert to sectors in the display below. */ | |
b30ab791 | 168 | unsigned long bm_bits = drbd_bm_bits(device); |
4896e8c1 | 169 | unsigned long bit_pos; |
58ffa580 | 170 | unsigned long long stop_sector = 0; |
b30ab791 AG |
171 | if (device->state.conn == C_VERIFY_S || |
172 | device->state.conn == C_VERIFY_T) { | |
173 | bit_pos = bm_bits - device->ov_left; | |
174 | if (verify_can_do_stop_sector(device)) | |
175 | stop_sector = device->ov_stop_sector; | |
58ffa580 | 176 | } else |
b30ab791 | 177 | bit_pos = device->bm_resync_fo; |
5f9915bb LE |
178 | /* Total sectors may be slightly off for oddly |
179 | * sized devices. So what. */ | |
180 | seq_printf(seq, | |
58ffa580 | 181 | "\t%3d%% sector pos: %llu/%llu", |
5f9915bb | 182 | (int)(bit_pos / (bm_bits/100+1)), |
4896e8c1 LE |
183 | (unsigned long long)bit_pos * BM_SECT_PER_BIT, |
184 | (unsigned long long)bm_bits * BM_SECT_PER_BIT); | |
58ffa580 LE |
185 | if (stop_sector != 0 && stop_sector != ULLONG_MAX) |
186 | seq_printf(seq, " stop sector: %llu", stop_sector); | |
187 | seq_printf(seq, "\n"); | |
5f9915bb | 188 | } |
b411b363 PR |
189 | } |
190 | ||
191 | static void resync_dump_detail(struct seq_file *seq, struct lc_element *e) | |
192 | { | |
193 | struct bm_extent *bme = lc_entry(e, struct bm_extent, lce); | |
194 | ||
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" : "------" | |
198 | ); | |
199 | } | |
200 | ||
201 | static int drbd_seq_show(struct seq_file *seq, void *v) | |
202 | { | |
81a5d60e | 203 | int i, prev_i = -1; |
b411b363 | 204 | const char *sn; |
b30ab791 | 205 | struct drbd_device *device; |
44ed167d PR |
206 | struct net_conf *nc; |
207 | char wp; | |
b411b363 PR |
208 | |
209 | static char write_ordering_chars[] = { | |
210 | [WO_none] = 'n', | |
211 | [WO_drain_io] = 'd', | |
212 | [WO_bdev_flush] = 'f', | |
b411b363 PR |
213 | }; |
214 | ||
215 | seq_printf(seq, "version: " REL_VERSION " (api:%d/proto:%d-%d)\n%s\n", | |
216 | API_VERSION, PRO_VERSION_MIN, PRO_VERSION_MAX, drbd_buildtag()); | |
217 | ||
218 | /* | |
219 | cs .. connection state | |
220 | ro .. node role (local/remote) | |
221 | ds .. disk state (local/remote) | |
222 | protocol | |
223 | various flags | |
224 | ns .. network send | |
225 | nr .. network receive | |
226 | dw .. disk write | |
227 | dr .. disk read | |
228 | al .. activity log write count | |
229 | bm .. bitmap update write count | |
230 | pe .. pending (waiting for ack or data reply) | |
231 | ua .. unack'd (still need to send ack or data reply) | |
232 | ap .. application requests accepted, but not yet completed | |
233 | ep .. number of epochs currently "on the fly", P_BARRIER_ACK pending | |
234 | wo .. write ordering mode currently in use | |
235 | oos .. known out-of-sync kB | |
236 | */ | |
237 | ||
c141ebda | 238 | rcu_read_lock(); |
05a10ec7 | 239 | idr_for_each_entry(&drbd_devices, device, i) { |
81a5d60e | 240 | if (prev_i != i - 1) |
b411b363 | 241 | seq_printf(seq, "\n"); |
81a5d60e | 242 | prev_i = i; |
b411b363 | 243 | |
b30ab791 | 244 | sn = drbd_conn_str(device->state.conn); |
b411b363 | 245 | |
b30ab791 AG |
246 | if (device->state.conn == C_STANDALONE && |
247 | device->state.disk == D_DISKLESS && | |
248 | device->state.role == R_SECONDARY) { | |
b411b363 PR |
249 | seq_printf(seq, "%2d: cs:Unconfigured\n", i); |
250 | } else { | |
b30ab791 AG |
251 | /* reset device->congestion_reason */ |
252 | bdi_rw_congested(&device->rq_queue->backing_dev_info); | |
8a943170 | 253 | |
a6b32bc3 | 254 | nc = rcu_dereference(first_peer_device(device)->connection->net_conf); |
44ed167d | 255 | wp = nc ? nc->wire_protocol - DRBD_PROT_A + 'A' : ' '; |
b411b363 | 256 | seq_printf(seq, |
0778286a | 257 | "%2d: cs:%s ro:%s/%s ds:%s/%s %c %c%c%c%c%c%c\n" |
b411b363 PR |
258 | " ns:%u nr:%u dw:%u dr:%u al:%u bm:%u " |
259 | "lo:%d pe:%d ua:%d ap:%d ep:%d wo:%c", | |
260 | i, sn, | |
b30ab791 AG |
261 | drbd_role_str(device->state.role), |
262 | drbd_role_str(device->state.peer), | |
263 | drbd_disk_str(device->state.disk), | |
264 | drbd_disk_str(device->state.pdsk), | |
44ed167d | 265 | wp, |
b30ab791 AG |
266 | drbd_suspended(device) ? 's' : 'r', |
267 | device->state.aftr_isp ? 'a' : '-', | |
268 | device->state.peer_isp ? 'p' : '-', | |
269 | device->state.user_isp ? 'u' : '-', | |
270 | device->congestion_reason ?: '-', | |
271 | test_bit(AL_SUSPENDED, &device->flags) ? 's' : '-', | |
272 | device->send_cnt/2, | |
273 | device->recv_cnt/2, | |
274 | device->writ_cnt/2, | |
275 | device->read_cnt/2, | |
276 | device->al_writ_cnt, | |
277 | device->bm_writ_cnt, | |
278 | atomic_read(&device->local_cnt), | |
279 | atomic_read(&device->ap_pending_cnt) + | |
280 | atomic_read(&device->rs_pending_cnt), | |
281 | atomic_read(&device->unacked_cnt), | |
282 | atomic_read(&device->ap_bio_cnt), | |
a6b32bc3 AG |
283 | first_peer_device(device)->connection->epochs, |
284 | write_ordering_chars[first_peer_device(device)->connection->write_ordering] | |
b411b363 | 285 | ); |
18edc0b9 LE |
286 | seq_printf(seq, " oos:%llu\n", |
287 | Bit2KB((unsigned long long) | |
b30ab791 | 288 | drbd_bm_total_weight(device))); |
b411b363 | 289 | } |
b30ab791 AG |
290 | if (device->state.conn == C_SYNC_SOURCE || |
291 | device->state.conn == C_SYNC_TARGET || | |
292 | device->state.conn == C_VERIFY_S || | |
293 | device->state.conn == C_VERIFY_T) | |
294 | drbd_syncer_progress(device, seq); | |
295 | ||
296 | if (proc_details >= 1 && get_ldev_if_state(device, D_FAILED)) { | |
297 | lc_seq_printf_stats(seq, device->resync); | |
298 | lc_seq_printf_stats(seq, device->act_log); | |
299 | put_ldev(device); | |
b411b363 PR |
300 | } |
301 | ||
302 | if (proc_details >= 2) { | |
b30ab791 AG |
303 | if (device->resync) { |
304 | lc_seq_dump_details(seq, device->resync, "rs_left", | |
b411b363 PR |
305 | resync_dump_detail); |
306 | } | |
307 | } | |
308 | } | |
c141ebda | 309 | rcu_read_unlock(); |
b411b363 PR |
310 | |
311 | return 0; | |
312 | } | |
313 | ||
314 | static int drbd_proc_open(struct inode *inode, struct file *file) | |
315 | { | |
193d0153 AK |
316 | int err; |
317 | ||
318 | if (try_module_get(THIS_MODULE)) { | |
ebb37277 | 319 | err = single_open(file, drbd_seq_show, PDE_DATA(inode)); |
193d0153 AK |
320 | if (err) |
321 | module_put(THIS_MODULE); | |
322 | return err; | |
323 | } | |
3da127fa LE |
324 | return -ENODEV; |
325 | } | |
326 | ||
327 | static int drbd_proc_release(struct inode *inode, struct file *file) | |
328 | { | |
329 | module_put(THIS_MODULE); | |
330 | return single_release(inode, file); | |
b411b363 PR |
331 | } |
332 | ||
333 | /* PROC FS stuff end */ |