Whamcloud - gitweb
b=23094 add layout lock connect flag
[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  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lustre/osd/osd_lproc.c
37  *
38  * Author: Mikhail Pershin <tappro@sun.com>
39  */
40
41 #define DEBUG_SUBSYSTEM S_CLASS
42
43 #include <lprocfs_status.h>
44 #include <lu_time.h>
45
46 #include <lustre/lustre_idl.h>
47
48 #include "osd_internal.h"
49
50 #ifdef LPROCFS
51 enum {
52         LPROC_OSD_NR
53 };
54
55 static const char *osd_counter_names[LPROC_OSD_NR] = {
56 };
57
58 int osd_procfs_init(struct osd_device *osd, const char *name)
59 {
60         struct lprocfs_static_vars lvars;
61         struct lu_device    *ld = &osd->od_dt_dev.dd_lu_dev;
62         struct obd_type     *type;
63         int                  rc;
64         ENTRY;
65
66         type = ld->ld_type->ldt_obd_type;
67
68         LASSERT(name != NULL);
69         LASSERT(type != NULL);
70
71         /* Find the type procroot and add the proc entry for this device */
72         lprocfs_osd_init_vars(&lvars);
73         osd->od_proc_entry = lprocfs_register(name, type->typ_procroot,
74                                               lvars.obd_vars, osd);
75         if (IS_ERR(osd->od_proc_entry)) {
76                 rc = PTR_ERR(osd->od_proc_entry);
77                 CERROR("Error %d setting up lprocfs for %s\n",
78                        rc, name);
79                 osd->od_proc_entry = NULL;
80                 GOTO(out, rc);
81         }
82
83         rc = lu_time_init(&osd->od_stats,
84                           osd->od_proc_entry,
85                           osd_counter_names, ARRAY_SIZE(osd_counter_names));
86         EXIT;
87 out:
88         if (rc)
89                osd_procfs_fini(osd);
90         return rc;
91 }
92
93 int osd_procfs_fini(struct osd_device *osd)
94 {
95         if (osd->od_stats)
96                 lu_time_fini(&osd->od_stats);
97
98         if (osd->od_proc_entry) {
99                  lprocfs_remove(&osd->od_proc_entry);
100                  osd->od_proc_entry = NULL;
101         }
102         RETURN(0);
103 }
104
105 void osd_lprocfs_time_start(const struct lu_env *env)
106 {
107         lu_lprocfs_time_start(env);
108 }
109
110 void osd_lprocfs_time_end(const struct lu_env *env, struct osd_device *osd,
111                           int idx)
112 {
113         lu_lprocfs_time_end(env, osd->od_stats, idx);
114 }
115
116
117
118 int lprocfs_osd_rd_blksize(char *page, char **start, off_t off, int count,
119                            int *eof, void *data)
120 {
121         struct osd_device *osd = data;
122         int rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
123         if (!rc) {
124                 *eof = 1;
125                 rc = snprintf(page, count, "%ld\n", osd->od_kstatfs.f_bsize);
126         }
127         return rc;
128 }
129
130 int lprocfs_osd_rd_kbytestotal(char *page, char **start, off_t off, int count,
131                                int *eof, void *data)
132 {
133         struct osd_device *osd = data;
134         int rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
135         if (!rc) {
136                 __u32 blk_size = osd->od_kstatfs.f_bsize >> 10;
137                 __u64 result = osd->od_kstatfs.f_blocks;
138
139                 while (blk_size >>= 1)
140                         result <<= 1;
141
142                 *eof = 1;
143                 rc = snprintf(page, count, LPU64"\n", result);
144         }
145         return rc;
146 }
147
148 int lprocfs_osd_rd_kbytesfree(char *page, char **start, off_t off, int count,
149                               int *eof, void *data)
150 {
151         struct osd_device *osd = data;
152         int rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
153         if (!rc) {
154                 __u32 blk_size = osd->od_kstatfs.f_bsize >> 10;
155                 __u64 result = osd->od_kstatfs.f_bfree;
156
157                 while (blk_size >>= 1)
158                         result <<= 1;
159
160                 *eof = 1;
161                 rc = snprintf(page, count, LPU64"\n", result);
162         }
163         return rc;
164 }
165
166 int lprocfs_osd_rd_kbytesavail(char *page, char **start, off_t off, int count,
167                                int *eof, void *data)
168 {
169         struct osd_device *osd = data;
170         int rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
171         if (!rc) {
172                 __u32 blk_size = osd->od_kstatfs.f_bsize >> 10;
173                 __u64 result = osd->od_kstatfs.f_bavail;
174
175                 while (blk_size >>= 1)
176                         result <<= 1;
177
178                 *eof = 1;
179                 rc = snprintf(page, count, LPU64"\n", result);
180         }
181         return rc;
182 }
183
184 int lprocfs_osd_rd_filestotal(char *page, char **start, off_t off, int count,
185                               int *eof, void *data)
186 {
187         struct osd_device *osd = data;
188         int rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
189         if (!rc) {
190                 *eof = 1;
191                 rc = snprintf(page, count, LPU64"\n", osd->od_kstatfs.f_files);
192         }
193
194         return rc;
195 }
196
197 int lprocfs_osd_rd_filesfree(char *page, char **start, off_t off, int count,
198                              int *eof, void *data)
199 {
200         struct osd_device *osd = data;
201         int rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
202         if (!rc) {
203                 *eof = 1;
204                 rc = snprintf(page, count, LPU64"\n", osd->od_kstatfs.f_ffree);
205         }
206         return rc;
207 }
208
209 int lprocfs_osd_rd_fstype(char *page, char **start, off_t off, int count,
210                           int *eof, void *data)
211 {
212         struct obd_device *osd = data;
213
214         LASSERT(osd != NULL);
215         return snprintf(page, count, "ldiskfs\n");
216 }
217
218 static int lprocfs_osd_rd_mntdev(char *page, char **start, off_t off, int count,
219                                  int *eof, void *data)
220 {
221         struct osd_device *osd = data;
222
223         LASSERT(osd != NULL);
224         LASSERT(osd->od_mount->lmi_mnt->mnt_devname);
225         *eof = 1;
226
227         return snprintf(page, count, "%s\n",
228                         osd->od_mount->lmi_mnt->mnt_devname);
229 }
230
231 struct lprocfs_vars lprocfs_osd_obd_vars[] = {
232         { "blocksize",       lprocfs_osd_rd_blksize,     0, 0 },
233         { "kbytestotal",     lprocfs_osd_rd_kbytestotal, 0, 0 },
234         { "kbytesfree",      lprocfs_osd_rd_kbytesfree,  0, 0 },
235         { "kbytesavail",     lprocfs_osd_rd_kbytesavail, 0, 0 },
236         { "filestotal",      lprocfs_osd_rd_filestotal,  0, 0 },
237         { "filesfree",       lprocfs_osd_rd_filesfree,   0, 0 },
238         { "fstype",          lprocfs_osd_rd_fstype,      0, 0 },
239         { "mntdev",          lprocfs_osd_rd_mntdev,      0, 0 },
240         { 0 }
241 };
242
243 struct lprocfs_vars lprocfs_osd_module_vars[] = {
244         { "num_refs",        lprocfs_rd_numrefs,     0, 0 },
245         { 0 }
246 };
247
248 void lprocfs_osd_init_vars(struct lprocfs_static_vars *lvars)
249 {
250         lvars->module_vars = lprocfs_osd_module_vars;
251         lvars->obd_vars = lprocfs_osd_obd_vars;
252 }
253 #endif