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 (c) 2008, 2010, Oracle and/or its affiliates. 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"
52 static const char *osd_counter_names[LPROC_OSD_NR] = {
54 [LPROC_OSD_THANDLE_STARTING] = "thandle starting",
55 [LPROC_OSD_THANDLE_OPEN] = "thandle open",
56 [LPROC_OSD_THANDLE_CLOSING] = "thandle closing"
60 int osd_procfs_init(struct osd_device *osd, const char *name)
62 struct lprocfs_static_vars lvars;
63 struct lu_device *ld = &osd->od_dt_dev.dd_lu_dev;
64 struct obd_type *type;
68 type = ld->ld_type->ldt_obd_type;
70 LASSERT(name != NULL);
71 LASSERT(type != NULL);
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,
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",
81 osd->od_proc_entry = NULL;
85 rc = lu_time_init(&osd->od_stats,
87 osd_counter_names, ARRAY_SIZE(osd_counter_names));
95 int osd_procfs_fini(struct osd_device *osd)
98 lu_time_fini(&osd->od_stats);
100 if (osd->od_proc_entry) {
101 lprocfs_remove(&osd->od_proc_entry);
102 osd->od_proc_entry = NULL;
107 void osd_lprocfs_time_start(const struct lu_env *env)
109 lu_lprocfs_time_start(env);
112 void osd_lprocfs_time_end(const struct lu_env *env, struct osd_device *osd,
115 lu_lprocfs_time_end(env, osd->od_stats, idx);
120 int lprocfs_osd_rd_blksize(char *page, char **start, off_t off, int count,
121 int *eof, void *data)
123 struct osd_device *osd = data;
124 int rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
127 rc = snprintf(page, count, "%ld\n", osd->od_kstatfs.f_bsize);
132 int lprocfs_osd_rd_kbytestotal(char *page, char **start, off_t off, int count,
133 int *eof, void *data)
135 struct osd_device *osd = data;
136 int rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
138 __u32 blk_size = osd->od_kstatfs.f_bsize >> 10;
139 __u64 result = osd->od_kstatfs.f_blocks;
141 while (blk_size >>= 1)
145 rc = snprintf(page, count, LPU64"\n", result);
150 int lprocfs_osd_rd_kbytesfree(char *page, char **start, off_t off, int count,
151 int *eof, void *data)
153 struct osd_device *osd = data;
154 int rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
156 __u32 blk_size = osd->od_kstatfs.f_bsize >> 10;
157 __u64 result = osd->od_kstatfs.f_bfree;
159 while (blk_size >>= 1)
163 rc = snprintf(page, count, LPU64"\n", result);
168 int lprocfs_osd_rd_kbytesavail(char *page, char **start, off_t off, int count,
169 int *eof, void *data)
171 struct osd_device *osd = data;
172 int rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
174 __u32 blk_size = osd->od_kstatfs.f_bsize >> 10;
175 __u64 result = osd->od_kstatfs.f_bavail;
177 while (blk_size >>= 1)
181 rc = snprintf(page, count, LPU64"\n", result);
186 int lprocfs_osd_rd_filestotal(char *page, char **start, off_t off, int count,
187 int *eof, void *data)
189 struct osd_device *osd = data;
190 int rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
193 rc = snprintf(page, count, LPU64"\n", osd->od_kstatfs.f_files);
199 int lprocfs_osd_rd_filesfree(char *page, char **start, off_t off, int count,
200 int *eof, void *data)
202 struct osd_device *osd = data;
203 int rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
206 rc = snprintf(page, count, LPU64"\n", osd->od_kstatfs.f_ffree);
211 int lprocfs_osd_rd_fstype(char *page, char **start, off_t off, int count,
212 int *eof, void *data)
214 struct obd_device *osd = data;
216 LASSERT(osd != NULL);
217 return snprintf(page, count, "ldiskfs\n");
220 static int lprocfs_osd_rd_mntdev(char *page, char **start, off_t off, int count,
221 int *eof, void *data)
223 struct osd_device *osd = data;
225 LASSERT(osd != NULL);
226 LASSERT(osd->od_mount->lmi_mnt->mnt_devname);
229 return snprintf(page, count, "%s\n",
230 osd->od_mount->lmi_mnt->mnt_devname);
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 },
245 struct lprocfs_vars lprocfs_osd_module_vars[] = {
246 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
250 void lprocfs_osd_init_vars(struct lprocfs_static_vars *lvars)
252 lvars->module_vars = lprocfs_osd_module_vars;
253 lvars->obd_vars = lprocfs_osd_obd_vars;