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, 2016, 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));
98 mdd_changelog_mask_seq_write(struct file *file, const char __user *buffer,
99 size_t count, loff_t *off)
101 struct seq_file *m = file->private_data;
102 struct mdd_device *mdd = m->private;
107 if (count >= PAGE_SIZE)
109 OBD_ALLOC(kernbuf, PAGE_SIZE);
112 if (copy_from_user(kernbuf, buffer, count))
113 GOTO(out, rc = -EFAULT);
116 rc = cfs_str2mask(kernbuf, changelog_type2str, &mdd->mdd_cl.mc_mask,
117 CHANGELOG_MINMASK, CHANGELOG_ALLMASK);
121 OBD_FREE(kernbuf, PAGE_SIZE);
124 LPROC_SEQ_FOPS(mdd_changelog_mask);
126 static int lprocfs_changelog_users_cb(const struct lu_env *env,
127 struct llog_handle *llh,
128 struct llog_rec_hdr *hdr, void *data)
130 struct llog_changelog_user_rec *rec;
131 struct seq_file *m = data;
133 LASSERT(llh->lgh_hdr->llh_flags & LLOG_F_IS_PLAIN);
135 rec = (struct llog_changelog_user_rec *)hdr;
137 seq_printf(m, CHANGELOG_USER_PREFIX"%-3d %llu\n",
138 rec->cur_id, rec->cur_endrec);
142 static int mdd_changelog_users_seq_show(struct seq_file *m, void *data)
145 struct mdd_device *mdd = m->private;
146 struct llog_ctxt *ctxt;
150 ctxt = llog_get_context(mdd2obd_dev(mdd),
151 LLOG_CHANGELOG_USER_ORIG_CTXT);
154 LASSERT(ctxt->loc_handle->lgh_hdr->llh_flags & LLOG_F_IS_CAT);
156 rc = lu_env_init(&env, LCT_LOCAL);
162 spin_lock(&mdd->mdd_cl.mc_lock);
163 cur = mdd->mdd_cl.mc_index;
164 spin_unlock(&mdd->mdd_cl.mc_lock);
166 seq_printf(m, "current index: %llu\n", cur);
167 seq_printf(m, "%-5s %s\n", "ID", "index");
169 llog_cat_process(&env, ctxt->loc_handle, lprocfs_changelog_users_cb,
176 LPROC_SEQ_FOPS_RO(mdd_changelog_users);
178 static int mdd_changelog_size_ctxt(const struct lu_env *env,
179 struct mdd_device *mdd,
180 int index, __u64 *val)
182 struct llog_ctxt *ctxt;
184 ctxt = llog_get_context(mdd2obd_dev(mdd),
189 if (!(ctxt->loc_handle->lgh_hdr->llh_flags & LLOG_F_IS_CAT)) {
190 CERROR("%s: ChangeLog has wrong flags: rc = %d\n",
191 ctxt->loc_obd->obd_name, -EINVAL);
196 *val += llog_cat_size(env, ctxt->loc_handle);
203 static int mdd_changelog_size_seq_show(struct seq_file *m, void *data)
206 struct mdd_device *mdd = m->private;
210 rc = lu_env_init(&env, LCT_LOCAL);
214 rc = mdd_changelog_size_ctxt(&env, mdd, LLOG_CHANGELOG_ORIG_CTXT, &tmp);
220 rc = mdd_changelog_size_ctxt(&env, mdd, LLOG_CHANGELOG_USER_ORIG_CTXT,
223 seq_printf(m, "%llu\n", tmp);
227 LPROC_SEQ_FOPS_RO(mdd_changelog_size);
229 static int mdd_sync_perm_seq_show(struct seq_file *m, void *data)
231 struct mdd_device *mdd = m->private;
233 LASSERT(mdd != NULL);
234 seq_printf(m, "%d\n", mdd->mdd_sync_permission);
239 mdd_sync_perm_seq_write(struct file *file, const char __user *buffer,
240 size_t count, loff_t *off)
242 struct seq_file *m = file->private_data;
243 struct mdd_device *mdd = m->private;
247 LASSERT(mdd != NULL);
248 rc = lprocfs_str_to_s64(buffer, count, &val);
252 mdd->mdd_sync_permission = !!val;
256 LPROC_SEQ_FOPS(mdd_sync_perm);
258 static int mdd_lfsck_speed_limit_seq_show(struct seq_file *m, void *data)
260 struct mdd_device *mdd = m->private;
262 LASSERT(mdd != NULL);
263 return lfsck_get_speed(m, mdd->mdd_bottom);
267 mdd_lfsck_speed_limit_seq_write(struct file *file, const char __user *buffer,
268 size_t count, loff_t *off)
270 struct seq_file *m = file->private_data;
271 struct mdd_device *mdd = m->private;
275 LASSERT(mdd != NULL);
276 rc = lprocfs_str_to_s64(buffer, count, &val);
279 if (val < 0 || val > INT_MAX)
282 rc = lfsck_set_speed(mdd->mdd_bottom, val);
283 return rc != 0 ? rc : count;
285 LPROC_SEQ_FOPS(mdd_lfsck_speed_limit);
287 static int mdd_lfsck_async_windows_seq_show(struct seq_file *m, void *data)
289 struct mdd_device *mdd = m->private;
291 LASSERT(mdd != NULL);
292 return lfsck_get_windows(m, mdd->mdd_bottom);
296 mdd_lfsck_async_windows_seq_write(struct file *file, const char __user *buffer,
297 size_t count, loff_t *off)
299 struct seq_file *m = file->private_data;
300 struct mdd_device *mdd = m->private;
304 LASSERT(mdd != NULL);
305 rc = lprocfs_str_to_s64(buffer, count, &val);
308 if (val < 0 || val > INT_MAX)
311 rc = lfsck_set_windows(mdd->mdd_bottom, val);
313 return rc != 0 ? rc : count;
315 LPROC_SEQ_FOPS(mdd_lfsck_async_windows);
317 static int mdd_lfsck_namespace_seq_show(struct seq_file *m, void *data)
319 struct mdd_device *mdd = m->private;
321 LASSERT(mdd != NULL);
323 return lfsck_dump(m, mdd->mdd_bottom, LFSCK_TYPE_NAMESPACE);
325 LPROC_SEQ_FOPS_RO(mdd_lfsck_namespace);
327 static int mdd_lfsck_layout_seq_show(struct seq_file *m, void *data)
329 struct mdd_device *mdd = m->private;
331 LASSERT(mdd != NULL);
333 return lfsck_dump(m, mdd->mdd_bottom, LFSCK_TYPE_LAYOUT);
335 LPROC_SEQ_FOPS_RO(mdd_lfsck_layout);
337 static struct lprocfs_vars lprocfs_mdd_obd_vars[] = {
338 { .name = "atime_diff",
339 .fops = &mdd_atime_diff_fops },
340 { .name = "changelog_mask",
341 .fops = &mdd_changelog_mask_fops },
342 { .name = "changelog_users",
343 .fops = &mdd_changelog_users_fops },
344 { .name = "changelog_size",
345 .fops = &mdd_changelog_size_fops },
346 { .name = "sync_permission",
347 .fops = &mdd_sync_perm_fops },
348 { .name = "lfsck_speed_limit",
349 .fops = &mdd_lfsck_speed_limit_fops },
350 { .name = "lfsck_async_windows",
351 .fops = &mdd_lfsck_async_windows_fops },
352 { .name = "lfsck_namespace",
353 .fops = &mdd_lfsck_namespace_fops },
354 { .name = "lfsck_layout",
355 .fops = &mdd_lfsck_layout_fops },
359 int mdd_procfs_init(struct mdd_device *mdd, const char *name)
361 struct obd_device *obd = mdd2obd_dev(mdd);
362 struct obd_type *type;
366 /* at the moment there is no linkage between lu_type
367 * and obd_type, so we lookup obd_type this way */
368 type = class_search_type(LUSTRE_MDD_NAME);
370 LASSERT(name != NULL);
371 LASSERT(type != NULL);
372 LASSERT(obd != NULL);
374 /* Find the type procroot and add the proc entry for this device */
375 obd->obd_vars = lprocfs_mdd_obd_vars;
376 mdd->mdd_proc_entry = lprocfs_register(name, type->typ_procroot,
378 if (IS_ERR(mdd->mdd_proc_entry)) {
379 rc = PTR_ERR(mdd->mdd_proc_entry);
380 CERROR("Error %d setting up lprocfs for %s\n",
382 mdd->mdd_proc_entry = NULL;
389 mdd_procfs_fini(mdd);
393 void mdd_procfs_fini(struct mdd_device *mdd)
395 if (mdd->mdd_proc_entry)
396 lprocfs_remove(&mdd->mdd_proc_entry);