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) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
31 * Copyright (c) 2012, Intel Corporation.
32 * Use is subject to license terms.
35 * This file is part of Lustre, http://www.lustre.org/
36 * Lustre is a trademark of Sun Microsystems, Inc.
38 * lustre/osd-zfs/osd_lproc.c
40 * Author: Alex Zhuravlev <bzzz@whamcloud.com>
41 * Author: Mike Pershin <tappro@whamcloud.com>
44 #define DEBUG_SUBSYSTEM S_OSD
47 #include <obd_class.h>
48 #include <lprocfs_status.h>
49 #include <lustre/lustre_idl.h>
51 #include "osd_internal.h"
55 static int osd_stats_init(struct osd_device *osd)
60 osd->od_stats = lprocfs_alloc_stats(LPROC_OSD_LAST, 0);
61 if (osd->od_stats != NULL) {
62 result = lprocfs_register_stats(osd->od_proc_entry, "stats",
67 lprocfs_counter_init(osd->od_stats, LPROC_OSD_GET_PAGE,
68 LPROCFS_CNTR_AVGMINMAX|LPROCFS_CNTR_STDDEV,
70 lprocfs_counter_init(osd->od_stats, LPROC_OSD_NO_PAGE,
71 LPROCFS_CNTR_AVGMINMAX,
72 "get_page_failures", "num");
73 lprocfs_counter_init(osd->od_stats, LPROC_OSD_CACHE_ACCESS,
74 LPROCFS_CNTR_AVGMINMAX,
75 "cache_access", "pages");
76 lprocfs_counter_init(osd->od_stats, LPROC_OSD_CACHE_HIT,
77 LPROCFS_CNTR_AVGMINMAX,
78 "cache_hit", "pages");
79 lprocfs_counter_init(osd->od_stats, LPROC_OSD_CACHE_MISS,
80 LPROCFS_CNTR_AVGMINMAX,
81 "cache_miss", "pages");
82 lprocfs_counter_init(osd->od_stats, LPROC_OSD_COPY_IO,
83 LPROCFS_CNTR_AVGMINMAX,
85 lprocfs_counter_init(osd->od_stats, LPROC_OSD_ZEROCOPY_IO,
86 LPROCFS_CNTR_AVGMINMAX,
88 lprocfs_counter_init(osd->od_stats, LPROC_OSD_TAIL_IO,
89 LPROCFS_CNTR_AVGMINMAX,
91 #ifdef OSD_THANDLE_STATS
92 lprocfs_counter_init(osd->od_stats, LPROC_OSD_THANDLE_STARTING,
93 LPROCFS_CNTR_AVGMINMAX,
94 "thandle_starting", "usec");
95 lprocfs_counter_init(osd->od_stats, LPROC_OSD_THANDLE_OPEN,
96 LPROCFS_CNTR_AVGMINMAX,
97 "thandle_open", "usec");
98 lprocfs_counter_init(osd->od_stats, LPROC_OSD_THANDLE_CLOSING,
99 LPROCFS_CNTR_AVGMINMAX,
100 "thandle_closing", "usec");
110 static int zfs_osd_fstype_seq_show(struct seq_file *m, void *data)
112 return seq_printf(m, "zfs\n");
114 LPROC_SEQ_FOPS_RO(zfs_osd_fstype);
116 static int zfs_osd_mntdev_seq_show(struct seq_file *m, void *data)
118 struct osd_device *osd = osd_dt_dev((struct dt_device *)m->private);
120 LASSERT(osd != NULL);
121 return seq_printf(m, "%s\n", osd->od_mntdev);
123 LPROC_SEQ_FOPS_RO(zfs_osd_mntdev);
126 lprocfs_osd_force_sync_seq_write(struct file *file, const char __user *buffer,
127 size_t count, loff_t *off)
129 struct seq_file *m = file->private_data;
130 struct dt_device *dt = m->private;
134 rc = lu_env_init(&env, LCT_LOCAL);
137 rc = dt_sync(&env, dt);
140 return rc == 0 ? count : rc;
142 LPROC_SEQ_FOPS_WO_TYPE(zfs, osd_force_sync);
144 static int zfs_osd_iused_est_seq_show(struct seq_file *m, void *data)
146 struct osd_device *osd = osd_dt_dev((struct dt_device *)m->private);
147 LASSERT(osd != NULL);
149 return seq_printf(m, "%d\n", osd->od_quota_iused_est);
153 zfs_osd_iused_est_seq_write(struct file *file, const char __user *buffer,
154 size_t count, loff_t *off)
156 struct seq_file *m = file->private_data;
157 struct dt_device *dt = m->private;
158 struct osd_device *osd = osd_dt_dev(dt);
161 LASSERT(osd != NULL);
163 rc = lprocfs_write_helper(buffer, count, &val);
167 osd->od_quota_iused_est = !!val;
171 LPROC_SEQ_FOPS(zfs_osd_iused_est);
173 LPROC_SEQ_FOPS_RO_TYPE(zfs, dt_blksize);
174 LPROC_SEQ_FOPS_RO_TYPE(zfs, dt_kbytestotal);
175 LPROC_SEQ_FOPS_RO_TYPE(zfs, dt_kbytesfree);
176 LPROC_SEQ_FOPS_RO_TYPE(zfs, dt_kbytesavail);
177 LPROC_SEQ_FOPS_RO_TYPE(zfs, dt_filestotal);
178 LPROC_SEQ_FOPS_RO_TYPE(zfs, dt_filesfree);
180 struct lprocfs_seq_vars lprocfs_osd_obd_vars[] = {
181 { .name = "blocksize",
182 .fops = &zfs_dt_blksize_fops },
183 { .name = "kbytestotal",
184 .fops = &zfs_dt_kbytestotal_fops },
185 { .name = "kbytesfree",
186 .fops = &zfs_dt_kbytesfree_fops },
187 { .name = "kbytesavail",
188 .fops = &zfs_dt_kbytesavail_fops },
189 { .name = "filestotal",
190 .fops = &zfs_dt_filestotal_fops },
191 { .name = "filesfree",
192 .fops = &zfs_dt_filesfree_fops },
194 .fops = &zfs_osd_fstype_fops },
196 .fops = &zfs_osd_mntdev_fops },
197 { .name = "force_sync",
198 .fops = &zfs_osd_force_sync_fops },
199 { .name = "quota_iused_estimate",
200 .fops = &zfs_osd_iused_est_fops },
204 int osd_procfs_init(struct osd_device *osd, const char *name)
206 struct obd_type *type;
210 if (osd->od_proc_entry)
213 /* at the moment there is no linkage between lu_type
214 * and obd_type, so we lookup obd_type this way */
215 type = class_search_type(LUSTRE_OSD_ZFS_NAME);
217 LASSERT(name != NULL);
218 LASSERT(type != NULL);
220 osd->od_proc_entry = lprocfs_seq_register(name, type->typ_procroot,
221 lprocfs_osd_obd_vars, &osd->od_dt_dev);
222 if (IS_ERR(osd->od_proc_entry)) {
223 rc = PTR_ERR(osd->od_proc_entry);
224 CERROR("Error %d setting up lprocfs for %s\n", rc, name);
225 osd->od_proc_entry = NULL;
229 rc = osd_stats_init(osd);
234 osd_procfs_fini(osd);
238 int osd_procfs_fini(struct osd_device *osd)
243 lprocfs_free_stats(&osd->od_stats);
245 if (osd->od_proc_entry) {
246 lprocfs_remove(&osd->od_proc_entry);
247 osd->od_proc_entry = NULL;