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) 2012, Intel Corporation.
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_seqs(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_seq_count);
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;
66 ofd = ofd_dev(obd->obd_lu_dev);
68 return snprintf(page, count, LPU64"\n", ofd->ofd_tot_dirty);
71 static int lprocfs_ofd_rd_tot_granted(char *page, char **start, off_t off,
72 int count, int *eof, void *data)
74 struct obd_device *obd = (struct obd_device *)data;
75 struct ofd_device *ofd;
78 ofd = ofd_dev(obd->obd_lu_dev);
80 return snprintf(page, count, LPU64"\n", ofd->ofd_tot_granted);
83 static int lprocfs_ofd_rd_tot_pending(char *page, char **start, off_t off,
84 int count, int *eof, void *data)
86 struct obd_device *obd = (struct obd_device *)data;
87 struct ofd_device *ofd;
90 ofd = ofd_dev(obd->obd_lu_dev);
92 return snprintf(page, count, LPU64"\n", ofd->ofd_tot_pending);
95 static int lprocfs_ofd_rd_grant_precreate(char *page, char **start, off_t off,
96 int count, int *eof, void *data)
98 struct obd_device *obd = (struct obd_device *)data;
100 LASSERT(obd != NULL);
102 return snprintf(page, count, "%ld\n",
103 obd->obd_self_export->exp_filter_data.fed_grant);
106 static int lprocfs_ofd_rd_grant_ratio(char *page, char **start, off_t off,
107 int count, int *eof, void *data)
109 struct obd_device *obd = (struct obd_device *)data;
110 struct ofd_device *ofd;
112 LASSERT(obd != NULL);
113 ofd = ofd_dev(obd->obd_lu_dev);
115 return snprintf(page, count, "%d%%\n",
116 (int) ofd_grant_reserved(ofd, 100));
119 static int lprocfs_ofd_wr_grant_ratio(struct file *file, const char *buffer,
120 unsigned long count, void *data)
122 struct obd_device *obd = (struct obd_device *)data;
123 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
127 rc = lprocfs_write_helper(buffer, count, &val);
131 if (val > 100 || val < 0)
135 CWARN("%s: disabling grant error margin\n", obd->obd_name);
137 CWARN("%s: setting grant error margin >50%%, be warned that "
138 "a huge part of the free space is now reserved for "
139 "grants\n", obd->obd_name);
141 spin_lock(&ofd->ofd_grant_lock);
142 ofd->ofd_grant_ratio = ofd_grant_ratio_conv(val);
143 spin_unlock(&ofd->ofd_grant_lock);
147 static int lprocfs_ofd_rd_precreate_batch(char *page, char **start, off_t off,
148 int count, int *eof, void *data)
150 struct obd_device *obd = (struct obd_device *)data;
151 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
153 LASSERT(obd != NULL);
155 return snprintf(page, count, "%d\n", ofd->ofd_precreate_batch);
158 static int lprocfs_ofd_wr_precreate_batch(struct file *file, const char *buffer,
159 unsigned long count, void *data)
161 struct obd_device *obd = (struct obd_device *)data;
162 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
166 rc = lprocfs_write_helper(buffer, count, &val);
173 spin_lock(&ofd->ofd_batch_lock);
174 ofd->ofd_precreate_batch = val;
175 spin_unlock(&ofd->ofd_batch_lock);
179 static int lprocfs_ofd_rd_last_id(char *page, char **start, off_t off,
180 int count, int *eof, void *data)
182 struct obd_device *obd = data;
183 struct ofd_device *ofd;
184 struct ofd_seq *oseq = NULL;
190 ofd = ofd_dev(obd->obd_lu_dev);
192 read_lock(&ofd->ofd_seq_list_lock);
193 cfs_list_for_each_entry(oseq, &ofd->ofd_seq_list, os_list) {
194 rc = snprintf(page, count, LPX64": "LPX64"\n",
195 oseq->os_seq, ofd_seq_last_oid(oseq));
204 read_unlock(&ofd->ofd_seq_list_lock);
208 int lprocfs_ofd_rd_fmd_max_num(char *page, char **start, off_t off,
209 int count, int *eof, void *data)
211 struct obd_device *obd = data;
212 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
215 rc = snprintf(page, count, "%u\n", ofd->ofd_fmd_max_num);
219 int lprocfs_ofd_wr_fmd_max_num(struct file *file, const char *buffer,
220 unsigned long count, void *data)
222 struct obd_device *obd = data;
223 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
227 rc = lprocfs_write_helper(buffer, count, &val);
231 if (val > 65536 || val < 1)
234 ofd->ofd_fmd_max_num = val;
238 int lprocfs_ofd_rd_fmd_max_age(char *page, char **start, off_t off,
239 int count, int *eof, void *data)
241 struct obd_device *obd = data;
242 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
245 rc = snprintf(page, count, "%ld\n", ofd->ofd_fmd_max_age / CFS_HZ);
249 int lprocfs_ofd_wr_fmd_max_age(struct file *file, const char *buffer,
250 unsigned long count, void *data)
252 struct obd_device *obd = data;
253 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
257 rc = lprocfs_write_helper(buffer, count, &val);
261 if (val > 65536 || val < 1)
264 ofd->ofd_fmd_max_age = val * CFS_HZ;
268 static int lprocfs_ofd_rd_capa(char *page, char **start, off_t off,
269 int count, int *eof, void *data)
271 struct obd_device *obd = data;
274 rc = snprintf(page, count, "capability on: %s\n",
275 obd->u.filter.fo_fl_oss_capa ? "oss" : "");
279 static int lprocfs_ofd_wr_capa(struct file *file, const char *buffer,
280 unsigned long count, void *data)
282 struct obd_device *obd = data;
285 rc = lprocfs_write_helper(buffer, count, &val);
290 CERROR("invalid capability mode, only 0/1 are accepted.\n"
291 " 1: enable oss fid capability\n"
292 " 0: disable oss fid capability\n");
296 obd->u.filter.fo_fl_oss_capa = val;
297 LCONSOLE_INFO("OSS %s %s fid capability.\n", obd->obd_name,
298 val ? "enabled" : "disabled");
302 static int lprocfs_ofd_rd_capa_count(char *page, char **start, off_t off,
303 int count, int *eof, void *data)
305 return snprintf(page, count, "%d %d\n",
306 capa_count[CAPA_SITE_CLIENT],
307 capa_count[CAPA_SITE_SERVER]);
310 int lprocfs_ofd_rd_degraded(char *page, char **start, off_t off,
311 int count, int *eof, void *data)
313 struct obd_device *obd = data;
314 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
316 return snprintf(page, count, "%u\n", ofd->ofd_raid_degraded);
319 int lprocfs_ofd_wr_degraded(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);
326 rc = lprocfs_write_helper(buffer, count, &val);
330 spin_lock(&ofd->ofd_flags_lock);
331 ofd->ofd_raid_degraded = !!val;
332 spin_unlock(&ofd->ofd_flags_lock);
337 int lprocfs_ofd_rd_fstype(char *page, char **start, off_t off, int count,
338 int *eof, void *data)
340 struct obd_device *obd = data;
341 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
344 LASSERT(ofd->ofd_osd);
345 d = &ofd->ofd_osd->dd_lu_dev;
347 return snprintf(page, count, "%s\n", d->ld_type->ldt_name);
350 int lprocfs_ofd_rd_syncjournal(char *page, char **start, off_t off,
351 int count, int *eof, void *data)
353 struct obd_device *obd = data;
354 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
357 rc = snprintf(page, count, "%u\n", ofd->ofd_syncjournal);
361 int lprocfs_ofd_wr_syncjournal(struct file *file, const char *buffer,
362 unsigned long count, void *data)
364 struct obd_device *obd = data;
365 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
369 rc = lprocfs_write_helper(buffer, count, &val);
376 spin_lock(&ofd->ofd_flags_lock);
377 ofd->ofd_syncjournal = !!val;
379 spin_unlock(&ofd->ofd_flags_lock);
384 static char *sync_on_cancel_states[] = {"never",
388 int lprocfs_ofd_rd_sync_lock_cancel(char *page, char **start, off_t off,
389 int count, int *eof, void *data)
391 struct obd_device *obd = data;
392 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
395 rc = snprintf(page, count, "%s\n",
396 sync_on_cancel_states[ofd->ofd_sync_lock_cancel]);
400 int lprocfs_ofd_wr_sync_lock_cancel(struct file *file, const char *buffer,
401 unsigned long count, void *data)
403 struct obd_device *obd = data;
404 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
408 for (i = 0 ; i < NUM_SYNC_ON_CANCEL_STATES; i++) {
409 if (memcmp(buffer, sync_on_cancel_states[i],
410 strlen(sync_on_cancel_states[i])) == 0) {
418 rc = lprocfs_write_helper(buffer, count, &val);
423 if (val < 0 || val > 2)
426 spin_lock(&ofd->ofd_flags_lock);
427 ofd->ofd_sync_lock_cancel = val;
428 spin_unlock(&ofd->ofd_flags_lock);
432 int lprocfs_ofd_rd_grant_compat_disable(char *page, char **start, off_t off,
433 int count, int *eof, void *data)
435 struct obd_device *obd = data;
436 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
439 rc = snprintf(page, count, "%u\n", ofd->ofd_grant_compat_disable);
443 int lprocfs_ofd_wr_grant_compat_disable(struct file *file, const char *buffer,
444 unsigned long count, void *data)
446 struct obd_device *obd = data;
447 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
451 rc = lprocfs_write_helper(buffer, count, &val);
458 spin_lock(&ofd->ofd_flags_lock);
459 ofd->ofd_grant_compat_disable = !!val;
460 spin_unlock(&ofd->ofd_flags_lock);
465 static struct lprocfs_vars lprocfs_ofd_obd_vars[] = {
466 { "uuid", lprocfs_rd_uuid, 0, 0 },
467 { "blocksize", lprocfs_rd_blksize, 0, 0 },
468 { "kbytestotal", lprocfs_rd_kbytestotal, 0, 0 },
469 { "kbytesfree", lprocfs_rd_kbytesfree, 0, 0 },
470 { "kbytesavail", lprocfs_rd_kbytesavail, 0, 0 },
471 { "filestotal", lprocfs_rd_filestotal, 0, 0 },
472 { "filesfree", lprocfs_rd_filesfree, 0, 0 },
473 { "seqs_allocated", lprocfs_ofd_rd_seqs, 0, 0 },
474 { "fstype", lprocfs_ofd_rd_fstype, 0, 0 },
475 { "last_id", lprocfs_ofd_rd_last_id, 0, 0 },
476 { "tot_dirty", lprocfs_ofd_rd_tot_dirty, 0, 0 },
477 { "tot_pending", lprocfs_ofd_rd_tot_pending, 0, 0 },
478 { "tot_granted", lprocfs_ofd_rd_tot_granted, 0, 0 },
479 { "grant_precreate", lprocfs_ofd_rd_grant_precreate, 0, 0 },
480 { "grant_ratio", lprocfs_ofd_rd_grant_ratio,
481 lprocfs_ofd_wr_grant_ratio, 0, 0 },
482 { "precreate_batch", lprocfs_ofd_rd_precreate_batch,
483 lprocfs_ofd_wr_precreate_batch, 0 },
484 { "recovery_status", lprocfs_obd_rd_recovery_status, 0, 0 },
485 { "recovery_time_soft", lprocfs_obd_rd_recovery_time_soft,
486 lprocfs_obd_wr_recovery_time_soft, 0},
487 { "recovery_time_hard", lprocfs_obd_rd_recovery_time_hard,
488 lprocfs_obd_wr_recovery_time_hard, 0},
489 { "evict_client", 0, lprocfs_wr_evict_client, 0,
490 &lprocfs_evict_client_fops},
491 { "num_exports", lprocfs_rd_num_exports, 0, 0 },
492 { "degraded", lprocfs_ofd_rd_degraded,
493 lprocfs_ofd_wr_degraded, 0},
494 { "sync_journal", lprocfs_ofd_rd_syncjournal,
495 lprocfs_ofd_wr_syncjournal, 0 },
496 { "sync_on_lock_cancel", lprocfs_ofd_rd_sync_lock_cancel,
497 lprocfs_ofd_wr_sync_lock_cancel, 0 },
498 { "instance", lprocfs_target_rd_instance, 0 },
499 { "ir_factor", lprocfs_obd_rd_ir_factor,
500 lprocfs_obd_wr_ir_factor, 0},
501 { "grant_compat_disable", lprocfs_ofd_rd_grant_compat_disable,
502 lprocfs_ofd_wr_grant_compat_disable, 0 },
503 { "client_cache_count", lprocfs_ofd_rd_fmd_max_num,
504 lprocfs_ofd_wr_fmd_max_num, 0 },
505 { "client_cache_seconds", lprocfs_ofd_rd_fmd_max_age,
506 lprocfs_ofd_wr_fmd_max_age, 0 },
507 { "capa", lprocfs_ofd_rd_capa,
508 lprocfs_ofd_wr_capa, 0 },
509 { "capa_count", lprocfs_ofd_rd_capa_count, 0, 0 },
510 { "job_cleanup_interval", lprocfs_rd_job_interval,
511 lprocfs_wr_job_interval, 0},
515 static struct lprocfs_vars lprocfs_ofd_module_vars[] = {
516 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
520 #define pct(a,b) (b ? a * 100 / b : 0)
522 static void display_brw_stats(struct seq_file *seq, char *name, char *units,
523 struct obd_histogram *read,
524 struct obd_histogram *write, int log2)
526 unsigned long read_tot, write_tot, r, w, read_cum = 0, write_cum = 0;
529 seq_printf(seq, "\n%26s read | write\n", " ");
530 seq_printf(seq, "%-22s %-5s %% cum %% | %-5s %% cum %%\n",
533 read_tot = lprocfs_oh_sum(read);
534 write_tot = lprocfs_oh_sum(write);
535 for (i = 0; i < OBD_HIST_MAX; i++) {
536 r = read->oh_buckets[i];
537 w = write->oh_buckets[i];
540 if (read_cum == 0 && write_cum == 0)
544 seq_printf(seq, "%u", i);
546 seq_printf(seq, "%u", 1 << i);
548 seq_printf(seq, "%uK", 1 << (i - 10));
550 seq_printf(seq, "%uM", 1 << (i - 20));
552 seq_printf(seq, ":\t\t%10lu %3lu %3lu | %4lu %3lu %3lu\n",
553 r, pct(r, read_tot), pct(read_cum, read_tot),
554 w, pct(w, write_tot), pct(write_cum, write_tot));
556 if (read_cum == read_tot && write_cum == write_tot)
561 static void brw_stats_show(struct seq_file *seq, struct brw_stats *brw_stats)
566 /* this sampling races with updates */
567 cfs_gettimeofday(&now);
568 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
569 now.tv_sec, now.tv_usec);
571 display_brw_stats(seq, "pages per bulk r/w", "rpcs",
572 &brw_stats->hist[BRW_R_PAGES],
573 &brw_stats->hist[BRW_W_PAGES], 1);
575 display_brw_stats(seq, "discontiguous pages", "rpcs",
576 &brw_stats->hist[BRW_R_DISCONT_PAGES],
577 &brw_stats->hist[BRW_W_DISCONT_PAGES], 0);
579 display_brw_stats(seq, "discontiguous blocks", "rpcs",
580 &brw_stats->hist[BRW_R_DISCONT_BLOCKS],
581 &brw_stats->hist[BRW_W_DISCONT_BLOCKS], 0);
583 display_brw_stats(seq, "disk fragmented I/Os", "ios",
584 &brw_stats->hist[BRW_R_DIO_FRAGS],
585 &brw_stats->hist[BRW_W_DIO_FRAGS], 0);
587 display_brw_stats(seq, "disk I/Os in flight", "ios",
588 &brw_stats->hist[BRW_R_RPC_HIST],
589 &brw_stats->hist[BRW_W_RPC_HIST], 0);
591 sprintf(title, "I/O time (1/%ds)", CFS_HZ);
592 display_brw_stats(seq, title, "ios",
593 &brw_stats->hist[BRW_R_IO_TIME],
594 &brw_stats->hist[BRW_W_IO_TIME], 1);
596 display_brw_stats(seq, "disk I/O size", "ios",
597 &brw_stats->hist[BRW_R_DISK_IOSIZE],
598 &brw_stats->hist[BRW_W_DISK_IOSIZE], 1);
603 static int ofd_brw_stats_seq_show(struct seq_file *seq, void *v)
605 struct obd_device *dev = seq->private;
606 struct filter_obd *ofd = &dev->u.filter;
608 brw_stats_show(seq, &ofd->fo_filter_stats);
613 static ssize_t ofd_brw_stats_seq_write(struct file *file, const char *buf,
614 size_t len, loff_t *off)
616 struct seq_file *seq = file->private_data;
617 struct obd_device *dev = seq->private;
618 struct filter_obd *ofd = &dev->u.filter;
621 for (i = 0; i < BRW_LAST; i++)
622 lprocfs_oh_clear(&ofd->fo_filter_stats.hist[i]);
627 LPROC_SEQ_FOPS(ofd_brw_stats);
629 int lproc_ofd_attach_seqstat(struct obd_device *dev)
631 return lprocfs_obd_seq_create(dev, "brw_stats", 0644,
632 &ofd_brw_stats_fops, dev);
635 void lprocfs_ofd_init_vars(struct lprocfs_static_vars *lvars)
637 lvars->module_vars = lprocfs_ofd_module_vars;
638 lvars->obd_vars = lprocfs_ofd_obd_vars;
641 static int ofd_per_nid_stats_seq_show(struct seq_file *seq, void *v)
643 nid_stat_t *stat = seq->private;
645 if (stat->nid_brw_stats)
646 brw_stats_show(seq, stat->nid_brw_stats);
651 static ssize_t ofd_per_nid_stats_seq_write(struct file *file, const char *buf,
652 size_t len, loff_t *off)
654 struct seq_file *seq = file->private_data;
655 nid_stat_t *stat = seq->private;
658 if (stat->nid_brw_stats)
659 for (i = 0; i < BRW_LAST; i++)
660 lprocfs_oh_clear(&stat->nid_brw_stats->hist[i]);
665 LPROC_SEQ_FOPS(ofd_per_nid_stats);
667 void ofd_stats_counter_init(struct lprocfs_stats *stats)
669 LASSERT(stats && stats->ls_num == LPROC_OFD_STATS_LAST);
670 lprocfs_counter_init(stats, LPROC_OFD_STATS_READ,
671 LPROCFS_CNTR_AVGMINMAX, "read", "bytes");
672 lprocfs_counter_init(stats, LPROC_OFD_STATS_WRITE,
673 LPROCFS_CNTR_AVGMINMAX, "write", "bytes");
674 lprocfs_counter_init(stats, LPROC_OFD_STATS_SETATTR,
675 0, "setattr", "reqs");
676 lprocfs_counter_init(stats, LPROC_OFD_STATS_PUNCH,
678 lprocfs_counter_init(stats, LPROC_OFD_STATS_SYNC,