Whamcloud - gitweb
LU-1883 osd: Fix niobuf_local offset usage
[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) 2011, 2012 Whamcloud, Inc.
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 <lu_time.h>
50
51 #include <lustre/lustre_idl.h>
52
53 #include "udmu.h"
54 #include "osd_internal.h"
55
56 #ifdef LPROCFS
57
58 static int osd_stats_init(struct osd_device *osd)
59 {
60         int result;
61         ENTRY;
62
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",
66                                 osd->od_stats);
67                 if (result)
68                         GOTO(out, result);
69
70                 lprocfs_counter_init(osd->od_stats, LPROC_OSD_GET_PAGE,
71                                 LPROCFS_CNTR_AVGMINMAX|LPROCFS_CNTR_STDDEV,
72                                 "get_page", "usec");
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,
87                                 "copy", "pages");
88                 lprocfs_counter_init(osd->od_stats, LPROC_OSD_ZEROCOPY_IO,
89                                 LPROCFS_CNTR_AVGMINMAX,
90                                 "zerocopy", "pages");
91                 lprocfs_counter_init(osd->od_stats, LPROC_OSD_TAIL_IO,
92                                 LPROCFS_CNTR_AVGMINMAX,
93                                 "tail", "pages");
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");
104 #endif
105         } else {
106                 result = -ENOMEM;
107         }
108
109 out:
110         RETURN(result);
111 }
112
113 static int lprocfs_osd_rd_fstype(char *page, char **start, off_t off,
114                                 int count, int *eof, void *data)
115 {
116         return snprintf(page, count, "zfs\n");
117 }
118
119 static int lprocfs_osd_rd_mntdev(char *page, char **start, off_t off, int count,
120                                 int *eof, void *data)
121 {
122         struct osd_device *osd = osd_dt_dev((struct dt_device *)data);
123
124         LASSERT(osd != NULL);
125         *eof = 1;
126
127         return snprintf(page, count, "%s\n", osd->od_mntdev);
128 }
129
130 static int lprocfs_osd_wr_force_sync(struct file *file, const char *buffer,
131                                         unsigned long count, void *data)
132 {
133         struct dt_device  *dt = data;
134         struct lu_env      env;
135         int rc;
136
137         rc = lu_env_init(&env, LCT_LOCAL);
138         if (rc)
139                 return rc;
140         rc = dt_sync(&env, dt);
141         lu_env_fini(&env);
142
143         return rc == 0 ? count : rc;
144 }
145
146 static int lprocfs_osd_rd_iused_est(char *page, char **start, off_t off, int count,
147                                         int *eof, void *data)
148 {
149         struct osd_device *osd = osd_dt_dev((struct dt_device *)data);
150         LASSERT(osd != NULL);
151
152         return snprintf(page, count, "%d\n", osd->od_quota_iused_est);
153 }
154
155 static int lprocfs_osd_wr_iused_est(struct file *file, const char *buffer,
156                                         unsigned long count, void *data)
157 {
158         struct osd_device *osd = osd_dt_dev((struct dt_device *)data);
159         int                rc, val;
160
161         LASSERT(osd != NULL);
162
163         rc = lprocfs_write_helper(buffer, count, &val);
164         if (rc)
165                 return rc;
166
167         osd->od_quota_iused_est = !!val;
168
169         return count;
170 }
171
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 },
184         { 0 }
185 };
186
187 struct lprocfs_vars lprocfs_osd_module_vars[] = {
188         { "num_refs",        lprocfs_rd_numrefs,         0, 0 },
189         { 0 }
190 };
191
192 int osd_procfs_init(struct osd_device *osd, const char *name)
193 {
194         struct obd_type *type;
195         int              rc;
196         ENTRY;
197
198         if (osd->od_proc_entry)
199                 RETURN(0);
200
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);
204
205         LASSERT(name != NULL);
206         LASSERT(type != NULL);
207
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;
214                 GOTO(out, rc);
215         }
216
217         rc = osd_stats_init(osd);
218
219         GOTO(out, rc);
220 out:
221         if (rc)
222                 osd_procfs_fini(osd);
223         return rc;
224 }
225
226 int osd_procfs_fini(struct osd_device *osd)
227 {
228         ENTRY;
229
230         if (osd->od_stats)
231                 lprocfs_free_stats(&osd->od_stats);
232
233         if (osd->od_proc_entry) {
234                 lprocfs_remove(&osd->od_proc_entry);
235                 osd->od_proc_entry = NULL;
236         }
237
238         RETURN(0);
239 }
240
241 #endif