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 2008 Sun Microsystems, Inc. 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/mdd/mdd_lproc.c
38 * Lustre Metadata Server (mdd) routines
40 * Author: Wang Di <wangdi@clusterfs.com>
44 # define EXPORT_SYMTAB
46 #define DEBUG_SUBSYSTEM S_MDS
48 #include <linux/module.h>
50 #include <obd_class.h>
51 #include <lustre_ver.h>
52 #include <obd_support.h>
53 #include <lprocfs_status.h>
56 #include <lustre/lustre_idl.h>
58 #include "mdd_internal.h"
60 static const char *mdd_counter_names[LPROC_MDD_NR] = {
63 int mdd_procfs_init(struct mdd_device *mdd, const char *name)
65 struct lprocfs_static_vars lvars;
66 struct lu_device *ld = &mdd->mdd_md_dev.md_lu_dev;
67 struct obd_type *type;
71 type = ld->ld_type->ldt_obd_type;
73 LASSERT(name != NULL);
74 LASSERT(type != NULL);
76 /* Find the type procroot and add the proc entry for this device */
77 lprocfs_mdd_init_vars(&lvars);
78 mdd->mdd_proc_entry = lprocfs_register(name, type->typ_procroot,
80 if (IS_ERR(mdd->mdd_proc_entry)) {
81 rc = PTR_ERR(mdd->mdd_proc_entry);
82 CERROR("Error %d setting up lprocfs for %s\n",
84 mdd->mdd_proc_entry = NULL;
88 rc = lu_time_init(&mdd->mdd_stats,
90 mdd_counter_names, ARRAY_SIZE(mdd_counter_names));
98 int mdd_procfs_fini(struct mdd_device *mdd)
101 lu_time_fini(&mdd->mdd_stats);
103 if (mdd->mdd_proc_entry) {
104 lprocfs_remove(&mdd->mdd_proc_entry);
105 mdd->mdd_proc_entry = NULL;
110 void mdd_lprocfs_time_start(const struct lu_env *env)
112 lu_lprocfs_time_start(env);
115 void mdd_lprocfs_time_end(const struct lu_env *env, struct mdd_device *mdd,
118 lu_lprocfs_time_end(env, mdd->mdd_stats, idx);
121 static int lprocfs_wr_atime_diff(struct file *file, const char *buffer,
122 unsigned long count, void *data)
124 struct mdd_device *mdd = data;
125 char kernbuf[20], *end;
126 unsigned long diff = 0;
128 if (count > (sizeof(kernbuf) - 1))
131 if (copy_from_user(kernbuf, buffer, count))
134 kernbuf[count] = '\0';
136 diff = simple_strtoul(kernbuf, &end, 0);
140 mdd->mdd_atime_diff = diff;
144 static int lprocfs_rd_atime_diff(char *page, char **start, off_t off,
145 int count, int *eof, void *data)
147 struct mdd_device *mdd = data;
150 return snprintf(page, count, "%lu\n", mdd->mdd_atime_diff);
153 static struct lprocfs_vars lprocfs_mdd_obd_vars[] = {
154 { "atime_diff", lprocfs_rd_atime_diff, lprocfs_wr_atime_diff, 0 },
158 static struct lprocfs_vars lprocfs_mdd_module_vars[] = {
159 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
163 void lprocfs_mdd_init_vars(struct lprocfs_static_vars *lvars)
165 lvars->module_vars = lprocfs_mdd_module_vars;
166 lvars->obd_vars = lprocfs_mdd_obd_vars;