/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- * vim:expandtab:shiftwidth=8:tabstop=8: * * Copyright (C) 2008 Sun Microsystems, Inc. All rights reserved. * Author: Mikhail Pershin * * This file is part of the Lustre file system, http://www.lustre.org * Lustre is a trademark of Cluster File Systems, Inc. * * You may have signed or agreed to another license before downloading * this software. If so, you are bound by the terms and conditions * of that agreement, and the following does not apply to you. See the * LICENSE file included with this distribution for more information. * * If you did not agree to a different license, then this copy of Lustre * is open source software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * In either case, Lustre is distributed in the hope that it will be * useful, but WITHOUT ANY WARRANTY; without even the implied warranty * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * license text for more details. * */ #define DEBUG_SUBSYSTEM S_CLASS #include #include #include #include "osd_internal.h" #ifdef LPROCFS enum { LPROC_OSD_NR }; static const char *osd_counter_names[LPROC_OSD_NR] = { }; int osd_procfs_init(struct osd_device *osd, const char *name) { struct lprocfs_static_vars lvars; struct lu_device *ld = &osd->od_dt_dev.dd_lu_dev; struct obd_type *type; int rc; ENTRY; type = ld->ld_type->ldt_obd_type; LASSERT(name != NULL); LASSERT(type != NULL); /* Find the type procroot and add the proc entry for this device */ lprocfs_osd_init_vars(&lvars); osd->od_proc_entry = lprocfs_register(name, type->typ_procroot, lvars.obd_vars, osd); if (IS_ERR(osd->od_proc_entry)) { rc = PTR_ERR(osd->od_proc_entry); CERROR("Error %d setting up lprocfs for %s\n", rc, name); osd->od_proc_entry = NULL; GOTO(out, rc); } rc = lu_time_init(&osd->od_stats, osd->od_proc_entry, osd_counter_names, ARRAY_SIZE(osd_counter_names)); EXIT; out: if (rc) osd_procfs_fini(osd); return rc; } int osd_procfs_fini(struct osd_device *osd) { if (osd->od_stats) lu_time_fini(&osd->od_stats); if (osd->od_proc_entry) { lprocfs_remove(&osd->od_proc_entry); osd->od_proc_entry = NULL; } RETURN(0); } void osd_lprocfs_time_start(const struct lu_env *env) { lu_lprocfs_time_start(env); } void osd_lprocfs_time_end(const struct lu_env *env, struct osd_device *osd, int idx) { lu_lprocfs_time_end(env, osd->od_stats, idx); } int lprocfs_osd_rd_blksize(char *page, char **start, off_t off, int count, int *eof, void *data) { struct osd_device *osd = data; int rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs); if (!rc) { *eof = 1; rc = snprintf(page, count, "%ld\n", osd->od_kstatfs.f_bsize); } return rc; } int lprocfs_osd_rd_kbytestotal(char *page, char **start, off_t off, int count, int *eof, void *data) { struct osd_device *osd = data; int rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs); if (!rc) { __u32 blk_size = osd->od_kstatfs.f_bsize >> 10; __u64 result = osd->od_kstatfs.f_blocks; while (blk_size >>= 1) result <<= 1; *eof = 1; rc = snprintf(page, count, LPU64"\n", result); } return rc; } int lprocfs_osd_rd_kbytesfree(char *page, char **start, off_t off, int count, int *eof, void *data) { struct osd_device *osd = data; int rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs); if (!rc) { __u32 blk_size = osd->od_kstatfs.f_bsize >> 10; __u64 result = osd->od_kstatfs.f_bfree; while (blk_size >>= 1) result <<= 1; *eof = 1; rc = snprintf(page, count, LPU64"\n", result); } return rc; } int lprocfs_osd_rd_kbytesavail(char *page, char **start, off_t off, int count, int *eof, void *data) { struct osd_device *osd = data; int rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs); if (!rc) { __u32 blk_size = osd->od_kstatfs.f_bsize >> 10; __u64 result = osd->od_kstatfs.f_bavail; while (blk_size >>= 1) result <<= 1; *eof = 1; rc = snprintf(page, count, LPU64"\n", result); } return rc; } int lprocfs_osd_rd_filestotal(char *page, char **start, off_t off, int count, int *eof, void *data) { struct osd_device *osd = data; int rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs); if (!rc) { *eof = 1; rc = snprintf(page, count, LPU64"\n", osd->od_kstatfs.f_files); } return rc; } int lprocfs_osd_rd_filesfree(char *page, char **start, off_t off, int count, int *eof, void *data) { struct osd_device *osd = data; int rc = osd_statfs(NULL, &osd->od_dt_dev, &osd->od_kstatfs); if (!rc) { *eof = 1; rc = snprintf(page, count, LPU64"\n", osd->od_kstatfs.f_ffree); } return rc; } int lprocfs_osd_rd_fstype(char *page, char **start, off_t off, int count, int *eof, void *data) { struct obd_device *osd = data; LASSERT(osd != NULL); return snprintf(page, count, "ldiskfs\n"); } static int lprocfs_osd_rd_mntdev(char *page, char **start, off_t off, int count, int *eof, void *data) { struct osd_device *osd = data; LASSERT(osd != NULL); LASSERT(osd->od_mount->lmi_mnt->mnt_devname); *eof = 1; return snprintf(page, count, "%s\n", osd->od_mount->lmi_mnt->mnt_devname); } struct lprocfs_vars lprocfs_osd_obd_vars[] = { { "blocksize", lprocfs_osd_rd_blksize, 0, 0 }, { "kbytestotal", lprocfs_osd_rd_kbytestotal, 0, 0 }, { "kbytesfree", lprocfs_osd_rd_kbytesfree, 0, 0 }, { "kbytesavail", lprocfs_osd_rd_kbytesavail, 0, 0 }, { "filestotal", lprocfs_osd_rd_filestotal, 0, 0 }, { "filesfree", lprocfs_osd_rd_filesfree, 0, 0 }, { "fstype", lprocfs_osd_rd_fstype, 0, 0 }, { "mntdev", lprocfs_osd_rd_mntdev, 0, 0 }, { 0 } }; struct lprocfs_vars lprocfs_osd_module_vars[] = { { "num_refs", lprocfs_rd_numrefs, 0, 0 }, { 0 } }; void lprocfs_osd_init_vars(struct lprocfs_static_vars *lvars) { lvars->module_vars = lprocfs_osd_module_vars; lvars->obd_vars = lprocfs_osd_obd_vars; } #endif