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, 2014, 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"
53 mdd_atime_diff_seq_write(struct file *file, const char __user *buffer,
54 size_t count, loff_t *off)
56 struct seq_file *m = file->private_data;
57 struct mdd_device *mdd = m->private;
58 char kernbuf[20], *end;
59 unsigned long diff = 0;
61 if (count > (sizeof(kernbuf) - 1))
64 if (copy_from_user(kernbuf, buffer, count))
67 kernbuf[count] = '\0';
69 diff = simple_strtoul(kernbuf, &end, 0);
73 mdd->mdd_atime_diff = diff;
77 static int mdd_atime_diff_seq_show(struct seq_file *m, void *data)
79 struct mdd_device *mdd = m->private;
81 seq_printf(m, "%lu\n", mdd->mdd_atime_diff);
84 LPROC_SEQ_FOPS(mdd_atime_diff);
86 /**** changelogs ****/
87 static int mdd_changelog_mask_seq_show(struct seq_file *m, void *data)
89 struct mdd_device *mdd = m->private;
93 if (mdd->mdd_cl.mc_mask & (1 << i))
94 seq_printf(m, "%s ", changelog_type2str(i));
101 mdd_changelog_mask_seq_write(struct file *file, const char __user *buffer,
102 size_t count, loff_t *off)
104 struct seq_file *m = file->private_data;
105 struct mdd_device *mdd = m->private;
110 if (count >= PAGE_CACHE_SIZE)
112 OBD_ALLOC(kernbuf, PAGE_CACHE_SIZE);
115 if (copy_from_user(kernbuf, buffer, count))
116 GOTO(out, rc = -EFAULT);
119 rc = cfs_str2mask(kernbuf, changelog_type2str, &mdd->mdd_cl.mc_mask,
120 CHANGELOG_MINMASK, CHANGELOG_ALLMASK);
124 OBD_FREE(kernbuf, PAGE_CACHE_SIZE);
127 LPROC_SEQ_FOPS(mdd_changelog_mask);
129 static int lprocfs_changelog_users_cb(const struct lu_env *env,
130 struct llog_handle *llh,
131 struct llog_rec_hdr *hdr, void *data)
133 struct llog_changelog_user_rec *rec;
134 struct seq_file *m = data;
136 LASSERT(llh->lgh_hdr->llh_flags & LLOG_F_IS_PLAIN);
138 rec = (struct llog_changelog_user_rec *)hdr;
140 seq_printf(m, CHANGELOG_USER_PREFIX"%-3d "LPU64"\n",
141 rec->cur_id, rec->cur_endrec);
145 static int mdd_changelog_users_seq_show(struct seq_file *m, void *data)
148 struct mdd_device *mdd = m->private;
149 struct llog_ctxt *ctxt;
153 ctxt = llog_get_context(mdd2obd_dev(mdd),
154 LLOG_CHANGELOG_USER_ORIG_CTXT);
157 LASSERT(ctxt->loc_handle->lgh_hdr->llh_flags & LLOG_F_IS_CAT);
159 rc = lu_env_init(&env, LCT_LOCAL);
165 spin_lock(&mdd->mdd_cl.mc_lock);
166 cur = mdd->mdd_cl.mc_index;
167 spin_unlock(&mdd->mdd_cl.mc_lock);
169 seq_printf(m, "current index: "LPU64"\n", cur);
170 seq_printf(m, "%-5s %s\n", "ID", "index");
172 llog_cat_process(&env, ctxt->loc_handle, lprocfs_changelog_users_cb,
179 LPROC_SEQ_FOPS_RO(mdd_changelog_users);
181 static int mdd_changelog_size_ctxt(const struct lu_env *env,
182 struct mdd_device *mdd,
183 int index, __u64 *val)
185 struct llog_ctxt *ctxt;
187 ctxt = llog_get_context(mdd2obd_dev(mdd),
192 if (!(ctxt->loc_handle->lgh_hdr->llh_flags & LLOG_F_IS_CAT)) {
193 CERROR("%s: ChangeLog has wrong flags: rc = %d\n",
194 ctxt->loc_obd->obd_name, -EINVAL);
199 *val += llog_cat_size(env, ctxt->loc_handle);
206 static int mdd_changelog_size_seq_show(struct seq_file *m, void *data)
209 struct mdd_device *mdd = m->private;
213 rc = lu_env_init(&env, LCT_LOCAL);
217 rc = mdd_changelog_size_ctxt(&env, mdd, LLOG_CHANGELOG_ORIG_CTXT, &tmp);
223 rc = mdd_changelog_size_ctxt(&env, mdd, LLOG_CHANGELOG_USER_ORIG_CTXT,
226 seq_printf(m, LPU64"\n", tmp);
230 LPROC_SEQ_FOPS_RO(mdd_changelog_size);
232 static int mdd_sync_perm_seq_show(struct seq_file *m, void *data)
234 struct mdd_device *mdd = m->private;
236 LASSERT(mdd != NULL);
237 seq_printf(m, "%d\n", mdd->mdd_sync_permission);
242 mdd_sync_perm_seq_write(struct file *file, const char __user *buffer,
243 size_t count, loff_t *off)
245 struct seq_file *m = file->private_data;
246 struct mdd_device *mdd = m->private;
249 LASSERT(mdd != NULL);
250 rc = lprocfs_write_helper(buffer, count, &val);
254 mdd->mdd_sync_permission = !!val;
257 LPROC_SEQ_FOPS(mdd_sync_perm);
259 static int mdd_lfsck_speed_limit_seq_show(struct seq_file *m, void *data)
261 struct mdd_device *mdd = m->private;
263 LASSERT(mdd != NULL);
264 return lfsck_get_speed(m, mdd->mdd_bottom);
268 mdd_lfsck_speed_limit_seq_write(struct file *file, const char __user *buffer,
269 size_t count, loff_t *off)
271 struct seq_file *m = file->private_data;
272 struct mdd_device *mdd = m->private;
276 LASSERT(mdd != NULL);
277 rc = lprocfs_write_helper(buffer, count, &val);
281 rc = lfsck_set_speed(mdd->mdd_bottom, val);
282 return rc != 0 ? rc : count;
284 LPROC_SEQ_FOPS(mdd_lfsck_speed_limit);
286 static int mdd_lfsck_async_windows_seq_show(struct seq_file *m, void *data)
288 struct mdd_device *mdd = m->private;
290 LASSERT(mdd != NULL);
291 return lfsck_get_windows(m, mdd->mdd_bottom);
295 mdd_lfsck_async_windows_seq_write(struct file *file, const char __user *buffer,
296 size_t count, loff_t *off)
298 struct seq_file *m = file->private_data;
299 struct mdd_device *mdd = m->private;
303 LASSERT(mdd != NULL);
304 rc = lprocfs_write_helper(buffer, count, &val);
306 rc = lfsck_set_windows(mdd->mdd_bottom, val);
308 return rc != 0 ? rc : count;
310 LPROC_SEQ_FOPS(mdd_lfsck_async_windows);
312 static int mdd_lfsck_namespace_seq_show(struct seq_file *m, void *data)
314 struct mdd_device *mdd = m->private;
316 LASSERT(mdd != NULL);
318 return lfsck_dump(m, mdd->mdd_bottom, LFSCK_TYPE_NAMESPACE);
320 LPROC_SEQ_FOPS_RO(mdd_lfsck_namespace);
322 static int mdd_lfsck_layout_seq_show(struct seq_file *m, void *data)
324 struct mdd_device *mdd = m->private;
326 LASSERT(mdd != NULL);
328 return lfsck_dump(m, mdd->mdd_bottom, LFSCK_TYPE_LAYOUT);
330 LPROC_SEQ_FOPS_RO(mdd_lfsck_layout);
332 static struct lprocfs_vars lprocfs_mdd_obd_vars[] = {
333 { .name = "atime_diff",
334 .fops = &mdd_atime_diff_fops },
335 { .name = "changelog_mask",
336 .fops = &mdd_changelog_mask_fops },
337 { .name = "changelog_users",
338 .fops = &mdd_changelog_users_fops },
339 { .name = "changelog_size",
340 .fops = &mdd_changelog_size_fops },
341 { .name = "sync_permission",
342 .fops = &mdd_sync_perm_fops },
343 { .name = "lfsck_speed_limit",
344 .fops = &mdd_lfsck_speed_limit_fops },
345 { .name = "lfsck_async_windows",
346 .fops = &mdd_lfsck_async_windows_fops },
347 { .name = "lfsck_namespace",
348 .fops = &mdd_lfsck_namespace_fops },
349 { .name = "lfsck_layout",
350 .fops = &mdd_lfsck_layout_fops },
354 int mdd_procfs_init(struct mdd_device *mdd, const char *name)
356 struct obd_device *obd = mdd2obd_dev(mdd);
357 struct obd_type *type;
361 /* at the moment there is no linkage between lu_type
362 * and obd_type, so we lookup obd_type this way */
363 type = class_search_type(LUSTRE_MDD_NAME);
365 LASSERT(name != NULL);
366 LASSERT(type != NULL);
367 LASSERT(obd != NULL);
369 /* Find the type procroot and add the proc entry for this device */
370 obd->obd_vars = lprocfs_mdd_obd_vars;
371 mdd->mdd_proc_entry = lprocfs_register(name, type->typ_procroot,
373 if (IS_ERR(mdd->mdd_proc_entry)) {
374 rc = PTR_ERR(mdd->mdd_proc_entry);
375 CERROR("Error %d setting up lprocfs for %s\n",
377 mdd->mdd_proc_entry = NULL;
384 mdd_procfs_fini(mdd);
388 void mdd_procfs_fini(struct mdd_device *mdd)
390 if (mdd->mdd_proc_entry)
391 lprocfs_remove(&mdd->mdd_proc_entry);