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.
32 * Copyright (c) 2011, Whamcloud, Inc.
35 * This file is part of Lustre, http://www.lustre.org/
36 * Lustre is a trademark of Sun Microsystems, Inc.
38 #define DEBUG_SUBSYSTEM S_CLASS
40 #include <linux/version.h>
41 #include <lprocfs_status.h>
43 #include <linux/seq_file.h>
44 #include <linux/version.h>
46 #include "filter_internal.h"
49 static int lprocfs_filter_rd_groups(char *page, char **start, off_t off,
50 int count, int *eof, void *data)
52 struct obd_device *obd = (struct obd_device *)data;
54 return snprintf(page, count, "%u\n", obd->u.filter.fo_group_count);
57 static int lprocfs_filter_rd_tot_dirty(char *page, char **start, off_t off,
58 int count, int *eof, void *data)
60 struct obd_device *obd = (struct obd_device *)data;
64 return snprintf(page, count, LPU64"\n", obd->u.filter.fo_tot_dirty);
67 static int lprocfs_filter_rd_tot_granted(char *page, char **start, off_t off,
68 int count, int *eof, void *data)
70 struct obd_device *obd = (struct obd_device *)data;
74 return snprintf(page, count, LPU64"\n", obd->u.filter.fo_tot_granted);
77 static int lprocfs_filter_rd_tot_pending(char *page, char **start, off_t off,
78 int count, int *eof, void *data)
80 struct obd_device *obd = (struct obd_device *)data;
84 return snprintf(page, count, LPU64"\n", obd->u.filter.fo_tot_pending);
87 static int lprocfs_filter_rd_last_id(char *page, char **start, off_t off,
88 int count, int *eof, void *data)
90 struct obd_device *obd = data;
91 struct filter_obd *filter = &obd->u.filter;
92 int retval = 0, rc, i;
94 if (obd == NULL || !obd->obd_set_up || obd->obd_stopping)
96 rc = snprintf(page, count, LPU64"\n",filter_last_id(filter, 0));
103 for (i = FID_SEQ_OST_MDT1; i < filter->fo_group_count; i++) {
104 rc = snprintf(page, count, LPU64"\n",filter_last_id(filter, i));
116 int lprocfs_filter_rd_readcache(char *page, char **start, off_t off, int count,
117 int *eof, void *data)
119 struct obd_device *obd = data;
122 rc = snprintf(page, count, LPU64"\n",
123 obd->u.filter.fo_readcache_max_filesize);
127 int lprocfs_filter_wr_readcache(struct file *file, const char *buffer,
128 unsigned long count, void *data)
130 struct obd_device *obd = data;
134 rc = lprocfs_write_u64_helper(buffer, count, &val);
138 obd->u.filter.fo_readcache_max_filesize = val;
142 int lprocfs_filter_rd_fmd_max_num(char *page, char **start, off_t off,
143 int count, int *eof, void *data)
145 struct obd_device *obd = data;
148 rc = snprintf(page, count, "%u\n", obd->u.filter.fo_fmd_max_num);
152 int lprocfs_filter_wr_fmd_max_num(struct file *file, const char *buffer,
153 unsigned long count, void *data)
155 struct obd_device *obd = data;
159 rc = lprocfs_write_helper(buffer, count, &val);
163 if (val > 65536 || val < 1)
166 obd->u.filter.fo_fmd_max_num = val;
170 int lprocfs_filter_rd_fmd_max_age(char *page, char **start, off_t off,
171 int count, int *eof, void *data)
173 struct obd_device *obd = data;
176 rc = snprintf(page, count, "%u\n",
177 obd->u.filter.fo_fmd_max_age / CFS_HZ);
181 int lprocfs_filter_wr_fmd_max_age(struct file *file, const char *buffer,
182 unsigned long count, void *data)
184 struct obd_device *obd = data;
188 rc = lprocfs_write_helper(buffer, count, &val);
192 if (val > 65536 || val < 1)
195 obd->u.filter.fo_fmd_max_age = val * CFS_HZ;
199 static int lprocfs_filter_rd_capa(char *page, char **start, off_t off,
200 int count, int *eof, void *data)
202 struct obd_device *obd = data;
205 rc = snprintf(page, count, "capability on: %s\n",
206 obd->u.filter.fo_fl_oss_capa ? "oss" : "");
210 static int lprocfs_filter_wr_capa(struct file *file, const char *buffer,
211 unsigned long count, void *data)
213 struct obd_device *obd = data;
216 rc = lprocfs_write_helper(buffer, count, &val);
221 CERROR("invalid capability mode, only 0/1 are accepted.\n"
222 " 1: enable oss fid capability\n"
223 " 0: disable oss fid capability\n");
227 obd->u.filter.fo_fl_oss_capa = val;
228 LCONSOLE_INFO("OSS %s %s fid capability.\n", obd->obd_name,
229 val ? "enabled" : "disabled");
233 static int lprocfs_filter_rd_capa_count(char *page, char **start, off_t off,
234 int count, int *eof, void *data)
236 return snprintf(page, count, "%d %d\n",
237 capa_count[CAPA_SITE_CLIENT],
238 capa_count[CAPA_SITE_SERVER]);
241 static int lprocfs_rd_sec_level(char *page, char **start, off_t off,
242 int count, int *eof, void *data)
244 struct obd_device *obd = data;
246 return snprintf(page, count, "%d\n", obd->u.filter.fo_sec_level);
249 static int lprocfs_wr_sec_level(struct file *file, const char *buffer,
250 unsigned long count, void *data)
252 struct obd_device *obd = data;
255 rc = lprocfs_write_helper(buffer, count, &val);
259 if (val > LUSTRE_SEC_ALL || val < LUSTRE_SEC_NONE)
262 if (val == LUSTRE_SEC_SPECIFY) {
263 CWARN("security level %d will be supported in future.\n",
268 obd->u.filter.fo_sec_level = val;
272 static int lprocfs_filter_rd_cache(char *page, char **start, off_t off,
273 int count, int *eof, void *data)
275 struct obd_device *obd = (struct obd_device *)data;
276 LASSERT(obd != NULL);
278 return snprintf(page, count, "%u\n", obd->u.filter.fo_read_cache);
281 static int lprocfs_filter_wr_cache(struct file *file, const char *buffer,
282 unsigned long count, void *data)
284 struct obd_device *obd = (struct obd_device *)data;
286 LASSERT(obd != NULL);
288 rc = lprocfs_write_helper(buffer, count, &val);
293 cfs_spin_lock_bh(&obd->u.filter.fo_flags_lock);
294 obd->u.filter.fo_read_cache = !!val;
295 cfs_spin_unlock_bh(&obd->u.filter.fo_flags_lock);
299 static int lprocfs_filter_rd_wcache(char *page, char **start, off_t off,
300 int count, int *eof, void *data)
302 struct obd_device *obd = (struct obd_device *)data;
303 LASSERT(obd != NULL);
305 return snprintf(page, count, "%u\n", obd->u.filter.fo_writethrough_cache);
308 static int lprocfs_filter_wr_wcache(struct file *file, const char *buffer,
309 unsigned long count, void *data)
311 struct obd_device *obd = (struct obd_device *)data;
313 LASSERT(obd != NULL);
315 rc = lprocfs_write_helper(buffer, count, &val);
320 cfs_spin_lock(&obd->u.filter.fo_flags_lock);
321 obd->u.filter.fo_writethrough_cache = !!val;
322 cfs_spin_unlock(&obd->u.filter.fo_flags_lock);
326 static int lprocfs_filter_rd_mds_sync(char *page, char **start, off_t off,
327 int count, int *eof, void *data)
329 struct obd_device *obd = (struct obd_device *)data;
330 LASSERT(obd != NULL);
332 return snprintf(page, count, "%u\n", obd->u.filter.fo_mds_ost_sync);
335 int lprocfs_filter_rd_degraded(char *page, char **start, off_t off,
336 int count, int *eof, void *data)
338 struct obd_device *obd = data;
340 return snprintf(page, count, "%u\n", obd->u.filter.fo_raid_degraded);
343 int lprocfs_filter_wr_degraded(struct file *file, const char *buffer,
344 unsigned long count, void *data)
346 struct obd_device *obd = data;
349 rc = lprocfs_write_helper(buffer, count, &val);
353 cfs_spin_lock(&obd->u.filter.fo_flags_lock);
354 obd->u.filter.fo_raid_degraded = !!val;
355 cfs_spin_unlock(&obd->u.filter.fo_flags_lock);
359 int lprocfs_filter_rd_syncjournal(char *page, char **start, off_t off,
360 int count, int *eof, void *data)
362 struct obd_device *obd = data;
365 rc = snprintf(page, count, "%u\n", obd->u.filter.fo_syncjournal);
369 int lprocfs_filter_wr_syncjournal(struct file *file, const char *buffer,
370 unsigned long count, void *data)
372 struct obd_device *obd = data;
376 rc = lprocfs_write_helper(buffer, count, &val);
383 obd->u.filter.fo_syncjournal = !!val;
384 filter_slc_set(&obd->u.filter);
389 static char *sync_on_cancel_states[] = {"never",
393 int lprocfs_filter_rd_sync_lock_cancel(char *page, char **start, off_t off,
394 int count, int *eof, void *data)
396 struct obd_device *obd = data;
399 rc = snprintf(page, count, "%s\n",
400 sync_on_cancel_states[obd->u.filter.fo_sync_lock_cancel]);
404 int lprocfs_filter_wr_sync_lock_cancel(struct file *file, const char *buffer,
405 unsigned long count, void *data)
407 struct obd_device *obd = data;
411 for (i = 0 ; i < NUM_SYNC_ON_CANCEL_STATES; i++) {
412 if (memcmp(buffer, sync_on_cancel_states[i],
413 strlen(sync_on_cancel_states[i])) == 0) {
420 rc = lprocfs_write_helper(buffer, count, &val);
425 if (val < 0 || val > 2)
428 obd->u.filter.fo_sync_lock_cancel = val;
432 static struct lprocfs_vars lprocfs_filter_obd_vars[] = {
433 { "uuid", lprocfs_rd_uuid, 0, 0 },
434 { "blocksize", lprocfs_rd_blksize, 0, 0 },
435 { "kbytestotal", lprocfs_rd_kbytestotal, 0, 0 },
436 { "kbytesfree", lprocfs_rd_kbytesfree, 0, 0 },
437 { "kbytesavail", lprocfs_rd_kbytesavail, 0, 0 },
438 { "filestotal", lprocfs_rd_filestotal, 0, 0 },
439 { "filesfree", lprocfs_rd_filesfree, 0, 0 },
440 { "filegroups", lprocfs_filter_rd_groups, 0, 0 },
441 { "fstype", lprocfs_rd_fstype, 0, 0 },
442 { "mntdev", lprocfs_obd_rd_mntdev, 0, 0 },
443 { "last_id", lprocfs_filter_rd_last_id,0, 0 },
444 { "tot_dirty", lprocfs_filter_rd_tot_dirty, 0, 0 },
445 { "tot_pending", lprocfs_filter_rd_tot_pending, 0, 0 },
446 { "tot_granted", lprocfs_filter_rd_tot_granted, 0, 0 },
447 { "hash_stats", lprocfs_obd_rd_hash, 0, 0 },
448 { "recovery_status", lprocfs_obd_rd_recovery_status, 0, 0 },
449 { "recovery_time_soft", lprocfs_obd_rd_recovery_time_soft,
450 lprocfs_obd_wr_recovery_time_soft, 0},
451 { "recovery_time_hard", lprocfs_obd_rd_recovery_time_hard,
452 lprocfs_obd_wr_recovery_time_hard, 0},
453 { "evict_client", 0, lprocfs_wr_evict_client, 0,
454 &lprocfs_evict_client_fops},
455 { "num_exports", lprocfs_rd_num_exports, 0, 0 },
456 { "readcache_max_filesize",
457 lprocfs_filter_rd_readcache,
458 lprocfs_filter_wr_readcache, 0 },
459 #ifdef HAVE_QUOTA_SUPPORT
460 { "quota_type", lprocfs_quota_rd_type,
461 lprocfs_quota_wr_type, 0},
463 { "client_cache_count", lprocfs_filter_rd_fmd_max_num,
464 lprocfs_filter_wr_fmd_max_num, 0 },
465 { "client_cache_seconds", lprocfs_filter_rd_fmd_max_age,
466 lprocfs_filter_wr_fmd_max_age, 0 },
467 { "capa", lprocfs_filter_rd_capa,
468 lprocfs_filter_wr_capa, 0 },
469 { "capa_count", lprocfs_filter_rd_capa_count, 0, 0 },
470 { "sec_level", lprocfs_rd_sec_level,
471 lprocfs_wr_sec_level, 0 },
472 { "read_cache_enable", lprocfs_filter_rd_cache, lprocfs_filter_wr_cache, 0},
473 { "writethrough_cache_enable", lprocfs_filter_rd_wcache,
474 lprocfs_filter_wr_wcache, 0},
475 { "mds_sync", lprocfs_filter_rd_mds_sync, 0, 0},
476 { "degraded", lprocfs_filter_rd_degraded,
477 lprocfs_filter_wr_degraded, 0 },
478 { "sync_journal", lprocfs_filter_rd_syncjournal,
479 lprocfs_filter_wr_syncjournal, 0 },
480 { "sync_on_lock_cancel", lprocfs_filter_rd_sync_lock_cancel,
481 lprocfs_filter_wr_sync_lock_cancel, 0 },
482 { "instance", lprocfs_target_rd_instance, 0 },
483 { "ir_factor", lprocfs_obd_rd_ir_factor,
484 lprocfs_obd_wr_ir_factor, 0},
488 static struct lprocfs_vars lprocfs_filter_module_vars[] = {
489 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
493 void filter_tally(struct obd_export *exp, struct page **pages, int nr_pages,
494 unsigned long *blocks, int blocks_per_page, int wr)
496 struct filter_obd *filter = &exp->exp_obd->u.filter;
497 struct page *last_page = NULL;
498 unsigned long *last_block = NULL;
499 unsigned long discont_pages = 0;
500 unsigned long discont_blocks = 0;
506 lprocfs_oh_tally_log2(&filter->fo_filter_stats.hist[BRW_R_PAGES + wr],
508 if (exp->exp_nid_stats && exp->exp_nid_stats->nid_brw_stats)
509 lprocfs_oh_tally_log2(&exp->exp_nid_stats->nid_brw_stats->
510 hist[BRW_R_PAGES + wr], nr_pages);
512 while (nr_pages-- > 0) {
513 if (last_page && (*pages)->index != (last_page->index + 1))
517 for (i = 0; i < blocks_per_page; i++) {
518 if (last_block && *blocks != (*last_block + 1))
520 last_block = blocks++;
524 lprocfs_oh_tally(&filter->fo_filter_stats.hist[BRW_R_DISCONT_PAGES +wr],
526 lprocfs_oh_tally(&filter->fo_filter_stats.hist[BRW_R_DISCONT_BLOCKS+wr],
529 if (exp->exp_nid_stats && exp->exp_nid_stats->nid_brw_stats) {
530 lprocfs_oh_tally_log2(&exp->exp_nid_stats->nid_brw_stats->
531 hist[BRW_R_DISCONT_PAGES + wr],
533 lprocfs_oh_tally_log2(&exp->exp_nid_stats->nid_brw_stats->
534 hist[BRW_R_DISCONT_BLOCKS + wr],
539 #define pct(a,b) (b ? a * 100 / b : 0)
541 static void display_brw_stats(struct seq_file *seq, char *name, char *units,
542 struct obd_histogram *read, struct obd_histogram *write, int log2)
544 unsigned long read_tot, write_tot, r, w, read_cum = 0, write_cum = 0;
547 seq_printf(seq, "\n%26s read | write\n", " ");
548 seq_printf(seq, "%-22s %-5s %% cum %% | %-5s %% cum %%\n",
551 read_tot = lprocfs_oh_sum(read);
552 write_tot = lprocfs_oh_sum(write);
553 for (i = 0; i < OBD_HIST_MAX; i++) {
554 r = read->oh_buckets[i];
555 w = write->oh_buckets[i];
558 if (read_cum == 0 && write_cum == 0)
562 seq_printf(seq, "%u", i);
564 seq_printf(seq, "%u", 1<<i);
566 seq_printf(seq, "%uK", 1<<(i-10));
568 seq_printf(seq, "%uM", 1<<(i-20));
570 seq_printf(seq, ":\t\t%10lu %3lu %3lu | %4lu %3lu %3lu\n",
571 r, pct(r, read_tot), pct(read_cum, read_tot),
572 w, pct(w, write_tot), pct(write_cum, write_tot));
574 if (read_cum == read_tot && write_cum == write_tot)
579 static void brw_stats_show(struct seq_file *seq, struct brw_stats *brw_stats)
583 /* this sampling races with updates */
584 cfs_gettimeofday(&now);
585 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
586 now.tv_sec, now.tv_usec);
588 display_brw_stats(seq, "pages per bulk r/w", "rpcs",
589 &brw_stats->hist[BRW_R_PAGES],
590 &brw_stats->hist[BRW_W_PAGES], 1);
592 display_brw_stats(seq, "discontiguous pages", "rpcs",
593 &brw_stats->hist[BRW_R_DISCONT_PAGES],
594 &brw_stats->hist[BRW_W_DISCONT_PAGES], 0);
596 display_brw_stats(seq, "discontiguous blocks", "rpcs",
597 &brw_stats->hist[BRW_R_DISCONT_BLOCKS],
598 &brw_stats->hist[BRW_W_DISCONT_BLOCKS], 0);
600 display_brw_stats(seq, "disk fragmented I/Os", "ios",
601 &brw_stats->hist[BRW_R_DIO_FRAGS],
602 &brw_stats->hist[BRW_W_DIO_FRAGS], 0);
604 display_brw_stats(seq, "disk I/Os in flight", "ios",
605 &brw_stats->hist[BRW_R_RPC_HIST],
606 &brw_stats->hist[BRW_W_RPC_HIST], 0);
610 sprintf(title, "I/O time (1/%ds)", CFS_HZ);
611 display_brw_stats(seq, title, "ios",
612 &brw_stats->hist[BRW_R_IO_TIME],
613 &brw_stats->hist[BRW_W_IO_TIME], 1);
616 display_brw_stats(seq, "disk I/O size", "ios",
617 &brw_stats->hist[BRW_R_DISK_IOSIZE],
618 &brw_stats->hist[BRW_W_DISK_IOSIZE], 1);
623 static int filter_brw_stats_seq_show(struct seq_file *seq, void *v)
625 struct obd_device *dev = seq->private;
626 struct filter_obd *filter = &dev->u.filter;
628 brw_stats_show(seq, &filter->fo_filter_stats);
633 static ssize_t filter_brw_stats_seq_write(struct file *file, const char *buf,
634 size_t len, loff_t *off)
636 struct seq_file *seq = file->private_data;
637 struct obd_device *dev = seq->private;
638 struct filter_obd *filter = &dev->u.filter;
641 for (i = 0; i < BRW_LAST; i++)
642 lprocfs_oh_clear(&filter->fo_filter_stats.hist[i]);
647 LPROC_SEQ_FOPS(filter_brw_stats);
649 int lproc_filter_attach_seqstat(struct obd_device *dev)
651 return lprocfs_obd_seq_create(dev, "brw_stats", 0444,
652 &filter_brw_stats_fops, dev);
655 void lprocfs_filter_init_vars(struct lprocfs_static_vars *lvars)
657 lvars->module_vars = lprocfs_filter_module_vars;
658 lvars->obd_vars = lprocfs_filter_obd_vars;
661 static int filter_per_nid_stats_seq_show(struct seq_file *seq, void *v)
663 nid_stat_t * stat = seq->private;
665 if (stat->nid_brw_stats)
666 brw_stats_show(seq, stat->nid_brw_stats);
671 static ssize_t filter_per_nid_stats_seq_write(struct file *file,
672 const char *buf, size_t len,
675 struct seq_file *seq = file->private_data;
676 nid_stat_t *stat = seq->private;
679 if (stat->nid_brw_stats)
680 for (i = 0; i < BRW_LAST; i++)
681 lprocfs_oh_clear(&stat->nid_brw_stats->hist[i]);
686 LPROC_SEQ_FOPS(filter_per_nid_stats);