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
44 #include <obd_class.h>
45 #include <obd_support.h>
46 #include <lprocfs_status.h>
48 #include <libcfs/libcfs_string.h>
50 #include "mdd_internal.h"
52 static const char *mdd_counter_names[LPROC_MDD_NR] = {
55 int mdd_procfs_init(struct mdd_device *mdd, const char *name)
57 struct lprocfs_static_vars lvars;
58 struct obd_type *type;
62 /* at the moment there is no linkage between lu_type
63 * and obd_type, so we lookup obd_type this way */
64 type = class_search_type(LUSTRE_MDD_NAME);
66 LASSERT(name != NULL);
67 LASSERT(type != NULL);
69 /* Find the type procroot and add the proc entry for this device */
70 lprocfs_mdd_init_vars(&lvars);
71 mdd->mdd_proc_entry = lprocfs_register(name, type->typ_procroot,
73 if (IS_ERR(mdd->mdd_proc_entry)) {
74 rc = PTR_ERR(mdd->mdd_proc_entry);
75 CERROR("Error %d setting up lprocfs for %s\n",
77 mdd->mdd_proc_entry = NULL;
81 rc = lu_time_init(&mdd->mdd_stats,
83 mdd_counter_names, ARRAY_SIZE(mdd_counter_names));
92 int mdd_procfs_fini(struct mdd_device *mdd)
95 lu_time_fini(&mdd->mdd_stats);
97 if (mdd->mdd_proc_entry) {
98 lprocfs_remove(&mdd->mdd_proc_entry);
99 mdd->mdd_proc_entry = NULL;
104 void mdd_lprocfs_time_start(const struct lu_env *env)
106 lu_lprocfs_time_start(env);
109 void mdd_lprocfs_time_end(const struct lu_env *env, struct mdd_device *mdd,
112 lu_lprocfs_time_end(env, mdd->mdd_stats, idx);
115 static int lprocfs_wr_atime_diff(struct file *file, const char *buffer,
116 unsigned long count, void *data)
118 struct mdd_device *mdd = data;
119 char kernbuf[20], *end;
120 unsigned long diff = 0;
122 if (count > (sizeof(kernbuf) - 1))
125 if (cfs_copy_from_user(kernbuf, buffer, count))
128 kernbuf[count] = '\0';
130 diff = simple_strtoul(kernbuf, &end, 0);
134 mdd->mdd_atime_diff = diff;
138 static int lprocfs_rd_atime_diff(char *page, char **start, off_t off,
139 int count, int *eof, void *data)
141 struct mdd_device *mdd = data;
144 return snprintf(page, count, "%lu\n", mdd->mdd_atime_diff);
148 /**** changelogs ****/
149 static int lprocfs_rd_changelog_mask(char *page, char **start, off_t off,
150 int count, int *eof, void *data)
152 struct mdd_device *mdd = data;
156 while (i < CL_LAST) {
157 if (mdd->mdd_cl.mc_mask & (1 << i))
158 rc += snprintf(page + rc, count - rc, "%s ",
159 changelog_type2str(i));
165 static int lprocfs_wr_changelog_mask(struct file *file, const char *buffer,
166 unsigned long count, void *data)
168 struct mdd_device *mdd = data;
173 if (count >= CFS_PAGE_SIZE)
175 OBD_ALLOC(kernbuf, CFS_PAGE_SIZE);
178 if (cfs_copy_from_user(kernbuf, buffer, count))
179 GOTO(out, rc = -EFAULT);
182 rc = cfs_str2mask(kernbuf, changelog_type2str, &mdd->mdd_cl.mc_mask,
183 CHANGELOG_MINMASK, CHANGELOG_ALLMASK);
187 OBD_FREE(kernbuf, CFS_PAGE_SIZE);
197 static int lprocfs_changelog_users_cb(const struct lu_env *env,
198 struct llog_handle *llh,
199 struct llog_rec_hdr *hdr, void *data)
201 struct llog_changelog_user_rec *rec;
202 struct cucb_data *cucb = (struct cucb_data *)data;
204 LASSERT(llh->lgh_hdr->llh_flags & LLOG_F_IS_PLAIN);
206 rec = (struct llog_changelog_user_rec *)hdr;
208 cucb->idx += snprintf(cucb->page + cucb->idx, cucb->count - cucb->idx,
209 CHANGELOG_USER_PREFIX"%-3d "LPU64"\n",
210 rec->cur_id, rec->cur_endrec);
211 if (cucb->idx >= cucb->count)
217 static int lprocfs_rd_changelog_users(char *page, char **start, off_t off,
218 int count, int *eof, void *data)
221 struct mdd_device *mdd = data;
222 struct llog_ctxt *ctxt;
223 struct cucb_data cucb;
229 ctxt = llog_get_context(mdd2obd_dev(mdd),
230 LLOG_CHANGELOG_USER_ORIG_CTXT);
233 LASSERT(ctxt->loc_handle->lgh_hdr->llh_flags & LLOG_F_IS_CAT);
235 rc = lu_env_init(&env, LCT_LOCAL);
241 spin_lock(&mdd->mdd_cl.mc_lock);
242 cur = mdd->mdd_cl.mc_index;
243 spin_unlock(&mdd->mdd_cl.mc_lock);
249 cucb.idx += snprintf(cucb.page + cucb.idx, cucb.count - cucb.idx,
250 "current index: "LPU64"\n", cur);
252 cucb.idx += snprintf(cucb.page + cucb.idx, cucb.count - cucb.idx,
253 "%-5s %s\n", "ID", "index");
255 llog_cat_process(&env, ctxt->loc_handle, lprocfs_changelog_users_cb,
263 static int lprocfs_rd_sync_perm(char *page, char **start, off_t off,
264 int count, int *eof, void *data)
266 struct mdd_device *mdd = data;
268 LASSERT(mdd != NULL);
269 return snprintf(page, count, "%d\n", mdd->mdd_sync_permission);
272 static int lprocfs_wr_sync_perm(struct file *file, const char *buffer,
273 unsigned long count, void *data)
275 struct mdd_device *mdd = data;
278 LASSERT(mdd != NULL);
279 rc = lprocfs_write_helper(buffer, count, &val);
283 mdd->mdd_sync_permission = !!val;
287 static int lprocfs_rd_lfsck_speed_limit(char *page, char **start, off_t off,
288 int count, int *eof, void *data)
290 struct mdd_device *mdd = data;
292 LASSERT(mdd != NULL);
294 return snprintf(page, count, "%u\n", mdd->mdd_lfsck.ml_speed_limit);
297 static int lprocfs_wr_lfsck_speed_limit(struct file *file, const char *buffer,
298 unsigned long count, void *data)
300 struct mdd_device *mdd = data;
301 struct md_lfsck *lfsck;
305 LASSERT(mdd != NULL);
306 rc = lprocfs_write_helper(buffer, count, &val);
310 lfsck = &mdd->mdd_lfsck;
311 if (val != lfsck->ml_speed_limit)
312 mdd_lfsck_set_speed(lfsck, val);
316 static struct lprocfs_vars lprocfs_mdd_obd_vars[] = {
317 { "atime_diff", lprocfs_rd_atime_diff, lprocfs_wr_atime_diff, 0 },
318 { "changelog_mask", lprocfs_rd_changelog_mask,
319 lprocfs_wr_changelog_mask, 0 },
320 { "changelog_users", lprocfs_rd_changelog_users, 0, 0},
321 { "sync_permission", lprocfs_rd_sync_perm, lprocfs_wr_sync_perm, 0 },
322 { "lfsck_speed_limit", lprocfs_rd_lfsck_speed_limit,
323 lprocfs_wr_lfsck_speed_limit, 0 },
327 static struct lprocfs_vars lprocfs_mdd_module_vars[] = {
328 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
332 void lprocfs_mdd_init_vars(struct lprocfs_static_vars *lvars)
334 lvars->module_vars = lprocfs_mdd_module_vars;
335 lvars->obd_vars = lprocfs_mdd_obd_vars;