1 /* -*- MODE: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
5 * Lustre Metadata Server (mdd) routines
7 * Copyright (C) 2006 Cluster File Systems, Inc.
8 * Author: Wang Di <wangdi@clusterfs.com>
10 * This file is part of the Lustre file system, http://www.lustre.org
11 * Lustre is a trademark of Cluster File Systems, Inc.
13 * You may have signed or agreed to another license before downloading
14 * this software. If so, you are bound by the terms and conditions
15 * of that agreement, and the following does not apply to you. See the
16 * LICENSE file included with this distribution for more information.
18 * If you did not agree to a different license, then this copy of Lustre
19 * is open source software; you can redistribute it and/or modify it
20 * under the terms of version 2 of the GNU General Public License as
21 * published by the Free Software Foundation.
23 * In either case, Lustre is distributed in the hope that it will be
24 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
25 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * license text for more details.
29 # define EXPORT_SYMTAB
31 #define DEBUG_SUBSYSTEM S_MDS
33 #include <linux/module.h>
35 #include <obd_class.h>
36 #include <lustre_ver.h>
37 #include <obd_support.h>
38 #include <lprocfs_status.h>
41 #include <lustre/lustre_idl.h>
43 #include "mdd_internal.h"
45 static const char *mdd_counter_names[LPROC_MDD_NR] = {
48 int mdd_procfs_init(struct mdd_device *mdd, const char *name)
50 struct lprocfs_static_vars lvars;
51 struct lu_device *ld = &mdd->mdd_md_dev.md_lu_dev;
52 struct obd_type *type;
56 type = ld->ld_type->ldt_obd_type;
58 LASSERT(name != NULL);
59 LASSERT(type != NULL);
61 /* Find the type procroot and add the proc entry for this device */
62 lprocfs_mdd_init_vars(&lvars);
63 mdd->mdd_proc_entry = lprocfs_register(name, type->typ_procroot,
65 if (IS_ERR(mdd->mdd_proc_entry)) {
66 rc = PTR_ERR(mdd->mdd_proc_entry);
67 CERROR("Error %d setting up lprocfs for %s\n",
69 mdd->mdd_proc_entry = NULL;
73 rc = lu_time_init(&mdd->mdd_stats,
75 mdd_counter_names, ARRAY_SIZE(mdd_counter_names));
83 int mdd_procfs_fini(struct mdd_device *mdd)
86 lu_time_fini(&mdd->mdd_stats);
88 if (mdd->mdd_proc_entry) {
89 lprocfs_remove(&mdd->mdd_proc_entry);
90 mdd->mdd_proc_entry = NULL;
95 void mdd_lprocfs_time_start(const struct lu_env *env)
97 lu_lprocfs_time_start(env);
100 void mdd_lprocfs_time_end(const struct lu_env *env, struct mdd_device *mdd,
103 lu_lprocfs_time_end(env, mdd->mdd_stats, idx);
106 static int lprocfs_wr_atime_diff(struct file *file, const char *buffer,
107 unsigned long count, void *data)
109 struct mdd_device *mdd = data;
110 char kernbuf[20], *end;
111 unsigned long diff = 0;
113 if (count > (sizeof(kernbuf) - 1))
116 if (copy_from_user(kernbuf, buffer, count))
119 kernbuf[count] = '\0';
121 diff = simple_strtoul(kernbuf, &end, 0);
125 mdd->mdd_atime_diff = diff;
129 static int lprocfs_rd_atime_diff(char *page, char **start, off_t off,
130 int count, int *eof, void *data)
132 struct mdd_device *mdd = data;
135 return snprintf(page, count, "%lu\n", mdd->mdd_atime_diff);
138 static struct lprocfs_vars lprocfs_mdd_obd_vars[] = {
139 { "atime_diff", lprocfs_rd_atime_diff, lprocfs_wr_atime_diff, 0 },
143 static struct lprocfs_vars lprocfs_mdd_module_vars[] = {
144 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
148 void lprocfs_mdd_init_vars(struct lprocfs_static_vars *lvars)
150 lvars->module_vars = lprocfs_mdd_module_vars;
151 lvars->obd_vars = lprocfs_mdd_obd_vars;