Whamcloud - gitweb
use special macro for print time_t, cleanup in includes.
[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  *  mdd/mdd_lproc.c
5  *  Lustre Metadata Server (mdd) routines
6  *
7  *  Copyright (C) 2006 Cluster File Systems, Inc.
8  *   Author: Wang Di <wangdi@clusterfs.com>
9  *
10  *   This file is part of the Lustre file system, http://www.lustre.org
11  *   Lustre is a trademark of Cluster File Systems, Inc.
12  *
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.
17  *
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.
22  *
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.
27  */
28 #ifndef EXPORT_SYMTAB
29 # define EXPORT_SYMTAB
30 #endif
31 #define DEBUG_SUBSYSTEM S_MDS
32
33 #include <linux/module.h>
34 #include <obd.h>
35 #include <obd_class.h>
36 #include <lustre_ver.h>
37 #include <obd_support.h>
38 #include <lprocfs_status.h>
39 #include <lu_time.h>
40
41 #include <lustre/lustre_idl.h>
42
43 #include "mdd_internal.h"
44
45 static const char *mdd_counter_names[LPROC_MDD_NR] = {
46 };
47
48 int mdd_procfs_init(struct mdd_device *mdd, const char *name)
49 {
50         struct lprocfs_static_vars lvars;
51         struct lu_device    *ld = &mdd->mdd_md_dev.md_lu_dev;
52         struct obd_type     *type;
53         int                  rc;
54         ENTRY;
55
56         type = ld->ld_type->ldt_obd_type;
57
58         LASSERT(name != NULL);
59         LASSERT(type != NULL);
60
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,
64                                                lvars.obd_vars, mdd);
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",
68                        rc, name);
69                 mdd->mdd_proc_entry = NULL;
70                 GOTO(out, rc);
71         }
72
73         rc = lu_time_init(&mdd->mdd_stats,
74                           mdd->mdd_proc_entry,
75                           mdd_counter_names, ARRAY_SIZE(mdd_counter_names));
76         EXIT;
77 out:
78         if (rc)
79                mdd_procfs_fini(mdd);
80         return rc;
81 }
82
83 int mdd_procfs_fini(struct mdd_device *mdd)
84 {
85         if (mdd->mdd_stats)
86                 lu_time_fini(&mdd->mdd_stats);
87
88         if (mdd->mdd_proc_entry) {
89                  lprocfs_remove(&mdd->mdd_proc_entry);
90                  mdd->mdd_proc_entry = NULL;
91         }
92         RETURN(0);
93 }
94
95 void mdd_lprocfs_time_start(const struct lu_env *env)
96 {
97         lu_lprocfs_time_start(env);
98 }
99
100 void mdd_lprocfs_time_end(const struct lu_env *env, struct mdd_device *mdd,
101                           int idx)
102 {
103         lu_lprocfs_time_end(env, mdd->mdd_stats, idx);
104 }
105
106 static int lprocfs_wr_atime_diff(struct file *file, const char *buffer,
107                                  unsigned long count, void *data)
108 {
109         struct mdd_device *mdd = data;
110         char kernbuf[20], *end;
111         unsigned long diff = 0;
112
113         if (count > (sizeof(kernbuf) - 1))
114                 return -EINVAL;
115
116         if (copy_from_user(kernbuf, buffer, count))
117                 return -EFAULT;
118
119         kernbuf[count] = '\0';
120
121         diff = simple_strtoul(kernbuf, &end, 0);
122         if (kernbuf == end)
123                 return -EINVAL;
124
125         mdd->mdd_atime_diff = diff;
126         return count;
127 }
128
129 static int lprocfs_rd_atime_diff(char *page, char **start, off_t off,
130                                  int count, int *eof, void *data)
131 {
132         struct mdd_device *mdd = data;
133
134         *eof = 1;
135         return snprintf(page, count, "%lu\n", mdd->mdd_atime_diff);
136 }
137
138 static struct lprocfs_vars lprocfs_mdd_obd_vars[] = {
139         { "atime_diff", lprocfs_rd_atime_diff, lprocfs_wr_atime_diff, 0 },
140         { 0 }
141 };
142
143 static struct lprocfs_vars lprocfs_mdd_module_vars[] = {
144         { "num_refs",   lprocfs_rd_numrefs, 0, 0 },
145         { 0 }
146 };
147
148 void lprocfs_mdd_init_vars(struct lprocfs_static_vars *lvars)
149 {
150         lvars->module_vars  = lprocfs_mdd_module_vars;
151         lvars->obd_vars     = lprocfs_mdd_obd_vars;
152 }