Whamcloud - gitweb
LU-1146 build: batch update copyright messages
[fs/lustre-release.git] / lustre / osd-ldiskfs / osd_lproc.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
30  * Use is subject to license terms.
31  *
32  * Copyright (c) 2011, Whamcloud, Inc.
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/osd_lproc.c
39  *
40  * Author: Mikhail Pershin <tappro@sun.com>
41  */
42
43 #define DEBUG_SUBSYSTEM S_CLASS
44
45 #include <lprocfs_status.h>
46 #include <lu_time.h>
47
48 #include <lustre/lustre_idl.h>
49
50 #include "osd_internal.h"
51
52 #ifdef LPROCFS
53
54 static const char *osd_counter_names[LPROC_OSD_NR] = {
55 #if OSD_THANDLE_STATS
56         [LPROC_OSD_THANDLE_STARTING] = "thandle starting",
57         [LPROC_OSD_THANDLE_OPEN]     = "thandle open",
58         [LPROC_OSD_THANDLE_CLOSING]  = "thandle closing"
59 #endif
60 };
61
62 int osd_procfs_init(struct osd_device *osd, const char *name)
63 {
64         struct lprocfs_static_vars lvars;
65         struct lu_device    *ld = &osd->od_dt_dev.dd_lu_dev;
66         struct obd_type     *type;
67         int                  rc;
68         ENTRY;
69
70         type = ld->ld_type->ldt_obd_type;
71
72         LASSERT(name != NULL);
73         LASSERT(type != NULL);
74
75         /* Find the type procroot and add the proc entry for this device */
76         lprocfs_osd_init_vars(&lvars);
77         osd->od_proc_entry = lprocfs_register(name, type->typ_procroot,
78                                               lvars.obd_vars, osd);
79         if (IS_ERR(osd->od_proc_entry)) {
80                 rc = PTR_ERR(osd->od_proc_entry);
81                 CERROR("Error %d setting up lprocfs for %s\n",
82                        rc, name);
83                 osd->od_proc_entry = NULL;
84                 GOTO(out, rc);
85         }
86
87         rc = lu_time_init(&osd->od_stats,
88                           osd->od_proc_entry,
89                           osd_counter_names, ARRAY_SIZE(osd_counter_names));
90         EXIT;
91 out:
92         if (rc)
93                osd_procfs_fini(osd);
94         return rc;
95 }
96
97 int osd_procfs_fini(struct osd_device *osd)
98 {
99         if (osd->od_stats)
100                 lu_time_fini(&osd->od_stats);
101
102         if (osd->od_proc_entry) {
103                  lprocfs_remove(&osd->od_proc_entry);
104                  osd->od_proc_entry = NULL;
105         }
106         RETURN(0);
107 }
108
109 void osd_lprocfs_time_start(const struct lu_env *env)
110 {
111         lu_lprocfs_time_start(env);
112 }
113
114 void osd_lprocfs_time_end(const struct lu_env *env, struct osd_device *osd,
115                           int idx)
116 {
117         lu_lprocfs_time_end(env, osd->od_stats, idx);
118 }
119
120
121
122 int lprocfs_osd_rd_blksize(char *page, char **start, off_t off, int count,
123                            int *eof, void *data)
124 {
125         struct osd_device *osd = data;
126         int rc;
127
128         if (unlikely(osd->od_mount == NULL))
129                 return -EINPROGRESS;
130
131         rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
132         if (!rc) {
133                 *eof = 1;
134                 rc = snprintf(page, count, "%ld\n", osd->od_kstatfs.f_bsize);
135         }
136         return rc;
137 }
138
139 int lprocfs_osd_rd_kbytestotal(char *page, char **start, off_t off, int count,
140                                int *eof, void *data)
141 {
142         struct osd_device *osd = data;
143         int rc;
144
145         if (unlikely(osd->od_mount == NULL))
146                 return -EINPROGRESS;
147
148         rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
149         if (!rc) {
150                 __u32 blk_size = osd->od_kstatfs.f_bsize >> 10;
151                 __u64 result = osd->od_kstatfs.f_blocks;
152
153                 while (blk_size >>= 1)
154                         result <<= 1;
155
156                 *eof = 1;
157                 rc = snprintf(page, count, LPU64"\n", result);
158         }
159         return rc;
160 }
161
162 int lprocfs_osd_rd_kbytesfree(char *page, char **start, off_t off, int count,
163                               int *eof, void *data)
164 {
165         struct osd_device *osd = data;
166         int rc;
167
168         if (unlikely(osd->od_mount == NULL))
169                 return -EINPROGRESS;
170
171         rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
172         if (!rc) {
173                 __u32 blk_size = osd->od_kstatfs.f_bsize >> 10;
174                 __u64 result = osd->od_kstatfs.f_bfree;
175
176                 while (blk_size >>= 1)
177                         result <<= 1;
178
179                 *eof = 1;
180                 rc = snprintf(page, count, LPU64"\n", result);
181         }
182         return rc;
183 }
184
185 int lprocfs_osd_rd_kbytesavail(char *page, char **start, off_t off, int count,
186                                int *eof, void *data)
187 {
188         struct osd_device *osd = data;
189         int rc;
190
191         if (unlikely(osd->od_mount == NULL))
192                 return -EINPROGRESS;
193
194         rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
195         if (!rc) {
196                 __u32 blk_size = osd->od_kstatfs.f_bsize >> 10;
197                 __u64 result = osd->od_kstatfs.f_bavail;
198
199                 while (blk_size >>= 1)
200                         result <<= 1;
201
202                 *eof = 1;
203                 rc = snprintf(page, count, LPU64"\n", result);
204         }
205         return rc;
206 }
207
208 int lprocfs_osd_rd_filestotal(char *page, char **start, off_t off, int count,
209                               int *eof, void *data)
210 {
211         struct osd_device *osd = data;
212         int rc;
213
214         if (unlikely(osd->od_mount == NULL))
215                 return -EINPROGRESS;
216
217         rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
218         if (!rc) {
219                 *eof = 1;
220                 rc = snprintf(page, count, LPU64"\n", osd->od_kstatfs.f_files);
221         }
222
223         return rc;
224 }
225
226 int lprocfs_osd_rd_filesfree(char *page, char **start, off_t off, int count,
227                              int *eof, void *data)
228 {
229         struct osd_device *osd = data;
230         int rc;
231
232         if (unlikely(osd->od_mount == NULL))
233                 return -EINPROGRESS;
234
235         rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
236         if (!rc) {
237                 *eof = 1;
238                 rc = snprintf(page, count, LPU64"\n", osd->od_kstatfs.f_ffree);
239         }
240         return rc;
241 }
242
243 int lprocfs_osd_rd_fstype(char *page, char **start, off_t off, int count,
244                           int *eof, void *data)
245 {
246         struct obd_device *osd = data;
247
248         LASSERT(osd != NULL);
249         return snprintf(page, count, "ldiskfs\n");
250 }
251
252 static int lprocfs_osd_rd_mntdev(char *page, char **start, off_t off, int count,
253                                  int *eof, void *data)
254 {
255         struct osd_device *osd = data;
256
257         LASSERT(osd != NULL);
258         if (unlikely(osd->od_mount == NULL))
259                 return -EINPROGRESS;
260
261         LASSERT(osd->od_mount->lmi_mnt->mnt_devname);
262         *eof = 1;
263
264         return snprintf(page, count, "%s\n",
265                         osd->od_mount->lmi_mnt->mnt_devname);
266 }
267
268 #ifdef HAVE_LDISKFS_PDO
269 static int lprocfs_osd_rd_pdo(char *page, char **start, off_t off, int count,
270                               int *eof, void *data)
271 {
272         *eof = 1;
273
274         return snprintf(page, count, "%s\n", ldiskfs_pdo ? "ON" : "OFF");
275 }
276
277 static int lprocfs_osd_wr_pdo(struct file *file, const char *buffer,
278                               unsigned long count, void *data)
279 {
280         int     pdo;
281         int     rc;
282
283         rc = lprocfs_write_helper(buffer, count, &pdo);
284         if (rc != 0)
285                 return rc;
286
287         ldiskfs_pdo = !!pdo;
288
289         return count;
290 }
291 #endif
292
293 struct lprocfs_vars lprocfs_osd_obd_vars[] = {
294         { "blocksize",       lprocfs_osd_rd_blksize,     0, 0 },
295         { "kbytestotal",     lprocfs_osd_rd_kbytestotal, 0, 0 },
296         { "kbytesfree",      lprocfs_osd_rd_kbytesfree,  0, 0 },
297         { "kbytesavail",     lprocfs_osd_rd_kbytesavail, 0, 0 },
298         { "filestotal",      lprocfs_osd_rd_filestotal,  0, 0 },
299         { "filesfree",       lprocfs_osd_rd_filesfree,   0, 0 },
300         { "fstype",          lprocfs_osd_rd_fstype,      0, 0 },
301         { "mntdev",          lprocfs_osd_rd_mntdev,      0, 0 },
302 #ifdef HAVE_LDISKFS_PDO
303         { "pdo",             lprocfs_osd_rd_pdo, lprocfs_osd_wr_pdo, 0 },
304 #endif
305         { 0 }
306 };
307
308 struct lprocfs_vars lprocfs_osd_module_vars[] = {
309         { "num_refs",        lprocfs_rd_numrefs,     0, 0 },
310         { 0 }
311 };
312
313 void lprocfs_osd_init_vars(struct lprocfs_static_vars *lvars)
314 {
315         lvars->module_vars = lprocfs_osd_module_vars;
316         lvars->obd_vars = lprocfs_osd_obd_vars;
317 }
318 #endif