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)
40 return snprintf(page, count, "%u\n", FILTER_GROUPS);
43 static int lprocfs_filter_rd_tot_dirty(char *page, char **start, off_t off,
44 int count, int *eof, void *data)
46 struct obd_device *obd = (struct obd_device *)data;
50 return snprintf(page, count, LPU64"\n", obd->u.filter.fo_tot_dirty);
53 static int lprocfs_filter_rd_tot_granted(char *page, char **start, off_t off,
54 int count, int *eof, void *data)
56 struct obd_device *obd = (struct obd_device *)data;
60 return snprintf(page, count, LPU64"\n", obd->u.filter.fo_tot_granted);
63 static int lprocfs_filter_rd_tot_pending(char *page, char **start, off_t off,
64 int count, int *eof, void *data)
66 struct obd_device *obd = (struct obd_device *)data;
70 return snprintf(page, count, LPU64"\n", obd->u.filter.fo_tot_pending);
73 static int lprocfs_filter_rd_mntdev(char *page, char **start, off_t off,
74 int count, int *eof, void *data)
76 struct obd_device *obd = (struct obd_device *)data;
79 LASSERT(obd->u.filter.fo_vfsmnt->mnt_devname);
81 return snprintf(page, count, "%s\n",
82 obd->u.filter.fo_vfsmnt->mnt_devname);
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;
93 return snprintf(page, count, LPU64"\n",
94 filter_last_id(&obd->u.filter, 0));
97 int lprocfs_filter_rd_readcache(char *page, char **start, off_t off, int count,
100 struct obd_device *obd = data;
103 rc = snprintf(page, count, LPU64"\n",
104 obd->u.filter.fo_readcache_max_filesize);
108 int lprocfs_filter_wr_readcache(struct file *file, const char *buffer,
109 unsigned long count, void *data)
111 struct obd_device *obd = data;
115 rc = lprocfs_write_u64_helper(buffer, count, &val);
119 obd->u.filter.fo_readcache_max_filesize = val;
123 int lprocfs_filter_rd_fmd_max_num(char *page, char **start, off_t off,
124 int count, int *eof, void *data)
126 struct obd_device *obd = data;
129 rc = snprintf(page, count, "%u\n", obd->u.filter.fo_fmd_max_num);
133 int lprocfs_filter_wr_fmd_max_num(struct file *file, const char *buffer,
134 unsigned long count, void *data)
136 struct obd_device *obd = data;
140 rc = lprocfs_write_helper(buffer, count, &val);
144 if (val > 65536 || val < 1)
147 obd->u.filter.fo_fmd_max_num = val;
151 int lprocfs_filter_rd_fmd_max_age(char *page, char **start, off_t off,
152 int count, int *eof, void *data)
154 struct obd_device *obd = data;
157 rc = snprintf(page, count, "%u\n", obd->u.filter.fo_fmd_max_age / HZ);
161 int lprocfs_filter_wr_fmd_max_age(struct file *file, const char *buffer,
162 unsigned long count, void *data)
164 struct obd_device *obd = data;
168 rc = lprocfs_write_helper(buffer, count, &val);
172 if (val > 65536 || val < 1)
175 obd->u.filter.fo_fmd_max_age = val * HZ;
179 static struct lprocfs_vars lprocfs_filter_obd_vars[] = {
180 { "uuid", lprocfs_rd_uuid, 0, 0 },
181 { "blocksize", lprocfs_rd_blksize, 0, 0 },
182 { "kbytestotal", lprocfs_rd_kbytestotal, 0, 0 },
183 { "kbytesfree", lprocfs_rd_kbytesfree, 0, 0 },
184 { "kbytesavail", lprocfs_rd_kbytesavail, 0, 0 },
185 { "filestotal", lprocfs_rd_filestotal, 0, 0 },
186 { "filesfree", lprocfs_rd_filesfree, 0, 0 },
187 { "filegroups", lprocfs_filter_rd_groups, 0, 0 },
188 { "fstype", lprocfs_rd_fstype, 0, 0 },
189 { "mntdev", lprocfs_filter_rd_mntdev, 0, 0 },
190 { "last_id", lprocfs_filter_rd_last_id,0, 0 },
191 { "tot_dirty", lprocfs_filter_rd_tot_dirty, 0, 0 },
192 { "tot_pending", lprocfs_filter_rd_tot_pending, 0, 0 },
193 { "tot_granted", lprocfs_filter_rd_tot_granted, 0, 0 },
194 { "recovery_status", lprocfs_obd_rd_recovery_status, 0, 0 },
196 { "recovery_maxtime", lprocfs_obd_rd_recovery_maxtime,
197 lprocfs_obd_wr_recovery_maxtime, 0},
199 { "evict_client", 0, lprocfs_wr_evict_client, 0,
200 &lprocfs_evict_client_fops},
201 { "num_exports", lprocfs_rd_num_exports, 0, 0 },
202 { "readcache_max_filesize",
203 lprocfs_filter_rd_readcache,
204 lprocfs_filter_wr_readcache, 0 },
205 #ifdef HAVE_QUOTA_SUPPORT
206 { "quota_bunit_sz", lprocfs_quota_rd_bunit,
207 lprocfs_quota_wr_bunit, 0},
208 { "quota_btune_sz", lprocfs_quota_rd_btune,
209 lprocfs_quota_wr_btune, 0},
210 { "quota_iunit_sz", lprocfs_quota_rd_iunit,
211 lprocfs_quota_wr_iunit, 0},
212 { "quota_itune_sz", lprocfs_quota_rd_itune,
213 lprocfs_quota_wr_itune, 0},
214 { "quota_type", lprocfs_quota_rd_type,
215 lprocfs_quota_wr_type, 0},
216 { "quota_switch_seconds", lprocfs_quota_rd_switch_seconds,
217 lprocfs_quota_wr_switch_seconds, 0 },
220 { "client_cache_count", lprocfs_filter_rd_fmd_max_num,
221 lprocfs_filter_wr_fmd_max_num, 0 },
222 { "client_cache_seconds", lprocfs_filter_rd_fmd_max_age,
223 lprocfs_filter_wr_fmd_max_age, 0 },
227 static struct lprocfs_vars lprocfs_filter_module_vars[] = {
228 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
232 void filter_tally(struct obd_export *exp, struct page **pages, int nr_pages,
233 unsigned long *blocks, int blocks_per_page, int wr)
235 struct filter_obd *filter = &exp->exp_obd->u.filter;
236 struct filter_export_data *fed = &exp->exp_filter_data;
237 struct page *last_page = NULL;
238 unsigned long *last_block = NULL;
239 unsigned long discont_pages = 0;
240 unsigned long discont_blocks = 0;
246 lprocfs_oh_tally_log2(&filter->fo_filter_stats.hist[BRW_R_PAGES + wr],
248 lprocfs_oh_tally_log2(&fed->fed_brw_stats.hist[BRW_R_PAGES + wr],
250 if (exp->exp_nid_stats && exp->exp_nid_stats->nid_brw_stats)
251 lprocfs_oh_tally_log2(&exp->exp_nid_stats->nid_brw_stats->hist[BRW_W_PAGES + wr],
254 while (nr_pages-- > 0) {
255 if (last_page && (*pages)->index != (last_page->index + 1))
259 for (i = 0; i < blocks_per_page; i++) {
260 if (last_block && *blocks != (*last_block + 1))
262 last_block = blocks++;
266 lprocfs_oh_tally(&filter->fo_filter_stats.hist[BRW_R_DISCONT_PAGES +wr],
268 lprocfs_oh_tally(&fed->fed_brw_stats.hist[BRW_R_DISCONT_PAGES + wr],
270 lprocfs_oh_tally(&filter->fo_filter_stats.hist[BRW_R_DISCONT_BLOCKS+wr],
272 lprocfs_oh_tally(&fed->fed_brw_stats.hist[BRW_R_DISCONT_BLOCKS + wr],
275 if (exp->exp_nid_stats && exp->exp_nid_stats->nid_brw_stats) {
276 lprocfs_oh_tally_log2(&exp->exp_nid_stats->nid_brw_stats->hist[BRW_W_DISCONT_PAGES + wr],
278 lprocfs_oh_tally_log2(&exp->exp_nid_stats->nid_brw_stats->hist[BRW_W_DISCONT_BLOCKS + wr],
283 #define pct(a,b) (b ? a * 100 / b : 0)
285 static void display_brw_stats(struct seq_file *seq, char *name, char *units,
286 struct obd_histogram *read, struct obd_histogram *write, int log2)
288 unsigned long read_tot, write_tot, r, w, read_cum = 0, write_cum = 0;
291 seq_printf(seq, "\n%26s read | write\n", " ");
292 seq_printf(seq, "%-22s %-5s %% cum %% | %-5s %% cum %%\n",
295 read_tot = lprocfs_oh_sum(read);
296 write_tot = lprocfs_oh_sum(write);
297 for (i = 0; i < OBD_HIST_MAX; i++) {
298 r = read->oh_buckets[i];
299 w = write->oh_buckets[i];
302 if (read_cum == 0 && write_cum == 0)
306 seq_printf(seq, "%u", i);
308 seq_printf(seq, "%u", 1<<i);
310 seq_printf(seq, "%uK", 1<<(i-10));
312 seq_printf(seq, "%uM", 1<<(i-20));
314 seq_printf(seq, ":\t\t%10lu %3lu %3lu | %4lu %3lu %3lu\n",
315 r, pct(r, read_tot), pct(read_cum, read_tot),
316 w, pct(w, write_tot), pct(write_cum, write_tot));
318 if (read_cum == read_tot && write_cum == write_tot)
323 static void brw_stats_show(struct seq_file *seq, struct brw_stats *brw_stats)
327 /* this sampling races with updates */
328 do_gettimeofday(&now);
329 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
330 now.tv_sec, now.tv_usec);
332 display_brw_stats(seq, "pages per bulk r/w", "rpcs",
333 &brw_stats->hist[BRW_R_PAGES],
334 &brw_stats->hist[BRW_W_PAGES], 1);
336 display_brw_stats(seq, "discontiguous pages", "rpcs",
337 &brw_stats->hist[BRW_R_DISCONT_PAGES],
338 &brw_stats->hist[BRW_W_DISCONT_PAGES], 0);
340 display_brw_stats(seq, "discontiguous blocks", "rpcs",
341 &brw_stats->hist[BRW_R_DISCONT_BLOCKS],
342 &brw_stats->hist[BRW_W_DISCONT_BLOCKS], 0);
344 display_brw_stats(seq, "disk fragmented I/Os", "ios",
345 &brw_stats->hist[BRW_R_DIO_FRAGS],
346 &brw_stats->hist[BRW_W_DIO_FRAGS], 0);
348 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
349 display_brw_stats(seq, "disk I/Os in flight", "ios",
350 &brw_stats->hist[BRW_R_RPC_HIST],
351 &brw_stats->hist[BRW_W_RPC_HIST], 0);
355 sprintf(title, "I/O time (1/%ds)", HZ);
356 display_brw_stats(seq, title, "ios",
357 &brw_stats->hist[BRW_R_IO_TIME],
358 &brw_stats->hist[BRW_W_IO_TIME], 1);
361 display_brw_stats(seq, "disk I/O size", "ios",
362 &brw_stats->hist[BRW_R_DISK_IOSIZE],
363 &brw_stats->hist[BRW_W_DISK_IOSIZE], 1);
369 static int filter_brw_stats_seq_show(struct seq_file *seq, void *v)
371 struct obd_device *dev = seq->private;
372 struct filter_obd *filter = &dev->u.filter;
374 brw_stats_show(seq, &filter->fo_filter_stats);
379 static ssize_t filter_brw_stats_seq_write(struct file *file, const char *buf,
380 size_t len, loff_t *off)
382 struct seq_file *seq = file->private_data;
383 struct obd_device *dev = seq->private;
384 struct filter_obd *filter = &dev->u.filter;
387 for (i = 0; i < BRW_LAST; i++)
388 lprocfs_oh_clear(&filter->fo_filter_stats.hist[i]);
393 LPROC_SEQ_FOPS(filter_brw_stats);
395 int lproc_filter_attach_seqstat(struct obd_device *dev)
397 return lprocfs_obd_seq_create(dev, "brw_stats", 0444,
398 &filter_brw_stats_fops, dev);
401 static int filter_per_export_stats_seq_show(struct seq_file *seq, void *v)
403 struct filter_export_data *fed = seq->private;
405 brw_stats_show(seq, &fed->fed_brw_stats);
410 static ssize_t filter_per_export_stats_seq_write(struct file *file,
411 const char *buf, size_t len, loff_t *off)
413 struct seq_file *seq = file->private_data;
414 struct filter_export_data *fed = seq->private;
417 for (i = 0; i < BRW_LAST; i++)
418 lprocfs_oh_clear(&fed->fed_brw_stats.hist[i]);
423 LPROC_SEQ_FOPS(filter_per_export_stats);
425 void lprocfs_filter_init_vars(struct lprocfs_static_vars *lvars)
427 lvars->module_vars = lprocfs_filter_module_vars;
428 lvars->obd_vars = lprocfs_filter_obd_vars;
431 static int filter_per_nid_stats_seq_show(struct seq_file *seq, void *v)
433 nid_stat_t *tmp = seq->private;
435 if (tmp->nid_brw_stats)
436 brw_stats_show(seq, tmp->nid_brw_stats);
441 static ssize_t filter_per_nid_stats_seq_write(struct file *file,
442 const char *buf, size_t len,
445 struct seq_file *seq = file->private_data;
446 nid_stat_t *tmp = seq->private;
449 if (tmp->nid_brw_stats)
450 for (i = 0; i < BRW_LAST; i++)
451 lprocfs_oh_clear(&tmp->nid_brw_stats->hist[i]);
456 LPROC_SEQ_FOPS(filter_per_nid_stats);