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)
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_mntdev(char *page, char **start, off_t off,
86 int count, int *eof, void *data)
88 struct obd_device *obd = (struct obd_device *)data;
91 LASSERT(obd->u.filter.fo_vfsmnt->mnt_devname);
93 return snprintf(page, count, "%s\n",
94 obd->u.filter.fo_vfsmnt->mnt_devname);
97 static int lprocfs_filter_rd_last_id(char *page, char **start, off_t off,
98 int count, int *eof, void *data)
100 struct obd_device *obd = data;
101 struct filter_obd *filter = &obd->u.filter;
102 int retval = 0, rc, i;
106 rc = snprintf(page, count, LPU64"\n",filter_last_id(filter, 0));
113 for (i = FILTER_GROUP_MDS1_N_BASE + 1; i < filter->fo_group_count; i++) {
114 rc = snprintf(page, count, LPU64"\n",filter_last_id(filter, i));
126 int lprocfs_filter_rd_readcache(char *page, char **start, off_t off, int count,
127 int *eof, void *data)
129 struct obd_device *obd = data;
132 rc = snprintf(page, count, LPU64"\n",
133 obd->u.filter.fo_readcache_max_filesize);
137 int lprocfs_filter_wr_readcache(struct file *file, const char *buffer,
138 unsigned long count, void *data)
140 struct obd_device *obd = data;
144 rc = lprocfs_write_u64_helper(buffer, count, &val);
148 obd->u.filter.fo_readcache_max_filesize = val;
152 int lprocfs_filter_rd_fmd_max_num(char *page, char **start, off_t off,
153 int count, int *eof, void *data)
155 struct obd_device *obd = data;
158 rc = snprintf(page, count, "%u\n", obd->u.filter.fo_fmd_max_num);
162 int lprocfs_filter_wr_fmd_max_num(struct file *file, const char *buffer,
163 unsigned long count, void *data)
165 struct obd_device *obd = data;
169 rc = lprocfs_write_helper(buffer, count, &val);
173 if (val > 65536 || val < 1)
176 obd->u.filter.fo_fmd_max_num = val;
180 int lprocfs_filter_rd_fmd_max_age(char *page, char **start, off_t off,
181 int count, int *eof, void *data)
183 struct obd_device *obd = data;
186 rc = snprintf(page, count, "%u\n", obd->u.filter.fo_fmd_max_age / HZ);
190 int lprocfs_filter_wr_fmd_max_age(struct file *file, const char *buffer,
191 unsigned long count, void *data)
193 struct obd_device *obd = data;
197 rc = lprocfs_write_helper(buffer, count, &val);
201 if (val > 65536 || val < 1)
204 obd->u.filter.fo_fmd_max_age = val * HZ;
208 static int lprocfs_filter_rd_capa(char *page, char **start, off_t off,
209 int count, int *eof, void *data)
211 struct obd_device *obd = data;
214 rc = snprintf(page, count, "capability on: %s\n",
215 obd->u.filter.fo_fl_oss_capa ? "oss" : "");
219 static int lprocfs_filter_wr_capa(struct file *file, const char *buffer,
220 unsigned long count, void *data)
222 struct obd_device *obd = data;
225 rc = lprocfs_write_helper(buffer, count, &val);
230 CERROR("invalid capability mode, only 0/1 are accepted.\n"
231 " 1: enable oss fid capability\n"
232 " 0: disable oss fid capability\n");
236 obd->u.filter.fo_fl_oss_capa = val;
237 LCONSOLE_INFO("OSS %s %s fid capability.\n", obd->obd_name,
238 val ? "enabled" : "disabled");
242 static int lprocfs_filter_rd_capa_count(char *page, char **start, off_t off,
243 int count, int *eof, void *data)
245 return snprintf(page, count, "%d %d\n",
246 capa_count[CAPA_SITE_CLIENT],
247 capa_count[CAPA_SITE_SERVER]);
250 static int lprocfs_rd_sec_level(char *page, char **start, off_t off,
251 int count, int *eof, void *data)
253 struct obd_device *obd = data;
255 return snprintf(page, count, "%d\n", obd->u.filter.fo_sec_level);
258 static int lprocfs_wr_sec_level(struct file *file, const char *buffer,
259 unsigned long count, void *data)
261 struct obd_device *obd = data;
264 rc = lprocfs_write_helper(buffer, count, &val);
268 if (val > LUSTRE_SEC_ALL || val < LUSTRE_SEC_NONE)
271 if (val == LUSTRE_SEC_SPECIFY) {
272 CWARN("security level %d will be supported in future.\n",
277 obd->u.filter.fo_sec_level = val;
281 static int lprocfs_filter_rd_cache(char *page, char **start, off_t off,
282 int count, int *eof, void *data)
284 struct obd_device *obd = (struct obd_device *)data;
285 LASSERT(obd != NULL);
287 return snprintf(page, count, "%u\n", obd->u.filter.fo_read_cache);
290 static int lprocfs_filter_wr_cache(struct file *file, const char *buffer,
291 unsigned long count, void *data)
293 struct obd_device *obd = (struct obd_device *)data;
295 LASSERT(obd != NULL);
297 rc = lprocfs_write_helper(buffer, count, &val);
302 spin_lock_bh(&obd->obd_processing_task_lock);
303 obd->u.filter.fo_read_cache = val;
304 spin_unlock_bh(&obd->obd_processing_task_lock);
308 static int lprocfs_filter_rd_wcache(char *page, char **start, off_t off,
309 int count, int *eof, void *data)
311 struct obd_device *obd = (struct obd_device *)data;
312 LASSERT(obd != NULL);
314 return snprintf(page, count, "%u\n", obd->u.filter.fo_writethrough_cache);
317 static int lprocfs_filter_wr_wcache(struct file *file, const char *buffer,
318 unsigned long count, void *data)
320 struct obd_device *obd = (struct obd_device *)data;
322 LASSERT(obd != NULL);
324 rc = lprocfs_write_helper(buffer, count, &val);
329 spin_lock_bh(&obd->obd_processing_task_lock);
330 obd->u.filter.fo_writethrough_cache = val;
331 spin_unlock_bh(&obd->obd_processing_task_lock);
335 static int lprocfs_filter_rd_mds_sync(char *page, char **start, off_t off,
336 int count, int *eof, void *data)
338 struct obd_device *obd = (struct obd_device *)data;
339 LASSERT(obd != NULL);
341 return snprintf(page, count, "%u\n", obd->u.filter.fo_mds_ost_sync);
344 int lprocfs_filter_rd_degraded(char *page, char **start, off_t off,
345 int count, int *eof, void *data)
347 struct obd_device *obd = data;
349 return snprintf(page, count, "%u\n", obd->u.filter.fo_raid_degraded);
352 int lprocfs_filter_wr_degraded(struct file *file, const char *buffer,
353 unsigned long count, void *data)
355 struct obd_device *obd = data;
358 rc = lprocfs_write_helper(buffer, count, &val);
362 spin_lock(&obd->obd_osfs_lock);
363 obd->u.filter.fo_raid_degraded = !!val;
364 spin_unlock(&obd->obd_osfs_lock);
368 static struct lprocfs_vars lprocfs_filter_obd_vars[] = {
369 { "uuid", lprocfs_rd_uuid, 0, 0 },
370 { "blocksize", lprocfs_rd_blksize, 0, 0 },
371 { "kbytestotal", lprocfs_rd_kbytestotal, 0, 0 },
372 { "kbytesfree", lprocfs_rd_kbytesfree, 0, 0 },
373 { "kbytesavail", lprocfs_rd_kbytesavail, 0, 0 },
374 { "filestotal", lprocfs_rd_filestotal, 0, 0 },
375 { "filesfree", lprocfs_rd_filesfree, 0, 0 },
376 { "filegroups", lprocfs_filter_rd_groups, 0, 0 },
377 { "fstype", lprocfs_rd_fstype, 0, 0 },
378 { "mntdev", lprocfs_filter_rd_mntdev, 0, 0 },
379 { "last_id", lprocfs_filter_rd_last_id,0, 0 },
380 { "tot_dirty", lprocfs_filter_rd_tot_dirty, 0, 0 },
381 { "tot_pending", lprocfs_filter_rd_tot_pending, 0, 0 },
382 { "tot_granted", lprocfs_filter_rd_tot_granted, 0, 0 },
383 { "hash_stats", lprocfs_obd_rd_hash, 0, 0 },
384 { "recovery_status", lprocfs_obd_rd_recovery_status, 0, 0 },
385 { "recovery_maxtime", lprocfs_obd_rd_recovery_maxtime,
386 lprocfs_obd_wr_recovery_maxtime, 0},
387 { "evict_client", 0, lprocfs_wr_evict_client, 0,
388 &lprocfs_evict_client_fops},
389 { "num_exports", lprocfs_rd_num_exports, 0, 0 },
390 { "readcache_max_filesize",
391 lprocfs_filter_rd_readcache,
392 lprocfs_filter_wr_readcache, 0 },
393 #ifdef HAVE_QUOTA_SUPPORT
394 { "quota_type", lprocfs_quota_rd_type,
395 lprocfs_quota_wr_type, 0},
397 { "client_cache_count", lprocfs_filter_rd_fmd_max_num,
398 lprocfs_filter_wr_fmd_max_num, 0 },
399 { "client_cache_seconds", lprocfs_filter_rd_fmd_max_age,
400 lprocfs_filter_wr_fmd_max_age, 0 },
401 { "capa", lprocfs_filter_rd_capa,
402 lprocfs_filter_wr_capa, 0 },
403 { "capa_count", lprocfs_filter_rd_capa_count, 0, 0 },
404 { "sec_level", lprocfs_rd_sec_level,
405 lprocfs_wr_sec_level, 0 },
406 { "read_cache_enable", lprocfs_filter_rd_cache, lprocfs_filter_wr_cache, 0},
407 { "writethrough_cache_enable", lprocfs_filter_rd_wcache,
408 lprocfs_filter_wr_wcache, 0},
409 { "mds_sync", lprocfs_filter_rd_mds_sync, 0, 0},
410 { "degraded", lprocfs_filter_rd_degraded,
411 lprocfs_filter_wr_degraded, 0 },
415 static struct lprocfs_vars lprocfs_filter_module_vars[] = {
416 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
420 void filter_tally(struct obd_export *exp, struct page **pages, int nr_pages,
421 unsigned long *blocks, int blocks_per_page, int wr)
423 struct filter_obd *filter = &exp->exp_obd->u.filter;
424 struct page *last_page = NULL;
425 unsigned long *last_block = NULL;
426 unsigned long discont_pages = 0;
427 unsigned long discont_blocks = 0;
433 lprocfs_oh_tally_log2(&filter->fo_filter_stats.hist[BRW_R_PAGES + wr],
435 if (exp->exp_nid_stats && exp->exp_nid_stats->nid_brw_stats)
436 lprocfs_oh_tally_log2(&exp->exp_nid_stats->nid_brw_stats->
437 hist[BRW_R_PAGES + wr], nr_pages);
439 while (nr_pages-- > 0) {
440 if (last_page && (*pages)->index != (last_page->index + 1))
444 for (i = 0; i < blocks_per_page; i++) {
445 if (last_block && *blocks != (*last_block + 1))
447 last_block = blocks++;
451 lprocfs_oh_tally(&filter->fo_filter_stats.hist[BRW_R_DISCONT_PAGES +wr],
453 lprocfs_oh_tally(&filter->fo_filter_stats.hist[BRW_R_DISCONT_BLOCKS+wr],
456 if (exp->exp_nid_stats && exp->exp_nid_stats->nid_brw_stats) {
457 lprocfs_oh_tally_log2(&exp->exp_nid_stats->nid_brw_stats->
458 hist[BRW_R_DISCONT_PAGES + wr],
460 lprocfs_oh_tally_log2(&exp->exp_nid_stats->nid_brw_stats->
461 hist[BRW_R_DISCONT_BLOCKS + wr],
466 #define pct(a,b) (b ? a * 100 / b : 0)
468 static void display_brw_stats(struct seq_file *seq, char *name, char *units,
469 struct obd_histogram *read, struct obd_histogram *write, int log2)
471 unsigned long read_tot, write_tot, r, w, read_cum = 0, write_cum = 0;
474 seq_printf(seq, "\n%26s read | write\n", " ");
475 seq_printf(seq, "%-22s %-5s %% cum %% | %-5s %% cum %%\n",
478 read_tot = lprocfs_oh_sum(read);
479 write_tot = lprocfs_oh_sum(write);
480 for (i = 0; i < OBD_HIST_MAX; i++) {
481 r = read->oh_buckets[i];
482 w = write->oh_buckets[i];
485 if (read_cum == 0 && write_cum == 0)
489 seq_printf(seq, "%u", i);
491 seq_printf(seq, "%u", 1<<i);
493 seq_printf(seq, "%uK", 1<<(i-10));
495 seq_printf(seq, "%uM", 1<<(i-20));
497 seq_printf(seq, ":\t\t%10lu %3lu %3lu | %4lu %3lu %3lu\n",
498 r, pct(r, read_tot), pct(read_cum, read_tot),
499 w, pct(w, write_tot), pct(write_cum, write_tot));
501 if (read_cum == read_tot && write_cum == write_tot)
506 static void brw_stats_show(struct seq_file *seq, struct brw_stats *brw_stats)
510 /* this sampling races with updates */
511 do_gettimeofday(&now);
512 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
513 now.tv_sec, now.tv_usec);
515 display_brw_stats(seq, "pages per bulk r/w", "rpcs",
516 &brw_stats->hist[BRW_R_PAGES],
517 &brw_stats->hist[BRW_W_PAGES], 1);
519 display_brw_stats(seq, "discontiguous pages", "rpcs",
520 &brw_stats->hist[BRW_R_DISCONT_PAGES],
521 &brw_stats->hist[BRW_W_DISCONT_PAGES], 0);
523 display_brw_stats(seq, "discontiguous blocks", "rpcs",
524 &brw_stats->hist[BRW_R_DISCONT_BLOCKS],
525 &brw_stats->hist[BRW_W_DISCONT_BLOCKS], 0);
527 display_brw_stats(seq, "disk fragmented I/Os", "ios",
528 &brw_stats->hist[BRW_R_DIO_FRAGS],
529 &brw_stats->hist[BRW_W_DIO_FRAGS], 0);
531 display_brw_stats(seq, "disk I/Os in flight", "ios",
532 &brw_stats->hist[BRW_R_RPC_HIST],
533 &brw_stats->hist[BRW_W_RPC_HIST], 0);
537 sprintf(title, "I/O time (1/%ds)", HZ);
538 display_brw_stats(seq, title, "ios",
539 &brw_stats->hist[BRW_R_IO_TIME],
540 &brw_stats->hist[BRW_W_IO_TIME], 1);
543 display_brw_stats(seq, "disk I/O size", "ios",
544 &brw_stats->hist[BRW_R_DISK_IOSIZE],
545 &brw_stats->hist[BRW_W_DISK_IOSIZE], 1);
550 static int filter_brw_stats_seq_show(struct seq_file *seq, void *v)
552 struct obd_device *dev = seq->private;
553 struct filter_obd *filter = &dev->u.filter;
555 brw_stats_show(seq, &filter->fo_filter_stats);
560 static ssize_t filter_brw_stats_seq_write(struct file *file, const char *buf,
561 size_t len, loff_t *off)
563 struct seq_file *seq = file->private_data;
564 struct obd_device *dev = seq->private;
565 struct filter_obd *filter = &dev->u.filter;
568 for (i = 0; i < BRW_LAST; i++)
569 lprocfs_oh_clear(&filter->fo_filter_stats.hist[i]);
574 LPROC_SEQ_FOPS(filter_brw_stats);
576 int lproc_filter_attach_seqstat(struct obd_device *dev)
578 return lprocfs_obd_seq_create(dev, "brw_stats", 0444,
579 &filter_brw_stats_fops, dev);
582 void lprocfs_filter_init_vars(struct lprocfs_static_vars *lvars)
584 lvars->module_vars = lprocfs_filter_module_vars;
585 lvars->obd_vars = lprocfs_filter_obd_vars;
588 static int filter_per_nid_stats_seq_show(struct seq_file *seq, void *v)
590 nid_stat_t * stat = seq->private;
592 if (stat->nid_brw_stats)
593 brw_stats_show(seq, stat->nid_brw_stats);
598 static ssize_t filter_per_nid_stats_seq_write(struct file *file,
599 const char *buf, size_t len,
602 struct seq_file *seq = file->private_data;
603 nid_stat_t *stat = seq->private;
606 if (stat->nid_brw_stats)
607 for (i = 0; i < BRW_LAST; i++)
608 lprocfs_oh_clear(&stat->nid_brw_stats->hist[i]);
613 LPROC_SEQ_FOPS(filter_per_nid_stats);