Whamcloud - gitweb
LU-1305 osd: object index for osd-zfs
[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 <lprocfs_status.h>
48 #include <lu_time.h>
49
50 #include <lustre/lustre_idl.h>
51
52 #include "udmu.h"
53 #include "osd_internal.h"
54
55 #ifdef LPROCFS
56
57 static int osd_stats_init(struct osd_device *osd)
58 {
59         int result;
60         ENTRY;
61
62         osd->od_stats = lprocfs_alloc_stats(LPROC_OSD_LAST, 0);
63         if (osd->od_stats != NULL) {
64                 result = lprocfs_register_stats(osd->od_proc_entry, "stats",
65                                 osd->od_stats);
66                 if (result)
67                         GOTO(out, result);
68
69                 lprocfs_counter_init(osd->od_stats, LPROC_OSD_GET_PAGE,
70                                 LPROCFS_CNTR_AVGMINMAX|LPROCFS_CNTR_STDDEV,
71                                 "get_page", "usec");
72                 lprocfs_counter_init(osd->od_stats, LPROC_OSD_NO_PAGE,
73                                 LPROCFS_CNTR_AVGMINMAX,
74                                 "get_page_failures", "num");
75                 lprocfs_counter_init(osd->od_stats, LPROC_OSD_CACHE_ACCESS,
76                                 LPROCFS_CNTR_AVGMINMAX,
77                                 "cache_access", "pages");
78                 lprocfs_counter_init(osd->od_stats, LPROC_OSD_CACHE_HIT,
79                                 LPROCFS_CNTR_AVGMINMAX,
80                                 "cache_hit", "pages");
81                 lprocfs_counter_init(osd->od_stats, LPROC_OSD_CACHE_MISS,
82                                 LPROCFS_CNTR_AVGMINMAX,
83                                 "cache_miss", "pages");
84                 lprocfs_counter_init(osd->od_stats, LPROC_OSD_COPY_IO,
85                                 LPROCFS_CNTR_AVGMINMAX,
86                                 "copy", "pages");
87                 lprocfs_counter_init(osd->od_stats, LPROC_OSD_ZEROCOPY_IO,
88                                 LPROCFS_CNTR_AVGMINMAX,
89                                 "zerocopy", "pages");
90                 lprocfs_counter_init(osd->od_stats, LPROC_OSD_TAIL_IO,
91                                 LPROCFS_CNTR_AVGMINMAX,
92                                 "tail", "pages");
93 #ifdef OSD_THANDLE_STATS
94                 lprocfs_counter_init(osd->od_stats, LPROC_OSD_THANDLE_STARTING,
95                                 LPROCFS_CNTR_AVGMINMAX,
96                                 "thandle_starting", "usec");
97                 lprocfs_counter_init(osd->od_stats, LPROC_OSD_THANDLE_OPEN,
98                                 LPROCFS_CNTR_AVGMINMAX,
99                                 "thandle_open", "usec");
100                 lprocfs_counter_init(osd->od_stats, LPROC_OSD_THANDLE_CLOSING,
101                                 LPROCFS_CNTR_AVGMINMAX,
102                                 "thandle_closing", "usec");
103 #endif
104         } else {
105                 result = -ENOMEM;
106         }
107
108 out:
109         RETURN(result);
110 }
111
112 static int lprocfs_osd_rd_fstype(char *page, char **start, off_t off,
113                                 int count, int *eof, void *data)
114 {
115         return snprintf(page, count, "zfs\n");
116 }
117
118 static int lprocfs_osd_rd_mntdev(char *page, char **start, off_t off, int count,
119                                 int *eof, void *data)
120 {
121         struct osd_device *osd = osd_dt_dev((struct dt_device *)data);
122
123         LASSERT(osd != NULL);
124         *eof = 1;
125
126         return snprintf(page, count, "%s\n", osd->od_mntdev);
127 }
128
129 static int lprocfs_osd_wr_force_sync(struct file *file, const char *buffer,
130                                         unsigned long count, void *data)
131 {
132         struct dt_device  *dt = data;
133         struct lu_env      env;
134         int rc;
135
136         rc = lu_env_init(&env, LCT_LOCAL);
137         if (rc)
138                 return rc;
139         rc = dt_sync(&env, dt);
140         lu_env_fini(&env);
141
142         return rc == 0 ? count : rc;
143 }
144
145 static int lprocfs_osd_rd_iused_est(char *page, char **start, off_t off, int count,
146                                         int *eof, void *data)
147 {
148         struct osd_device *osd = osd_dt_dev((struct dt_device *)data);
149         LASSERT(osd != NULL);
150
151         return snprintf(page, count, "%d\n", osd->od_quota_iused_est);
152 }
153
154 static int lprocfs_osd_wr_iused_est(struct file *file, const char *buffer,
155                                         unsigned long count, void *data)
156 {
157         struct osd_device *osd = osd_dt_dev((struct dt_device *)data);
158         int                rc, val;
159
160         LASSERT(osd != NULL);
161
162         rc = lprocfs_write_helper(buffer, count, &val);
163         if (rc)
164                 return rc;
165
166         osd->od_quota_iused_est = !!val;
167
168         return count;
169 }
170
171 struct lprocfs_vars lprocfs_osd_obd_vars[] = {
172         { "blocksize",       lprocfs_osd_rd_blksize,     0, 0 },
173         { "kbytestotal",     lprocfs_osd_rd_kbytestotal, 0, 0 },
174         { "kbytesfree",      lprocfs_osd_rd_kbytesfree,  0, 0 },
175         { "kbytesavail",     lprocfs_osd_rd_kbytesavail, 0, 0 },
176         { "filestotal",      lprocfs_osd_rd_filestotal,  0, 0 },
177         { "filesfree",       lprocfs_osd_rd_filesfree,   0, 0 },
178         { "fstype",          lprocfs_osd_rd_fstype,      0, 0 },
179         { "mntdev",          lprocfs_osd_rd_mntdev,      0, 0 },
180         { "force_sync",      0, lprocfs_osd_wr_force_sync     },
181         { "quota_iused_estimate",  lprocfs_osd_rd_iused_est,
182                 lprocfs_osd_wr_iused_est,   0, 0 },
183         { 0 }
184 };
185
186 struct lprocfs_vars lprocfs_osd_module_vars[] = {
187         { "num_refs",        lprocfs_rd_numrefs,         0, 0 },
188         { 0 }
189 };
190
191 int osd_procfs_init(struct osd_device *osd, const char *name)
192 {
193         struct lu_device    *ld = &osd->od_dt_dev.dd_lu_dev;
194         struct obd_type     *type = ld->ld_type->ldt_obd_type;
195         int                  rc;
196         ENTRY;
197
198         if (osd->od_proc_entry)
199                 RETURN(0);
200
201         LASSERT(name != NULL);
202         LASSERT(type != NULL);
203
204         osd->od_proc_entry = lprocfs_register(name, type->typ_procroot,
205                         lprocfs_osd_obd_vars, &osd->od_dt_dev);
206         if (IS_ERR(osd->od_proc_entry)) {
207                 rc = PTR_ERR(osd->od_proc_entry);
208                 CERROR("Error %d setting up lprocfs for %s\n", rc, name);
209                 osd->od_proc_entry = NULL;
210                 GOTO(out, rc);
211         }
212
213         rc = osd_stats_init(osd);
214
215         GOTO(out, rc);
216 out:
217         if (rc)
218                 osd_procfs_fini(osd);
219         return rc;
220 }
221
222 int osd_procfs_fini(struct osd_device *osd)
223 {
224         ENTRY;
225
226         if (osd->od_stats)
227                 lprocfs_free_stats(&osd->od_stats);
228
229         if (osd->od_proc_entry) {
230                 lprocfs_remove(&osd->od_proc_entry);
231                 osd->od_proc_entry = NULL;
232         }
233
234         RETURN(0);
235 }
236
237 #endif