Whamcloud - gitweb
Land b_head_quota onto HEAD (20081116_0105)
[fs/lustre-release.git] / lustre / mdd / mdd_lproc.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
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.
11  *
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).
17  *
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
21  *
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
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lustre/mdd/mdd_lproc.c
37  *
38  * Lustre Metadata Server (mdd) routines
39  *
40  * Author: Wang Di <wangdi@clusterfs.com>
41  */
42
43 #ifndef EXPORT_SYMTAB
44 # define EXPORT_SYMTAB
45 #endif
46 #define DEBUG_SUBSYSTEM S_MDS
47
48 #include <linux/module.h>
49 #include <obd.h>
50 #include <obd_class.h>
51 #include <lustre_ver.h>
52 #include <obd_support.h>
53 #include <lprocfs_status.h>
54 #include <lu_time.h>
55
56 #include <lustre/lustre_idl.h>
57
58 #include "mdd_internal.h"
59
60 static const char *mdd_counter_names[LPROC_MDD_NR] = {
61 };
62
63 int mdd_procfs_init(struct mdd_device *mdd, const char *name)
64 {
65         struct lprocfs_static_vars lvars;
66         struct lu_device    *ld = &mdd->mdd_md_dev.md_lu_dev;
67         struct obd_type     *type;
68         int                  rc;
69         ENTRY;
70
71         type = ld->ld_type->ldt_obd_type;
72
73         LASSERT(name != NULL);
74         LASSERT(type != NULL);
75
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,
79                                                lvars.obd_vars, mdd);
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",
83                        rc, name);
84                 mdd->mdd_proc_entry = NULL;
85                 GOTO(out, rc);
86         }
87
88         rc = lu_time_init(&mdd->mdd_stats,
89                           mdd->mdd_proc_entry,
90                           mdd_counter_names, ARRAY_SIZE(mdd_counter_names));
91         EXIT;
92 out:
93         if (rc)
94                mdd_procfs_fini(mdd);
95         return rc;
96 }
97
98 int mdd_procfs_fini(struct mdd_device *mdd)
99 {
100         if (mdd->mdd_stats)
101                 lu_time_fini(&mdd->mdd_stats);
102
103         if (mdd->mdd_proc_entry) {
104                  lprocfs_remove(&mdd->mdd_proc_entry);
105                  mdd->mdd_proc_entry = NULL;
106         }
107         RETURN(0);
108 }
109
110 void mdd_lprocfs_time_start(const struct lu_env *env)
111 {
112         lu_lprocfs_time_start(env);
113 }
114
115 void mdd_lprocfs_time_end(const struct lu_env *env, struct mdd_device *mdd,
116                           int idx)
117 {
118         lu_lprocfs_time_end(env, mdd->mdd_stats, idx);
119 }
120
121 static int lprocfs_wr_atime_diff(struct file *file, const char *buffer,
122                                  unsigned long count, void *data)
123 {
124         struct mdd_device *mdd = data;
125         char kernbuf[20], *end;
126         unsigned long diff = 0;
127
128         if (count > (sizeof(kernbuf) - 1))
129                 return -EINVAL;
130
131         if (copy_from_user(kernbuf, buffer, count))
132                 return -EFAULT;
133
134         kernbuf[count] = '\0';
135
136         diff = simple_strtoul(kernbuf, &end, 0);
137         if (kernbuf == end)
138                 return -EINVAL;
139
140         mdd->mdd_atime_diff = diff;
141         return count;
142 }
143
144 static int lprocfs_rd_atime_diff(char *page, char **start, off_t off,
145                                  int count, int *eof, void *data)
146 {
147         struct mdd_device *mdd = data;
148
149         *eof = 1;
150         return snprintf(page, count, "%lu\n", mdd->mdd_atime_diff);
151 }
152
153 #ifdef HAVE_QUOTA_SUPPORT
154 static int mdd_lprocfs_quota_rd_type(char *page, char **start, off_t off,
155                                      int count, int *eof, void *data)
156 {
157         struct mdd_device *mdd = data;
158         return lprocfs_quota_rd_type(page, start, off, count, eof,
159                                      mdd->mdd_obd_dev);
160 }
161
162 static int mdd_lprocfs_quota_wr_type(struct file *file, const char *buffer,
163                                      unsigned long count, void *data)
164 {
165         struct mdd_device *mdd = data;
166         return lprocfs_quota_wr_type(file, buffer, count, mdd->mdd_obd_dev);
167 }
168 #endif
169
170 static struct lprocfs_vars lprocfs_mdd_obd_vars[] = {
171         { "atime_diff", lprocfs_rd_atime_diff, lprocfs_wr_atime_diff, 0 },
172 #ifdef HAVE_QUOTA_SUPPORT
173         { "quota_type",      mdd_lprocfs_quota_rd_type,
174                              mdd_lprocfs_quota_wr_type, 0 },
175 #endif
176         { 0 }
177 };
178
179 static struct lprocfs_vars lprocfs_mdd_module_vars[] = {
180         { "num_refs",   lprocfs_rd_numrefs, 0, 0 },
181         { 0 }
182 };
183
184 void lprocfs_mdd_init_vars(struct lprocfs_static_vars *lvars)
185 {
186         lvars->module_vars  = lprocfs_mdd_module_vars;
187         lvars->obd_vars     = lprocfs_mdd_obd_vars;
188 }