Whamcloud - gitweb
b=12882
[fs/lustre-release.git] / lustre / osd / osd_lproc.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2008 Sun Microsystems, Inc. All rights reserved.
5  *  Author: Mikhail Pershin <tappro@sun.com>
6  *
7  *   This file is part of the Lustre file system, http://www.lustre.org
8  *   Lustre is a trademark of Cluster File Systems, Inc.
9  *
10  *   You may have signed or agreed to another license before downloading
11  *   this software.  If so, you are bound by the terms and conditions
12  *   of that agreement, and the following does not apply to you.  See the
13  *   LICENSE file included with this distribution for more information.
14  *
15  *   If you did not agree to a different license, then this copy of Lustre
16  *   is open source software; you can redistribute it and/or modify it
17  *   under the terms of version 2 of the GNU General Public License as
18  *   published by the Free Software Foundation.
19  *
20  *   In either case, Lustre is distributed in the hope that it will be
21  *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
22  *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  *   license text for more details.
24  *
25  */
26 #define DEBUG_SUBSYSTEM S_CLASS
27
28 #include <lprocfs_status.h>
29 #include <lu_time.h>
30
31 #include <lustre/lustre_idl.h>
32
33 #include "osd_internal.h"
34
35 #ifdef LPROCFS
36 enum {
37         LPROC_OSD_NR
38 };
39
40 static const char *osd_counter_names[LPROC_OSD_NR] = {
41 };
42
43 int osd_procfs_init(struct osd_device *osd, const char *name)
44 {
45         struct lprocfs_static_vars lvars;
46         struct lu_device    *ld = &osd->od_dt_dev.dd_lu_dev;
47         struct obd_type     *type;
48         int                  rc;
49         ENTRY;
50
51         type = ld->ld_type->ldt_obd_type;
52
53         LASSERT(name != NULL);
54         LASSERT(type != NULL);
55
56         /* Find the type procroot and add the proc entry for this device */
57         lprocfs_osd_init_vars(&lvars);
58         osd->od_proc_entry = lprocfs_register(name, type->typ_procroot,
59                                               lvars.obd_vars, osd);
60         if (IS_ERR(osd->od_proc_entry)) {
61                 rc = PTR_ERR(osd->od_proc_entry);
62                 CERROR("Error %d setting up lprocfs for %s\n",
63                        rc, name);
64                 osd->od_proc_entry = NULL;
65                 GOTO(out, rc);
66         }
67
68         rc = lu_time_init(&osd->od_stats,
69                           osd->od_proc_entry,
70                           osd_counter_names, ARRAY_SIZE(osd_counter_names));
71         EXIT;
72 out:
73         if (rc)
74                osd_procfs_fini(osd);
75         return rc;
76 }
77
78 int osd_procfs_fini(struct osd_device *osd)
79 {
80         if (osd->od_stats)
81                 lu_time_fini(&osd->od_stats);
82
83         if (osd->od_proc_entry) {
84                  lprocfs_remove(&osd->od_proc_entry);
85                  osd->od_proc_entry = NULL;
86         }
87         RETURN(0);
88 }
89
90 void osd_lprocfs_time_start(const struct lu_env *env)
91 {
92         lu_lprocfs_time_start(env);
93 }
94
95 void osd_lprocfs_time_end(const struct lu_env *env, struct osd_device *osd,
96                           int idx)
97 {
98         lu_lprocfs_time_end(env, osd->od_stats, idx);
99 }
100
101
102
103 int lprocfs_osd_rd_blksize(char *page, char **start, off_t off, int count,
104                            int *eof, void *data)
105 {
106         struct osd_device *osd = data;
107         int rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
108         if (!rc) {
109                 *eof = 1;
110                 rc = snprintf(page, count, "%ld\n", osd->od_kstatfs.f_bsize);
111         }
112         return rc;
113 }
114
115 int lprocfs_osd_rd_kbytestotal(char *page, char **start, off_t off, int count,
116                                int *eof, void *data)
117 {
118         struct osd_device *osd = data;
119         int rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
120         if (!rc) {
121                 __u32 blk_size = osd->od_kstatfs.f_bsize >> 10;
122                 __u64 result = osd->od_kstatfs.f_blocks;
123
124                 while (blk_size >>= 1)
125                         result <<= 1;
126
127                 *eof = 1;
128                 rc = snprintf(page, count, LPU64"\n", result);
129         }
130         return rc;
131 }
132
133 int lprocfs_osd_rd_kbytesfree(char *page, char **start, off_t off, int count,
134                               int *eof, void *data)
135 {
136         struct osd_device *osd = data;
137         int rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
138         if (!rc) {
139                 __u32 blk_size = osd->od_kstatfs.f_bsize >> 10;
140                 __u64 result = osd->od_kstatfs.f_bfree;
141
142                 while (blk_size >>= 1)
143                         result <<= 1;
144
145                 *eof = 1;
146                 rc = snprintf(page, count, LPU64"\n", result);
147         }
148         return rc;
149 }
150
151 int lprocfs_osd_rd_kbytesavail(char *page, char **start, off_t off, int count,
152                                int *eof, void *data)
153 {
154         struct osd_device *osd = data;
155         int rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
156         if (!rc) {
157                 __u32 blk_size = osd->od_kstatfs.f_bsize >> 10;
158                 __u64 result = osd->od_kstatfs.f_bavail;
159
160                 while (blk_size >>= 1)
161                         result <<= 1;
162
163                 *eof = 1;
164                 rc = snprintf(page, count, LPU64"\n", result);
165         }
166         return rc;
167 }
168
169 int lprocfs_osd_rd_filestotal(char *page, char **start, off_t off, int count,
170                               int *eof, void *data)
171 {
172         struct osd_device *osd = data;
173         int rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
174         if (!rc) {
175                 *eof = 1;
176                 rc = snprintf(page, count, LPU64"\n", osd->od_kstatfs.f_files);
177         }
178
179         return rc;
180 }
181
182 int lprocfs_osd_rd_filesfree(char *page, char **start, off_t off, int count,
183                              int *eof, void *data)
184 {
185         struct osd_device *osd = data;
186         int rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
187         if (!rc) {
188                 *eof = 1;
189                 rc = snprintf(page, count, LPU64"\n", osd->od_kstatfs.f_ffree);
190         }
191         return rc;
192 }
193
194 int lprocfs_osd_rd_fstype(char *page, char **start, off_t off, int count,
195                           int *eof, void *data)
196 {
197         struct obd_device *osd = data;
198
199         LASSERT(osd != NULL);
200         return snprintf(page, count, "ldiskfs\n");
201 }
202
203 static int lprocfs_osd_rd_mntdev(char *page, char **start, off_t off, int count,
204                                  int *eof, void *data)
205 {
206         struct osd_device *osd = data;
207
208         LASSERT(osd != NULL);
209         LASSERT(osd->od_mount->lmi_mnt->mnt_devname);
210         *eof = 1;
211
212         return snprintf(page, count, "%s\n",
213                         osd->od_mount->lmi_mnt->mnt_devname);
214 }
215
216 struct lprocfs_vars lprocfs_osd_obd_vars[] = {
217         { "blocksize",       lprocfs_osd_rd_blksize,     0, 0 },
218         { "kbytestotal",     lprocfs_osd_rd_kbytestotal, 0, 0 },
219         { "kbytesfree",      lprocfs_osd_rd_kbytesfree,  0, 0 },
220         { "kbytesavail",     lprocfs_osd_rd_kbytesavail, 0, 0 },
221         { "filestotal",      lprocfs_osd_rd_filestotal,  0, 0 },
222         { "filesfree",       lprocfs_osd_rd_filesfree,   0, 0 },
223         { "fstype",          lprocfs_osd_rd_fstype,      0, 0 },
224         { "mntdev",          lprocfs_osd_rd_mntdev,      0, 0 },
225         { 0 }
226 };
227
228 struct lprocfs_vars lprocfs_osd_module_vars[] = {
229         { "num_refs",        lprocfs_rd_numrefs,     0, 0 },
230         { 0 }
231 };
232
233 void lprocfs_osd_init_vars(struct lprocfs_static_vars *lvars)
234 {
235         lvars->module_vars = lprocfs_osd_module_vars;
236         lvars->obd_vars = lprocfs_osd_obd_vars;
237 }
238 #endif