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