1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
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
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/osd/osd_lproc.c
38 * Author: Mikhail Pershin <tappro@sun.com>
41 #define DEBUG_SUBSYSTEM S_CLASS
43 #include <lprocfs_status.h>
46 #include <lustre/lustre_idl.h>
48 #include "osd_internal.h"
55 static const char *osd_counter_names[LPROC_OSD_NR] = {
58 int osd_procfs_init(struct osd_device *osd, const char *name)
60 struct lprocfs_static_vars lvars;
61 struct lu_device *ld = &osd->od_dt_dev.dd_lu_dev;
62 struct obd_type *type;
66 type = ld->ld_type->ldt_obd_type;
68 LASSERT(name != NULL);
69 LASSERT(type != NULL);
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,
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",
79 osd->od_proc_entry = NULL;
83 rc = lu_time_init(&osd->od_stats,
85 osd_counter_names, ARRAY_SIZE(osd_counter_names));
93 int osd_procfs_fini(struct osd_device *osd)
96 lu_time_fini(&osd->od_stats);
98 if (osd->od_proc_entry) {
99 lprocfs_remove(&osd->od_proc_entry);
100 osd->od_proc_entry = NULL;
105 void osd_lprocfs_time_start(const struct lu_env *env)
107 lu_lprocfs_time_start(env);
110 void osd_lprocfs_time_end(const struct lu_env *env, struct osd_device *osd,
113 lu_lprocfs_time_end(env, osd->od_stats, idx);
118 int lprocfs_osd_rd_blksize(char *page, char **start, off_t off, int count,
119 int *eof, void *data)
121 struct osd_device *osd = data;
122 int rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
125 rc = snprintf(page, count, "%ld\n", osd->od_kstatfs.f_bsize);
130 int lprocfs_osd_rd_kbytestotal(char *page, char **start, off_t off, int count,
131 int *eof, void *data)
133 struct osd_device *osd = data;
134 int rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
136 __u32 blk_size = osd->od_kstatfs.f_bsize >> 10;
137 __u64 result = osd->od_kstatfs.f_blocks;
139 while (blk_size >>= 1)
143 rc = snprintf(page, count, LPU64"\n", result);
148 int lprocfs_osd_rd_kbytesfree(char *page, char **start, off_t off, int count,
149 int *eof, void *data)
151 struct osd_device *osd = data;
152 int rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
154 __u32 blk_size = osd->od_kstatfs.f_bsize >> 10;
155 __u64 result = osd->od_kstatfs.f_bfree;
157 while (blk_size >>= 1)
161 rc = snprintf(page, count, LPU64"\n", result);
166 int lprocfs_osd_rd_kbytesavail(char *page, char **start, off_t off, int count,
167 int *eof, void *data)
169 struct osd_device *osd = data;
170 int rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
172 __u32 blk_size = osd->od_kstatfs.f_bsize >> 10;
173 __u64 result = osd->od_kstatfs.f_bavail;
175 while (blk_size >>= 1)
179 rc = snprintf(page, count, LPU64"\n", result);
184 int lprocfs_osd_rd_filestotal(char *page, char **start, off_t off, int count,
185 int *eof, void *data)
187 struct osd_device *osd = data;
188 int rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
191 rc = snprintf(page, count, LPU64"\n", osd->od_kstatfs.f_files);
197 int lprocfs_osd_rd_filesfree(char *page, char **start, off_t off, int count,
198 int *eof, void *data)
200 struct osd_device *osd = data;
201 int rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
204 rc = snprintf(page, count, LPU64"\n", osd->od_kstatfs.f_ffree);
209 int lprocfs_osd_rd_fstype(char *page, char **start, off_t off, int count,
210 int *eof, void *data)
212 struct obd_device *osd = data;
214 LASSERT(osd != NULL);
215 return snprintf(page, count, "ldiskfs\n");
218 static int lprocfs_osd_rd_mntdev(char *page, char **start, off_t off, int count,
219 int *eof, void *data)
221 struct osd_device *osd = data;
223 LASSERT(osd != NULL);
224 LASSERT(osd->od_mount->lmi_mnt->mnt_devname);
227 return snprintf(page, count, "%s\n",
228 osd->od_mount->lmi_mnt->mnt_devname);
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 },
243 struct lprocfs_vars lprocfs_osd_module_vars[] = {
244 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
248 void lprocfs_osd_init_vars(struct lprocfs_static_vars *lvars)
250 lvars->module_vars = lprocfs_osd_module_vars;
251 lvars->obd_vars = lprocfs_osd_obd_vars;