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.
32 * Copyright (c) 2011, Whamcloud, Inc.
35 * This file is part of Lustre, http://www.lustre.org/
36 * Lustre is a trademark of Sun Microsystems, Inc.
38 * lustre/osd/osd_lproc.c
40 * Author: Mikhail Pershin <tappro@sun.com>
43 #define DEBUG_SUBSYSTEM S_CLASS
45 #include <lprocfs_status.h>
48 #include <lustre/lustre_idl.h>
50 #include "osd_internal.h"
54 static const char *osd_counter_names[LPROC_OSD_NR] = {
56 [LPROC_OSD_THANDLE_STARTING] = "thandle starting",
57 [LPROC_OSD_THANDLE_OPEN] = "thandle open",
58 [LPROC_OSD_THANDLE_CLOSING] = "thandle closing"
62 int osd_procfs_init(struct osd_device *osd, const char *name)
64 struct lprocfs_static_vars lvars;
65 struct lu_device *ld = &osd->od_dt_dev.dd_lu_dev;
66 struct obd_type *type;
70 type = ld->ld_type->ldt_obd_type;
72 LASSERT(name != NULL);
73 LASSERT(type != NULL);
75 /* Find the type procroot and add the proc entry for this device */
76 lprocfs_osd_init_vars(&lvars);
77 osd->od_proc_entry = lprocfs_register(name, type->typ_procroot,
79 if (IS_ERR(osd->od_proc_entry)) {
80 rc = PTR_ERR(osd->od_proc_entry);
81 CERROR("Error %d setting up lprocfs for %s\n",
83 osd->od_proc_entry = NULL;
87 rc = lu_time_init(&osd->od_stats,
89 osd_counter_names, ARRAY_SIZE(osd_counter_names));
97 int osd_procfs_fini(struct osd_device *osd)
100 lu_time_fini(&osd->od_stats);
102 if (osd->od_proc_entry) {
103 lprocfs_remove(&osd->od_proc_entry);
104 osd->od_proc_entry = NULL;
109 void osd_lprocfs_time_start(const struct lu_env *env)
111 lu_lprocfs_time_start(env);
114 void osd_lprocfs_time_end(const struct lu_env *env, struct osd_device *osd,
117 lu_lprocfs_time_end(env, osd->od_stats, idx);
122 int lprocfs_osd_rd_blksize(char *page, char **start, off_t off, int count,
123 int *eof, void *data)
125 struct osd_device *osd = data;
128 if (unlikely(osd->od_mount == NULL))
131 rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
134 rc = snprintf(page, count, "%ld\n", osd->od_kstatfs.f_bsize);
139 int lprocfs_osd_rd_kbytestotal(char *page, char **start, off_t off, int count,
140 int *eof, void *data)
142 struct osd_device *osd = data;
145 if (unlikely(osd->od_mount == NULL))
148 rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
150 __u32 blk_size = osd->od_kstatfs.f_bsize >> 10;
151 __u64 result = osd->od_kstatfs.f_blocks;
153 while (blk_size >>= 1)
157 rc = snprintf(page, count, LPU64"\n", result);
162 int lprocfs_osd_rd_kbytesfree(char *page, char **start, off_t off, int count,
163 int *eof, void *data)
165 struct osd_device *osd = data;
168 if (unlikely(osd->od_mount == NULL))
171 rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
173 __u32 blk_size = osd->od_kstatfs.f_bsize >> 10;
174 __u64 result = osd->od_kstatfs.f_bfree;
176 while (blk_size >>= 1)
180 rc = snprintf(page, count, LPU64"\n", result);
185 int lprocfs_osd_rd_kbytesavail(char *page, char **start, off_t off, int count,
186 int *eof, void *data)
188 struct osd_device *osd = data;
191 if (unlikely(osd->od_mount == NULL))
194 rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
196 __u32 blk_size = osd->od_kstatfs.f_bsize >> 10;
197 __u64 result = osd->od_kstatfs.f_bavail;
199 while (blk_size >>= 1)
203 rc = snprintf(page, count, LPU64"\n", result);
208 int lprocfs_osd_rd_filestotal(char *page, char **start, off_t off, int count,
209 int *eof, void *data)
211 struct osd_device *osd = data;
214 if (unlikely(osd->od_mount == NULL))
217 rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
220 rc = snprintf(page, count, LPU64"\n", osd->od_kstatfs.f_files);
226 int lprocfs_osd_rd_filesfree(char *page, char **start, off_t off, int count,
227 int *eof, void *data)
229 struct osd_device *osd = data;
232 if (unlikely(osd->od_mount == NULL))
235 rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
238 rc = snprintf(page, count, LPU64"\n", osd->od_kstatfs.f_ffree);
243 int lprocfs_osd_rd_fstype(char *page, char **start, off_t off, int count,
244 int *eof, void *data)
246 struct obd_device *osd = data;
248 LASSERT(osd != NULL);
249 return snprintf(page, count, "ldiskfs\n");
252 static int lprocfs_osd_rd_mntdev(char *page, char **start, off_t off, int count,
253 int *eof, void *data)
255 struct osd_device *osd = data;
257 LASSERT(osd != NULL);
258 if (unlikely(osd->od_mount == NULL))
261 LASSERT(osd->od_mount->lmi_mnt->mnt_devname);
264 return snprintf(page, count, "%s\n",
265 osd->od_mount->lmi_mnt->mnt_devname);
268 #ifdef HAVE_LDISKFS_PDO
269 static int lprocfs_osd_rd_pdo(char *page, char **start, off_t off, int count,
270 int *eof, void *data)
274 return snprintf(page, count, "%s\n", ldiskfs_pdo ? "ON" : "OFF");
277 static int lprocfs_osd_wr_pdo(struct file *file, const char *buffer,
278 unsigned long count, void *data)
283 rc = lprocfs_write_helper(buffer, count, &pdo);
293 struct lprocfs_vars lprocfs_osd_obd_vars[] = {
294 { "blocksize", lprocfs_osd_rd_blksize, 0, 0 },
295 { "kbytestotal", lprocfs_osd_rd_kbytestotal, 0, 0 },
296 { "kbytesfree", lprocfs_osd_rd_kbytesfree, 0, 0 },
297 { "kbytesavail", lprocfs_osd_rd_kbytesavail, 0, 0 },
298 { "filestotal", lprocfs_osd_rd_filestotal, 0, 0 },
299 { "filesfree", lprocfs_osd_rd_filesfree, 0, 0 },
300 { "fstype", lprocfs_osd_rd_fstype, 0, 0 },
301 { "mntdev", lprocfs_osd_rd_mntdev, 0, 0 },
302 #ifdef HAVE_LDISKFS_PDO
303 { "pdo", lprocfs_osd_rd_pdo, lprocfs_osd_wr_pdo, 0 },
308 struct lprocfs_vars lprocfs_osd_module_vars[] = {
309 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
313 void lprocfs_osd_init_vars(struct lprocfs_static_vars *lvars)
315 lvars->module_vars = lprocfs_osd_module_vars;
316 lvars->obd_vars = lprocfs_osd_obd_vars;