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, 2013, 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>
49 #include <libcfs/libcfs_string.h>
50 #include "mdd_internal.h"
52 int mdd_procfs_init(struct mdd_device *mdd, const char *name)
54 struct lprocfs_static_vars lvars;
55 struct obd_type *type;
59 /* at the moment there is no linkage between lu_type
60 * and obd_type, so we lookup obd_type this way */
61 type = class_search_type(LUSTRE_MDD_NAME);
63 LASSERT(name != NULL);
64 LASSERT(type != NULL);
66 /* Find the type procroot and add the proc entry for this device */
67 lprocfs_mdd_init_vars(&lvars);
68 mdd->mdd_proc_entry = lprocfs_register(name, type->typ_procroot,
70 if (IS_ERR(mdd->mdd_proc_entry)) {
71 rc = PTR_ERR(mdd->mdd_proc_entry);
72 CERROR("Error %d setting up lprocfs for %s\n",
74 mdd->mdd_proc_entry = NULL;
87 int mdd_procfs_fini(struct mdd_device *mdd)
89 if (mdd->mdd_proc_entry) {
90 lprocfs_remove(&mdd->mdd_proc_entry);
91 mdd->mdd_proc_entry = NULL;
96 static int lprocfs_wr_atime_diff(struct file *file, const char *buffer,
97 unsigned long count, void *data)
99 struct mdd_device *mdd = data;
100 char kernbuf[20], *end;
101 unsigned long diff = 0;
103 if (count > (sizeof(kernbuf) - 1))
106 if (cfs_copy_from_user(kernbuf, buffer, count))
109 kernbuf[count] = '\0';
111 diff = simple_strtoul(kernbuf, &end, 0);
115 mdd->mdd_atime_diff = diff;
119 static int lprocfs_rd_atime_diff(char *page, char **start, off_t off,
120 int count, int *eof, void *data)
122 struct mdd_device *mdd = data;
125 return snprintf(page, count, "%lu\n", mdd->mdd_atime_diff);
129 /**** changelogs ****/
130 static int lprocfs_rd_changelog_mask(char *page, char **start, off_t off,
131 int count, int *eof, void *data)
133 struct mdd_device *mdd = data;
137 while (i < CL_LAST) {
138 if (mdd->mdd_cl.mc_mask & (1 << i))
139 rc += snprintf(page + rc, count - rc, "%s ",
140 changelog_type2str(i));
146 static int lprocfs_wr_changelog_mask(struct file *file, const char *buffer,
147 unsigned long count, void *data)
149 struct mdd_device *mdd = data;
154 if (count >= CFS_PAGE_SIZE)
156 OBD_ALLOC(kernbuf, CFS_PAGE_SIZE);
159 if (cfs_copy_from_user(kernbuf, buffer, count))
160 GOTO(out, rc = -EFAULT);
163 rc = cfs_str2mask(kernbuf, changelog_type2str, &mdd->mdd_cl.mc_mask,
164 CHANGELOG_MINMASK, CHANGELOG_ALLMASK);
168 OBD_FREE(kernbuf, CFS_PAGE_SIZE);
178 static int lprocfs_changelog_users_cb(const struct lu_env *env,
179 struct llog_handle *llh,
180 struct llog_rec_hdr *hdr, void *data)
182 struct llog_changelog_user_rec *rec;
183 struct cucb_data *cucb = (struct cucb_data *)data;
185 LASSERT(llh->lgh_hdr->llh_flags & LLOG_F_IS_PLAIN);
187 rec = (struct llog_changelog_user_rec *)hdr;
189 cucb->idx += snprintf(cucb->page + cucb->idx, cucb->count - cucb->idx,
190 CHANGELOG_USER_PREFIX"%-3d "LPU64"\n",
191 rec->cur_id, rec->cur_endrec);
192 if (cucb->idx >= cucb->count)
198 static int lprocfs_rd_changelog_users(char *page, char **start, off_t off,
199 int count, int *eof, void *data)
202 struct mdd_device *mdd = data;
203 struct llog_ctxt *ctxt;
204 struct cucb_data cucb;
210 ctxt = llog_get_context(mdd2obd_dev(mdd),
211 LLOG_CHANGELOG_USER_ORIG_CTXT);
214 LASSERT(ctxt->loc_handle->lgh_hdr->llh_flags & LLOG_F_IS_CAT);
216 rc = lu_env_init(&env, LCT_LOCAL);
222 spin_lock(&mdd->mdd_cl.mc_lock);
223 cur = mdd->mdd_cl.mc_index;
224 spin_unlock(&mdd->mdd_cl.mc_lock);
230 cucb.idx += snprintf(cucb.page + cucb.idx, cucb.count - cucb.idx,
231 "current index: "LPU64"\n", cur);
233 cucb.idx += snprintf(cucb.page + cucb.idx, cucb.count - cucb.idx,
234 "%-5s %s\n", "ID", "index");
236 llog_cat_process(&env, ctxt->loc_handle, lprocfs_changelog_users_cb,
244 static int lprocfs_rd_sync_perm(char *page, char **start, off_t off,
245 int count, int *eof, void *data)
247 struct mdd_device *mdd = data;
249 LASSERT(mdd != NULL);
250 return snprintf(page, count, "%d\n", mdd->mdd_sync_permission);
253 static int lprocfs_wr_sync_perm(struct file *file, const char *buffer,
254 unsigned long count, void *data)
256 struct mdd_device *mdd = data;
259 LASSERT(mdd != NULL);
260 rc = lprocfs_write_helper(buffer, count, &val);
264 mdd->mdd_sync_permission = !!val;
268 static int lprocfs_rd_lfsck_speed_limit(char *page, char **start, off_t off,
269 int count, int *eof, void *data)
271 struct mdd_device *mdd = data;
273 LASSERT(mdd != NULL);
275 return snprintf(page, count, "%u\n",
276 mdd->mdd_lfsck.ml_bookmark_ram.lb_speed_limit);
279 static int lprocfs_wr_lfsck_speed_limit(struct file *file, const char *buffer,
280 unsigned long count, void *data)
282 struct mdd_device *mdd = data;
283 struct md_lfsck *lfsck;
287 LASSERT(mdd != NULL);
288 rc = lprocfs_write_helper(buffer, count, &val);
292 lfsck = &mdd->mdd_lfsck;
293 if (val != lfsck->ml_bookmark_ram.lb_speed_limit) {
296 rc = lu_env_init(&env, LCT_MD_THREAD | LCT_DT_THREAD);
300 rc = mdd_lfsck_set_speed(&env, lfsck, val);
303 return rc != 0 ? rc : count;
306 static int lprocfs_rd_lfsck_namespace(char *page, char **start, off_t off,
307 int count, int *eof, void *data)
310 struct mdd_device *mdd = data;
313 LASSERT(mdd != NULL);
316 rc = lu_env_init(&env, LCT_MD_THREAD | LCT_DT_THREAD);
320 rc = mdd_lfsck_dump(&env, &mdd->mdd_lfsck, LT_NAMESPACE, page, count);
325 static struct lprocfs_vars lprocfs_mdd_obd_vars[] = {
326 { "atime_diff", lprocfs_rd_atime_diff, lprocfs_wr_atime_diff, 0 },
327 { "changelog_mask", lprocfs_rd_changelog_mask,
328 lprocfs_wr_changelog_mask, 0 },
329 { "changelog_users", lprocfs_rd_changelog_users, 0, 0},
330 { "sync_permission", lprocfs_rd_sync_perm, lprocfs_wr_sync_perm, 0 },
331 { "lfsck_speed_limit", lprocfs_rd_lfsck_speed_limit,
332 lprocfs_wr_lfsck_speed_limit, 0 },
333 { "lfsck_namespace", lprocfs_rd_lfsck_namespace, 0, 0 },
337 static struct lprocfs_vars lprocfs_mdd_module_vars[] = {
338 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
342 void lprocfs_mdd_init_vars(struct lprocfs_static_vars *lvars)
344 lvars->module_vars = lprocfs_mdd_module_vars;
345 lvars->obd_vars = lprocfs_mdd_obd_vars;