1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2002, 2003 Cluster File Systems, Inc.
6 * This file is part of the Lustre file system, http://www.lustre.org
7 * Lustre is a trademark of Cluster File Systems, Inc.
9 * You may have signed or agreed to another license before downloading
10 * this software. If so, you are bound by the terms and conditions
11 * of that agreement, and the following does not apply to you. See the
12 * LICENSE file included with this distribution for more information.
14 * If you did not agree to a different license, then this copy of Lustre
15 * is open source software; you can redistribute it and/or modify it
16 * under the terms of version 2 of the GNU General Public License as
17 * published by the Free Software Foundation.
19 * In either case, Lustre is distributed in the hope that it will be
20 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
21 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * license text for more details.
25 #define DEBUG_SUBSYSTEM S_CLASS
27 #include <linux/version.h>
28 #include <lprocfs_status.h>
30 #include <linux/seq_file.h>
31 #include <linux/version.h>
33 #include "filter_internal.h"
36 static int lprocfs_filter_rd_groups(char *page, char **start, off_t off,
37 int count, int *eof, void *data)
39 struct obd_device *obd = (struct obd_device *)data;
41 return snprintf(page, count, "%u\n", obd->u.filter.fo_group_count);
44 static int lprocfs_filter_rd_tot_dirty(char *page, char **start, off_t off,
45 int count, int *eof, void *data)
47 struct obd_device *obd = (struct obd_device *)data;
51 return snprintf(page, count, LPU64"\n", obd->u.filter.fo_tot_dirty);
54 static int lprocfs_filter_rd_tot_granted(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_granted);
64 static int lprocfs_filter_rd_tot_pending(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_pending);
74 static int lprocfs_filter_rd_mntdev(char *page, char **start, off_t off,
75 int count, int *eof, void *data)
77 struct obd_device *obd = (struct obd_device *)data;
80 LASSERT(obd->u.filter.fo_vfsmnt->mnt_devname);
82 return snprintf(page, count, "%s\n",
83 obd->u.filter.fo_vfsmnt->mnt_devname);
86 static int lprocfs_filter_rd_last_id(char *page, char **start, off_t off,
87 int count, int *eof, void *data)
89 struct obd_device *obd = data;
90 struct filter_obd *filter = &obd->u.filter;
91 int retval = 0, rc, i;
96 for (i = FILTER_GROUP_MDS0; i < filter->fo_group_count; i++) {
97 rc = snprintf(page, count, LPU64"\n",filter_last_id(filter, i));
109 int lprocfs_filter_rd_readcache(char *page, char **start, off_t off, int count,
110 int *eof, void *data)
112 struct obd_device *obd = data;
115 rc = snprintf(page, count, LPU64"\n",
116 obd->u.filter.fo_readcache_max_filesize);
120 int lprocfs_filter_wr_readcache(struct file *file, const char *buffer,
121 unsigned long count, void *data)
123 struct obd_device *obd = data;
127 rc = lprocfs_write_u64_helper(buffer, count, &val);
131 obd->u.filter.fo_readcache_max_filesize = val;
135 #ifdef HAVE_QUOTA_SUPPORT
136 static int lprocfs_filter_rd_bunit(char *page, char **start, off_t off, int count,
137 int *eof, void *data)
139 struct obd_device *obd = (struct obd_device *)data;
140 LASSERT(obd != NULL);
142 return snprintf(page, count, "%lu\n",
143 obd->u.obt.obt_qctxt.lqc_bunit_sz);
146 static int lprocfs_filter_rd_iunit(char *page, char **start, off_t off, int count,
147 int *eof, void *data)
149 struct obd_device *obd = (struct obd_device *)data;
150 LASSERT(obd != NULL);
152 return snprintf(page, count, "%lu\n",
153 obd->u.obt.obt_qctxt.lqc_iunit_sz);
156 static int lprocfs_filter_wr_bunit(struct file *file, const char *buffer,
157 unsigned long count, void *data)
159 struct obd_device *obd = (struct obd_device *)data;
161 LASSERT(obd != NULL);
163 rc = lprocfs_write_helper(buffer, count, &val);
167 if (val % QUOTABLOCK_SIZE ||
168 val <= obd->u.obt.obt_qctxt.lqc_btune_sz)
171 obd->u.obt.obt_qctxt.lqc_bunit_sz = val;
175 static int lprocfs_filter_wr_iunit(struct file *file, const char *buffer,
176 unsigned long count, void *data)
178 struct obd_device *obd = (struct obd_device *)data;
180 LASSERT(obd != NULL);
182 rc = lprocfs_write_helper(buffer, count, &val);
186 if (val <= obd->u.obt.obt_qctxt.lqc_itune_sz)
189 obd->u.obt.obt_qctxt.lqc_iunit_sz = val;
193 static int lprocfs_filter_rd_btune(char *page, char **start, off_t off, int count,
194 int *eof, void *data)
196 struct obd_device *obd = (struct obd_device *)data;
197 LASSERT(obd != NULL);
199 return snprintf(page, count, "%lu\n",
200 obd->u.obt.obt_qctxt.lqc_btune_sz);
203 static int lprocfs_filter_rd_itune(char *page, char **start, off_t off, int count,
204 int *eof, void *data)
206 struct obd_device *obd = (struct obd_device *)data;
207 LASSERT(obd != NULL);
209 return snprintf(page, count, "%lu\n",
210 obd->u.obt.obt_qctxt.lqc_itune_sz);
213 static int lprocfs_filter_wr_btune(struct file *file, const char *buffer,
214 unsigned long count, void *data)
216 struct obd_device *obd = (struct obd_device *)data;
218 LASSERT(obd != NULL);
220 rc = lprocfs_write_helper(buffer, count, &val);
224 if (val <= QUOTABLOCK_SIZE * MIN_QLIMIT || val % QUOTABLOCK_SIZE ||
225 val >= obd->u.obt.obt_qctxt.lqc_bunit_sz)
228 obd->u.obt.obt_qctxt.lqc_btune_sz = val;
232 static int lprocfs_filter_wr_itune(struct file *file, const char *buffer,
233 unsigned long count, void *data)
235 struct obd_device *obd = (struct obd_device *)data;
237 LASSERT(obd != NULL);
239 rc = lprocfs_write_helper(buffer, count, &val);
243 if (val <= MIN_QLIMIT ||
244 val >= obd->u.obt.obt_qctxt.lqc_iunit_sz)
247 obd->u.obt.obt_qctxt.lqc_itune_sz = val;
252 int lprocfs_filter_rd_fmd_max_num(char *page, char **start, off_t off,
253 int count, int *eof, void *data)
255 struct obd_device *obd = data;
258 rc = snprintf(page, count, "%u\n", obd->u.filter.fo_fmd_max_num);
262 int lprocfs_filter_wr_fmd_max_num(struct file *file, const char *buffer,
263 unsigned long count, void *data)
265 struct obd_device *obd = data;
269 rc = lprocfs_write_helper(buffer, count, &val);
273 if (val > 65536 || val < 1)
276 obd->u.filter.fo_fmd_max_num = val;
280 int lprocfs_filter_rd_fmd_max_age(char *page, char **start, off_t off,
281 int count, int *eof, void *data)
283 struct obd_device *obd = data;
286 rc = snprintf(page, count, "%u\n", obd->u.filter.fo_fmd_max_age / HZ);
290 int lprocfs_filter_wr_fmd_max_age(struct file *file, const char *buffer,
291 unsigned long count, void *data)
293 struct obd_device *obd = data;
297 rc = lprocfs_write_helper(buffer, count, &val);
301 if (val > 65536 || val < 1)
304 obd->u.filter.fo_fmd_max_age = val * HZ;
308 static int lprocfs_filter_rd_capa(char *page, char **start, off_t off,
309 int count, int *eof, void *data)
311 struct obd_device *obd = data;
314 rc = snprintf(page, count, "capability on: %s\n",
315 obd->u.filter.fo_fl_oss_capa ? "oss" : "");
319 static int lprocfs_filter_wr_capa(struct file *file, const char *buffer,
320 unsigned long count, void *data)
322 struct obd_device *obd = data;
325 rc = lprocfs_write_helper(buffer, count, &val);
330 CERROR("invalid capability mode, only 0/1 are accepted.\n"
331 " 1: enable oss fid capability\n"
332 " 0: disable oss fid capability\n");
336 obd->u.filter.fo_fl_oss_capa = val;
340 static int lprocfs_filter_rd_capa_count(char *page, char **start, off_t off,
341 int count, int *eof, void *data)
343 return snprintf(page, count, "%d %d\n",
344 capa_count[CAPA_SITE_CLIENT],
345 capa_count[CAPA_SITE_SERVER]);
348 static struct lprocfs_vars lprocfs_obd_vars[] = {
349 { "uuid", lprocfs_rd_uuid, 0, 0 },
350 { "blocksize", lprocfs_rd_blksize, 0, 0 },
351 { "kbytestotal", lprocfs_rd_kbytestotal, 0, 0 },
352 { "kbytesfree", lprocfs_rd_kbytesfree, 0, 0 },
353 { "kbytesavail", lprocfs_rd_kbytesavail, 0, 0 },
354 { "filestotal", lprocfs_rd_filestotal, 0, 0 },
355 { "filesfree", lprocfs_rd_filesfree, 0, 0 },
356 { "filegroups", lprocfs_filter_rd_groups, 0, 0 },
357 { "fstype", lprocfs_rd_fstype, 0, 0 },
358 { "mntdev", lprocfs_filter_rd_mntdev, 0, 0 },
359 { "last_id", lprocfs_filter_rd_last_id,0, 0 },
360 { "tot_dirty", lprocfs_filter_rd_tot_dirty, 0, 0 },
361 { "tot_pending", lprocfs_filter_rd_tot_pending, 0, 0 },
362 { "tot_granted", lprocfs_filter_rd_tot_granted, 0, 0 },
363 { "recovery_status", lprocfs_obd_rd_recovery_status, 0, 0 },
364 { "evict_client", 0, lprocfs_wr_evict_client, 0 },
365 { "num_exports", lprocfs_rd_num_exports, 0, 0 },
366 { "readcache_max_filesize",
367 lprocfs_filter_rd_readcache,
368 lprocfs_filter_wr_readcache, 0 },
369 #ifdef HAVE_QUOTA_SUPPORT
370 { "quota_bunit_sz", lprocfs_filter_rd_bunit,
371 lprocfs_filter_wr_bunit, 0},
372 { "quota_btune_sz", lprocfs_filter_rd_btune,
373 lprocfs_filter_wr_btune, 0},
374 { "quota_iunit_sz", lprocfs_filter_rd_iunit,
375 lprocfs_filter_wr_iunit, 0},
376 { "quota_itune_sz", lprocfs_filter_rd_itune,
377 lprocfs_filter_wr_itune, 0},
379 { "client_cache_count", lprocfs_filter_rd_fmd_max_num,
380 lprocfs_filter_wr_fmd_max_num, 0 },
381 { "client_cache_seconds", lprocfs_filter_rd_fmd_max_age,
382 lprocfs_filter_wr_fmd_max_age, 0 },
383 { "capa", lprocfs_filter_rd_capa,
384 lprocfs_filter_wr_capa, 0 },
385 { "capa_count", lprocfs_filter_rd_capa_count, 0, 0 },
389 static struct lprocfs_vars lprocfs_module_vars[] = {
390 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
394 void filter_tally_write(struct filter_obd *filter, struct page **pages,
395 int nr_pages, unsigned long *blocks, int blocks_per_page)
397 struct page *last_page = NULL;
398 unsigned long *last_block = NULL;
399 unsigned long discont_pages = 0;
400 unsigned long discont_blocks = 0;
406 lprocfs_oh_tally_log2(&filter->fo_w_pages, nr_pages);
408 while (nr_pages-- > 0) {
409 if (last_page && (*pages)->index != (last_page->index + 1))
413 for (i = 0; i < blocks_per_page; i++) {
414 if (last_block && *blocks != (*last_block + 1))
416 last_block = blocks++;
420 lprocfs_oh_tally(&filter->fo_w_discont_pages, discont_pages);
421 lprocfs_oh_tally(&filter->fo_w_discont_blocks, discont_blocks);
424 void filter_tally_read(struct filter_obd *filter, struct niobuf_local *lnb,
427 struct niobuf_local *end;
428 struct page *last_page = NULL;
429 unsigned long discont_pages = 0;
430 unsigned long discont_blocks = 0;
435 for (end = lnb + niocount; lnb < end && lnb->page; lnb++) {
436 struct page *page = lnb->page;
438 if (page->index != (last_page->index + 1))
440 /* XXX not so smart for now */
441 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
442 if ((page->buffers && last_page->buffers) &&
443 (page->buffers->b_blocknr !=
444 (last_page->buffers->b_blocknr + 1)))
447 #warning "port on 2.6 -bzzz"
453 lprocfs_oh_tally_log2(&filter->fo_r_pages, niocount);
454 lprocfs_oh_tally(&filter->fo_r_discont_pages, discont_pages);
455 lprocfs_oh_tally(&filter->fo_r_discont_blocks, discont_blocks);
458 #define pct(a,b) (b ? a * 100 / b : 0)
460 static int filter_brw_stats_seq_show(struct seq_file *seq, void *v)
463 struct obd_device *dev = seq->private;
464 struct filter_obd *filter = &dev->u.filter;
465 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
468 do_gettimeofday(&now);
470 /* this sampling races with updates */
472 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
473 now.tv_sec, now.tv_usec);
475 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
476 seq_printf(seq, "pages per brw brws %% cum %% |");
477 seq_printf(seq, " rpcs %% cum %%\n");
479 read_tot = lprocfs_oh_sum(&filter->fo_r_pages);
480 write_tot = lprocfs_oh_sum(&filter->fo_w_pages);
484 for (i = 0; i < OBD_HIST_MAX; i++) {
485 unsigned long r = filter->fo_r_pages.oh_buckets[i];
486 unsigned long w = filter->fo_w_pages.oh_buckets[i];
489 seq_printf(seq, "%u:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
490 1 << i, r, pct(r, read_tot),
491 pct(read_cum, read_tot), w,
493 pct(write_cum, write_tot));
494 if (read_cum == read_tot && write_cum == write_tot)
498 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
499 seq_printf(seq, "discont pages rpcs %% cum %% |");
500 seq_printf(seq, " rpcs %% cum %%\n");
502 read_tot = lprocfs_oh_sum(&filter->fo_r_discont_pages);
503 write_tot = lprocfs_oh_sum(&filter->fo_w_discont_pages);
508 for (i = 0; i < OBD_HIST_MAX; i++) {
509 unsigned long r = filter->fo_r_discont_pages.oh_buckets[i];
510 unsigned long w = filter->fo_w_discont_pages.oh_buckets[i];
513 seq_printf(seq, "%u:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
514 i, r, pct(r, read_tot),
515 pct(read_cum, read_tot), w,
517 pct(write_cum, write_tot));
518 if (read_cum == read_tot && write_cum == write_tot)
522 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
523 seq_printf(seq, "discont blocks rpcs %% cum %% |");
524 seq_printf(seq, " rpcs %% cum %%\n");
526 read_tot = lprocfs_oh_sum(&filter->fo_r_discont_blocks);
527 write_tot = lprocfs_oh_sum(&filter->fo_w_discont_blocks);
531 for (i = 0; i < OBD_HIST_MAX; i++) {
532 unsigned long r = filter->fo_r_discont_blocks.oh_buckets[i];
533 unsigned long w = filter->fo_w_discont_blocks.oh_buckets[i];
536 seq_printf(seq, "%u:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
537 i, r, pct(r, read_tot),
538 pct(read_cum, read_tot), w,
540 pct(write_cum, write_tot));
541 if (read_cum == read_tot && write_cum == write_tot)
545 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
546 seq_printf(seq, "dio frags rpcs %% cum %% |");
547 seq_printf(seq, " rpcs %% cum %%\n");
549 read_tot = lprocfs_oh_sum(&filter->fo_r_dio_frags);
550 write_tot = lprocfs_oh_sum(&filter->fo_w_dio_frags);
554 for (i = 0; i < OBD_HIST_MAX; i++) {
555 unsigned long r = filter->fo_r_dio_frags.oh_buckets[i];
556 unsigned long w = filter->fo_w_dio_frags.oh_buckets[i];
559 seq_printf(seq, "%u:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
560 i, r, pct(r, read_tot),
561 pct(read_cum, read_tot), w,
563 pct(write_cum, write_tot));
564 if (read_cum == read_tot && write_cum == write_tot)
568 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
569 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
570 seq_printf(seq, "disk ios in flight ios %% cum %% |");
571 seq_printf(seq, " rpcs %% cum %%\n");
573 read_tot = lprocfs_oh_sum(&filter->fo_read_rpc_hist);
574 write_tot = lprocfs_oh_sum(&filter->fo_write_rpc_hist);
578 for (i = 0; i < OBD_HIST_MAX; i++) {
579 unsigned long r = filter->fo_read_rpc_hist.oh_buckets[i];
580 unsigned long w = filter->fo_write_rpc_hist.oh_buckets[i];
583 seq_printf(seq, "%u:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
584 i, r, pct(r, read_tot),
585 pct(read_cum, read_tot), w,
587 pct(write_cum, write_tot));
588 if (read_cum == read_tot && write_cum == write_tot)
592 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
593 seq_printf(seq, "io time (1/%ds) rpcs %% cum %% |", HZ);
594 seq_printf(seq, " rpcs %% cum %%\n");
596 read_tot = lprocfs_oh_sum(&filter->fo_r_io_time);
597 write_tot = lprocfs_oh_sum(&filter->fo_w_io_time);
601 for (i = 0; i < OBD_HIST_MAX; i++) {
602 unsigned long r = filter->fo_r_io_time.oh_buckets[i];
603 unsigned long w = filter->fo_w_io_time.oh_buckets[i];
606 seq_printf(seq, "%u:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
607 1 << i, r, pct(r, read_tot),
608 pct(read_cum, read_tot), w,
610 pct(write_cum, write_tot));
611 if (read_cum == read_tot && write_cum == write_tot)
615 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
616 seq_printf(seq, "disk I/O size count %% cum %% |");
617 seq_printf(seq, " count %% cum %%\n");
619 read_tot = lprocfs_oh_sum(&filter->fo_r_disk_iosize);
620 write_tot = lprocfs_oh_sum(&filter->fo_w_disk_iosize);
624 for (i = 0; i < OBD_HIST_MAX; i++) {
625 unsigned long r = filter->fo_r_disk_iosize.oh_buckets[i];
626 unsigned long w = filter->fo_w_disk_iosize.oh_buckets[i];
630 if (read_cum == 0 && write_cum == 0)
634 seq_printf(seq, "%u", 1<<i);
636 seq_printf(seq, "%uK", 1<<(i-10));
638 seq_printf(seq, "%uM", 1<<(i-20));
640 seq_printf(seq, ":\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
641 r, pct(r, read_tot), pct(read_cum, read_tot),
642 w, pct(w, write_tot), pct(write_cum, write_tot));
643 if (read_cum == read_tot && write_cum == write_tot)
652 static void *filter_brw_stats_seq_start(struct seq_file *p, loff_t *pos)
658 static void *filter_brw_stats_seq_next(struct seq_file *p, void *v, loff_t *pos)
663 static void filter_brw_stats_seq_stop(struct seq_file *p, void *v)
666 struct seq_operations filter_brw_stats_seq_sops = {
667 .start = filter_brw_stats_seq_start,
668 .stop = filter_brw_stats_seq_stop,
669 .next = filter_brw_stats_seq_next,
670 .show = filter_brw_stats_seq_show,
673 static int filter_brw_stats_seq_open(struct inode *inode, struct file *file)
675 struct proc_dir_entry *dp = PDE(inode);
676 struct seq_file *seq;
679 rc = seq_open(file, &filter_brw_stats_seq_sops);
682 seq = file->private_data;
683 seq->private = dp->data;
687 static ssize_t filter_brw_stats_seq_write(struct file *file, const char *buf,
688 size_t len, loff_t *off)
690 struct seq_file *seq = file->private_data;
691 struct obd_device *dev = seq->private;
692 struct filter_obd *filter = &dev->u.filter;
694 lprocfs_oh_clear(&filter->fo_r_pages);
695 lprocfs_oh_clear(&filter->fo_w_pages);
696 lprocfs_oh_clear(&filter->fo_read_rpc_hist);
697 lprocfs_oh_clear(&filter->fo_write_rpc_hist);
698 lprocfs_oh_clear(&filter->fo_r_io_time);
699 lprocfs_oh_clear(&filter->fo_w_io_time);
700 lprocfs_oh_clear(&filter->fo_r_discont_pages);
701 lprocfs_oh_clear(&filter->fo_w_discont_pages);
702 lprocfs_oh_clear(&filter->fo_r_discont_blocks);
703 lprocfs_oh_clear(&filter->fo_w_discont_blocks);
704 lprocfs_oh_clear(&filter->fo_r_disk_iosize);
705 lprocfs_oh_clear(&filter->fo_w_disk_iosize);
706 lprocfs_oh_clear(&filter->fo_r_dio_frags);
707 lprocfs_oh_clear(&filter->fo_w_dio_frags);
712 struct file_operations filter_brw_stats_fops = {
713 .owner = THIS_MODULE,
714 .open = filter_brw_stats_seq_open,
716 .write = filter_brw_stats_seq_write,
718 .release = seq_release,
721 int lproc_filter_attach_seqstat(struct obd_device *dev)
723 return lprocfs_obd_seq_create(dev, "brw_stats", 0444,
724 &filter_brw_stats_fops, dev);
727 LPROCFS_INIT_VARS(filter, lprocfs_module_vars, lprocfs_obd_vars)