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.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2012, 2014, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * lustre/mdd/mdd_lproc.c
34 * Lustre Metadata Server (mdd) routines
36 * Author: Wang Di <wangdi@clusterfs.com>
39 #define DEBUG_SUBSYSTEM S_MDS
42 #include <obd_class.h>
43 #include <obd_support.h>
44 #include <lprocfs_status.h>
45 #include <libcfs/libcfs_string.h>
46 #include "mdd_internal.h"
49 mdd_atime_diff_seq_write(struct file *file, const char __user *buffer,
50 size_t count, loff_t *off)
52 struct seq_file *m = file->private_data;
53 struct mdd_device *mdd = m->private;
54 char kernbuf[20], *end;
55 unsigned long diff = 0;
57 if (count > (sizeof(kernbuf) - 1))
60 if (copy_from_user(kernbuf, buffer, count))
63 kernbuf[count] = '\0';
65 diff = simple_strtoul(kernbuf, &end, 0);
69 mdd->mdd_atime_diff = diff;
73 static int mdd_atime_diff_seq_show(struct seq_file *m, void *data)
75 struct mdd_device *mdd = m->private;
77 seq_printf(m, "%lu\n", mdd->mdd_atime_diff);
80 LPROC_SEQ_FOPS(mdd_atime_diff);
82 /**** changelogs ****/
83 static int mdd_changelog_mask_seq_show(struct seq_file *m, void *data)
85 struct mdd_device *mdd = m->private;
89 if (mdd->mdd_cl.mc_mask & (1 << i))
90 seq_printf(m, "%s ", changelog_type2str(i));
97 mdd_changelog_mask_seq_write(struct file *file, const char __user *buffer,
98 size_t count, loff_t *off)
100 struct seq_file *m = file->private_data;
101 struct mdd_device *mdd = m->private;
106 if (count >= PAGE_SIZE)
108 OBD_ALLOC(kernbuf, PAGE_SIZE);
111 if (copy_from_user(kernbuf, buffer, count))
112 GOTO(out, rc = -EFAULT);
115 rc = cfs_str2mask(kernbuf, changelog_type2str, &mdd->mdd_cl.mc_mask,
116 CHANGELOG_MINMASK, CHANGELOG_ALLMASK);
120 OBD_FREE(kernbuf, PAGE_SIZE);
123 LPROC_SEQ_FOPS(mdd_changelog_mask);
125 static int lprocfs_changelog_users_cb(const struct lu_env *env,
126 struct llog_handle *llh,
127 struct llog_rec_hdr *hdr, void *data)
129 struct llog_changelog_user_rec *rec;
130 struct seq_file *m = data;
132 LASSERT(llh->lgh_hdr->llh_flags & LLOG_F_IS_PLAIN);
134 rec = (struct llog_changelog_user_rec *)hdr;
136 seq_printf(m, CHANGELOG_USER_PREFIX"%-3d %llu\n",
137 rec->cur_id, rec->cur_endrec);
141 static int mdd_changelog_users_seq_show(struct seq_file *m, void *data)
144 struct mdd_device *mdd = m->private;
145 struct llog_ctxt *ctxt;
149 ctxt = llog_get_context(mdd2obd_dev(mdd),
150 LLOG_CHANGELOG_USER_ORIG_CTXT);
153 LASSERT(ctxt->loc_handle->lgh_hdr->llh_flags & LLOG_F_IS_CAT);
155 rc = lu_env_init(&env, LCT_LOCAL);
161 spin_lock(&mdd->mdd_cl.mc_lock);
162 cur = mdd->mdd_cl.mc_index;
163 spin_unlock(&mdd->mdd_cl.mc_lock);
165 seq_printf(m, "current index: %llu\n", cur);
166 seq_printf(m, "%-5s %s\n", "ID", "index");
168 llog_cat_process(&env, ctxt->loc_handle, lprocfs_changelog_users_cb,
175 LPROC_SEQ_FOPS_RO(mdd_changelog_users);
177 static int mdd_changelog_size_ctxt(const struct lu_env *env,
178 struct mdd_device *mdd,
179 int index, __u64 *val)
181 struct llog_ctxt *ctxt;
183 ctxt = llog_get_context(mdd2obd_dev(mdd),
188 if (!(ctxt->loc_handle->lgh_hdr->llh_flags & LLOG_F_IS_CAT)) {
189 CERROR("%s: ChangeLog has wrong flags: rc = %d\n",
190 ctxt->loc_obd->obd_name, -EINVAL);
195 *val += llog_cat_size(env, ctxt->loc_handle);
202 static int mdd_changelog_size_seq_show(struct seq_file *m, void *data)
205 struct mdd_device *mdd = m->private;
209 rc = lu_env_init(&env, LCT_LOCAL);
213 rc = mdd_changelog_size_ctxt(&env, mdd, LLOG_CHANGELOG_ORIG_CTXT, &tmp);
219 rc = mdd_changelog_size_ctxt(&env, mdd, LLOG_CHANGELOG_USER_ORIG_CTXT,
222 seq_printf(m, "%llu\n", tmp);
226 LPROC_SEQ_FOPS_RO(mdd_changelog_size);
228 static int mdd_sync_perm_seq_show(struct seq_file *m, void *data)
230 struct mdd_device *mdd = m->private;
232 LASSERT(mdd != NULL);
233 seq_printf(m, "%d\n", mdd->mdd_sync_permission);
238 mdd_sync_perm_seq_write(struct file *file, const char __user *buffer,
239 size_t count, loff_t *off)
241 struct seq_file *m = file->private_data;
242 struct mdd_device *mdd = m->private;
246 LASSERT(mdd != NULL);
247 rc = lprocfs_str_to_s64(buffer, count, &val);
251 mdd->mdd_sync_permission = !!val;
255 LPROC_SEQ_FOPS(mdd_sync_perm);
257 static int mdd_lfsck_speed_limit_seq_show(struct seq_file *m, void *data)
259 struct mdd_device *mdd = m->private;
261 LASSERT(mdd != NULL);
262 return lfsck_get_speed(m, mdd->mdd_bottom);
266 mdd_lfsck_speed_limit_seq_write(struct file *file, const char __user *buffer,
267 size_t count, loff_t *off)
269 struct seq_file *m = file->private_data;
270 struct mdd_device *mdd = m->private;
274 LASSERT(mdd != NULL);
275 rc = lprocfs_str_to_s64(buffer, count, &val);
278 if (val < 0 || val > INT_MAX)
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_str_to_s64(buffer, count, &val);
307 if (val < 0 || val > INT_MAX)
310 rc = lfsck_set_windows(mdd->mdd_bottom, val);
312 return rc != 0 ? rc : count;
314 LPROC_SEQ_FOPS(mdd_lfsck_async_windows);
316 static int mdd_lfsck_namespace_seq_show(struct seq_file *m, void *data)
318 struct mdd_device *mdd = m->private;
320 LASSERT(mdd != NULL);
322 return lfsck_dump(m, mdd->mdd_bottom, LFSCK_TYPE_NAMESPACE);
324 LPROC_SEQ_FOPS_RO(mdd_lfsck_namespace);
326 static int mdd_lfsck_layout_seq_show(struct seq_file *m, void *data)
328 struct mdd_device *mdd = m->private;
330 LASSERT(mdd != NULL);
332 return lfsck_dump(m, mdd->mdd_bottom, LFSCK_TYPE_LAYOUT);
334 LPROC_SEQ_FOPS_RO(mdd_lfsck_layout);
336 static struct lprocfs_vars lprocfs_mdd_obd_vars[] = {
337 { .name = "atime_diff",
338 .fops = &mdd_atime_diff_fops },
339 { .name = "changelog_mask",
340 .fops = &mdd_changelog_mask_fops },
341 { .name = "changelog_users",
342 .fops = &mdd_changelog_users_fops },
343 { .name = "changelog_size",
344 .fops = &mdd_changelog_size_fops },
345 { .name = "sync_permission",
346 .fops = &mdd_sync_perm_fops },
347 { .name = "lfsck_speed_limit",
348 .fops = &mdd_lfsck_speed_limit_fops },
349 { .name = "lfsck_async_windows",
350 .fops = &mdd_lfsck_async_windows_fops },
351 { .name = "lfsck_namespace",
352 .fops = &mdd_lfsck_namespace_fops },
353 { .name = "lfsck_layout",
354 .fops = &mdd_lfsck_layout_fops },
358 int mdd_procfs_init(struct mdd_device *mdd, const char *name)
360 struct obd_device *obd = mdd2obd_dev(mdd);
361 struct obd_type *type;
365 /* at the moment there is no linkage between lu_type
366 * and obd_type, so we lookup obd_type this way */
367 type = class_search_type(LUSTRE_MDD_NAME);
369 LASSERT(name != NULL);
370 LASSERT(type != NULL);
371 LASSERT(obd != NULL);
373 /* Find the type procroot and add the proc entry for this device */
374 obd->obd_vars = lprocfs_mdd_obd_vars;
375 mdd->mdd_proc_entry = lprocfs_register(name, type->typ_procroot,
377 if (IS_ERR(mdd->mdd_proc_entry)) {
378 rc = PTR_ERR(mdd->mdd_proc_entry);
379 CERROR("Error %d setting up lprocfs for %s\n",
381 mdd->mdd_proc_entry = NULL;
388 mdd_procfs_fini(mdd);
392 void mdd_procfs_fini(struct mdd_device *mdd)
394 if (mdd->mdd_proc_entry)
395 lprocfs_remove(&mdd->mdd_proc_entry);