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;
126 if (unlikely(osd->od_mount == NULL))
129 rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
132 rc = snprintf(page, count, "%ld\n", osd->od_kstatfs.f_bsize);
137 int lprocfs_osd_rd_kbytestotal(char *page, char **start, off_t off, int count,
138 int *eof, void *data)
140 struct osd_device *osd = data;
143 if (unlikely(osd->od_mount == NULL))
146 rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
148 __u32 blk_size = osd->od_kstatfs.f_bsize >> 10;
149 __u64 result = osd->od_kstatfs.f_blocks;
151 while (blk_size >>= 1)
155 rc = snprintf(page, count, LPU64"\n", result);
160 int lprocfs_osd_rd_kbytesfree(char *page, char **start, off_t off, int count,
161 int *eof, void *data)
163 struct osd_device *osd = data;
166 if (unlikely(osd->od_mount == NULL))
169 rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
171 __u32 blk_size = osd->od_kstatfs.f_bsize >> 10;
172 __u64 result = osd->od_kstatfs.f_bfree;
174 while (blk_size >>= 1)
178 rc = snprintf(page, count, LPU64"\n", result);
183 int lprocfs_osd_rd_kbytesavail(char *page, char **start, off_t off, int count,
184 int *eof, void *data)
186 struct osd_device *osd = data;
189 if (unlikely(osd->od_mount == NULL))
192 rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
194 __u32 blk_size = osd->od_kstatfs.f_bsize >> 10;
195 __u64 result = osd->od_kstatfs.f_bavail;
197 while (blk_size >>= 1)
201 rc = snprintf(page, count, LPU64"\n", result);
206 int lprocfs_osd_rd_filestotal(char *page, char **start, off_t off, int count,
207 int *eof, void *data)
209 struct osd_device *osd = data;
212 if (unlikely(osd->od_mount == NULL))
215 rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
218 rc = snprintf(page, count, LPU64"\n", osd->od_kstatfs.f_files);
224 int lprocfs_osd_rd_filesfree(char *page, char **start, off_t off, int count,
225 int *eof, void *data)
227 struct osd_device *osd = data;
230 if (unlikely(osd->od_mount == NULL))
233 rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs);
236 rc = snprintf(page, count, LPU64"\n", osd->od_kstatfs.f_ffree);
241 int lprocfs_osd_rd_fstype(char *page, char **start, off_t off, int count,
242 int *eof, void *data)
244 struct obd_device *osd = data;
246 LASSERT(osd != NULL);
247 return snprintf(page, count, "ldiskfs\n");
250 static int lprocfs_osd_rd_mntdev(char *page, char **start, off_t off, int count,
251 int *eof, void *data)
253 struct osd_device *osd = data;
255 LASSERT(osd != NULL);
256 if (unlikely(osd->od_mount == NULL))
259 LASSERT(osd->od_mount->lmi_mnt->mnt_devname);
262 return snprintf(page, count, "%s\n",
263 osd->od_mount->lmi_mnt->mnt_devname);
266 #ifdef HAVE_LDISKFS_PDO
267 static int lprocfs_osd_rd_pdo(char *page, char **start, off_t off, int count,
268 int *eof, void *data)
272 return snprintf(page, count, "%s\n", ldiskfs_pdo ? "ON" : "OFF");
275 static int lprocfs_osd_wr_pdo(struct file *file, const char *buffer,
276 unsigned long count, void *data)
281 rc = lprocfs_write_helper(buffer, count, &pdo);
291 struct lprocfs_vars lprocfs_osd_obd_vars[] = {
292 { "blocksize", lprocfs_osd_rd_blksize, 0, 0 },
293 { "kbytestotal", lprocfs_osd_rd_kbytestotal, 0, 0 },
294 { "kbytesfree", lprocfs_osd_rd_kbytesfree, 0, 0 },
295 { "kbytesavail", lprocfs_osd_rd_kbytesavail, 0, 0 },
296 { "filestotal", lprocfs_osd_rd_filestotal, 0, 0 },
297 { "filesfree", lprocfs_osd_rd_filesfree, 0, 0 },
298 { "fstype", lprocfs_osd_rd_fstype, 0, 0 },
299 { "mntdev", lprocfs_osd_rd_mntdev, 0, 0 },
300 #ifdef HAVE_LDISKFS_PDO
301 { "pdo", lprocfs_osd_rd_pdo, lprocfs_osd_wr_pdo, 0 },
306 struct lprocfs_vars lprocfs_osd_module_vars[] = {
307 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
311 void lprocfs_osd_init_vars(struct lprocfs_static_vars *lvars)
313 lvars->module_vars = lprocfs_osd_module_vars;
314 lvars->obd_vars = lprocfs_osd_obd_vars;