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 (c) 2002, 2010, Oracle and/or its affiliates. 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)
50 struct obd_device *obd = (struct obd_device *)data;
52 return snprintf(page, count, "%u\n", obd->u.filter.fo_group_count);
55 static int lprocfs_filter_rd_tot_dirty(char *page, char **start, off_t off,
56 int count, int *eof, void *data)
58 struct obd_device *obd = (struct obd_device *)data;
62 return snprintf(page, count, LPU64"\n", obd->u.filter.fo_tot_dirty);
65 static int lprocfs_filter_rd_tot_granted(char *page, char **start, off_t off,
66 int count, int *eof, void *data)
68 struct obd_device *obd = (struct obd_device *)data;
72 return snprintf(page, count, LPU64"\n", obd->u.filter.fo_tot_granted);
75 static int lprocfs_filter_rd_tot_pending(char *page, char **start, off_t off,
76 int count, int *eof, void *data)
78 struct obd_device *obd = (struct obd_device *)data;
82 return snprintf(page, count, LPU64"\n", obd->u.filter.fo_tot_pending);
85 static int lprocfs_filter_rd_last_id(char *page, char **start, off_t off,
86 int count, int *eof, void *data)
88 struct obd_device *obd = data;
89 struct filter_obd *filter = &obd->u.filter;
90 int retval = 0, rc, i;
92 if (obd == NULL || !obd->obd_set_up || obd->obd_stopping)
94 rc = snprintf(page, count, LPU64"\n",filter_last_id(filter, 0));
101 for (i = FID_SEQ_OST_MDT1; i < filter->fo_group_count; i++) {
102 rc = snprintf(page, count, LPU64"\n",filter_last_id(filter, i));
114 int lprocfs_filter_rd_readcache(char *page, char **start, off_t off, int count,
115 int *eof, void *data)
117 struct obd_device *obd = data;
120 rc = snprintf(page, count, LPU64"\n",
121 obd->u.filter.fo_readcache_max_filesize);
125 int lprocfs_filter_wr_readcache(struct file *file, const char *buffer,
126 unsigned long count, void *data)
128 struct obd_device *obd = data;
132 rc = lprocfs_write_u64_helper(buffer, count, &val);
136 obd->u.filter.fo_readcache_max_filesize = val;
140 int lprocfs_filter_rd_fmd_max_num(char *page, char **start, off_t off,
141 int count, int *eof, void *data)
143 struct obd_device *obd = data;
146 rc = snprintf(page, count, "%u\n", obd->u.filter.fo_fmd_max_num);
150 int lprocfs_filter_wr_fmd_max_num(struct file *file, const char *buffer,
151 unsigned long count, void *data)
153 struct obd_device *obd = data;
157 rc = lprocfs_write_helper(buffer, count, &val);
161 if (val > 65536 || val < 1)
164 obd->u.filter.fo_fmd_max_num = val;
168 int lprocfs_filter_rd_fmd_max_age(char *page, char **start, off_t off,
169 int count, int *eof, void *data)
171 struct obd_device *obd = data;
174 rc = snprintf(page, count, "%u\n",
175 obd->u.filter.fo_fmd_max_age / CFS_HZ);
179 int lprocfs_filter_wr_fmd_max_age(struct file *file, const char *buffer,
180 unsigned long count, void *data)
182 struct obd_device *obd = data;
186 rc = lprocfs_write_helper(buffer, count, &val);
190 if (val > 65536 || val < 1)
193 obd->u.filter.fo_fmd_max_age = val * CFS_HZ;
197 static int lprocfs_filter_rd_capa(char *page, char **start, off_t off,
198 int count, int *eof, void *data)
200 struct obd_device *obd = data;
203 rc = snprintf(page, count, "capability on: %s\n",
204 obd->u.filter.fo_fl_oss_capa ? "oss" : "");
208 static int lprocfs_filter_wr_capa(struct file *file, const char *buffer,
209 unsigned long count, void *data)
211 struct obd_device *obd = data;
214 rc = lprocfs_write_helper(buffer, count, &val);
219 CERROR("invalid capability mode, only 0/1 are accepted.\n"
220 " 1: enable oss fid capability\n"
221 " 0: disable oss fid capability\n");
225 obd->u.filter.fo_fl_oss_capa = val;
226 LCONSOLE_INFO("OSS %s %s fid capability.\n", obd->obd_name,
227 val ? "enabled" : "disabled");
231 static int lprocfs_filter_rd_capa_count(char *page, char **start, off_t off,
232 int count, int *eof, void *data)
234 return snprintf(page, count, "%d %d\n",
235 capa_count[CAPA_SITE_CLIENT],
236 capa_count[CAPA_SITE_SERVER]);
239 static int lprocfs_rd_sec_level(char *page, char **start, off_t off,
240 int count, int *eof, void *data)
242 struct obd_device *obd = data;
244 return snprintf(page, count, "%d\n", obd->u.filter.fo_sec_level);
247 static int lprocfs_wr_sec_level(struct file *file, const char *buffer,
248 unsigned long count, void *data)
250 struct obd_device *obd = data;
253 rc = lprocfs_write_helper(buffer, count, &val);
257 if (val > LUSTRE_SEC_ALL || val < LUSTRE_SEC_NONE)
260 if (val == LUSTRE_SEC_SPECIFY) {
261 CWARN("security level %d will be supported in future.\n",
266 obd->u.filter.fo_sec_level = val;
270 static int lprocfs_filter_rd_cache(char *page, char **start, off_t off,
271 int count, int *eof, void *data)
273 struct obd_device *obd = (struct obd_device *)data;
274 LASSERT(obd != NULL);
276 return snprintf(page, count, "%u\n", obd->u.filter.fo_read_cache);
279 static int lprocfs_filter_wr_cache(struct file *file, const char *buffer,
280 unsigned long count, void *data)
282 struct obd_device *obd = (struct obd_device *)data;
284 LASSERT(obd != NULL);
286 rc = lprocfs_write_helper(buffer, count, &val);
291 cfs_spin_lock_bh(&obd->u.filter.fo_flags_lock);
292 obd->u.filter.fo_read_cache = !!val;
293 cfs_spin_unlock_bh(&obd->u.filter.fo_flags_lock);
297 static int lprocfs_filter_rd_wcache(char *page, char **start, off_t off,
298 int count, int *eof, void *data)
300 struct obd_device *obd = (struct obd_device *)data;
301 LASSERT(obd != NULL);
303 return snprintf(page, count, "%u\n", obd->u.filter.fo_writethrough_cache);
306 static int lprocfs_filter_wr_wcache(struct file *file, const char *buffer,
307 unsigned long count, void *data)
309 struct obd_device *obd = (struct obd_device *)data;
311 LASSERT(obd != NULL);
313 rc = lprocfs_write_helper(buffer, count, &val);
318 cfs_spin_lock(&obd->u.filter.fo_flags_lock);
319 obd->u.filter.fo_writethrough_cache = !!val;
320 cfs_spin_unlock(&obd->u.filter.fo_flags_lock);
324 static int lprocfs_filter_rd_mds_sync(char *page, char **start, off_t off,
325 int count, int *eof, void *data)
327 struct obd_device *obd = (struct obd_device *)data;
328 LASSERT(obd != NULL);
330 return snprintf(page, count, "%u\n", obd->u.filter.fo_mds_ost_sync);
333 int lprocfs_filter_rd_degraded(char *page, char **start, off_t off,
334 int count, int *eof, void *data)
336 struct obd_device *obd = data;
338 return snprintf(page, count, "%u\n", obd->u.filter.fo_raid_degraded);
341 int lprocfs_filter_wr_degraded(struct file *file, const char *buffer,
342 unsigned long count, void *data)
344 struct obd_device *obd = data;
347 rc = lprocfs_write_helper(buffer, count, &val);
351 cfs_spin_lock(&obd->u.filter.fo_flags_lock);
352 obd->u.filter.fo_raid_degraded = !!val;
353 cfs_spin_unlock(&obd->u.filter.fo_flags_lock);
357 int lprocfs_filter_rd_syncjournal(char *page, char **start, off_t off,
358 int count, int *eof, void *data)
360 struct obd_device *obd = data;
363 rc = snprintf(page, count, "%u\n", obd->u.filter.fo_syncjournal);
367 int lprocfs_filter_wr_syncjournal(struct file *file, const char *buffer,
368 unsigned long count, void *data)
370 struct obd_device *obd = data;
374 rc = lprocfs_write_helper(buffer, count, &val);
381 obd->u.filter.fo_syncjournal = !!val;
382 filter_slc_set(&obd->u.filter);
387 static char *sync_on_cancel_states[] = {"never",
391 int lprocfs_filter_rd_sync_lock_cancel(char *page, char **start, off_t off,
392 int count, int *eof, void *data)
394 struct obd_device *obd = data;
397 rc = snprintf(page, count, "%s\n",
398 sync_on_cancel_states[obd->u.filter.fo_sync_lock_cancel]);
402 int lprocfs_filter_wr_sync_lock_cancel(struct file *file, const char *buffer,
403 unsigned long count, void *data)
405 struct obd_device *obd = data;
409 for (i = 0 ; i < NUM_SYNC_ON_CANCEL_STATES; i++) {
410 if (memcmp(buffer, sync_on_cancel_states[i],
411 strlen(sync_on_cancel_states[i])) == 0) {
418 rc = lprocfs_write_helper(buffer, count, &val);
423 if (val < 0 || val > 2)
426 obd->u.filter.fo_sync_lock_cancel = val;
430 static struct lprocfs_vars lprocfs_filter_obd_vars[] = {
431 { "uuid", lprocfs_rd_uuid, 0, 0 },
432 { "blocksize", lprocfs_rd_blksize, 0, 0 },
433 { "kbytestotal", lprocfs_rd_kbytestotal, 0, 0 },
434 { "kbytesfree", lprocfs_rd_kbytesfree, 0, 0 },
435 { "kbytesavail", lprocfs_rd_kbytesavail, 0, 0 },
436 { "filestotal", lprocfs_rd_filestotal, 0, 0 },
437 { "filesfree", lprocfs_rd_filesfree, 0, 0 },
438 { "filegroups", lprocfs_filter_rd_groups, 0, 0 },
439 { "fstype", lprocfs_rd_fstype, 0, 0 },
440 { "mntdev", lprocfs_obd_rd_mntdev, 0, 0 },
441 { "last_id", lprocfs_filter_rd_last_id,0, 0 },
442 { "tot_dirty", lprocfs_filter_rd_tot_dirty, 0, 0 },
443 { "tot_pending", lprocfs_filter_rd_tot_pending, 0, 0 },
444 { "tot_granted", lprocfs_filter_rd_tot_granted, 0, 0 },
445 { "hash_stats", lprocfs_obd_rd_hash, 0, 0 },
446 { "recovery_status", lprocfs_obd_rd_recovery_status, 0, 0 },
447 { "recovery_time_soft", lprocfs_obd_rd_recovery_time_soft,
448 lprocfs_obd_wr_recovery_time_soft, 0},
449 { "recovery_time_hard", lprocfs_obd_rd_recovery_time_hard,
450 lprocfs_obd_wr_recovery_time_hard, 0},
451 { "evict_client", 0, lprocfs_wr_evict_client, 0,
452 &lprocfs_evict_client_fops},
453 { "num_exports", lprocfs_rd_num_exports, 0, 0 },
454 { "readcache_max_filesize",
455 lprocfs_filter_rd_readcache,
456 lprocfs_filter_wr_readcache, 0 },
457 #ifdef HAVE_QUOTA_SUPPORT
458 { "quota_type", lprocfs_quota_rd_type,
459 lprocfs_quota_wr_type, 0},
461 { "client_cache_count", lprocfs_filter_rd_fmd_max_num,
462 lprocfs_filter_wr_fmd_max_num, 0 },
463 { "client_cache_seconds", lprocfs_filter_rd_fmd_max_age,
464 lprocfs_filter_wr_fmd_max_age, 0 },
465 { "capa", lprocfs_filter_rd_capa,
466 lprocfs_filter_wr_capa, 0 },
467 { "capa_count", lprocfs_filter_rd_capa_count, 0, 0 },
468 { "sec_level", lprocfs_rd_sec_level,
469 lprocfs_wr_sec_level, 0 },
470 { "read_cache_enable", lprocfs_filter_rd_cache, lprocfs_filter_wr_cache, 0},
471 { "writethrough_cache_enable", lprocfs_filter_rd_wcache,
472 lprocfs_filter_wr_wcache, 0},
473 { "mds_sync", lprocfs_filter_rd_mds_sync, 0, 0},
474 { "degraded", lprocfs_filter_rd_degraded,
475 lprocfs_filter_wr_degraded, 0 },
476 { "sync_journal", lprocfs_filter_rd_syncjournal,
477 lprocfs_filter_wr_syncjournal, 0 },
478 { "sync_on_lock_cancel", lprocfs_filter_rd_sync_lock_cancel,
479 lprocfs_filter_wr_sync_lock_cancel, 0 },
483 static struct lprocfs_vars lprocfs_filter_module_vars[] = {
484 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
488 void filter_tally(struct obd_export *exp, struct page **pages, int nr_pages,
489 unsigned long *blocks, int blocks_per_page, int wr)
491 struct filter_obd *filter = &exp->exp_obd->u.filter;
492 struct page *last_page = NULL;
493 unsigned long *last_block = NULL;
494 unsigned long discont_pages = 0;
495 unsigned long discont_blocks = 0;
501 lprocfs_oh_tally_log2(&filter->fo_filter_stats.hist[BRW_R_PAGES + wr],
503 if (exp->exp_nid_stats && exp->exp_nid_stats->nid_brw_stats)
504 lprocfs_oh_tally_log2(&exp->exp_nid_stats->nid_brw_stats->
505 hist[BRW_R_PAGES + wr], nr_pages);
507 while (nr_pages-- > 0) {
508 if (last_page && (*pages)->index != (last_page->index + 1))
512 for (i = 0; i < blocks_per_page; i++) {
513 if (last_block && *blocks != (*last_block + 1))
515 last_block = blocks++;
519 lprocfs_oh_tally(&filter->fo_filter_stats.hist[BRW_R_DISCONT_PAGES +wr],
521 lprocfs_oh_tally(&filter->fo_filter_stats.hist[BRW_R_DISCONT_BLOCKS+wr],
524 if (exp->exp_nid_stats && exp->exp_nid_stats->nid_brw_stats) {
525 lprocfs_oh_tally_log2(&exp->exp_nid_stats->nid_brw_stats->
526 hist[BRW_R_DISCONT_PAGES + wr],
528 lprocfs_oh_tally_log2(&exp->exp_nid_stats->nid_brw_stats->
529 hist[BRW_R_DISCONT_BLOCKS + wr],
534 #define pct(a,b) (b ? a * 100 / b : 0)
536 static void display_brw_stats(struct seq_file *seq, char *name, char *units,
537 struct obd_histogram *read, struct obd_histogram *write, int log2)
539 unsigned long read_tot, write_tot, r, w, read_cum = 0, write_cum = 0;
542 seq_printf(seq, "\n%26s read | write\n", " ");
543 seq_printf(seq, "%-22s %-5s %% cum %% | %-5s %% cum %%\n",
546 read_tot = lprocfs_oh_sum(read);
547 write_tot = lprocfs_oh_sum(write);
548 for (i = 0; i < OBD_HIST_MAX; i++) {
549 r = read->oh_buckets[i];
550 w = write->oh_buckets[i];
553 if (read_cum == 0 && write_cum == 0)
557 seq_printf(seq, "%u", i);
559 seq_printf(seq, "%u", 1<<i);
561 seq_printf(seq, "%uK", 1<<(i-10));
563 seq_printf(seq, "%uM", 1<<(i-20));
565 seq_printf(seq, ":\t\t%10lu %3lu %3lu | %4lu %3lu %3lu\n",
566 r, pct(r, read_tot), pct(read_cum, read_tot),
567 w, pct(w, write_tot), pct(write_cum, write_tot));
569 if (read_cum == read_tot && write_cum == write_tot)
574 static void brw_stats_show(struct seq_file *seq, struct brw_stats *brw_stats)
578 /* this sampling races with updates */
579 cfs_gettimeofday(&now);
580 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
581 now.tv_sec, now.tv_usec);
583 display_brw_stats(seq, "pages per bulk r/w", "rpcs",
584 &brw_stats->hist[BRW_R_PAGES],
585 &brw_stats->hist[BRW_W_PAGES], 1);
587 display_brw_stats(seq, "discontiguous pages", "rpcs",
588 &brw_stats->hist[BRW_R_DISCONT_PAGES],
589 &brw_stats->hist[BRW_W_DISCONT_PAGES], 0);
591 display_brw_stats(seq, "discontiguous blocks", "rpcs",
592 &brw_stats->hist[BRW_R_DISCONT_BLOCKS],
593 &brw_stats->hist[BRW_W_DISCONT_BLOCKS], 0);
595 display_brw_stats(seq, "disk fragmented I/Os", "ios",
596 &brw_stats->hist[BRW_R_DIO_FRAGS],
597 &brw_stats->hist[BRW_W_DIO_FRAGS], 0);
599 display_brw_stats(seq, "disk I/Os in flight", "ios",
600 &brw_stats->hist[BRW_R_RPC_HIST],
601 &brw_stats->hist[BRW_W_RPC_HIST], 0);
605 sprintf(title, "I/O time (1/%ds)", CFS_HZ);
606 display_brw_stats(seq, title, "ios",
607 &brw_stats->hist[BRW_R_IO_TIME],
608 &brw_stats->hist[BRW_W_IO_TIME], 1);
611 display_brw_stats(seq, "disk I/O size", "ios",
612 &brw_stats->hist[BRW_R_DISK_IOSIZE],
613 &brw_stats->hist[BRW_W_DISK_IOSIZE], 1);
618 static int filter_brw_stats_seq_show(struct seq_file *seq, void *v)
620 struct obd_device *dev = seq->private;
621 struct filter_obd *filter = &dev->u.filter;
623 brw_stats_show(seq, &filter->fo_filter_stats);
628 static ssize_t filter_brw_stats_seq_write(struct file *file, const char *buf,
629 size_t len, loff_t *off)
631 struct seq_file *seq = file->private_data;
632 struct obd_device *dev = seq->private;
633 struct filter_obd *filter = &dev->u.filter;
636 for (i = 0; i < BRW_LAST; i++)
637 lprocfs_oh_clear(&filter->fo_filter_stats.hist[i]);
642 LPROC_SEQ_FOPS(filter_brw_stats);
644 int lproc_filter_attach_seqstat(struct obd_device *dev)
646 return lprocfs_obd_seq_create(dev, "brw_stats", 0444,
647 &filter_brw_stats_fops, dev);
650 void lprocfs_filter_init_vars(struct lprocfs_static_vars *lvars)
652 lvars->module_vars = lprocfs_filter_module_vars;
653 lvars->obd_vars = lprocfs_filter_obd_vars;
656 static int filter_per_nid_stats_seq_show(struct seq_file *seq, void *v)
658 nid_stat_t * stat = seq->private;
660 if (stat->nid_brw_stats)
661 brw_stats_show(seq, stat->nid_brw_stats);
666 static ssize_t filter_per_nid_stats_seq_write(struct file *file,
667 const char *buf, size_t len,
670 struct seq_file *seq = file->private_data;
671 nid_stat_t *stat = seq->private;
674 if (stat->nid_brw_stats)
675 for (i = 0; i < BRW_LAST; i++)
676 lprocfs_oh_clear(&stat->nid_brw_stats->hist[i]);
681 LPROC_SEQ_FOPS(filter_per_nid_stats);