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;
107 for (i = FILTER_GROUP_MDS0; i < filter->fo_group_count; i++) {
108 rc = snprintf(page, count, LPU64"\n",filter_last_id(filter, i));
120 int lprocfs_filter_rd_readcache(char *page, char **start, off_t off, int count,
121 int *eof, void *data)
123 struct obd_device *obd = data;
126 rc = snprintf(page, count, LPU64"\n",
127 obd->u.filter.fo_readcache_max_filesize);
131 int lprocfs_filter_wr_readcache(struct file *file, const char *buffer,
132 unsigned long count, void *data)
134 struct obd_device *obd = data;
138 rc = lprocfs_write_u64_helper(buffer, count, &val);
142 obd->u.filter.fo_readcache_max_filesize = val;
147 int lprocfs_filter_rd_fmd_max_num(char *page, char **start, off_t off,
148 int count, int *eof, void *data)
150 struct obd_device *obd = data;
153 rc = snprintf(page, count, "%u\n", obd->u.filter.fo_fmd_max_num);
157 int lprocfs_filter_wr_fmd_max_num(struct file *file, const char *buffer,
158 unsigned long count, void *data)
160 struct obd_device *obd = data;
164 rc = lprocfs_write_helper(buffer, count, &val);
168 if (val > 65536 || val < 1)
171 obd->u.filter.fo_fmd_max_num = val;
175 int lprocfs_filter_rd_fmd_max_age(char *page, char **start, off_t off,
176 int count, int *eof, void *data)
178 struct obd_device *obd = data;
181 rc = snprintf(page, count, "%u\n", obd->u.filter.fo_fmd_max_age / HZ);
185 int lprocfs_filter_wr_fmd_max_age(struct file *file, const char *buffer,
186 unsigned long count, void *data)
188 struct obd_device *obd = data;
192 rc = lprocfs_write_helper(buffer, count, &val);
196 if (val > 65536 || val < 1)
199 obd->u.filter.fo_fmd_max_age = val * HZ;
203 static int lprocfs_filter_rd_capa(char *page, char **start, off_t off,
204 int count, int *eof, void *data)
206 struct obd_device *obd = data;
209 rc = snprintf(page, count, "capability on: %s\n",
210 obd->u.filter.fo_fl_oss_capa ? "oss" : "");
214 static int lprocfs_filter_wr_capa(struct file *file, const char *buffer,
215 unsigned long count, void *data)
217 struct obd_device *obd = data;
220 rc = lprocfs_write_helper(buffer, count, &val);
225 CERROR("invalid capability mode, only 0/1 are accepted.\n"
226 " 1: enable oss fid capability\n"
227 " 0: disable oss fid capability\n");
231 obd->u.filter.fo_fl_oss_capa = val;
232 LCONSOLE_INFO("OSS %s %s fid capability.\n", obd->obd_name,
233 val ? "enabled" : "disabled");
237 static int lprocfs_filter_rd_capa_count(char *page, char **start, off_t off,
238 int count, int *eof, void *data)
240 return snprintf(page, count, "%d %d\n",
241 capa_count[CAPA_SITE_CLIENT],
242 capa_count[CAPA_SITE_SERVER]);
245 static struct lprocfs_vars lprocfs_filter_obd_vars[] = {
246 { "uuid", lprocfs_rd_uuid, 0, 0 },
247 { "blocksize", lprocfs_rd_blksize, 0, 0 },
248 { "kbytestotal", lprocfs_rd_kbytestotal, 0, 0 },
249 { "kbytesfree", lprocfs_rd_kbytesfree, 0, 0 },
250 { "kbytesavail", lprocfs_rd_kbytesavail, 0, 0 },
251 { "filestotal", lprocfs_rd_filestotal, 0, 0 },
252 { "filesfree", lprocfs_rd_filesfree, 0, 0 },
253 { "filegroups", lprocfs_filter_rd_groups, 0, 0 },
254 { "fstype", lprocfs_rd_fstype, 0, 0 },
255 { "mntdev", lprocfs_filter_rd_mntdev, 0, 0 },
256 { "last_id", lprocfs_filter_rd_last_id,0, 0 },
257 { "tot_dirty", lprocfs_filter_rd_tot_dirty, 0, 0 },
258 { "tot_pending", lprocfs_filter_rd_tot_pending, 0, 0 },
259 { "tot_granted", lprocfs_filter_rd_tot_granted, 0, 0 },
260 { "hash_stats", lprocfs_obd_rd_hash, 0, 0 },
261 { "recovery_status", lprocfs_obd_rd_recovery_status, 0, 0 },
262 { "recovery_maxtime", lprocfs_obd_rd_recovery_maxtime,
263 lprocfs_obd_wr_recovery_maxtime, 0},
264 { "evict_client", 0, lprocfs_wr_evict_client, 0,
265 &lprocfs_evict_client_fops},
266 { "num_exports", lprocfs_rd_num_exports, 0, 0 },
267 { "readcache_max_filesize",
268 lprocfs_filter_rd_readcache,
269 lprocfs_filter_wr_readcache, 0 },
270 #ifdef HAVE_QUOTA_SUPPORT
271 { "quota_bunit_sz", lprocfs_rd_bunit, lprocfs_wr_bunit, 0},
272 { "quota_btune_sz", lprocfs_rd_btune, lprocfs_wr_btune, 0},
273 { "quota_iunit_sz", lprocfs_rd_iunit, lprocfs_wr_iunit, 0},
274 { "quota_itune_sz", lprocfs_rd_itune, lprocfs_wr_itune, 0},
275 { "quota_type", lprocfs_rd_type, lprocfs_wr_type, 0},
277 { "client_cache_count", lprocfs_filter_rd_fmd_max_num,
278 lprocfs_filter_wr_fmd_max_num, 0 },
279 { "client_cache_seconds", lprocfs_filter_rd_fmd_max_age,
280 lprocfs_filter_wr_fmd_max_age, 0 },
281 { "capa", lprocfs_filter_rd_capa,
282 lprocfs_filter_wr_capa, 0 },
283 { "capa_count", lprocfs_filter_rd_capa_count, 0, 0 },
287 static struct lprocfs_vars lprocfs_filter_module_vars[] = {
288 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
292 void filter_tally(struct obd_export *exp, struct page **pages, int nr_pages,
293 unsigned long *blocks, int blocks_per_page, int wr)
295 struct filter_obd *filter = &exp->exp_obd->u.filter;
296 struct filter_export_data *fed = &exp->exp_filter_data;
297 struct page *last_page = NULL;
298 unsigned long *last_block = NULL;
299 unsigned long discont_pages = 0;
300 unsigned long discont_blocks = 0;
306 lprocfs_oh_tally_log2(&filter->fo_filter_stats.hist[BRW_R_PAGES + wr],
308 lprocfs_oh_tally_log2(&fed->fed_brw_stats.hist[BRW_R_PAGES + wr],
310 if (exp->exp_nid_stats && exp->exp_nid_stats->nid_brw_stats)
311 lprocfs_oh_tally_log2(&exp->exp_nid_stats->nid_brw_stats->hist[BRW_W_PAGES + wr],
314 while (nr_pages-- > 0) {
315 if (last_page && (*pages)->index != (last_page->index + 1))
319 for (i = 0; i < blocks_per_page; i++) {
320 if (last_block && *blocks != (*last_block + 1))
322 last_block = blocks++;
326 lprocfs_oh_tally(&filter->fo_filter_stats.hist[BRW_R_DISCONT_PAGES +wr],
328 lprocfs_oh_tally(&fed->fed_brw_stats.hist[BRW_R_DISCONT_PAGES + wr],
330 lprocfs_oh_tally(&filter->fo_filter_stats.hist[BRW_R_DISCONT_BLOCKS+wr],
332 lprocfs_oh_tally(&fed->fed_brw_stats.hist[BRW_R_DISCONT_BLOCKS + wr],
335 if (exp->exp_nid_stats && exp->exp_nid_stats->nid_brw_stats) {
336 lprocfs_oh_tally_log2(&exp->exp_nid_stats->nid_brw_stats->hist[BRW_W_DISCONT_PAGES + wr],
338 lprocfs_oh_tally_log2(&exp->exp_nid_stats->nid_brw_stats->hist[BRW_W_DISCONT_BLOCKS + wr],
343 #define pct(a,b) (b ? a * 100 / b : 0)
345 static void display_brw_stats(struct seq_file *seq, char *name, char *units,
346 struct obd_histogram *read, struct obd_histogram *write, int log2)
348 unsigned long read_tot, write_tot, r, w, read_cum = 0, write_cum = 0;
351 seq_printf(seq, "\n%26s read | write\n", " ");
352 seq_printf(seq, "%-22s %-5s %% cum %% | %-5s %% cum %%\n",
355 read_tot = lprocfs_oh_sum(read);
356 write_tot = lprocfs_oh_sum(write);
357 for (i = 0; i < OBD_HIST_MAX; i++) {
358 r = read->oh_buckets[i];
359 w = write->oh_buckets[i];
362 if (read_cum == 0 && write_cum == 0)
366 seq_printf(seq, "%u", i);
368 seq_printf(seq, "%u", 1<<i);
370 seq_printf(seq, "%uK", 1<<(i-10));
372 seq_printf(seq, "%uM", 1<<(i-20));
374 seq_printf(seq, ":\t\t%10lu %3lu %3lu | %4lu %3lu %3lu\n",
375 r, pct(r, read_tot), pct(read_cum, read_tot),
376 w, pct(w, write_tot), pct(write_cum, write_tot));
378 if (read_cum == read_tot && write_cum == write_tot)
383 static void brw_stats_show(struct seq_file *seq, struct brw_stats *brw_stats)
387 /* this sampling races with updates */
388 do_gettimeofday(&now);
389 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
390 now.tv_sec, now.tv_usec);
392 display_brw_stats(seq, "pages per bulk r/w", "rpcs",
393 &brw_stats->hist[BRW_R_PAGES],
394 &brw_stats->hist[BRW_W_PAGES], 1);
396 display_brw_stats(seq, "discontiguous pages", "rpcs",
397 &brw_stats->hist[BRW_R_DISCONT_PAGES],
398 &brw_stats->hist[BRW_W_DISCONT_PAGES], 0);
400 display_brw_stats(seq, "discontiguous blocks", "rpcs",
401 &brw_stats->hist[BRW_R_DISCONT_BLOCKS],
402 &brw_stats->hist[BRW_W_DISCONT_BLOCKS], 0);
404 display_brw_stats(seq, "disk fragmented I/Os", "ios",
405 &brw_stats->hist[BRW_R_DIO_FRAGS],
406 &brw_stats->hist[BRW_W_DIO_FRAGS], 0);
408 display_brw_stats(seq, "disk I/Os in flight", "ios",
409 &brw_stats->hist[BRW_R_RPC_HIST],
410 &brw_stats->hist[BRW_W_RPC_HIST], 0);
414 sprintf(title, "I/O time (1/%ds)", HZ);
415 display_brw_stats(seq, title, "ios",
416 &brw_stats->hist[BRW_R_IO_TIME],
417 &brw_stats->hist[BRW_W_IO_TIME], 1);
420 display_brw_stats(seq, "disk I/O size", "ios",
421 &brw_stats->hist[BRW_R_DISK_IOSIZE],
422 &brw_stats->hist[BRW_W_DISK_IOSIZE], 1);
427 static int filter_brw_stats_seq_show(struct seq_file *seq, void *v)
429 struct obd_device *dev = seq->private;
430 struct filter_obd *filter = &dev->u.filter;
432 brw_stats_show(seq, &filter->fo_filter_stats);
437 static ssize_t filter_brw_stats_seq_write(struct file *file, const char *buf,
438 size_t len, loff_t *off)
440 struct seq_file *seq = file->private_data;
441 struct obd_device *dev = seq->private;
442 struct filter_obd *filter = &dev->u.filter;
445 for (i = 0; i < BRW_LAST; i++)
446 lprocfs_oh_clear(&filter->fo_filter_stats.hist[i]);
451 LPROC_SEQ_FOPS(filter_brw_stats);
453 int lproc_filter_attach_seqstat(struct obd_device *dev)
455 return lprocfs_obd_seq_create(dev, "brw_stats", 0444,
456 &filter_brw_stats_fops, dev);
459 static int filter_per_export_stats_seq_show(struct seq_file *seq, void *v)
461 struct filter_export_data *fed = seq->private;
463 brw_stats_show(seq, &fed->fed_brw_stats);
468 static ssize_t filter_per_export_stats_seq_write(struct file *file,
469 const char *buf, size_t len, loff_t *off)
471 struct seq_file *seq = file->private_data;
472 struct filter_export_data *fed = seq->private;
475 for (i = 0; i < BRW_LAST; i++)
476 lprocfs_oh_clear(&fed->fed_brw_stats.hist[i]);
481 LPROC_SEQ_FOPS(filter_per_export_stats);
483 void lprocfs_filter_init_vars(struct lprocfs_static_vars *lvars)
485 lvars->module_vars = lprocfs_filter_module_vars;
486 lvars->obd_vars = lprocfs_filter_obd_vars;
489 static int filter_per_nid_stats_seq_show(struct seq_file *seq, void *v)
491 nid_stat_t *tmp = seq->private;
493 if (tmp->nid_brw_stats)
494 brw_stats_show(seq, tmp->nid_brw_stats);
499 static ssize_t filter_per_nid_stats_seq_write(struct file *file,
500 const char *buf, size_t len,
503 struct seq_file *seq = file->private_data;
504 nid_stat_t *tmp = seq->private;
507 if (tmp->nid_brw_stats)
508 for (i = 0; i < BRW_LAST; i++)
509 lprocfs_oh_clear(&tmp->nid_brw_stats->hist[i]);
514 LPROC_SEQ_FOPS(filter_per_nid_stats);