Whamcloud - gitweb
LU-1330 proc: remove osd proc handlers from lprocfs_status.c
[fs/lustre-release.git] / lustre / osd-zfs / osd_lproc.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
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.
9  *
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).
15  *
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
19  *
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
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  */
30 /*
31  * Copyright (c) 2012, Intel Corporation.
32  * Use is subject to license terms.
33  */
34 /*
35  * This file is part of Lustre, http://www.lustre.org/
36  * Lustre is a trademark of Sun Microsystems, Inc.
37  *
38  * lustre/osd-zfs/osd_lproc.c
39  *
40  * Author: Alex Zhuravlev <bzzz@whamcloud.com>
41  * Author: Mike Pershin <tappro@whamcloud.com>
42  */
43
44 #define DEBUG_SUBSYSTEM S_CLASS
45
46 #include <obd.h>
47 #include <obd_class.h>
48 #include <lprocfs_status.h>
49 #include <lustre/lustre_idl.h>
50
51 #include "udmu.h"
52 #include "osd_internal.h"
53
54 #ifdef LPROCFS
55
56 static int osd_stats_init(struct osd_device *osd)
57 {
58         int result;
59         ENTRY;
60
61         osd->od_stats = lprocfs_alloc_stats(LPROC_OSD_LAST, 0);
62         if (osd->od_stats != NULL) {
63                 result = lprocfs_register_stats(osd->od_proc_entry, "stats",
64                                 osd->od_stats);
65                 if (result)
66                         GOTO(out, result);
67
68                 lprocfs_counter_init(osd->od_stats, LPROC_OSD_GET_PAGE,
69                                 LPROCFS_CNTR_AVGMINMAX|LPROCFS_CNTR_STDDEV,
70                                 "get_page", "usec");
71                 lprocfs_counter_init(osd->od_stats, LPROC_OSD_NO_PAGE,
72                                 LPROCFS_CNTR_AVGMINMAX,
73                                 "get_page_failures", "num");
74                 lprocfs_counter_init(osd->od_stats, LPROC_OSD_CACHE_ACCESS,
75                                 LPROCFS_CNTR_AVGMINMAX,
76                                 "cache_access", "pages");
77                 lprocfs_counter_init(osd->od_stats, LPROC_OSD_CACHE_HIT,
78                                 LPROCFS_CNTR_AVGMINMAX,
79                                 "cache_hit", "pages");
80                 lprocfs_counter_init(osd->od_stats, LPROC_OSD_CACHE_MISS,
81                                 LPROCFS_CNTR_AVGMINMAX,
82                                 "cache_miss", "pages");
83                 lprocfs_counter_init(osd->od_stats, LPROC_OSD_COPY_IO,
84                                 LPROCFS_CNTR_AVGMINMAX,
85                                 "copy", "pages");
86                 lprocfs_counter_init(osd->od_stats, LPROC_OSD_ZEROCOPY_IO,
87                                 LPROCFS_CNTR_AVGMINMAX,
88                                 "zerocopy", "pages");
89                 lprocfs_counter_init(osd->od_stats, LPROC_OSD_TAIL_IO,
90                                 LPROCFS_CNTR_AVGMINMAX,
91                                 "tail", "pages");
92 #ifdef OSD_THANDLE_STATS
93                 lprocfs_counter_init(osd->od_stats, LPROC_OSD_THANDLE_STARTING,
94                                 LPROCFS_CNTR_AVGMINMAX,
95                                 "thandle_starting", "usec");
96                 lprocfs_counter_init(osd->od_stats, LPROC_OSD_THANDLE_OPEN,
97                                 LPROCFS_CNTR_AVGMINMAX,
98                                 "thandle_open", "usec");
99                 lprocfs_counter_init(osd->od_stats, LPROC_OSD_THANDLE_CLOSING,
100                                 LPROCFS_CNTR_AVGMINMAX,
101                                 "thandle_closing", "usec");
102 #endif
103         } else {
104                 result = -ENOMEM;
105         }
106
107 out:
108         RETURN(result);
109 }
110
111 static int lprocfs_osd_rd_fstype(char *page, char **start, off_t off,
112                                 int count, int *eof, void *data)
113 {
114         return snprintf(page, count, "zfs\n");
115 }
116
117 static int lprocfs_osd_rd_mntdev(char *page, char **start, off_t off, int count,
118                                 int *eof, void *data)
119 {
120         struct osd_device *osd = osd_dt_dev((struct dt_device *)data);
121
122         LASSERT(osd != NULL);
123         *eof = 1;
124
125         return snprintf(page, count, "%s\n", osd->od_mntdev);
126 }
127
128 static int lprocfs_osd_wr_force_sync(struct file *file, const char *buffer,
129                                         unsigned long count, void *data)
130 {
131         struct dt_device  *dt = data;
132         struct lu_env      env;
133         int rc;
134
135         rc = lu_env_init(&env, LCT_LOCAL);
136         if (rc)
137                 return rc;
138         rc = dt_sync(&env, dt);
139         lu_env_fini(&env);
140
141         return rc == 0 ? count : rc;
142 }
143
144 static int lprocfs_osd_rd_iused_est(char *page, char **start, off_t off, int count,
145                                         int *eof, void *data)
146 {
147         struct osd_device *osd = osd_dt_dev((struct dt_device *)data);
148         LASSERT(osd != NULL);
149
150         return snprintf(page, count, "%d\n", osd->od_quota_iused_est);
151 }
152
153 static int lprocfs_osd_wr_iused_est(struct file *file, const char *buffer,
154                                         unsigned long count, void *data)
155 {
156         struct osd_device *osd = osd_dt_dev((struct dt_device *)data);
157         int                rc, val;
158
159         LASSERT(osd != NULL);
160
161         rc = lprocfs_write_helper(buffer, count, &val);
162         if (rc)
163                 return rc;
164
165         osd->od_quota_iused_est = !!val;
166
167         return count;
168 }
169
170 struct lprocfs_vars lprocfs_osd_obd_vars[] = {
171         { "blocksize",          lprocfs_dt_rd_blksize,  0, 0 },
172         { "kbytestotal",        lprocfs_dt_rd_kbytestotal,      0, 0 },
173         { "kbytesfree",         lprocfs_dt_rd_kbytesfree,       0, 0 },
174         { "kbytesavail",        lprocfs_dt_rd_kbytesavail,      0, 0 },
175         { "filestotal",         lprocfs_dt_rd_filestotal,       0, 0 },
176         { "filesfree",          lprocfs_dt_rd_filesfree,        0, 0 },
177         { "fstype",          lprocfs_osd_rd_fstype,      0, 0 },
178         { "mntdev",          lprocfs_osd_rd_mntdev,      0, 0 },
179         { "force_sync",      0, lprocfs_osd_wr_force_sync     },
180         { "quota_iused_estimate",  lprocfs_osd_rd_iused_est,
181                 lprocfs_osd_wr_iused_est,   0, 0 },
182         { 0 }
183 };
184
185 struct lprocfs_vars lprocfs_osd_module_vars[] = {
186         { "num_refs",        lprocfs_rd_numrefs,         0, 0 },
187         { 0 }
188 };
189
190 int osd_procfs_init(struct osd_device *osd, const char *name)
191 {
192         struct obd_type *type;
193         int              rc;
194         ENTRY;
195
196         if (osd->od_proc_entry)
197                 RETURN(0);
198
199         /* at the moment there is no linkage between lu_type
200          * and obd_type, so we lookup obd_type this way */
201         type = class_search_type(LUSTRE_OSD_ZFS_NAME);
202
203         LASSERT(name != NULL);
204         LASSERT(type != NULL);
205
206         osd->od_proc_entry = lprocfs_register(name, type->typ_procroot,
207                         lprocfs_osd_obd_vars, &osd->od_dt_dev);
208         if (IS_ERR(osd->od_proc_entry)) {
209                 rc = PTR_ERR(osd->od_proc_entry);
210                 CERROR("Error %d setting up lprocfs for %s\n", rc, name);
211                 osd->od_proc_entry = NULL;
212                 GOTO(out, rc);
213         }
214
215         rc = osd_stats_init(osd);
216
217         GOTO(out, rc);
218 out:
219         if (rc)
220                 osd_procfs_fini(osd);
221         return rc;
222 }
223
224 int osd_procfs_fini(struct osd_device *osd)
225 {
226         ENTRY;
227
228         if (osd->od_stats)
229                 lprocfs_free_stats(&osd->od_stats);
230
231         if (osd->od_proc_entry) {
232                 lprocfs_remove(&osd->od_proc_entry);
233                 osd->od_proc_entry = NULL;
234         }
235
236         RETURN(0);
237 }
238
239 #endif