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 static int lprocfs_ofd_rd_capa(char *page, char **start, off_t off,
83 int count, int *eof, void *data)
85 struct obd_device *obd = data;
88 rc = snprintf(page, count, "capability on: %s\n",
89 obd->u.filter.fo_fl_oss_capa ? "oss" : "");
93 static int lprocfs_ofd_wr_capa(struct file *file, const char *buffer,
94 unsigned long count, void *data)
96 struct obd_device *obd = data;
99 rc = lprocfs_write_helper(buffer, count, &val);
104 CERROR("invalid capability mode, only 0/1 are accepted.\n"
105 " 1: enable oss fid capability\n"
106 " 0: disable oss fid capability\n");
110 obd->u.filter.fo_fl_oss_capa = val;
111 LCONSOLE_INFO("OSS %s %s fid capability.\n", obd->obd_name,
112 val ? "enabled" : "disabled");
116 static int lprocfs_ofd_rd_capa_count(char *page, char **start, off_t off,
117 int count, int *eof, void *data)
119 return snprintf(page, count, "%d %d\n",
120 capa_count[CAPA_SITE_CLIENT],
121 capa_count[CAPA_SITE_SERVER]);
124 int lprocfs_ofd_rd_degraded(char *page, char **start, off_t off,
125 int count, int *eof, void *data)
127 struct obd_device *obd = data;
128 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
130 return snprintf(page, count, "%u\n", ofd->ofd_raid_degraded);
133 int lprocfs_ofd_wr_degraded(struct file *file, const char *buffer,
134 unsigned long count, void *data)
136 struct obd_device *obd = data;
137 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
140 rc = lprocfs_write_helper(buffer, count, &val);
144 cfs_spin_lock(&ofd->ofd_flags_lock);
145 ofd->ofd_raid_degraded = !!val;
146 cfs_spin_unlock(&ofd->ofd_flags_lock);
151 int lprocfs_ofd_rd_fstype(char *page, char **start, off_t off, int count,
152 int *eof, void *data)
154 struct obd_device *obd = data;
155 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
158 LASSERT(ofd->ofd_osd);
159 d = &ofd->ofd_osd->dd_lu_dev;
161 return snprintf(page, count, "%s\n", d->ld_type->ldt_name);
164 int lprocfs_ofd_rd_syncjournal(char *page, char **start, off_t off,
165 int count, int *eof, void *data)
167 struct obd_device *obd = data;
168 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
171 rc = snprintf(page, count, "%u\n", ofd->ofd_syncjournal);
175 int lprocfs_ofd_wr_syncjournal(struct file *file, const char *buffer,
176 unsigned long count, void *data)
178 struct obd_device *obd = data;
179 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
183 rc = lprocfs_write_helper(buffer, count, &val);
190 cfs_spin_lock(&ofd->ofd_flags_lock);
191 ofd->ofd_syncjournal = !!val;
193 cfs_spin_unlock(&ofd->ofd_flags_lock);
198 static char *sync_on_cancel_states[] = {"never",
202 int lprocfs_ofd_rd_sync_lock_cancel(char *page, char **start, off_t off,
203 int count, int *eof, void *data)
205 struct obd_device *obd = data;
206 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
209 rc = snprintf(page, count, "%s\n",
210 sync_on_cancel_states[ofd->ofd_sync_lock_cancel]);
214 int lprocfs_ofd_wr_sync_lock_cancel(struct file *file, const char *buffer,
215 unsigned long count, void *data)
217 struct obd_device *obd = data;
218 struct ofd_device *ofd = ofd_dev(obd->obd_lu_dev);
222 for (i = 0 ; i < NUM_SYNC_ON_CANCEL_STATES; i++) {
223 if (memcmp(buffer, sync_on_cancel_states[i],
224 strlen(sync_on_cancel_states[i])) == 0) {
232 rc = lprocfs_write_helper(buffer, count, &val);
237 if (val < 0 || val > 2)
240 cfs_spin_lock(&ofd->ofd_flags_lock);
241 ofd->ofd_sync_lock_cancel = val;
242 cfs_spin_unlock(&ofd->ofd_flags_lock);
246 static struct lprocfs_vars lprocfs_ofd_obd_vars[] = {
247 { "uuid", lprocfs_rd_uuid, 0, 0 },
248 { "blocksize", lprocfs_rd_blksize, 0, 0 },
249 { "kbytestotal", lprocfs_rd_kbytestotal, 0, 0 },
250 { "kbytesfree", lprocfs_rd_kbytesfree, 0, 0 },
251 { "kbytesavail", lprocfs_rd_kbytesavail, 0, 0 },
252 { "filestotal", lprocfs_rd_filestotal, 0, 0 },
253 { "filesfree", lprocfs_rd_filesfree, 0, 0 },
254 { "filegroups", lprocfs_ofd_rd_groups, 0, 0 },
255 { "fstype", lprocfs_ofd_rd_fstype, 0, 0 },
256 { "last_id", lprocfs_ofd_rd_last_id, 0, 0 },
257 { "recovery_status", lprocfs_obd_rd_recovery_status, 0, 0 },
258 { "recovery_time_soft", lprocfs_obd_rd_recovery_time_soft,
259 lprocfs_obd_wr_recovery_time_soft, 0},
260 { "recovery_time_hard", lprocfs_obd_rd_recovery_time_hard,
261 lprocfs_obd_wr_recovery_time_hard, 0},
262 { "evict_client", 0, lprocfs_wr_evict_client, 0,
263 &lprocfs_evict_client_fops},
264 { "num_exports", lprocfs_rd_num_exports, 0, 0 },
265 { "degraded", lprocfs_ofd_rd_degraded,
266 lprocfs_ofd_wr_degraded, 0},
267 { "sync_journal", lprocfs_ofd_rd_syncjournal,
268 lprocfs_ofd_wr_syncjournal, 0 },
269 { "sync_on_lock_cancel", lprocfs_ofd_rd_sync_lock_cancel,
270 lprocfs_ofd_wr_sync_lock_cancel, 0 },
271 { "instance", lprocfs_target_rd_instance, 0 },
272 { "ir_factor", lprocfs_obd_rd_ir_factor,
273 lprocfs_obd_wr_ir_factor, 0},
274 { "capa", lprocfs_ofd_rd_capa,
275 lprocfs_ofd_wr_capa, 0 },
276 { "capa_count", lprocfs_ofd_rd_capa_count, 0, 0 },
280 static struct lprocfs_vars lprocfs_ofd_module_vars[] = {
281 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
285 #define pct(a,b) (b ? a * 100 / b : 0)
287 static void display_brw_stats(struct seq_file *seq, char *name, char *units,
288 struct obd_histogram *read,
289 struct obd_histogram *write, int log2)
291 unsigned long read_tot, write_tot, r, w, read_cum = 0, write_cum = 0;
294 seq_printf(seq, "\n%26s read | write\n", " ");
295 seq_printf(seq, "%-22s %-5s %% cum %% | %-5s %% cum %%\n",
298 read_tot = lprocfs_oh_sum(read);
299 write_tot = lprocfs_oh_sum(write);
300 for (i = 0; i < OBD_HIST_MAX; i++) {
301 r = read->oh_buckets[i];
302 w = write->oh_buckets[i];
305 if (read_cum == 0 && write_cum == 0)
309 seq_printf(seq, "%u", i);
311 seq_printf(seq, "%u", 1 << i);
313 seq_printf(seq, "%uK", 1 << (i - 10));
315 seq_printf(seq, "%uM", 1 << (i - 20));
317 seq_printf(seq, ":\t\t%10lu %3lu %3lu | %4lu %3lu %3lu\n",
318 r, pct(r, read_tot), pct(read_cum, read_tot),
319 w, pct(w, write_tot), pct(write_cum, write_tot));
321 if (read_cum == read_tot && write_cum == write_tot)
326 static void brw_stats_show(struct seq_file *seq, struct brw_stats *brw_stats)
331 /* this sampling races with updates */
332 cfs_gettimeofday(&now);
333 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
334 now.tv_sec, now.tv_usec);
336 display_brw_stats(seq, "pages per bulk r/w", "rpcs",
337 &brw_stats->hist[BRW_R_PAGES],
338 &brw_stats->hist[BRW_W_PAGES], 1);
340 display_brw_stats(seq, "discontiguous pages", "rpcs",
341 &brw_stats->hist[BRW_R_DISCONT_PAGES],
342 &brw_stats->hist[BRW_W_DISCONT_PAGES], 0);
344 display_brw_stats(seq, "discontiguous blocks", "rpcs",
345 &brw_stats->hist[BRW_R_DISCONT_BLOCKS],
346 &brw_stats->hist[BRW_W_DISCONT_BLOCKS], 0);
348 display_brw_stats(seq, "disk fragmented I/Os", "ios",
349 &brw_stats->hist[BRW_R_DIO_FRAGS],
350 &brw_stats->hist[BRW_W_DIO_FRAGS], 0);
352 display_brw_stats(seq, "disk I/Os in flight", "ios",
353 &brw_stats->hist[BRW_R_RPC_HIST],
354 &brw_stats->hist[BRW_W_RPC_HIST], 0);
356 sprintf(title, "I/O time (1/%ds)", CFS_HZ);
357 display_brw_stats(seq, title, "ios",
358 &brw_stats->hist[BRW_R_IO_TIME],
359 &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);
368 static int ofd_brw_stats_seq_show(struct seq_file *seq, void *v)
370 struct obd_device *dev = seq->private;
371 struct filter_obd *ofd = &dev->u.filter;
373 brw_stats_show(seq, &ofd->fo_filter_stats);
378 static ssize_t ofd_brw_stats_seq_write(struct file *file, const char *buf,
379 size_t len, loff_t *off)
381 struct seq_file *seq = file->private_data;
382 struct obd_device *dev = seq->private;
383 struct filter_obd *ofd = &dev->u.filter;
386 for (i = 0; i < BRW_LAST; i++)
387 lprocfs_oh_clear(&ofd->fo_filter_stats.hist[i]);
392 LPROC_SEQ_FOPS(ofd_brw_stats);
394 int lproc_ofd_attach_seqstat(struct obd_device *dev)
396 return lprocfs_obd_seq_create(dev, "brw_stats", 0444,
397 &ofd_brw_stats_fops, dev);
400 void lprocfs_ofd_init_vars(struct lprocfs_static_vars *lvars)
402 lvars->module_vars = lprocfs_ofd_module_vars;
403 lvars->obd_vars = lprocfs_ofd_obd_vars;
406 static int ofd_per_nid_stats_seq_show(struct seq_file *seq, void *v)
408 nid_stat_t *stat = seq->private;
410 if (stat->nid_brw_stats)
411 brw_stats_show(seq, stat->nid_brw_stats);
416 static ssize_t ofd_per_nid_stats_seq_write(struct file *file, const char *buf,
417 size_t len, loff_t *off)
419 struct seq_file *seq = file->private_data;
420 nid_stat_t *stat = seq->private;
423 if (stat->nid_brw_stats)
424 for (i = 0; i < BRW_LAST; i++)
425 lprocfs_oh_clear(&stat->nid_brw_stats->hist[i]);
430 LPROC_SEQ_FOPS(ofd_per_nid_stats);