1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 #define DEBUG_SUBSYSTEM S_CLASS
38 #include <linux/version.h>
39 #include <lprocfs_status.h>
41 #include <linux/seq_file.h>
42 #include <linux/version.h>
44 #include "filter_internal.h"
47 static int lprocfs_filter_rd_groups(char *page, char **start, off_t off,
48 int count, int *eof, void *data)
51 return snprintf(page, count, "%u\n", FILTER_GROUPS);
54 static int lprocfs_filter_rd_tot_dirty(char *page, char **start, off_t off,
55 int count, int *eof, void *data)
57 struct obd_device *obd = (struct obd_device *)data;
61 return snprintf(page, count, LPU64"\n", obd->u.filter.fo_tot_dirty);
64 static int lprocfs_filter_rd_tot_granted(char *page, char **start, off_t off,
65 int count, int *eof, void *data)
67 struct obd_device *obd = (struct obd_device *)data;
71 return snprintf(page, count, LPU64"\n", obd->u.filter.fo_tot_granted);
74 static int lprocfs_filter_rd_tot_pending(char *page, char **start, off_t off,
75 int count, int *eof, void *data)
77 struct obd_device *obd = (struct obd_device *)data;
81 return snprintf(page, count, LPU64"\n", obd->u.filter.fo_tot_pending);
84 static int lprocfs_filter_rd_mntdev(char *page, char **start, off_t off,
85 int count, int *eof, void *data)
87 struct obd_device *obd = (struct obd_device *)data;
90 LASSERT(obd->u.filter.fo_vfsmnt->mnt_devname);
92 return snprintf(page, count, "%s\n",
93 obd->u.filter.fo_vfsmnt->mnt_devname);
96 static int lprocfs_filter_rd_last_id(char *page, char **start, off_t off,
97 int count, int *eof, void *data)
99 struct obd_device *obd = data;
101 if (obd == NULL || !obd->obd_set_up || obd->obd_stopping)
104 return snprintf(page, count, LPU64"\n",
105 filter_last_id(&obd->u.filter, 0));
108 int lprocfs_filter_rd_readcache(char *page, char **start, off_t off, int count,
109 int *eof, void *data)
111 struct obd_device *obd = data;
114 rc = snprintf(page, count, LPU64"\n",
115 obd->u.filter.fo_readcache_max_filesize);
119 int lprocfs_filter_wr_readcache(struct file *file, const char *buffer,
120 unsigned long count, void *data)
122 struct obd_device *obd = data;
126 rc = lprocfs_write_u64_helper(buffer, count, &val);
130 obd->u.filter.fo_readcache_max_filesize = val;
134 int lprocfs_filter_rd_fmd_max_num(char *page, char **start, off_t off,
135 int count, int *eof, void *data)
137 struct obd_device *obd = data;
140 rc = snprintf(page, count, "%u\n", obd->u.filter.fo_fmd_max_num);
144 int lprocfs_filter_wr_fmd_max_num(struct file *file, const char *buffer,
145 unsigned long count, void *data)
147 struct obd_device *obd = data;
151 rc = lprocfs_write_helper(buffer, count, &val);
155 if (val > 65536 || val < 1)
158 obd->u.filter.fo_fmd_max_num = val;
162 int lprocfs_filter_rd_fmd_max_age(char *page, char **start, off_t off,
163 int count, int *eof, void *data)
165 struct obd_device *obd = data;
168 rc = snprintf(page, count, "%u\n", obd->u.filter.fo_fmd_max_age / HZ);
172 int lprocfs_filter_wr_fmd_max_age(struct file *file, const char *buffer,
173 unsigned long count, void *data)
175 struct obd_device *obd = data;
179 rc = lprocfs_write_helper(buffer, count, &val);
183 if (val > 65536 || val < 1)
186 obd->u.filter.fo_fmd_max_age = val * HZ;
190 static int lprocfs_filter_rd_cache(char *page, char **start, off_t off,
191 int count, int *eof, void *data)
193 struct obd_device *obd = (struct obd_device *)data;
194 LASSERT(obd != NULL);
196 return snprintf(page, count, "%u\n", obd->u.filter.fo_read_cache);
199 static int lprocfs_filter_wr_cache(struct file *file, const char *buffer,
200 unsigned long count, void *data)
202 struct obd_device *obd = (struct obd_device *)data;
204 LASSERT(obd != NULL);
206 rc = lprocfs_write_helper(buffer, count, &val);
211 obd->u.filter.fo_read_cache = val;
215 static int lprocfs_filter_rd_wcache(char *page, char **start, off_t off,
216 int count, int *eof, void *data)
218 struct obd_device *obd = (struct obd_device *)data;
219 LASSERT(obd != NULL);
221 return snprintf(page, count, "%u\n", obd->u.filter.fo_writethrough_cache);
224 static int lprocfs_filter_wr_wcache(struct file *file, const char *buffer,
225 unsigned long count, void *data)
227 struct obd_device *obd = (struct obd_device *)data;
229 LASSERT(obd != NULL);
231 rc = lprocfs_write_helper(buffer, count, &val);
236 obd->u.filter.fo_writethrough_cache = val;
240 int lprocfs_filter_rd_syncjournal(char *page, char **start, off_t off,
241 int count, int *eof, void *data)
243 struct obd_device *obd = data;
246 rc = snprintf(page, count, "%u\n", obd->u.filter.fo_syncjournal);
250 int lprocfs_filter_wr_syncjournal(struct file *file, const char *buffer,
251 unsigned long count, void *data)
253 struct obd_device *obd = data;
257 rc = lprocfs_write_helper(buffer, count, &val);
264 obd->u.filter.fo_syncjournal = !!val;
268 int lprocfs_filter_rd_degraded(char *page, char **start, off_t off,
269 int count, int *eof, void *data)
271 struct obd_device *obd = data;
273 return snprintf(page, count, "%u\n", obd->u.filter.fo_raid_degraded);
276 int lprocfs_filter_wr_degraded(struct file *file, const char *buffer,
277 unsigned long count, void *data)
279 struct obd_device *obd = data;
282 rc = lprocfs_write_helper(buffer, count, &val);
286 spin_lock(&obd->obd_osfs_lock);
287 obd->u.filter.fo_raid_degraded = !!val;
288 spin_unlock(&obd->obd_osfs_lock);
292 static struct lprocfs_vars lprocfs_filter_obd_vars[] = {
293 { "uuid", lprocfs_rd_uuid, 0, 0 },
294 { "blocksize", lprocfs_rd_blksize, 0, 0 },
295 { "kbytestotal", lprocfs_rd_kbytestotal, 0, 0 },
296 { "kbytesfree", lprocfs_rd_kbytesfree, 0, 0 },
297 { "kbytesavail", lprocfs_rd_kbytesavail, 0, 0 },
298 { "filestotal", lprocfs_rd_filestotal, 0, 0 },
299 { "filesfree", lprocfs_rd_filesfree, 0, 0 },
300 { "filegroups", lprocfs_filter_rd_groups, 0, 0 },
301 { "fstype", lprocfs_rd_fstype, 0, 0 },
302 { "mntdev", lprocfs_filter_rd_mntdev, 0, 0 },
303 { "last_id", lprocfs_filter_rd_last_id,0, 0 },
304 { "tot_dirty", lprocfs_filter_rd_tot_dirty, 0, 0 },
305 { "tot_pending", lprocfs_filter_rd_tot_pending, 0, 0 },
306 { "tot_granted", lprocfs_filter_rd_tot_granted, 0, 0 },
307 { "recovery_status", lprocfs_obd_rd_recovery_status, 0, 0 },
308 { "recovery_time_soft", lprocfs_obd_rd_recovery_time_soft,
309 lprocfs_obd_wr_recovery_time_soft, 0},
310 { "recovery_time_hard", lprocfs_obd_rd_recovery_time_hard,
311 lprocfs_obd_wr_recovery_time_hard, 0},
312 { "hash_stats", lprocfs_obd_rd_hash, 0, 0 },
313 { "evict_client", 0, lprocfs_wr_evict_client, 0,
314 &lprocfs_evict_client_fops},
315 { "num_exports", lprocfs_rd_num_exports, 0, 0 },
316 { "readcache_max_filesize",
317 lprocfs_filter_rd_readcache,
318 lprocfs_filter_wr_readcache, 0 },
319 #ifdef HAVE_QUOTA_SUPPORT
320 { "quota_bunit_sz", lprocfs_quota_rd_bunit,
321 lprocfs_quota_wr_bunit, 0},
322 { "quota_btune_sz", lprocfs_quota_rd_btune,
323 lprocfs_quota_wr_btune, 0},
324 { "quota_iunit_sz", lprocfs_quota_rd_iunit,
325 lprocfs_quota_wr_iunit, 0},
326 { "quota_itune_sz", lprocfs_quota_rd_itune,
327 lprocfs_quota_wr_itune, 0},
328 { "quota_type", lprocfs_quota_rd_type,
329 lprocfs_quota_wr_type, 0},
330 { "quota_switch_seconds", lprocfs_quota_rd_switch_seconds,
331 lprocfs_quota_wr_switch_seconds, 0 },
333 { "client_cache_count", lprocfs_filter_rd_fmd_max_num,
334 lprocfs_filter_wr_fmd_max_num, 0 },
335 { "client_cache_seconds", lprocfs_filter_rd_fmd_max_age,
336 lprocfs_filter_wr_fmd_max_age, 0 },
337 { "read_cache_enable", lprocfs_filter_rd_cache, lprocfs_filter_wr_cache, 0},
338 { "writethrough_cache_enable", lprocfs_filter_rd_wcache,
339 lprocfs_filter_wr_wcache, 0},
340 #ifdef HAVE_DELAYED_RECOVERY
341 { "stale_export_age", lprocfs_obd_rd_stale_export_age,
342 lprocfs_obd_wr_stale_export_age, 0},
343 { "flush_stale_exports", 0, lprocfs_obd_wr_flush_stale_exports, 0 },
345 { "sync_journal", lprocfs_filter_rd_syncjournal,
346 lprocfs_filter_wr_syncjournal, 0 },
347 { "degraded", lprocfs_filter_rd_degraded,
348 lprocfs_filter_wr_degraded, 0 },
352 static struct lprocfs_vars lprocfs_filter_module_vars[] = {
353 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
357 void filter_tally(struct obd_export *exp, struct page **pages, int nr_pages,
358 unsigned long *blocks, int blocks_per_page, int wr)
360 struct filter_obd *filter = &exp->exp_obd->u.filter;
361 struct page *last_page = NULL;
362 unsigned long *last_block = NULL;
363 unsigned long discont_pages = 0;
364 unsigned long discont_blocks = 0;
370 lprocfs_oh_tally_log2(&filter->fo_filter_stats.hist[BRW_R_PAGES + wr],
372 if (exp->exp_nid_stats && exp->exp_nid_stats->nid_brw_stats)
373 lprocfs_oh_tally_log2(&exp->exp_nid_stats->nid_brw_stats->
374 hist[BRW_R_PAGES + wr], nr_pages);
376 while (nr_pages-- > 0) {
377 if (last_page && (*pages)->index != (last_page->index + 1))
381 for (i = 0; i < blocks_per_page; i++) {
382 if (last_block && *blocks != (*last_block + 1))
384 last_block = blocks++;
388 lprocfs_oh_tally(&filter->fo_filter_stats.hist[BRW_R_DISCONT_PAGES +wr],
390 lprocfs_oh_tally(&filter->fo_filter_stats.hist[BRW_R_DISCONT_BLOCKS+wr],
393 if (exp->exp_nid_stats && exp->exp_nid_stats->nid_brw_stats) {
394 lprocfs_oh_tally_log2(&exp->exp_nid_stats->nid_brw_stats->
395 hist[BRW_R_DISCONT_PAGES + wr],
397 lprocfs_oh_tally_log2(&exp->exp_nid_stats->nid_brw_stats->
398 hist[BRW_R_DISCONT_BLOCKS + wr],
403 #define pct(a,b) (b ? a * 100 / b : 0)
405 static void display_brw_stats(struct seq_file *seq, char *name, char *units,
406 struct obd_histogram *read, struct obd_histogram *write, int log2)
408 unsigned long read_tot, write_tot, r, w, read_cum = 0, write_cum = 0;
411 seq_printf(seq, "\n%26s read | write\n", " ");
412 seq_printf(seq, "%-22s %-5s %% cum %% | %-5s %% cum %%\n",
415 read_tot = lprocfs_oh_sum(read);
416 write_tot = lprocfs_oh_sum(write);
417 for (i = 0; i < OBD_HIST_MAX; i++) {
418 r = read->oh_buckets[i];
419 w = write->oh_buckets[i];
422 if (read_cum == 0 && write_cum == 0)
426 seq_printf(seq, "%u", i);
428 seq_printf(seq, "%u", 1<<i);
430 seq_printf(seq, "%uK", 1<<(i-10));
432 seq_printf(seq, "%uM", 1<<(i-20));
434 seq_printf(seq, ":\t\t%10lu %3lu %3lu | %4lu %3lu %3lu\n",
435 r, pct(r, read_tot), pct(read_cum, read_tot),
436 w, pct(w, write_tot), pct(write_cum, write_tot));
438 if (read_cum == read_tot && write_cum == write_tot)
443 static void brw_stats_show(struct seq_file *seq, struct brw_stats *brw_stats)
447 /* this sampling races with updates */
448 do_gettimeofday(&now);
449 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
450 now.tv_sec, now.tv_usec);
452 display_brw_stats(seq, "pages per bulk r/w", "rpcs",
453 &brw_stats->hist[BRW_R_PAGES],
454 &brw_stats->hist[BRW_W_PAGES], 1);
456 display_brw_stats(seq, "discontiguous pages", "rpcs",
457 &brw_stats->hist[BRW_R_DISCONT_PAGES],
458 &brw_stats->hist[BRW_W_DISCONT_PAGES], 0);
460 display_brw_stats(seq, "discontiguous blocks", "rpcs",
461 &brw_stats->hist[BRW_R_DISCONT_BLOCKS],
462 &brw_stats->hist[BRW_W_DISCONT_BLOCKS], 0);
464 display_brw_stats(seq, "disk fragmented I/Os", "ios",
465 &brw_stats->hist[BRW_R_DIO_FRAGS],
466 &brw_stats->hist[BRW_W_DIO_FRAGS], 0);
468 display_brw_stats(seq, "disk I/Os in flight", "ios",
469 &brw_stats->hist[BRW_R_RPC_HIST],
470 &brw_stats->hist[BRW_W_RPC_HIST], 0);
474 sprintf(title, "I/O time (1/%ds)", HZ);
475 display_brw_stats(seq, title, "ios",
476 &brw_stats->hist[BRW_R_IO_TIME],
477 &brw_stats->hist[BRW_W_IO_TIME], 1);
480 display_brw_stats(seq, "disk I/O size", "ios",
481 &brw_stats->hist[BRW_R_DISK_IOSIZE],
482 &brw_stats->hist[BRW_W_DISK_IOSIZE], 1);
487 static int filter_brw_stats_seq_show(struct seq_file *seq, void *v)
489 struct obd_device *dev = seq->private;
490 struct filter_obd *filter = &dev->u.filter;
492 brw_stats_show(seq, &filter->fo_filter_stats);
497 static ssize_t filter_brw_stats_seq_write(struct file *file, const char *buf,
498 size_t len, loff_t *off)
500 struct seq_file *seq = file->private_data;
501 struct obd_device *dev = seq->private;
502 struct filter_obd *filter = &dev->u.filter;
505 for (i = 0; i < BRW_LAST; i++)
506 lprocfs_oh_clear(&filter->fo_filter_stats.hist[i]);
511 LPROC_SEQ_FOPS(filter_brw_stats);
513 int lproc_filter_attach_seqstat(struct obd_device *dev)
515 return lprocfs_obd_seq_create(dev, "brw_stats", 0444,
516 &filter_brw_stats_fops, dev);
519 void lprocfs_filter_init_vars(struct lprocfs_static_vars *lvars)
521 lvars->module_vars = lprocfs_filter_module_vars;
522 lvars->obd_vars = lprocfs_filter_obd_vars;
525 static int filter_per_nid_stats_seq_show(struct seq_file *seq, void *v)
527 nid_stat_t * stat = seq->private;
529 if (stat->nid_brw_stats)
530 brw_stats_show(seq, stat->nid_brw_stats);
535 static ssize_t filter_per_nid_stats_seq_write(struct file *file,
536 const char *buf, size_t len,
539 struct seq_file *seq = file->private_data;
540 nid_stat_t *stat = seq->private;
543 if (stat->nid_brw_stats)
544 for (i = 0; i < BRW_LAST; i++)
545 lprocfs_oh_clear(&stat->nid_brw_stats->hist[i]);
550 LPROC_SEQ_FOPS(filter_per_nid_stats);