Whamcloud - gitweb
LU-1347 style: removes obsolete EXPORT_SYMTAB macros
[fs/lustre-release.git] / lustre / mdd / mdd_lproc.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  */
30 /*
31  * This file is part of Lustre, http://www.lustre.org/
32  * Lustre is a trademark of Sun Microsystems, Inc.
33  *
34  * lustre/mdd/mdd_lproc.c
35  *
36  * Lustre Metadata Server (mdd) routines
37  *
38  * Author: Wang Di <wangdi@clusterfs.com>
39  */
40
41 #define DEBUG_SUBSYSTEM S_MDS
42
43 #include <linux/module.h>
44 #include <linux/poll.h>
45 #include <obd.h>
46 #include <obd_class.h>
47 #include <lustre_ver.h>
48 #include <obd_support.h>
49 #include <lprocfs_status.h>
50 #include <lu_time.h>
51 #include <lustre_log.h>
52 #include <lustre/lustre_idl.h>
53 #include <libcfs/libcfs_string.h>
54
55 #include "mdd_internal.h"
56
57 static const char *mdd_counter_names[LPROC_MDD_NR] = {
58 };
59
60 int mdd_procfs_init(struct mdd_device *mdd, const char *name)
61 {
62         struct lprocfs_static_vars lvars;
63         struct lu_device    *ld = &mdd->mdd_md_dev.md_lu_dev;
64         struct obd_type     *type;
65         int                  rc;
66         ENTRY;
67
68         type = ld->ld_type->ldt_obd_type;
69
70         LASSERT(name != NULL);
71         LASSERT(type != NULL);
72
73         /* Find the type procroot and add the proc entry for this device */
74         lprocfs_mdd_init_vars(&lvars);
75         mdd->mdd_proc_entry = lprocfs_register(name, type->typ_procroot,
76                                                lvars.obd_vars, mdd);
77         if (IS_ERR(mdd->mdd_proc_entry)) {
78                 rc = PTR_ERR(mdd->mdd_proc_entry);
79                 CERROR("Error %d setting up lprocfs for %s\n",
80                        rc, name);
81                 mdd->mdd_proc_entry = NULL;
82                 GOTO(out, rc);
83         }
84
85         rc = lu_time_init(&mdd->mdd_stats,
86                           mdd->mdd_proc_entry,
87                           mdd_counter_names, ARRAY_SIZE(mdd_counter_names));
88
89         EXIT;
90 out:
91         if (rc)
92                mdd_procfs_fini(mdd);
93         return rc;
94 }
95
96 int mdd_procfs_fini(struct mdd_device *mdd)
97 {
98         if (mdd->mdd_stats)
99                 lu_time_fini(&mdd->mdd_stats);
100
101         if (mdd->mdd_proc_entry) {
102                  lprocfs_remove(&mdd->mdd_proc_entry);
103                  mdd->mdd_proc_entry = NULL;
104         }
105         RETURN(0);
106 }
107
108 void mdd_lprocfs_time_start(const struct lu_env *env)
109 {
110         lu_lprocfs_time_start(env);
111 }
112
113 void mdd_lprocfs_time_end(const struct lu_env *env, struct mdd_device *mdd,
114                           int idx)
115 {
116         lu_lprocfs_time_end(env, mdd->mdd_stats, idx);
117 }
118
119 static int lprocfs_wr_atime_diff(struct file *file, const char *buffer,
120                                  unsigned long count, void *data)
121 {
122         struct mdd_device *mdd = data;
123         char kernbuf[20], *end;
124         unsigned long diff = 0;
125
126         if (count > (sizeof(kernbuf) - 1))
127                 return -EINVAL;
128
129         if (cfs_copy_from_user(kernbuf, buffer, count))
130                 return -EFAULT;
131
132         kernbuf[count] = '\0';
133
134         diff = simple_strtoul(kernbuf, &end, 0);
135         if (kernbuf == end)
136                 return -EINVAL;
137
138         mdd->mdd_atime_diff = diff;
139         return count;
140 }
141
142 static int lprocfs_rd_atime_diff(char *page, char **start, off_t off,
143                                  int count, int *eof, void *data)
144 {
145         struct mdd_device *mdd = data;
146
147         *eof = 1;
148         return snprintf(page, count, "%lu\n", mdd->mdd_atime_diff);
149 }
150
151
152 /**** changelogs ****/
153 static int lprocfs_rd_changelog_mask(char *page, char **start, off_t off,
154                                      int count, int *eof, void *data)
155 {
156         struct mdd_device *mdd = data;
157         int i = 0, rc = 0;
158
159         *eof = 1;
160         while (i < CL_LAST) {
161                 if (mdd->mdd_cl.mc_mask & (1 << i))
162                         rc += snprintf(page + rc, count - rc, "%s ",
163                                        changelog_type2str(i));
164                 i++;
165         }
166         return rc;
167 }
168
169 static int lprocfs_wr_changelog_mask(struct file *file, const char *buffer,
170                                      unsigned long count, void *data)
171 {
172         struct mdd_device *mdd = data;
173         char *kernbuf;
174         int rc;
175         ENTRY;
176
177         if (count >= CFS_PAGE_SIZE)
178                 RETURN(-EINVAL);
179         OBD_ALLOC(kernbuf, CFS_PAGE_SIZE);
180         if (kernbuf == NULL)
181                 RETURN(-ENOMEM);
182         if (cfs_copy_from_user(kernbuf, buffer, count))
183                 GOTO(out, rc = -EFAULT);
184         kernbuf[count] = 0;
185
186         rc = cfs_str2mask(kernbuf, changelog_type2str, &mdd->mdd_cl.mc_mask,
187                           CHANGELOG_MINMASK, CHANGELOG_ALLMASK);
188         if (rc == 0)
189                 rc = count;
190 out:
191         OBD_FREE(kernbuf, CFS_PAGE_SIZE);
192         return rc;
193 }
194
195 struct cucb_data {
196         char *page;
197         int count;
198         int idx;
199 };
200
201 static int lprocfs_changelog_users_cb(struct llog_handle *llh,
202                                       struct llog_rec_hdr *hdr, void *data)
203 {
204         struct llog_changelog_user_rec *rec;
205         struct cucb_data *cucb = (struct cucb_data *)data;
206
207         LASSERT(llh->lgh_hdr->llh_flags & LLOG_F_IS_PLAIN);
208
209         rec = (struct llog_changelog_user_rec *)hdr;
210
211         cucb->idx += snprintf(cucb->page + cucb->idx, cucb->count - cucb->idx,
212                               CHANGELOG_USER_PREFIX"%-3d "LPU64"\n",
213                               rec->cur_id, rec->cur_endrec);
214         if (cucb->idx >= cucb->count)
215                 return -ENOSPC;
216
217         return 0;
218 }
219
220 static int lprocfs_rd_changelog_users(char *page, char **start, off_t off,
221                                       int count, int *eof, void *data)
222 {
223         struct mdd_device *mdd = data;
224         struct llog_ctxt *ctxt;
225         struct cucb_data cucb;
226         __u64 cur;
227
228         *eof = 1;
229
230         ctxt = llog_get_context(mdd2obd_dev(mdd),LLOG_CHANGELOG_USER_ORIG_CTXT);
231         if (ctxt == NULL)
232                 return -ENXIO;
233         LASSERT(ctxt->loc_handle->lgh_hdr->llh_flags & LLOG_F_IS_CAT);
234
235         cfs_spin_lock(&mdd->mdd_cl.mc_lock);
236         cur = mdd->mdd_cl.mc_index;
237         cfs_spin_unlock(&mdd->mdd_cl.mc_lock);
238
239         cucb.count = count;
240         cucb.page = page;
241         cucb.idx = 0;
242
243         cucb.idx += snprintf(cucb.page + cucb.idx, cucb.count - cucb.idx,
244                               "current index: "LPU64"\n", cur);
245
246         cucb.idx += snprintf(cucb.page + cucb.idx, cucb.count - cucb.idx,
247                               "%-5s %s\n", "ID", "index");
248
249         llog_cat_process(ctxt->loc_handle, lprocfs_changelog_users_cb,
250                          &cucb, 0, 0);
251
252         llog_ctxt_put(ctxt);
253         return cucb.idx;
254 }
255
256 #ifdef HAVE_QUOTA_SUPPORT
257 static int mdd_lprocfs_quota_rd_type(char *page, char **start, off_t off,
258                                      int count, int *eof, void *data)
259 {
260         struct mdd_device *mdd = data;
261         return lprocfs_quota_rd_type(page, start, off, count, eof,
262                                      mdd->mdd_obd_dev);
263 }
264
265 static int mdd_lprocfs_quota_wr_type(struct file *file, const char *buffer,
266                                      unsigned long count, void *data)
267 {
268         struct mdd_device *mdd = data;
269         return lprocfs_quota_wr_type(file, buffer, count, mdd->mdd_obd_dev);
270 }
271 #endif
272
273 static int lprocfs_rd_sync_perm(char *page, char **start, off_t off,
274                                 int count, int *eof, void *data)
275 {
276         struct mdd_device *mdd = data;
277
278         LASSERT(mdd != NULL);
279         return snprintf(page, count, "%d\n", mdd->mdd_sync_permission);
280 }
281
282 static int lprocfs_wr_sync_perm(struct file *file, const char *buffer,
283                                 unsigned long count, void *data)
284 {
285         struct mdd_device *mdd = data;
286         int val, rc;
287
288         LASSERT(mdd != NULL);
289         rc = lprocfs_write_helper(buffer, count, &val);
290         if (rc)
291                 return rc;
292
293         mdd->mdd_sync_permission = !!val;
294         return count;
295 }
296
297 static struct lprocfs_vars lprocfs_mdd_obd_vars[] = {
298         { "atime_diff",      lprocfs_rd_atime_diff, lprocfs_wr_atime_diff, 0 },
299         { "changelog_mask",  lprocfs_rd_changelog_mask,
300                              lprocfs_wr_changelog_mask, 0 },
301         { "changelog_users", lprocfs_rd_changelog_users, 0, 0},
302 #ifdef HAVE_QUOTA_SUPPORT
303         { "quota_type",      mdd_lprocfs_quota_rd_type,
304                              mdd_lprocfs_quota_wr_type, 0 },
305 #endif
306         { "sync_permission", lprocfs_rd_sync_perm, lprocfs_wr_sync_perm, 0 },
307         { 0 }
308 };
309
310 static struct lprocfs_vars lprocfs_mdd_module_vars[] = {
311         { "num_refs",   lprocfs_rd_numrefs, 0, 0 },
312         { 0 }
313 };
314
315 void lprocfs_mdd_init_vars(struct lprocfs_static_vars *lvars)
316 {
317         lvars->module_vars  = lprocfs_mdd_module_vars;
318         lvars->obd_vars     = lprocfs_mdd_obd_vars;
319 }
320