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_CLASS
47 #include <obd_class.h>
48 #include <lprocfs_status.h>
51 #include <lustre/lustre_idl.h>
54 #include "osd_internal.h"
58 static int osd_stats_init(struct osd_device *osd)
63 osd->od_stats = lprocfs_alloc_stats(LPROC_OSD_LAST, 0);
64 if (osd->od_stats != NULL) {
65 result = lprocfs_register_stats(osd->od_proc_entry, "stats",
70 lprocfs_counter_init(osd->od_stats, LPROC_OSD_GET_PAGE,
71 LPROCFS_CNTR_AVGMINMAX|LPROCFS_CNTR_STDDEV,
73 lprocfs_counter_init(osd->od_stats, LPROC_OSD_NO_PAGE,
74 LPROCFS_CNTR_AVGMINMAX,
75 "get_page_failures", "num");
76 lprocfs_counter_init(osd->od_stats, LPROC_OSD_CACHE_ACCESS,
77 LPROCFS_CNTR_AVGMINMAX,
78 "cache_access", "pages");
79 lprocfs_counter_init(osd->od_stats, LPROC_OSD_CACHE_HIT,
80 LPROCFS_CNTR_AVGMINMAX,
81 "cache_hit", "pages");
82 lprocfs_counter_init(osd->od_stats, LPROC_OSD_CACHE_MISS,
83 LPROCFS_CNTR_AVGMINMAX,
84 "cache_miss", "pages");
85 lprocfs_counter_init(osd->od_stats, LPROC_OSD_COPY_IO,
86 LPROCFS_CNTR_AVGMINMAX,
88 lprocfs_counter_init(osd->od_stats, LPROC_OSD_ZEROCOPY_IO,
89 LPROCFS_CNTR_AVGMINMAX,
91 lprocfs_counter_init(osd->od_stats, LPROC_OSD_TAIL_IO,
92 LPROCFS_CNTR_AVGMINMAX,
94 #ifdef OSD_THANDLE_STATS
95 lprocfs_counter_init(osd->od_stats, LPROC_OSD_THANDLE_STARTING,
96 LPROCFS_CNTR_AVGMINMAX,
97 "thandle_starting", "usec");
98 lprocfs_counter_init(osd->od_stats, LPROC_OSD_THANDLE_OPEN,
99 LPROCFS_CNTR_AVGMINMAX,
100 "thandle_open", "usec");
101 lprocfs_counter_init(osd->od_stats, LPROC_OSD_THANDLE_CLOSING,
102 LPROCFS_CNTR_AVGMINMAX,
103 "thandle_closing", "usec");
113 static int lprocfs_osd_rd_fstype(char *page, char **start, off_t off,
114 int count, int *eof, void *data)
116 return snprintf(page, count, "zfs\n");
119 static int lprocfs_osd_rd_mntdev(char *page, char **start, off_t off, int count,
120 int *eof, void *data)
122 struct osd_device *osd = osd_dt_dev((struct dt_device *)data);
124 LASSERT(osd != NULL);
127 return snprintf(page, count, "%s\n", osd->od_mntdev);
130 static int lprocfs_osd_wr_force_sync(struct file *file, const char *buffer,
131 unsigned long count, void *data)
133 struct dt_device *dt = data;
137 rc = lu_env_init(&env, LCT_LOCAL);
140 rc = dt_sync(&env, dt);
143 return rc == 0 ? count : rc;
146 static int lprocfs_osd_rd_iused_est(char *page, char **start, off_t off, int count,
147 int *eof, void *data)
149 struct osd_device *osd = osd_dt_dev((struct dt_device *)data);
150 LASSERT(osd != NULL);
152 return snprintf(page, count, "%d\n", osd->od_quota_iused_est);
155 static int lprocfs_osd_wr_iused_est(struct file *file, const char *buffer,
156 unsigned long count, void *data)
158 struct osd_device *osd = osd_dt_dev((struct dt_device *)data);
161 LASSERT(osd != NULL);
163 rc = lprocfs_write_helper(buffer, count, &val);
167 osd->od_quota_iused_est = !!val;
172 struct lprocfs_vars lprocfs_osd_obd_vars[] = {
173 { "blocksize", lprocfs_osd_rd_blksize, 0, 0 },
174 { "kbytestotal", lprocfs_osd_rd_kbytestotal, 0, 0 },
175 { "kbytesfree", lprocfs_osd_rd_kbytesfree, 0, 0 },
176 { "kbytesavail", lprocfs_osd_rd_kbytesavail, 0, 0 },
177 { "filestotal", lprocfs_osd_rd_filestotal, 0, 0 },
178 { "filesfree", lprocfs_osd_rd_filesfree, 0, 0 },
179 { "fstype", lprocfs_osd_rd_fstype, 0, 0 },
180 { "mntdev", lprocfs_osd_rd_mntdev, 0, 0 },
181 { "force_sync", 0, lprocfs_osd_wr_force_sync },
182 { "quota_iused_estimate", lprocfs_osd_rd_iused_est,
183 lprocfs_osd_wr_iused_est, 0, 0 },
187 struct lprocfs_vars lprocfs_osd_module_vars[] = {
188 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
192 int osd_procfs_init(struct osd_device *osd, const char *name)
194 struct obd_type *type;
198 if (osd->od_proc_entry)
201 /* at the moment there is no linkage between lu_type
202 * and obd_type, so we lookup obd_type this way */
203 type = class_search_type(LUSTRE_OSD_ZFS_NAME);
205 LASSERT(name != NULL);
206 LASSERT(type != NULL);
208 osd->od_proc_entry = lprocfs_register(name, type->typ_procroot,
209 lprocfs_osd_obd_vars, &osd->od_dt_dev);
210 if (IS_ERR(osd->od_proc_entry)) {
211 rc = PTR_ERR(osd->od_proc_entry);
212 CERROR("Error %d setting up lprocfs for %s\n", rc, name);
213 osd->od_proc_entry = NULL;
217 rc = osd_stats_init(osd);
222 osd_procfs_fini(osd);
226 int osd_procfs_fini(struct osd_device *osd)
231 lprocfs_free_stats(&osd->od_stats);
233 if (osd->od_proc_entry) {
234 lprocfs_remove(&osd->od_proc_entry);
235 osd->od_proc_entry = NULL;