4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2012, Whamcloud, Inc.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/ofd/lproc_ofd.c
39 #define DEBUG_SUBSYSTEM S_CLASS
42 #include <lprocfs_status.h>
43 #include <linux/seq_file.h>
45 #include "ofd_internal.h"
49 static int lprocfs_ofd_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;
53 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
56 return snprintf(page, count, "%u\n", ofd->ofd_max_group);
59 static int lprocfs_ofd_rd_tot_dirty(char *page, char **start, off_t off,
60 int count, int *eof, void *data)
62 struct obd_device *obd = (struct obd_device *)data;
63 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
67 return snprintf(page, count, LPU64"\n", ofd->ofd_tot_dirty);
70 static int lprocfs_ofd_rd_tot_granted(char *page, char **start, off_t off,
71 int count, int *eof, void *data)
73 struct obd_device *obd = (struct obd_device *)data;
74 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
78 return snprintf(page, count, LPU64"\n", ofd->ofd_tot_granted);
81 static int lprocfs_ofd_rd_tot_pending(char *page, char **start, off_t off,
82 int count, int *eof, void *data)
84 struct obd_device *obd = (struct obd_device *)data;
85 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
89 return snprintf(page, count, LPU64"\n", ofd->ofd_tot_pending);
92 static int lprocfs_ofd_rd_grant_precreate(char *page, char **start, off_t off,
93 int count, int *eof, void *data)
95 struct obd_device *obd = (struct obd_device *)data;
99 return snprintf(page, count, "%ld\n",
100 obd->obd_self_export->exp_filter_data.fed_grant);
103 static int lprocfs_ofd_rd_grant_ratio(char *page, char **start, off_t off,
104 int count, int *eof, void *data)
106 struct obd_device *obd = (struct obd_device *)data;
107 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
109 LASSERT(obd != NULL);
111 return snprintf(page, count, "%d%%\n",
112 (int) ofd_grant_reserved(ofd, 100));
115 static int lprocfs_ofd_wr_grant_ratio(struct file *file, const char *buffer,
116 unsigned long count, void *data)
118 struct obd_device *obd = (struct obd_device *)data;
119 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
123 rc = lprocfs_write_helper(buffer, count, &val);
127 if (val > 100 || val < 0)
131 CWARN("%s: disabling grant error margin\n", obd->obd_name);
133 CWARN("%s: setting grant error margin >50%%, be warned that "
134 "a huge part of the free space is now reserved for "
135 "grants\n", obd->obd_name);
137 cfs_spin_lock(&ofd->ofd_grant_lock);
138 ofd->ofd_grant_ratio = ofd_grant_ratio_conv(val);
139 cfs_spin_unlock(&ofd->ofd_grant_lock);
143 static int lprocfs_ofd_rd_last_id(char *page, char **start, off_t off,
144 int count, int *eof, void *data)
146 struct obd_device *obd = data;
147 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
148 int retval = 0, rc, i;
153 for (i = FID_SEQ_OST_MDT0; i <= ofd->ofd_max_group; i++) {
154 rc = snprintf(page, count, LPU64"\n", ofd_last_id(ofd, i));
166 int lprocfs_ofd_rd_fmd_max_num(char *page, char **start, off_t off,
167 int count, int *eof, void *data)
169 struct obd_device *obd = data;
170 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
173 rc = snprintf(page, count, "%u\n", ofd->ofd_fmd_max_num);
177 int lprocfs_ofd_wr_fmd_max_num(struct file *file, const char *buffer,
178 unsigned long count, void *data)
180 struct obd_device *obd = data;
181 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
185 rc = lprocfs_write_helper(buffer, count, &val);
189 if (val > 65536 || val < 1)
192 ofd->ofd_fmd_max_num = val;
196 int lprocfs_ofd_rd_fmd_max_age(char *page, char **start, off_t off,
197 int count, int *eof, void *data)
199 struct obd_device *obd = data;
200 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
203 rc = snprintf(page, count, "%ld\n", ofd->ofd_fmd_max_age / CFS_HZ);
207 int lprocfs_ofd_wr_fmd_max_age(struct file *file, const char *buffer,
208 unsigned long count, void *data)
210 struct obd_device *obd = data;
211 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
215 rc = lprocfs_write_helper(buffer, count, &val);
219 if (val > 65536 || val < 1)
222 ofd->ofd_fmd_max_age = val * CFS_HZ;
226 static int lprocfs_ofd_rd_capa(char *page, char **start, off_t off,
227 int count, int *eof, void *data)
229 struct obd_device *obd = data;
232 rc = snprintf(page, count, "capability on: %s\n",
233 obd->u.filter.fo_fl_oss_capa ? "oss" : "");
237 static int lprocfs_ofd_wr_capa(struct file *file, const char *buffer,
238 unsigned long count, void *data)
240 struct obd_device *obd = data;
243 rc = lprocfs_write_helper(buffer, count, &val);
248 CERROR("invalid capability mode, only 0/1 are accepted.\n"
249 " 1: enable oss fid capability\n"
250 " 0: disable oss fid capability\n");
254 obd->u.filter.fo_fl_oss_capa = val;
255 LCONSOLE_INFO("OSS %s %s fid capability.\n", obd->obd_name,
256 val ? "enabled" : "disabled");
260 static int lprocfs_ofd_rd_capa_count(char *page, char **start, off_t off,
261 int count, int *eof, void *data)
263 return snprintf(page, count, "%d %d\n",
264 capa_count[CAPA_SITE_CLIENT],
265 capa_count[CAPA_SITE_SERVER]);
268 int lprocfs_ofd_rd_degraded(char *page, char **start, off_t off,
269 int count, int *eof, void *data)
271 struct obd_device *obd = data;
272 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
274 return snprintf(page, count, "%u\n", ofd->ofd_raid_degraded);
277 int lprocfs_ofd_wr_degraded(struct file *file, const char *buffer,
278 unsigned long count, void *data)
280 struct obd_device *obd = data;
281 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
284 rc = lprocfs_write_helper(buffer, count, &val);
288 cfs_spin_lock(&ofd->ofd_flags_lock);
289 ofd->ofd_raid_degraded = !!val;
290 cfs_spin_unlock(&ofd->ofd_flags_lock);
295 int lprocfs_ofd_rd_fstype(char *page, char **start, off_t off, int count,
296 int *eof, void *data)
298 struct obd_device *obd = data;
299 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
302 LASSERT(ofd->ofd_osd);
303 d = &ofd->ofd_osd->dd_lu_dev;
305 return snprintf(page, count, "%s\n", d->ld_type->ldt_name);
308 int lprocfs_ofd_rd_syncjournal(char *page, char **start, off_t off,
309 int count, int *eof, void *data)
311 struct obd_device *obd = data;
312 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
315 rc = snprintf(page, count, "%u\n", ofd->ofd_syncjournal);
319 int lprocfs_ofd_wr_syncjournal(struct file *file, const char *buffer,
320 unsigned long count, void *data)
322 struct obd_device *obd = data;
323 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
327 rc = lprocfs_write_helper(buffer, count, &val);
334 cfs_spin_lock(&ofd->ofd_flags_lock);
335 ofd->ofd_syncjournal = !!val;
337 cfs_spin_unlock(&ofd->ofd_flags_lock);
342 static char *sync_on_cancel_states[] = {"never",
346 int lprocfs_ofd_rd_sync_lock_cancel(char *page, char **start, off_t off,
347 int count, int *eof, void *data)
349 struct obd_device *obd = data;
350 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
353 rc = snprintf(page, count, "%s\n",
354 sync_on_cancel_states[ofd->ofd_sync_lock_cancel]);
358 int lprocfs_ofd_wr_sync_lock_cancel(struct file *file, const char *buffer,
359 unsigned long count, void *data)
361 struct obd_device *obd = data;
362 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
366 for (i = 0 ; i < NUM_SYNC_ON_CANCEL_STATES; i++) {
367 if (memcmp(buffer, sync_on_cancel_states[i],
368 strlen(sync_on_cancel_states[i])) == 0) {
376 rc = lprocfs_write_helper(buffer, count, &val);
381 if (val < 0 || val > 2)
384 cfs_spin_lock(&ofd->ofd_flags_lock);
385 ofd->ofd_sync_lock_cancel = val;
386 cfs_spin_unlock(&ofd->ofd_flags_lock);
390 int lprocfs_ofd_rd_grant_compat_disable(char *page, char **start, off_t off,
391 int count, int *eof, void *data)
393 struct obd_device *obd = data;
394 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
397 rc = snprintf(page, count, "%u\n", ofd->ofd_grant_compat_disable);
401 int lprocfs_ofd_wr_grant_compat_disable(struct file *file, const char *buffer,
402 unsigned long count, void *data)
404 struct obd_device *obd = data;
405 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
409 rc = lprocfs_write_helper(buffer, count, &val);
416 cfs_spin_lock(&ofd->ofd_flags_lock);
417 ofd->ofd_grant_compat_disable = !!val;
418 cfs_spin_unlock(&ofd->ofd_flags_lock);
423 static struct lprocfs_vars lprocfs_ofd_obd_vars[] = {
424 { "uuid", lprocfs_rd_uuid, 0, 0 },
425 { "blocksize", lprocfs_rd_blksize, 0, 0 },
426 { "kbytestotal", lprocfs_rd_kbytestotal, 0, 0 },
427 { "kbytesfree", lprocfs_rd_kbytesfree, 0, 0 },
428 { "kbytesavail", lprocfs_rd_kbytesavail, 0, 0 },
429 { "filestotal", lprocfs_rd_filestotal, 0, 0 },
430 { "filesfree", lprocfs_rd_filesfree, 0, 0 },
431 { "filegroups", lprocfs_ofd_rd_groups, 0, 0 },
432 { "fstype", lprocfs_ofd_rd_fstype, 0, 0 },
433 { "last_id", lprocfs_ofd_rd_last_id, 0, 0 },
434 { "tot_dirty", lprocfs_ofd_rd_tot_dirty, 0, 0 },
435 { "tot_pending", lprocfs_ofd_rd_tot_pending, 0, 0 },
436 { "tot_granted", lprocfs_ofd_rd_tot_granted, 0, 0 },
437 { "grant_precreate", lprocfs_ofd_rd_grant_precreate, 0, 0 },
438 { "grant_ratio", lprocfs_ofd_rd_grant_ratio,
439 lprocfs_ofd_wr_grant_ratio, 0, 0 },
440 { "recovery_status", lprocfs_obd_rd_recovery_status, 0, 0 },
441 { "recovery_time_soft", lprocfs_obd_rd_recovery_time_soft,
442 lprocfs_obd_wr_recovery_time_soft, 0},
443 { "recovery_time_hard", lprocfs_obd_rd_recovery_time_hard,
444 lprocfs_obd_wr_recovery_time_hard, 0},
445 { "evict_client", 0, lprocfs_wr_evict_client, 0,
446 &lprocfs_evict_client_fops},
447 { "num_exports", lprocfs_rd_num_exports, 0, 0 },
448 { "degraded", lprocfs_ofd_rd_degraded,
449 lprocfs_ofd_wr_degraded, 0},
450 { "sync_journal", lprocfs_ofd_rd_syncjournal,
451 lprocfs_ofd_wr_syncjournal, 0 },
452 { "sync_on_lock_cancel", lprocfs_ofd_rd_sync_lock_cancel,
453 lprocfs_ofd_wr_sync_lock_cancel, 0 },
454 { "instance", lprocfs_target_rd_instance, 0 },
455 { "ir_factor", lprocfs_obd_rd_ir_factor,
456 lprocfs_obd_wr_ir_factor, 0},
457 { "grant_compat_disable", lprocfs_ofd_rd_grant_compat_disable,
458 lprocfs_ofd_wr_grant_compat_disable, 0 },
459 { "client_cache_count", lprocfs_ofd_rd_fmd_max_num,
460 lprocfs_ofd_wr_fmd_max_num, 0 },
461 { "client_cache_seconds", lprocfs_ofd_rd_fmd_max_age,
462 lprocfs_ofd_wr_fmd_max_age, 0 },
463 { "capa", lprocfs_ofd_rd_capa,
464 lprocfs_ofd_wr_capa, 0 },
465 { "capa_count", lprocfs_ofd_rd_capa_count, 0, 0 },
469 static struct lprocfs_vars lprocfs_ofd_module_vars[] = {
470 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
474 #define pct(a,b) (b ? a * 100 / b : 0)
476 static void display_brw_stats(struct seq_file *seq, char *name, char *units,
477 struct obd_histogram *read,
478 struct obd_histogram *write, int log2)
480 unsigned long read_tot, write_tot, r, w, read_cum = 0, write_cum = 0;
483 seq_printf(seq, "\n%26s read | write\n", " ");
484 seq_printf(seq, "%-22s %-5s %% cum %% | %-5s %% cum %%\n",
487 read_tot = lprocfs_oh_sum(read);
488 write_tot = lprocfs_oh_sum(write);
489 for (i = 0; i < OBD_HIST_MAX; i++) {
490 r = read->oh_buckets[i];
491 w = write->oh_buckets[i];
494 if (read_cum == 0 && write_cum == 0)
498 seq_printf(seq, "%u", i);
500 seq_printf(seq, "%u", 1 << i);
502 seq_printf(seq, "%uK", 1 << (i - 10));
504 seq_printf(seq, "%uM", 1 << (i - 20));
506 seq_printf(seq, ":\t\t%10lu %3lu %3lu | %4lu %3lu %3lu\n",
507 r, pct(r, read_tot), pct(read_cum, read_tot),
508 w, pct(w, write_tot), pct(write_cum, write_tot));
510 if (read_cum == read_tot && write_cum == write_tot)
515 static void brw_stats_show(struct seq_file *seq, struct brw_stats *brw_stats)
520 /* this sampling races with updates */
521 cfs_gettimeofday(&now);
522 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
523 now.tv_sec, now.tv_usec);
525 display_brw_stats(seq, "pages per bulk r/w", "rpcs",
526 &brw_stats->hist[BRW_R_PAGES],
527 &brw_stats->hist[BRW_W_PAGES], 1);
529 display_brw_stats(seq, "discontiguous pages", "rpcs",
530 &brw_stats->hist[BRW_R_DISCONT_PAGES],
531 &brw_stats->hist[BRW_W_DISCONT_PAGES], 0);
533 display_brw_stats(seq, "discontiguous blocks", "rpcs",
534 &brw_stats->hist[BRW_R_DISCONT_BLOCKS],
535 &brw_stats->hist[BRW_W_DISCONT_BLOCKS], 0);
537 display_brw_stats(seq, "disk fragmented I/Os", "ios",
538 &brw_stats->hist[BRW_R_DIO_FRAGS],
539 &brw_stats->hist[BRW_W_DIO_FRAGS], 0);
541 display_brw_stats(seq, "disk I/Os in flight", "ios",
542 &brw_stats->hist[BRW_R_RPC_HIST],
543 &brw_stats->hist[BRW_W_RPC_HIST], 0);
545 sprintf(title, "I/O time (1/%ds)", CFS_HZ);
546 display_brw_stats(seq, title, "ios",
547 &brw_stats->hist[BRW_R_IO_TIME],
548 &brw_stats->hist[BRW_W_IO_TIME], 1);
550 display_brw_stats(seq, "disk I/O size", "ios",
551 &brw_stats->hist[BRW_R_DISK_IOSIZE],
552 &brw_stats->hist[BRW_W_DISK_IOSIZE], 1);
557 static int ofd_brw_stats_seq_show(struct seq_file *seq, void *v)
559 struct obd_device *dev = seq->private;
560 struct filter_obd *ofd = &dev->u.filter;
562 brw_stats_show(seq, &ofd->fo_filter_stats);
567 static ssize_t ofd_brw_stats_seq_write(struct file *file, const char *buf,
568 size_t len, loff_t *off)
570 struct seq_file *seq = file->private_data;
571 struct obd_device *dev = seq->private;
572 struct filter_obd *ofd = &dev->u.filter;
575 for (i = 0; i < BRW_LAST; i++)
576 lprocfs_oh_clear(&ofd->fo_filter_stats.hist[i]);
581 LPROC_SEQ_FOPS(ofd_brw_stats);
583 int lproc_ofd_attach_seqstat(struct obd_device *dev)
585 return lprocfs_obd_seq_create(dev, "brw_stats", 0444,
586 &ofd_brw_stats_fops, dev);
589 void lprocfs_ofd_init_vars(struct lprocfs_static_vars *lvars)
591 lvars->module_vars = lprocfs_ofd_module_vars;
592 lvars->obd_vars = lprocfs_ofd_obd_vars;
595 static int ofd_per_nid_stats_seq_show(struct seq_file *seq, void *v)
597 nid_stat_t *stat = seq->private;
599 if (stat->nid_brw_stats)
600 brw_stats_show(seq, stat->nid_brw_stats);
605 static ssize_t ofd_per_nid_stats_seq_write(struct file *file, const char *buf,
606 size_t len, loff_t *off)
608 struct seq_file *seq = file->private_data;
609 nid_stat_t *stat = seq->private;
612 if (stat->nid_brw_stats)
613 for (i = 0; i < BRW_LAST; i++)
614 lprocfs_oh_clear(&stat->nid_brw_stats->hist[i]);
619 LPROC_SEQ_FOPS(ofd_per_nid_stats);