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.
30 * Copyright (c) 2012, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/mdd/mdd_lproc.c
38 * Lustre Metadata Server (mdd) routines
40 * Author: Wang Di <wangdi@clusterfs.com>
43 #define DEBUG_SUBSYSTEM S_MDS
46 #include <obd_class.h>
47 #include <obd_support.h>
48 #include <lprocfs_status.h>
50 #include <libcfs/libcfs_string.h>
52 #include "mdd_internal.h"
54 static const char *mdd_counter_names[LPROC_MDD_NR] = {
57 int mdd_procfs_init(struct mdd_device *mdd, const char *name)
59 struct lprocfs_static_vars lvars;
60 struct obd_type *type;
64 /* at the moment there is no linkage between lu_type
65 * and obd_type, so we lookup obd_type this way */
66 type = class_search_type(LUSTRE_MDD_NAME);
68 LASSERT(name != NULL);
69 LASSERT(type != NULL);
71 /* Find the type procroot and add the proc entry for this device */
72 lprocfs_mdd_init_vars(&lvars);
73 mdd->mdd_proc_entry = lprocfs_register(name, type->typ_procroot,
75 if (IS_ERR(mdd->mdd_proc_entry)) {
76 rc = PTR_ERR(mdd->mdd_proc_entry);
77 CERROR("Error %d setting up lprocfs for %s\n",
79 mdd->mdd_proc_entry = NULL;
83 rc = lu_time_init(&mdd->mdd_stats,
85 mdd_counter_names, ARRAY_SIZE(mdd_counter_names));
94 int mdd_procfs_fini(struct mdd_device *mdd)
97 lu_time_fini(&mdd->mdd_stats);
99 if (mdd->mdd_proc_entry) {
100 lprocfs_remove(&mdd->mdd_proc_entry);
101 mdd->mdd_proc_entry = NULL;
106 void mdd_lprocfs_time_start(const struct lu_env *env)
108 lu_lprocfs_time_start(env);
111 void mdd_lprocfs_time_end(const struct lu_env *env, struct mdd_device *mdd,
114 lu_lprocfs_time_end(env, mdd->mdd_stats, idx);
117 static int lprocfs_wr_atime_diff(struct file *file, const char *buffer,
118 unsigned long count, void *data)
120 struct mdd_device *mdd = data;
121 char kernbuf[20], *end;
122 unsigned long diff = 0;
124 if (count > (sizeof(kernbuf) - 1))
127 if (cfs_copy_from_user(kernbuf, buffer, count))
130 kernbuf[count] = '\0';
132 diff = simple_strtoul(kernbuf, &end, 0);
136 mdd->mdd_atime_diff = diff;
140 static int lprocfs_rd_atime_diff(char *page, char **start, off_t off,
141 int count, int *eof, void *data)
143 struct mdd_device *mdd = data;
146 return snprintf(page, count, "%lu\n", mdd->mdd_atime_diff);
150 /**** changelogs ****/
151 static int lprocfs_rd_changelog_mask(char *page, char **start, off_t off,
152 int count, int *eof, void *data)
154 struct mdd_device *mdd = data;
158 while (i < CL_LAST) {
159 if (mdd->mdd_cl.mc_mask & (1 << i))
160 rc += snprintf(page + rc, count - rc, "%s ",
161 changelog_type2str(i));
167 static int lprocfs_wr_changelog_mask(struct file *file, const char *buffer,
168 unsigned long count, void *data)
170 struct mdd_device *mdd = data;
175 if (count >= CFS_PAGE_SIZE)
177 OBD_ALLOC(kernbuf, CFS_PAGE_SIZE);
180 if (cfs_copy_from_user(kernbuf, buffer, count))
181 GOTO(out, rc = -EFAULT);
184 rc = cfs_str2mask(kernbuf, changelog_type2str, &mdd->mdd_cl.mc_mask,
185 CHANGELOG_MINMASK, CHANGELOG_ALLMASK);
189 OBD_FREE(kernbuf, CFS_PAGE_SIZE);
199 static int lprocfs_changelog_users_cb(const struct lu_env *env,
200 struct llog_handle *llh,
201 struct llog_rec_hdr *hdr, void *data)
203 struct llog_changelog_user_rec *rec;
204 struct cucb_data *cucb = (struct cucb_data *)data;
206 LASSERT(llh->lgh_hdr->llh_flags & LLOG_F_IS_PLAIN);
208 rec = (struct llog_changelog_user_rec *)hdr;
210 cucb->idx += snprintf(cucb->page + cucb->idx, cucb->count - cucb->idx,
211 CHANGELOG_USER_PREFIX"%-3d "LPU64"\n",
212 rec->cur_id, rec->cur_endrec);
213 if (cucb->idx >= cucb->count)
219 static int lprocfs_rd_changelog_users(char *page, char **start, off_t off,
220 int count, int *eof, void *data)
223 struct mdd_device *mdd = data;
224 struct llog_ctxt *ctxt;
225 struct cucb_data cucb;
231 ctxt = llog_get_context(mdd2obd_dev(mdd),
232 LLOG_CHANGELOG_USER_ORIG_CTXT);
235 LASSERT(ctxt->loc_handle->lgh_hdr->llh_flags & LLOG_F_IS_CAT);
237 rc = lu_env_init(&env, LCT_LOCAL);
243 spin_lock(&mdd->mdd_cl.mc_lock);
244 cur = mdd->mdd_cl.mc_index;
245 spin_unlock(&mdd->mdd_cl.mc_lock);
251 cucb.idx += snprintf(cucb.page + cucb.idx, cucb.count - cucb.idx,
252 "current index: "LPU64"\n", cur);
254 cucb.idx += snprintf(cucb.page + cucb.idx, cucb.count - cucb.idx,
255 "%-5s %s\n", "ID", "index");
257 llog_cat_process(&env, ctxt->loc_handle, lprocfs_changelog_users_cb,
265 static int lprocfs_rd_sync_perm(char *page, char **start, off_t off,
266 int count, int *eof, void *data)
268 struct mdd_device *mdd = data;
270 LASSERT(mdd != NULL);
271 return snprintf(page, count, "%d\n", mdd->mdd_sync_permission);
274 static int lprocfs_wr_sync_perm(struct file *file, const char *buffer,
275 unsigned long count, void *data)
277 struct mdd_device *mdd = data;
280 LASSERT(mdd != NULL);
281 rc = lprocfs_write_helper(buffer, count, &val);
285 mdd->mdd_sync_permission = !!val;
289 static int lprocfs_rd_lfsck_speed_limit(char *page, char **start, off_t off,
290 int count, int *eof, void *data)
292 struct mdd_device *mdd = data;
294 LASSERT(mdd != NULL);
296 return snprintf(page, count, "%u\n", mdd->mdd_lfsck.ml_speed_limit);
299 static int lprocfs_wr_lfsck_speed_limit(struct file *file, const char *buffer,
300 unsigned long count, void *data)
302 struct mdd_device *mdd = data;
303 struct md_lfsck *lfsck;
307 LASSERT(mdd != NULL);
308 rc = lprocfs_write_helper(buffer, count, &val);
312 lfsck = &mdd->mdd_lfsck;
313 if (val != lfsck->ml_speed_limit)
314 mdd_lfsck_set_speed(lfsck, val);
318 static struct lprocfs_vars lprocfs_mdd_obd_vars[] = {
319 { "atime_diff", lprocfs_rd_atime_diff, lprocfs_wr_atime_diff, 0 },
320 { "changelog_mask", lprocfs_rd_changelog_mask,
321 lprocfs_wr_changelog_mask, 0 },
322 { "changelog_users", lprocfs_rd_changelog_users, 0, 0},
323 { "sync_permission", lprocfs_rd_sync_perm, lprocfs_wr_sync_perm, 0 },
324 { "lfsck_speed_limit", lprocfs_rd_lfsck_speed_limit,
325 lprocfs_wr_lfsck_speed_limit, 0 },
329 static struct lprocfs_vars lprocfs_mdd_module_vars[] = {
330 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
334 void lprocfs_mdd_init_vars(struct lprocfs_static_vars *lvars)
336 lvars->module_vars = lprocfs_mdd_module_vars;
337 lvars->obd_vars = lprocfs_mdd_obd_vars;