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_last_id(char *page, char **start, off_t off,
60 int count, int *eof, void *data)
62 struct obd_device *obd = data;
63 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
64 int retval = 0, rc, i;
69 for (i = FID_SEQ_OST_MDT0; i <= ofd->ofd_max_group; i++) {
70 rc = snprintf(page, count, LPU64"\n", ofd_last_id(ofd, i));
82 int lprocfs_ofd_rd_fmd_max_num(char *page, char **start, off_t off,
83 int count, int *eof, void *data)
85 struct obd_device *obd = data;
86 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
89 rc = snprintf(page, count, "%u\n", ofd->ofd_fmd_max_num);
93 int lprocfs_ofd_wr_fmd_max_num(struct file *file, const char *buffer,
94 unsigned long count, void *data)
96 struct obd_device *obd = data;
97 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
101 rc = lprocfs_write_helper(buffer, count, &val);
105 if (val > 65536 || val < 1)
108 ofd->ofd_fmd_max_num = val;
112 int lprocfs_ofd_rd_fmd_max_age(char *page, char **start, off_t off,
113 int count, int *eof, void *data)
115 struct obd_device *obd = data;
116 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
119 rc = snprintf(page, count, "%ld\n", ofd->ofd_fmd_max_age / CFS_HZ);
123 int lprocfs_ofd_wr_fmd_max_age(struct file *file, const char *buffer,
124 unsigned long count, void *data)
126 struct obd_device *obd = data;
127 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
131 rc = lprocfs_write_helper(buffer, count, &val);
135 if (val > 65536 || val < 1)
138 ofd->ofd_fmd_max_age = val * CFS_HZ;
142 static int lprocfs_ofd_rd_capa(char *page, char **start, off_t off,
143 int count, int *eof, void *data)
145 struct obd_device *obd = data;
148 rc = snprintf(page, count, "capability on: %s\n",
149 obd->u.filter.fo_fl_oss_capa ? "oss" : "");
153 static int lprocfs_ofd_wr_capa(struct file *file, const char *buffer,
154 unsigned long count, void *data)
156 struct obd_device *obd = data;
159 rc = lprocfs_write_helper(buffer, count, &val);
164 CERROR("invalid capability mode, only 0/1 are accepted.\n"
165 " 1: enable oss fid capability\n"
166 " 0: disable oss fid capability\n");
170 obd->u.filter.fo_fl_oss_capa = val;
171 LCONSOLE_INFO("OSS %s %s fid capability.\n", obd->obd_name,
172 val ? "enabled" : "disabled");
176 static int lprocfs_ofd_rd_capa_count(char *page, char **start, off_t off,
177 int count, int *eof, void *data)
179 return snprintf(page, count, "%d %d\n",
180 capa_count[CAPA_SITE_CLIENT],
181 capa_count[CAPA_SITE_SERVER]);
184 int lprocfs_ofd_rd_degraded(char *page, char **start, off_t off,
185 int count, int *eof, void *data)
187 struct obd_device *obd = data;
188 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
190 return snprintf(page, count, "%u\n", ofd->ofd_raid_degraded);
193 int lprocfs_ofd_wr_degraded(struct file *file, const char *buffer,
194 unsigned long count, void *data)
196 struct obd_device *obd = data;
197 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
200 rc = lprocfs_write_helper(buffer, count, &val);
204 cfs_spin_lock(&ofd->ofd_flags_lock);
205 ofd->ofd_raid_degraded = !!val;
206 cfs_spin_unlock(&ofd->ofd_flags_lock);
211 int lprocfs_ofd_rd_fstype(char *page, char **start, off_t off, int count,
212 int *eof, void *data)
214 struct obd_device *obd = data;
215 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
218 LASSERT(ofd->ofd_osd);
219 d = &ofd->ofd_osd->dd_lu_dev;
221 return snprintf(page, count, "%s\n", d->ld_type->ldt_name);
224 int lprocfs_ofd_rd_syncjournal(char *page, char **start, off_t off,
225 int count, int *eof, void *data)
227 struct obd_device *obd = data;
228 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
231 rc = snprintf(page, count, "%u\n", ofd->ofd_syncjournal);
235 int lprocfs_ofd_wr_syncjournal(struct file *file, const char *buffer,
236 unsigned long count, void *data)
238 struct obd_device *obd = data;
239 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
243 rc = lprocfs_write_helper(buffer, count, &val);
250 cfs_spin_lock(&ofd->ofd_flags_lock);
251 ofd->ofd_syncjournal = !!val;
253 cfs_spin_unlock(&ofd->ofd_flags_lock);
258 static char *sync_on_cancel_states[] = {"never",
262 int lprocfs_ofd_rd_sync_lock_cancel(char *page, char **start, off_t off,
263 int count, int *eof, void *data)
265 struct obd_device *obd = data;
266 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
269 rc = snprintf(page, count, "%s\n",
270 sync_on_cancel_states[ofd->ofd_sync_lock_cancel]);
274 int lprocfs_ofd_wr_sync_lock_cancel(struct file *file, const char *buffer,
275 unsigned long count, void *data)
277 struct obd_device *obd = data;
278 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
282 for (i = 0 ; i < NUM_SYNC_ON_CANCEL_STATES; i++) {
283 if (memcmp(buffer, sync_on_cancel_states[i],
284 strlen(sync_on_cancel_states[i])) == 0) {
292 rc = lprocfs_write_helper(buffer, count, &val);
297 if (val < 0 || val > 2)
300 cfs_spin_lock(&ofd->ofd_flags_lock);
301 ofd->ofd_sync_lock_cancel = val;
302 cfs_spin_unlock(&ofd->ofd_flags_lock);
306 static struct lprocfs_vars lprocfs_ofd_obd_vars[] = {
307 { "uuid", lprocfs_rd_uuid, 0, 0 },
308 { "blocksize", lprocfs_rd_blksize, 0, 0 },
309 { "kbytestotal", lprocfs_rd_kbytestotal, 0, 0 },
310 { "kbytesfree", lprocfs_rd_kbytesfree, 0, 0 },
311 { "kbytesavail", lprocfs_rd_kbytesavail, 0, 0 },
312 { "filestotal", lprocfs_rd_filestotal, 0, 0 },
313 { "filesfree", lprocfs_rd_filesfree, 0, 0 },
314 { "filegroups", lprocfs_ofd_rd_groups, 0, 0 },
315 { "fstype", lprocfs_ofd_rd_fstype, 0, 0 },
316 { "last_id", lprocfs_ofd_rd_last_id, 0, 0 },
317 { "recovery_status", lprocfs_obd_rd_recovery_status, 0, 0 },
318 { "recovery_time_soft", lprocfs_obd_rd_recovery_time_soft,
319 lprocfs_obd_wr_recovery_time_soft, 0},
320 { "recovery_time_hard", lprocfs_obd_rd_recovery_time_hard,
321 lprocfs_obd_wr_recovery_time_hard, 0},
322 { "evict_client", 0, lprocfs_wr_evict_client, 0,
323 &lprocfs_evict_client_fops},
324 { "num_exports", lprocfs_rd_num_exports, 0, 0 },
325 { "degraded", lprocfs_ofd_rd_degraded,
326 lprocfs_ofd_wr_degraded, 0},
327 { "sync_journal", lprocfs_ofd_rd_syncjournal,
328 lprocfs_ofd_wr_syncjournal, 0 },
329 { "sync_on_lock_cancel", lprocfs_ofd_rd_sync_lock_cancel,
330 lprocfs_ofd_wr_sync_lock_cancel, 0 },
331 { "instance", lprocfs_target_rd_instance, 0 },
332 { "ir_factor", lprocfs_obd_rd_ir_factor,
333 lprocfs_obd_wr_ir_factor, 0},
334 { "client_cache_count", lprocfs_ofd_rd_fmd_max_num,
335 lprocfs_ofd_wr_fmd_max_num, 0 },
336 { "client_cache_seconds", lprocfs_ofd_rd_fmd_max_age,
337 lprocfs_ofd_wr_fmd_max_age, 0 },
338 { "capa", lprocfs_ofd_rd_capa,
339 lprocfs_ofd_wr_capa, 0 },
340 { "capa_count", lprocfs_ofd_rd_capa_count, 0, 0 },
344 static struct lprocfs_vars lprocfs_ofd_module_vars[] = {
345 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
349 #define pct(a,b) (b ? a * 100 / b : 0)
351 static void display_brw_stats(struct seq_file *seq, char *name, char *units,
352 struct obd_histogram *read,
353 struct obd_histogram *write, int log2)
355 unsigned long read_tot, write_tot, r, w, read_cum = 0, write_cum = 0;
358 seq_printf(seq, "\n%26s read | write\n", " ");
359 seq_printf(seq, "%-22s %-5s %% cum %% | %-5s %% cum %%\n",
362 read_tot = lprocfs_oh_sum(read);
363 write_tot = lprocfs_oh_sum(write);
364 for (i = 0; i < OBD_HIST_MAX; i++) {
365 r = read->oh_buckets[i];
366 w = write->oh_buckets[i];
369 if (read_cum == 0 && write_cum == 0)
373 seq_printf(seq, "%u", i);
375 seq_printf(seq, "%u", 1 << i);
377 seq_printf(seq, "%uK", 1 << (i - 10));
379 seq_printf(seq, "%uM", 1 << (i - 20));
381 seq_printf(seq, ":\t\t%10lu %3lu %3lu | %4lu %3lu %3lu\n",
382 r, pct(r, read_tot), pct(read_cum, read_tot),
383 w, pct(w, write_tot), pct(write_cum, write_tot));
385 if (read_cum == read_tot && write_cum == write_tot)
390 static void brw_stats_show(struct seq_file *seq, struct brw_stats *brw_stats)
395 /* this sampling races with updates */
396 cfs_gettimeofday(&now);
397 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
398 now.tv_sec, now.tv_usec);
400 display_brw_stats(seq, "pages per bulk r/w", "rpcs",
401 &brw_stats->hist[BRW_R_PAGES],
402 &brw_stats->hist[BRW_W_PAGES], 1);
404 display_brw_stats(seq, "discontiguous pages", "rpcs",
405 &brw_stats->hist[BRW_R_DISCONT_PAGES],
406 &brw_stats->hist[BRW_W_DISCONT_PAGES], 0);
408 display_brw_stats(seq, "discontiguous blocks", "rpcs",
409 &brw_stats->hist[BRW_R_DISCONT_BLOCKS],
410 &brw_stats->hist[BRW_W_DISCONT_BLOCKS], 0);
412 display_brw_stats(seq, "disk fragmented I/Os", "ios",
413 &brw_stats->hist[BRW_R_DIO_FRAGS],
414 &brw_stats->hist[BRW_W_DIO_FRAGS], 0);
416 display_brw_stats(seq, "disk I/Os in flight", "ios",
417 &brw_stats->hist[BRW_R_RPC_HIST],
418 &brw_stats->hist[BRW_W_RPC_HIST], 0);
420 sprintf(title, "I/O time (1/%ds)", CFS_HZ);
421 display_brw_stats(seq, title, "ios",
422 &brw_stats->hist[BRW_R_IO_TIME],
423 &brw_stats->hist[BRW_W_IO_TIME], 1);
425 display_brw_stats(seq, "disk I/O size", "ios",
426 &brw_stats->hist[BRW_R_DISK_IOSIZE],
427 &brw_stats->hist[BRW_W_DISK_IOSIZE], 1);
432 static int ofd_brw_stats_seq_show(struct seq_file *seq, void *v)
434 struct obd_device *dev = seq->private;
435 struct filter_obd *ofd = &dev->u.filter;
437 brw_stats_show(seq, &ofd->fo_filter_stats);
442 static ssize_t ofd_brw_stats_seq_write(struct file *file, const char *buf,
443 size_t len, loff_t *off)
445 struct seq_file *seq = file->private_data;
446 struct obd_device *dev = seq->private;
447 struct filter_obd *ofd = &dev->u.filter;
450 for (i = 0; i < BRW_LAST; i++)
451 lprocfs_oh_clear(&ofd->fo_filter_stats.hist[i]);
456 LPROC_SEQ_FOPS(ofd_brw_stats);
458 int lproc_ofd_attach_seqstat(struct obd_device *dev)
460 return lprocfs_obd_seq_create(dev, "brw_stats", 0444,
461 &ofd_brw_stats_fops, dev);
464 void lprocfs_ofd_init_vars(struct lprocfs_static_vars *lvars)
466 lvars->module_vars = lprocfs_ofd_module_vars;
467 lvars->obd_vars = lprocfs_ofd_obd_vars;
470 static int ofd_per_nid_stats_seq_show(struct seq_file *seq, void *v)
472 nid_stat_t *stat = seq->private;
474 if (stat->nid_brw_stats)
475 brw_stats_show(seq, stat->nid_brw_stats);
480 static ssize_t ofd_per_nid_stats_seq_write(struct file *file, const char *buf,
481 size_t len, loff_t *off)
483 struct seq_file *seq = file->private_data;
484 nid_stat_t *stat = seq->private;
487 if (stat->nid_brw_stats)
488 for (i = 0; i < BRW_LAST; i++)
489 lprocfs_oh_clear(&stat->nid_brw_stats->hist[i]);
494 LPROC_SEQ_FOPS(ofd_per_nid_stats);