4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
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
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
31 * This file is part of Lustre, http://www.lustre.org/
32 * Lustre is a trademark of Sun Microsystems, Inc.
34 * lustre/mdd/mdd_lproc.c
36 * Lustre Metadata Server (mdd) routines
38 * Author: Wang Di <wangdi@clusterfs.com>
41 #define DEBUG_SUBSYSTEM S_MDS
43 #include <linux/module.h>
44 #include <linux/poll.h>
46 #include <obd_class.h>
47 #include <lustre_ver.h>
48 #include <obd_support.h>
49 #include <lprocfs_status.h>
51 #include <lustre_log.h>
52 #include <lustre/lustre_idl.h>
53 #include <libcfs/libcfs_string.h>
55 #include "mdd_internal.h"
57 static const char *mdd_counter_names[LPROC_MDD_NR] = {
60 int mdd_procfs_init(struct mdd_device *mdd, const char *name)
62 struct lprocfs_static_vars lvars;
63 struct lu_device *ld = &mdd->mdd_md_dev.md_lu_dev;
64 struct obd_type *type;
68 type = ld->ld_type->ldt_obd_type;
70 LASSERT(name != NULL);
71 LASSERT(type != NULL);
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,
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",
81 mdd->mdd_proc_entry = NULL;
85 rc = lu_time_init(&mdd->mdd_stats,
87 mdd_counter_names, ARRAY_SIZE(mdd_counter_names));
96 int mdd_procfs_fini(struct mdd_device *mdd)
99 lu_time_fini(&mdd->mdd_stats);
101 if (mdd->mdd_proc_entry) {
102 lprocfs_remove(&mdd->mdd_proc_entry);
103 mdd->mdd_proc_entry = NULL;
108 void mdd_lprocfs_time_start(const struct lu_env *env)
110 lu_lprocfs_time_start(env);
113 void mdd_lprocfs_time_end(const struct lu_env *env, struct mdd_device *mdd,
116 lu_lprocfs_time_end(env, mdd->mdd_stats, idx);
119 static int lprocfs_wr_atime_diff(struct file *file, const char *buffer,
120 unsigned long count, void *data)
122 struct mdd_device *mdd = data;
123 char kernbuf[20], *end;
124 unsigned long diff = 0;
126 if (count > (sizeof(kernbuf) - 1))
129 if (cfs_copy_from_user(kernbuf, buffer, count))
132 kernbuf[count] = '\0';
134 diff = simple_strtoul(kernbuf, &end, 0);
138 mdd->mdd_atime_diff = diff;
142 static int lprocfs_rd_atime_diff(char *page, char **start, off_t off,
143 int count, int *eof, void *data)
145 struct mdd_device *mdd = data;
148 return snprintf(page, count, "%lu\n", mdd->mdd_atime_diff);
152 /**** changelogs ****/
153 static int lprocfs_rd_changelog_mask(char *page, char **start, off_t off,
154 int count, int *eof, void *data)
156 struct mdd_device *mdd = data;
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));
169 static int lprocfs_wr_changelog_mask(struct file *file, const char *buffer,
170 unsigned long count, void *data)
172 struct mdd_device *mdd = data;
177 if (count >= CFS_PAGE_SIZE)
179 OBD_ALLOC(kernbuf, CFS_PAGE_SIZE);
182 if (cfs_copy_from_user(kernbuf, buffer, count))
183 GOTO(out, rc = -EFAULT);
186 rc = cfs_str2mask(kernbuf, changelog_type2str, &mdd->mdd_cl.mc_mask,
187 CHANGELOG_MINMASK, CHANGELOG_ALLMASK);
191 OBD_FREE(kernbuf, CFS_PAGE_SIZE);
201 static int lprocfs_changelog_users_cb(struct llog_handle *llh,
202 struct llog_rec_hdr *hdr, void *data)
204 struct llog_changelog_user_rec *rec;
205 struct cucb_data *cucb = (struct cucb_data *)data;
207 LASSERT(llh->lgh_hdr->llh_flags & LLOG_F_IS_PLAIN);
209 rec = (struct llog_changelog_user_rec *)hdr;
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)
220 static int lprocfs_rd_changelog_users(char *page, char **start, off_t off,
221 int count, int *eof, void *data)
223 struct mdd_device *mdd = data;
224 struct llog_ctxt *ctxt;
225 struct cucb_data cucb;
230 ctxt = llog_get_context(mdd2obd_dev(mdd),LLOG_CHANGELOG_USER_ORIG_CTXT);
233 LASSERT(ctxt->loc_handle->lgh_hdr->llh_flags & LLOG_F_IS_CAT);
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);
243 cucb.idx += snprintf(cucb.page + cucb.idx, cucb.count - cucb.idx,
244 "current index: "LPU64"\n", cur);
246 cucb.idx += snprintf(cucb.page + cucb.idx, cucb.count - cucb.idx,
247 "%-5s %s\n", "ID", "index");
249 llog_cat_process(NULL, ctxt->loc_handle, lprocfs_changelog_users_cb,
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)
260 struct mdd_device *mdd = data;
261 return lprocfs_quota_rd_type(page, start, off, count, eof,
265 static int mdd_lprocfs_quota_wr_type(struct file *file, const char *buffer,
266 unsigned long count, void *data)
268 struct mdd_device *mdd = data;
269 return lprocfs_quota_wr_type(file, buffer, count, mdd->mdd_obd_dev);
273 static int lprocfs_rd_sync_perm(char *page, char **start, off_t off,
274 int count, int *eof, void *data)
276 struct mdd_device *mdd = data;
278 LASSERT(mdd != NULL);
279 return snprintf(page, count, "%d\n", mdd->mdd_sync_permission);
282 static int lprocfs_wr_sync_perm(struct file *file, const char *buffer,
283 unsigned long count, void *data)
285 struct mdd_device *mdd = data;
288 LASSERT(mdd != NULL);
289 rc = lprocfs_write_helper(buffer, count, &val);
293 mdd->mdd_sync_permission = !!val;
297 static int lprocfs_rd_lfsck_speed_limit(char *page, char **start, off_t off,
298 int count, int *eof, void *data)
300 struct mdd_device *mdd = data;
302 LASSERT(mdd != NULL);
304 return snprintf(page, count, "%u\n", mdd->mdd_lfsck.ml_speed_limit);
307 static int lprocfs_wr_lfsck_speed_limit(struct file *file, const char *buffer,
308 unsigned long count, void *data)
310 struct mdd_device *mdd = data;
311 struct md_lfsck *lfsck;
315 LASSERT(mdd != NULL);
316 rc = lprocfs_write_helper(buffer, count, &val);
320 lfsck = &mdd->mdd_lfsck;
321 if (val != lfsck->ml_speed_limit)
322 mdd_lfsck_set_speed(lfsck, val);
326 static struct lprocfs_vars lprocfs_mdd_obd_vars[] = {
327 { "atime_diff", lprocfs_rd_atime_diff, lprocfs_wr_atime_diff, 0 },
328 { "changelog_mask", lprocfs_rd_changelog_mask,
329 lprocfs_wr_changelog_mask, 0 },
330 { "changelog_users", lprocfs_rd_changelog_users, 0, 0},
331 #ifdef HAVE_QUOTA_SUPPORT
332 { "quota_type", mdd_lprocfs_quota_rd_type,
333 mdd_lprocfs_quota_wr_type, 0 },
335 { "sync_permission", lprocfs_rd_sync_perm, lprocfs_wr_sync_perm, 0 },
336 { "lfsck_speed_limit", lprocfs_rd_lfsck_speed_limit,
337 lprocfs_wr_lfsck_speed_limit, 0 },
341 static struct lprocfs_vars lprocfs_mdd_module_vars[] = {
342 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
346 void lprocfs_mdd_init_vars(struct lprocfs_static_vars *lvars)
348 lvars->module_vars = lprocfs_mdd_module_vars;
349 lvars->obd_vars = lprocfs_mdd_obd_vars;