1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2008 Sun Microsystems, Inc. All rights reserved.
5 * Author: Mikhail Pershin <tappro@sun.com>
7 * This file is part of the Lustre file system, http://www.lustre.org
8 * Lustre is a trademark of Cluster File Systems, Inc.
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.
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.
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.
26 #define DEBUG_SUBSYSTEM S_CLASS
28 #include <lprocfs_status.h>
31 #include <lustre/lustre_idl.h>
33 #include "osd_internal.h"
40 static const char *osd_counter_names[LPROC_OSD_NR] = {
43 int osd_procfs_init(struct osd_device *osd, const char *name)
45 struct lprocfs_static_vars lvars;
46 struct lu_device *ld = &osd->od_dt_dev.dd_lu_dev;
47 struct obd_type *type;
51 type = ld->ld_type->ldt_obd_type;
53 LASSERT(name != NULL);
54 LASSERT(type != NULL);
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,
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",
64 osd->od_proc_entry = NULL;
68 rc = lu_time_init(&osd->od_stats,
70 osd_counter_names, ARRAY_SIZE(osd_counter_names));
78 int osd_procfs_fini(struct osd_device *osd)
81 lu_time_fini(&osd->od_stats);
83 if (osd->od_proc_entry) {
84 lprocfs_remove(&osd->od_proc_entry);
85 osd->od_proc_entry = NULL;
90 void osd_lprocfs_time_start(const struct lu_env *env)
92 lu_lprocfs_time_start(env);
95 void osd_lprocfs_time_end(const struct lu_env *env, struct osd_device *osd,
98 lu_lprocfs_time_end(env, osd->od_stats, idx);
103 int lprocfs_osd_rd_blksize(char *page, char **start, off_t off, int count,
104 int *eof, void *data)
106 struct osd_device *osd = data;
107 int rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
110 rc = snprintf(page, count, "%ld\n", osd->od_kstatfs.f_bsize);
115 int lprocfs_osd_rd_kbytestotal(char *page, char **start, off_t off, int count,
116 int *eof, void *data)
118 struct osd_device *osd = data;
119 int rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
121 __u32 blk_size = osd->od_kstatfs.f_bsize >> 10;
122 __u64 result = osd->od_kstatfs.f_blocks;
124 while (blk_size >>= 1)
128 rc = snprintf(page, count, LPU64"\n", result);
133 int lprocfs_osd_rd_kbytesfree(char *page, char **start, off_t off, int count,
134 int *eof, void *data)
136 struct osd_device *osd = data;
137 int rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
139 __u32 blk_size = osd->od_kstatfs.f_bsize >> 10;
140 __u64 result = osd->od_kstatfs.f_bfree;
142 while (blk_size >>= 1)
146 rc = snprintf(page, count, LPU64"\n", result);
151 int lprocfs_osd_rd_kbytesavail(char *page, char **start, off_t off, int count,
152 int *eof, void *data)
154 struct osd_device *osd = data;
155 int rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
157 __u32 blk_size = osd->od_kstatfs.f_bsize >> 10;
158 __u64 result = osd->od_kstatfs.f_bavail;
160 while (blk_size >>= 1)
164 rc = snprintf(page, count, LPU64"\n", result);
169 int lprocfs_osd_rd_filestotal(char *page, char **start, off_t off, int count,
170 int *eof, void *data)
172 struct osd_device *osd = data;
173 int rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
176 rc = snprintf(page, count, LPU64"\n", osd->od_kstatfs.f_files);
182 int lprocfs_osd_rd_filesfree(char *page, char **start, off_t off, int count,
183 int *eof, void *data)
185 struct osd_device *osd = data;
186 int rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
189 rc = snprintf(page, count, LPU64"\n", osd->od_kstatfs.f_ffree);
194 int lprocfs_osd_rd_fstype(char *page, char **start, off_t off, int count,
195 int *eof, void *data)
197 struct obd_device *osd = data;
199 LASSERT(osd != NULL);
200 return snprintf(page, count, "ldiskfs\n");
203 static int lprocfs_osd_rd_mntdev(char *page, char **start, off_t off, int count,
204 int *eof, void *data)
206 struct osd_device *osd = data;
208 LASSERT(osd != NULL);
209 LASSERT(osd->od_mount->lmi_mnt->mnt_devname);
212 return snprintf(page, count, "%s\n",
213 osd->od_mount->lmi_mnt->mnt_devname);
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 },
228 struct lprocfs_vars lprocfs_osd_module_vars[] = {
229 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
233 void lprocfs_osd_init_vars(struct lprocfs_static_vars *lvars)
235 lvars->module_vars = lprocfs_osd_module_vars;
236 lvars->obd_vars = lprocfs_osd_obd_vars;