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;
136 int lprocfs_filter_rd_fmd_max_num(char *page, char **start, off_t off,
137 int count, int *eof, void *data)
139 struct obd_device *obd = data;
142 rc = snprintf(page, count, "%u\n", obd->u.filter.fo_fmd_max_num);
146 int lprocfs_filter_wr_fmd_max_num(struct file *file, const char *buffer,
147 unsigned long count, void *data)
149 struct obd_device *obd = data;
153 rc = lprocfs_write_helper(buffer, count, &val);
157 if (val > 65536 || val < 1)
160 obd->u.filter.fo_fmd_max_num = val;
164 int lprocfs_filter_rd_fmd_max_age(char *page, char **start, off_t off,
165 int count, int *eof, void *data)
167 struct obd_device *obd = data;
170 rc = snprintf(page, count, "%u\n", obd->u.filter.fo_fmd_max_age / HZ);
174 int lprocfs_filter_wr_fmd_max_age(struct file *file, const char *buffer,
175 unsigned long count, void *data)
177 struct obd_device *obd = data;
181 rc = lprocfs_write_helper(buffer, count, &val);
185 if (val > 65536 || val < 1)
188 obd->u.filter.fo_fmd_max_age = val * HZ;
192 static int lprocfs_filter_rd_capa(char *page, char **start, off_t off,
193 int count, int *eof, void *data)
195 struct obd_device *obd = data;
198 rc = snprintf(page, count, "capability on: %s\n",
199 obd->u.filter.fo_fl_oss_capa ? "oss" : "");
203 static int lprocfs_filter_wr_capa(struct file *file, const char *buffer,
204 unsigned long count, void *data)
206 struct obd_device *obd = data;
209 rc = lprocfs_write_helper(buffer, count, &val);
214 CERROR("invalid capability mode, only 0/1 are accepted.\n"
215 " 1: enable oss fid capability\n"
216 " 0: disable oss fid capability\n");
220 obd->u.filter.fo_fl_oss_capa = val;
221 LCONSOLE_INFO("OSS %s %s fid capability.\n", obd->obd_name,
222 val ? "enabled" : "disabled");
226 static int lprocfs_filter_rd_capa_count(char *page, char **start, off_t off,
227 int count, int *eof, void *data)
229 return snprintf(page, count, "%d %d\n",
230 capa_count[CAPA_SITE_CLIENT],
231 capa_count[CAPA_SITE_SERVER]);
234 static struct lprocfs_vars lprocfs_filter_obd_vars[] = {
235 { "uuid", lprocfs_rd_uuid, 0, 0 },
236 { "blocksize", lprocfs_rd_blksize, 0, 0 },
237 { "kbytestotal", lprocfs_rd_kbytestotal, 0, 0 },
238 { "kbytesfree", lprocfs_rd_kbytesfree, 0, 0 },
239 { "kbytesavail", lprocfs_rd_kbytesavail, 0, 0 },
240 { "filestotal", lprocfs_rd_filestotal, 0, 0 },
241 { "filesfree", lprocfs_rd_filesfree, 0, 0 },
242 { "filegroups", lprocfs_filter_rd_groups, 0, 0 },
243 { "fstype", lprocfs_rd_fstype, 0, 0 },
244 { "mntdev", lprocfs_filter_rd_mntdev, 0, 0 },
245 { "last_id", lprocfs_filter_rd_last_id,0, 0 },
246 { "tot_dirty", lprocfs_filter_rd_tot_dirty, 0, 0 },
247 { "tot_pending", lprocfs_filter_rd_tot_pending, 0, 0 },
248 { "tot_granted", lprocfs_filter_rd_tot_granted, 0, 0 },
249 { "recovery_status", lprocfs_obd_rd_recovery_status, 0, 0 },
250 { "recovery_maxtime", lprocfs_obd_rd_recovery_maxtime,
251 lprocfs_obd_wr_recovery_maxtime, 0},
252 { "evict_client", 0, lprocfs_wr_evict_client, 0,
253 &lprocfs_evict_client_fops},
254 { "num_exports", lprocfs_rd_num_exports, 0, 0 },
255 { "readcache_max_filesize",
256 lprocfs_filter_rd_readcache,
257 lprocfs_filter_wr_readcache, 0 },
258 #ifdef HAVE_QUOTA_SUPPORT
259 { "quota_bunit_sz", lprocfs_rd_bunit, lprocfs_wr_bunit, 0},
260 { "quota_btune_sz", lprocfs_rd_btune, lprocfs_wr_btune, 0},
261 { "quota_iunit_sz", lprocfs_rd_iunit, lprocfs_wr_iunit, 0},
262 { "quota_itune_sz", lprocfs_rd_itune, lprocfs_wr_itune, 0},
263 { "quota_type", lprocfs_rd_type, lprocfs_wr_type, 0},
265 { "client_cache_count", lprocfs_filter_rd_fmd_max_num,
266 lprocfs_filter_wr_fmd_max_num, 0 },
267 { "client_cache_seconds", lprocfs_filter_rd_fmd_max_age,
268 lprocfs_filter_wr_fmd_max_age, 0 },
269 { "capa", lprocfs_filter_rd_capa,
270 lprocfs_filter_wr_capa, 0 },
271 { "capa_count", lprocfs_filter_rd_capa_count, 0, 0 },
275 static struct lprocfs_vars lprocfs_filter_module_vars[] = {
276 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
280 void filter_tally(struct obd_export *exp, struct page **pages, int nr_pages,
281 unsigned long *blocks, int blocks_per_page, int wr)
283 struct filter_obd *filter = &exp->exp_obd->u.filter;
284 struct filter_export_data *fed = &exp->exp_filter_data;
285 struct page *last_page = NULL;
286 unsigned long *last_block = NULL;
287 unsigned long discont_pages = 0;
288 unsigned long discont_blocks = 0;
294 lprocfs_oh_tally_log2(&filter->fo_filter_stats.hist[BRW_R_PAGES + wr],
296 lprocfs_oh_tally_log2(&fed->fed_brw_stats.hist[BRW_R_PAGES + wr],
298 if (exp->exp_nid_stats && exp->exp_nid_stats->nid_brw_stats)
299 lprocfs_oh_tally_log2(&exp->exp_nid_stats->nid_brw_stats->hist[BRW_W_PAGES + wr],
302 while (nr_pages-- > 0) {
303 if (last_page && (*pages)->index != (last_page->index + 1))
307 for (i = 0; i < blocks_per_page; i++) {
308 if (last_block && *blocks != (*last_block + 1))
310 last_block = blocks++;
314 lprocfs_oh_tally(&filter->fo_filter_stats.hist[BRW_R_DISCONT_PAGES +wr],
316 lprocfs_oh_tally(&fed->fed_brw_stats.hist[BRW_R_DISCONT_PAGES + wr],
318 lprocfs_oh_tally(&filter->fo_filter_stats.hist[BRW_R_DISCONT_BLOCKS+wr],
320 lprocfs_oh_tally(&fed->fed_brw_stats.hist[BRW_R_DISCONT_BLOCKS + wr],
323 if (exp->exp_nid_stats && exp->exp_nid_stats->nid_brw_stats) {
324 lprocfs_oh_tally_log2(&exp->exp_nid_stats->nid_brw_stats->hist[BRW_W_DISCONT_PAGES + wr],
326 lprocfs_oh_tally_log2(&exp->exp_nid_stats->nid_brw_stats->hist[BRW_W_DISCONT_BLOCKS + wr],
331 #define pct(a,b) (b ? a * 100 / b : 0)
333 static void display_brw_stats(struct seq_file *seq, char *name, char *units,
334 struct obd_histogram *read, struct obd_histogram *write, int log2)
336 unsigned long read_tot, write_tot, r, w, read_cum = 0, write_cum = 0;
339 seq_printf(seq, "\n%26s read | write\n", " ");
340 seq_printf(seq, "%-22s %-5s %% cum %% | %-5s %% cum %%\n",
343 read_tot = lprocfs_oh_sum(read);
344 write_tot = lprocfs_oh_sum(write);
345 for (i = 0; i < OBD_HIST_MAX; i++) {
346 r = read->oh_buckets[i];
347 w = write->oh_buckets[i];
350 if (read_cum == 0 && write_cum == 0)
354 seq_printf(seq, "%u", i);
356 seq_printf(seq, "%u", 1<<i);
358 seq_printf(seq, "%uK", 1<<(i-10));
360 seq_printf(seq, "%uM", 1<<(i-20));
362 seq_printf(seq, ":\t\t%10lu %3lu %3lu | %4lu %3lu %3lu\n",
363 r, pct(r, read_tot), pct(read_cum, read_tot),
364 w, pct(w, write_tot), pct(write_cum, write_tot));
366 if (read_cum == read_tot && write_cum == write_tot)
371 static void brw_stats_show(struct seq_file *seq, struct brw_stats *brw_stats)
375 /* this sampling races with updates */
376 do_gettimeofday(&now);
377 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
378 now.tv_sec, now.tv_usec);
380 display_brw_stats(seq, "pages per bulk r/w", "rpcs",
381 &brw_stats->hist[BRW_R_PAGES],
382 &brw_stats->hist[BRW_W_PAGES], 1);
384 display_brw_stats(seq, "discontiguous pages", "rpcs",
385 &brw_stats->hist[BRW_R_DISCONT_PAGES],
386 &brw_stats->hist[BRW_W_DISCONT_PAGES], 0);
388 display_brw_stats(seq, "discontiguous blocks", "rpcs",
389 &brw_stats->hist[BRW_R_DISCONT_BLOCKS],
390 &brw_stats->hist[BRW_W_DISCONT_BLOCKS], 0);
392 display_brw_stats(seq, "disk fragmented I/Os", "ios",
393 &brw_stats->hist[BRW_R_DIO_FRAGS],
394 &brw_stats->hist[BRW_W_DIO_FRAGS], 0);
396 display_brw_stats(seq, "disk I/Os in flight", "ios",
397 &brw_stats->hist[BRW_R_RPC_HIST],
398 &brw_stats->hist[BRW_W_RPC_HIST], 0);
402 sprintf(title, "I/O time (1/%ds)", HZ);
403 display_brw_stats(seq, title, "ios",
404 &brw_stats->hist[BRW_R_IO_TIME],
405 &brw_stats->hist[BRW_W_IO_TIME], 1);
408 display_brw_stats(seq, "disk I/O size", "ios",
409 &brw_stats->hist[BRW_R_DISK_IOSIZE],
410 &brw_stats->hist[BRW_W_DISK_IOSIZE], 1);
415 static int filter_brw_stats_seq_show(struct seq_file *seq, void *v)
417 struct obd_device *dev = seq->private;
418 struct filter_obd *filter = &dev->u.filter;
420 brw_stats_show(seq, &filter->fo_filter_stats);
425 static ssize_t filter_brw_stats_seq_write(struct file *file, const char *buf,
426 size_t len, loff_t *off)
428 struct seq_file *seq = file->private_data;
429 struct obd_device *dev = seq->private;
430 struct filter_obd *filter = &dev->u.filter;
433 for (i = 0; i < BRW_LAST; i++)
434 lprocfs_oh_clear(&filter->fo_filter_stats.hist[i]);
439 LPROC_SEQ_FOPS(filter_brw_stats);
441 int lproc_filter_attach_seqstat(struct obd_device *dev)
443 return lprocfs_obd_seq_create(dev, "brw_stats", 0444,
444 &filter_brw_stats_fops, dev);
447 static int filter_per_export_stats_seq_show(struct seq_file *seq, void *v)
449 struct filter_export_data *fed = seq->private;
451 brw_stats_show(seq, &fed->fed_brw_stats);
456 static ssize_t filter_per_export_stats_seq_write(struct file *file,
457 const char *buf, size_t len, loff_t *off)
459 struct seq_file *seq = file->private_data;
460 struct filter_export_data *fed = seq->private;
463 for (i = 0; i < BRW_LAST; i++)
464 lprocfs_oh_clear(&fed->fed_brw_stats.hist[i]);
469 LPROC_SEQ_FOPS(filter_per_export_stats);
471 void lprocfs_filter_init_vars(struct lprocfs_static_vars *lvars)
473 lvars->module_vars = lprocfs_filter_module_vars;
474 lvars->obd_vars = lprocfs_filter_obd_vars;
477 static int filter_per_nid_stats_seq_show(struct seq_file *seq, void *v)
479 nid_stat_t *tmp = seq->private;
481 if (tmp->nid_brw_stats)
482 brw_stats_show(seq, tmp->nid_brw_stats);
487 static ssize_t filter_per_nid_stats_seq_write(struct file *file,
488 const char *buf, size_t len,
491 struct seq_file *seq = file->private_data;
492 nid_stat_t *tmp = seq->private;
495 if (tmp->nid_brw_stats)
496 for (i = 0; i < BRW_LAST; i++)
497 lprocfs_oh_clear(&tmp->nid_brw_stats->hist[i]);
502 LPROC_SEQ_FOPS(filter_per_nid_stats);