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>
42 # define EXPORT_SYMTAB
44 #define DEBUG_SUBSYSTEM S_MDS
46 #include <linux/module.h>
47 #include <linux/poll.h>
49 #include <obd_class.h>
50 #include <lustre_ver.h>
51 #include <obd_support.h>
52 #include <lprocfs_status.h>
54 #include <lustre_log.h>
55 #include <lustre/lustre_idl.h>
56 #include <libcfs/libcfs_string.h>
58 #include "mdd_internal.h"
60 static const char *mdd_counter_names[LPROC_MDD_NR] = {
63 int mdd_procfs_init(struct mdd_device *mdd, const char *name)
65 struct lprocfs_static_vars lvars;
66 struct lu_device *ld = &mdd->mdd_md_dev.md_lu_dev;
67 struct obd_type *type;
71 type = ld->ld_type->ldt_obd_type;
73 LASSERT(name != NULL);
74 LASSERT(type != NULL);
76 /* Find the type procroot and add the proc entry for this device */
77 lprocfs_mdd_init_vars(&lvars);
78 mdd->mdd_proc_entry = lprocfs_register(name, type->typ_procroot,
80 if (IS_ERR(mdd->mdd_proc_entry)) {
81 rc = PTR_ERR(mdd->mdd_proc_entry);
82 CERROR("Error %d setting up lprocfs for %s\n",
84 mdd->mdd_proc_entry = NULL;
88 rc = lu_time_init(&mdd->mdd_stats,
90 mdd_counter_names, ARRAY_SIZE(mdd_counter_names));
99 int mdd_procfs_fini(struct mdd_device *mdd)
102 lu_time_fini(&mdd->mdd_stats);
104 if (mdd->mdd_proc_entry) {
105 lprocfs_remove(&mdd->mdd_proc_entry);
106 mdd->mdd_proc_entry = NULL;
111 void mdd_lprocfs_time_start(const struct lu_env *env)
113 lu_lprocfs_time_start(env);
116 void mdd_lprocfs_time_end(const struct lu_env *env, struct mdd_device *mdd,
119 lu_lprocfs_time_end(env, mdd->mdd_stats, idx);
122 static int lprocfs_wr_atime_diff(struct file *file, const char *buffer,
123 unsigned long count, void *data)
125 struct mdd_device *mdd = data;
126 char kernbuf[20], *end;
127 unsigned long diff = 0;
129 if (count > (sizeof(kernbuf) - 1))
132 if (cfs_copy_from_user(kernbuf, buffer, count))
135 kernbuf[count] = '\0';
137 diff = simple_strtoul(kernbuf, &end, 0);
141 mdd->mdd_atime_diff = diff;
145 static int lprocfs_rd_atime_diff(char *page, char **start, off_t off,
146 int count, int *eof, void *data)
148 struct mdd_device *mdd = data;
151 return snprintf(page, count, "%lu\n", mdd->mdd_atime_diff);
155 /**** changelogs ****/
156 static int lprocfs_rd_changelog_mask(char *page, char **start, off_t off,
157 int count, int *eof, void *data)
159 struct mdd_device *mdd = data;
163 while (i < CL_LAST) {
164 if (mdd->mdd_cl.mc_mask & (1 << i))
165 rc += snprintf(page + rc, count - rc, "%s ",
166 changelog_type2str(i));
172 static int lprocfs_wr_changelog_mask(struct file *file, const char *buffer,
173 unsigned long count, void *data)
175 struct mdd_device *mdd = data;
180 if (count >= CFS_PAGE_SIZE)
182 OBD_ALLOC(kernbuf, CFS_PAGE_SIZE);
185 if (cfs_copy_from_user(kernbuf, buffer, count))
186 GOTO(out, rc = -EFAULT);
189 rc = cfs_str2mask(kernbuf, changelog_type2str, &mdd->mdd_cl.mc_mask,
190 CHANGELOG_MINMASK, CHANGELOG_ALLMASK);
194 OBD_FREE(kernbuf, CFS_PAGE_SIZE);
204 static int lprocfs_changelog_users_cb(struct llog_handle *llh,
205 struct llog_rec_hdr *hdr, void *data)
207 struct llog_changelog_user_rec *rec;
208 struct cucb_data *cucb = (struct cucb_data *)data;
210 LASSERT(llh->lgh_hdr->llh_flags & LLOG_F_IS_PLAIN);
212 rec = (struct llog_changelog_user_rec *)hdr;
214 cucb->idx += snprintf(cucb->page + cucb->idx, cucb->count - cucb->idx,
215 CHANGELOG_USER_PREFIX"%-3d "LPU64"\n",
216 rec->cur_id, rec->cur_endrec);
217 if (cucb->idx >= cucb->count)
223 static int lprocfs_rd_changelog_users(char *page, char **start, off_t off,
224 int count, int *eof, void *data)
226 struct mdd_device *mdd = data;
227 struct llog_ctxt *ctxt;
228 struct cucb_data cucb;
233 ctxt = llog_get_context(mdd2obd_dev(mdd),LLOG_CHANGELOG_USER_ORIG_CTXT);
236 LASSERT(ctxt->loc_handle->lgh_hdr->llh_flags & LLOG_F_IS_CAT);
238 cfs_spin_lock(&mdd->mdd_cl.mc_lock);
239 cur = mdd->mdd_cl.mc_index;
240 cfs_spin_unlock(&mdd->mdd_cl.mc_lock);
246 cucb.idx += snprintf(cucb.page + cucb.idx, cucb.count - cucb.idx,
247 "current index: "LPU64"\n", cur);
249 cucb.idx += snprintf(cucb.page + cucb.idx, cucb.count - cucb.idx,
250 "%-5s %s\n", "ID", "index");
252 llog_cat_process(ctxt->loc_handle, lprocfs_changelog_users_cb,
259 #ifdef HAVE_QUOTA_SUPPORT
260 static int mdd_lprocfs_quota_rd_type(char *page, char **start, off_t off,
261 int count, int *eof, void *data)
263 struct mdd_device *mdd = data;
264 return lprocfs_quota_rd_type(page, start, off, count, eof,
268 static int mdd_lprocfs_quota_wr_type(struct file *file, const char *buffer,
269 unsigned long count, void *data)
271 struct mdd_device *mdd = data;
272 return lprocfs_quota_wr_type(file, buffer, count, mdd->mdd_obd_dev);
276 static int lprocfs_rd_sync_perm(char *page, char **start, off_t off,
277 int count, int *eof, void *data)
279 struct mdd_device *mdd = data;
281 LASSERT(mdd != NULL);
282 return snprintf(page, count, "%d\n", mdd->mdd_sync_permission);
285 static int lprocfs_wr_sync_perm(struct file *file, const char *buffer,
286 unsigned long count, void *data)
288 struct mdd_device *mdd = data;
291 LASSERT(mdd != NULL);
292 rc = lprocfs_write_helper(buffer, count, &val);
296 mdd->mdd_sync_permission = !!val;
300 static struct lprocfs_vars lprocfs_mdd_obd_vars[] = {
301 { "atime_diff", lprocfs_rd_atime_diff, lprocfs_wr_atime_diff, 0 },
302 { "changelog_mask", lprocfs_rd_changelog_mask,
303 lprocfs_wr_changelog_mask, 0 },
304 { "changelog_users", lprocfs_rd_changelog_users, 0, 0},
305 #ifdef HAVE_QUOTA_SUPPORT
306 { "quota_type", mdd_lprocfs_quota_rd_type,
307 mdd_lprocfs_quota_wr_type, 0 },
309 { "sync_permission", lprocfs_rd_sync_perm, lprocfs_wr_sync_perm, 0 },
313 static struct lprocfs_vars lprocfs_mdd_module_vars[] = {
314 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
318 void lprocfs_mdd_init_vars(struct lprocfs_static_vars *lvars)
320 lvars->module_vars = lprocfs_mdd_module_vars;
321 lvars->obd_vars = lprocfs_mdd_obd_vars;