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, 2017, 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"
48 static ssize_t uuid_show(struct kobject *kobj, struct attribute *attr,
51 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
53 struct obd_device *obd = mdd2obd_dev(mdd);
55 return sprintf(buf, "%s\n", obd->obd_uuid.uuid);
59 static ssize_t atime_diff_show(struct kobject *kobj, struct attribute *attr,
62 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
65 return sprintf(buf, "%lld\n", mdd->mdd_atime_diff);
68 static ssize_t atime_diff_store(struct kobject *kobj,
69 struct attribute *attr,
70 const char *buffer, size_t count)
72 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
77 rc = kstrtoll(buffer, 10, &diff);
81 mdd->mdd_atime_diff = diff;
84 LUSTRE_RW_ATTR(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));
102 mdd_changelog_mask_seq_write(struct file *file, const char __user *buffer,
103 size_t count, loff_t *off)
105 struct seq_file *m = file->private_data;
106 struct mdd_device *mdd = m->private;
111 if (count >= PAGE_SIZE)
113 OBD_ALLOC(kernbuf, PAGE_SIZE);
116 if (copy_from_user(kernbuf, buffer, count))
117 GOTO(out, rc = -EFAULT);
120 rc = cfs_str2mask(kernbuf, changelog_type2str, &mdd->mdd_cl.mc_mask,
121 CHANGELOG_MINMASK, CHANGELOG_ALLMASK);
125 OBD_FREE(kernbuf, PAGE_SIZE);
128 LDEBUGFS_SEQ_FOPS(mdd_changelog_mask);
130 static int lprocfs_changelog_users_cb(const struct lu_env *env,
131 struct llog_handle *llh,
132 struct llog_rec_hdr *hdr, void *data)
134 struct llog_changelog_user_rec *rec;
135 struct seq_file *m = data;
137 LASSERT(llh->lgh_hdr->llh_flags & LLOG_F_IS_PLAIN);
139 rec = (struct llog_changelog_user_rec *)hdr;
141 seq_printf(m, CHANGELOG_USER_PREFIX"%-3d %llu (%u)\n",
142 rec->cur_id, rec->cur_endrec, (__u32)get_seconds() -
147 static int mdd_changelog_users_seq_show(struct seq_file *m, void *data)
150 struct mdd_device *mdd = m->private;
151 struct llog_ctxt *ctxt;
155 ctxt = llog_get_context(mdd2obd_dev(mdd),
156 LLOG_CHANGELOG_USER_ORIG_CTXT);
159 LASSERT(ctxt->loc_handle->lgh_hdr->llh_flags & LLOG_F_IS_CAT);
161 rc = lu_env_init(&env, LCT_LOCAL);
167 spin_lock(&mdd->mdd_cl.mc_lock);
168 cur = mdd->mdd_cl.mc_index;
169 spin_unlock(&mdd->mdd_cl.mc_lock);
171 seq_printf(m, "current index: %llu\n", cur);
172 seq_printf(m, "%-5s %s %s\n", "ID", "index", "(idle seconds)");
174 llog_cat_process(&env, ctxt->loc_handle, lprocfs_changelog_users_cb,
181 LDEBUGFS_SEQ_FOPS_RO(mdd_changelog_users);
183 static int mdd_changelog_size_ctxt(const struct lu_env *env,
184 struct mdd_device *mdd,
185 int index, __u64 *val)
187 struct llog_ctxt *ctxt;
189 ctxt = llog_get_context(mdd2obd_dev(mdd),
194 if (!(ctxt->loc_handle->lgh_hdr->llh_flags & LLOG_F_IS_CAT)) {
195 CERROR("%s: ChangeLog has wrong flags: rc = %d\n",
196 ctxt->loc_obd->obd_name, -EINVAL);
201 *val += llog_cat_size(env, ctxt->loc_handle);
208 static ssize_t changelog_size_show(struct kobject *kobj,
209 struct attribute *attr,
212 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
218 rc = lu_env_init(&env, LCT_LOCAL);
222 rc = mdd_changelog_size_ctxt(&env, mdd, LLOG_CHANGELOG_ORIG_CTXT, &tmp);
228 rc = mdd_changelog_size_ctxt(&env, mdd, LLOG_CHANGELOG_USER_ORIG_CTXT,
231 rc = sprintf(buf, "%llu\n", tmp);
235 LUSTRE_RO_ATTR(changelog_size);
237 static ssize_t changelog_gc_show(struct kobject *kobj,
238 struct attribute *attr,
241 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
244 return sprintf(buf, "%u\n", mdd->mdd_changelog_gc);
247 static ssize_t changelog_gc_store(struct kobject *kobj,
248 struct attribute *attr,
249 const char *buffer, size_t count)
251 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
256 rc = kstrtobool(buffer, &val);
260 mdd->mdd_changelog_gc = val;
264 LUSTRE_RW_ATTR(changelog_gc);
266 static ssize_t changelog_max_idle_time_show(struct kobject *kobj,
267 struct attribute *attr,
270 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
273 return sprintf(buf, "%lld\n", mdd->mdd_changelog_max_idle_time);
276 static ssize_t changelog_max_idle_time_store(struct kobject *kobj,
277 struct attribute *attr,
278 const char *buffer, size_t count)
280 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
285 rc = kstrtoll(buffer, 10, &val);
289 /* as it sounds reasonable, do not allow a user to be idle since
290 * more than about 68 years, this will allow to use 32bits
291 * timestamps for comparison
293 if (val < 1 || val > INT_MAX)
296 mdd->mdd_changelog_max_idle_time = val;
300 LUSTRE_RW_ATTR(changelog_max_idle_time);
302 static ssize_t changelog_max_idle_indexes_show(struct kobject *kobj,
303 struct attribute *attr,
306 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
309 return sprintf(buf, "%lu\n", mdd->mdd_changelog_max_idle_indexes);
312 static ssize_t changelog_max_idle_indexes_store(struct kobject *kobj,
313 struct attribute *attr,
317 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
322 LASSERT(mdd != NULL);
323 rc = kstrtoul(buffer, 0, &val);
327 /* XXX may need to limit/check with reasonable elapsed/idle indexes */
328 /* XXX may better allow to specify a % of full ChangeLogs */
330 mdd->mdd_changelog_max_idle_indexes = val;
334 LUSTRE_RW_ATTR(changelog_max_idle_indexes);
336 static ssize_t changelog_min_gc_interval_show(struct kobject *kobj,
337 struct attribute *attr,
340 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
343 return sprintf(buf, "%lld\n", mdd->mdd_changelog_min_gc_interval);
346 static ssize_t changelog_min_gc_interval_store(struct kobject *kobj,
347 struct attribute *attr,
351 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
356 rc = kstrtoll(buffer, 10, &val);
360 /* XXX may need to limit with reasonable elapsed/interval times */
364 mdd->mdd_changelog_min_gc_interval = val;
368 LUSTRE_RW_ATTR(changelog_min_gc_interval);
370 static ssize_t changelog_min_free_cat_entries_show(struct kobject *kobj,
371 struct attribute *attr,
374 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
377 return sprintf(buf, "%u\n", mdd->mdd_changelog_min_free_cat_entries);
380 static ssize_t changelog_min_free_cat_entries_store(struct kobject *kobj,
381 struct attribute *attr,
385 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
390 rc = kstrtouint(buffer, 10, &val);
394 /* XXX may need to limit with more reasonable number of free entries */
398 mdd->mdd_changelog_min_free_cat_entries = val;
402 LUSTRE_RW_ATTR(changelog_min_free_cat_entries);
404 static ssize_t changelog_deniednext_show(struct kobject *kobj,
405 struct attribute *attr,
408 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
411 return sprintf(buf, "%u\n", mdd->mdd_cl.mc_deniednext);
414 static ssize_t changelog_deniednext_store(struct kobject *kobj,
415 struct attribute *attr,
419 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
421 unsigned int time = 0;
424 rc = kstrtouint(buffer, 0, &time);
428 mdd->mdd_cl.mc_deniednext = time;
431 LUSTRE_RW_ATTR(changelog_deniednext);
433 static ssize_t sync_permission_show(struct kobject *kobj,
434 struct attribute *attr, char *buf)
436 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
439 return sprintf(buf, "%d\n", mdd->mdd_sync_permission);
442 static ssize_t sync_permission_store(struct kobject *kobj,
443 struct attribute *attr,
444 const char *buffer, size_t count)
446 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
451 rc = kstrtobool(buffer, &val);
455 mdd->mdd_sync_permission = val;
459 LUSTRE_RW_ATTR(sync_permission);
461 static ssize_t lfsck_speed_limit_show(struct kobject *kobj,
462 struct attribute *attr, char *buf)
464 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
467 return lfsck_get_speed(buf, mdd->mdd_bottom);
470 static ssize_t lfsck_speed_limit_store(struct kobject *kobj,
471 struct attribute *attr,
472 const char *buffer, size_t count)
474 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
479 rc = kstrtouint(buffer, 10, &val);
483 rc = lfsck_set_speed(mdd->mdd_bottom, val);
484 return rc != 0 ? rc : count;
486 LUSTRE_RW_ATTR(lfsck_speed_limit);
488 static ssize_t lfsck_async_windows_show(struct kobject *kobj,
489 struct attribute *attr, char *buf)
491 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
494 return lfsck_get_windows(buf, mdd->mdd_bottom);
497 static ssize_t lfsck_async_windows_store(struct kobject *kobj,
498 struct attribute *attr,
499 const char *buffer, size_t count)
501 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
506 rc = kstrtouint(buffer, 10, &val);
510 rc = lfsck_set_windows(mdd->mdd_bottom, val);
512 return rc != 0 ? rc : count;
514 LUSTRE_RW_ATTR(lfsck_async_windows);
516 static int mdd_lfsck_namespace_seq_show(struct seq_file *m, void *data)
518 struct mdd_device *mdd = m->private;
520 LASSERT(mdd != NULL);
522 return lfsck_dump(m, mdd->mdd_bottom, LFSCK_TYPE_NAMESPACE);
524 LDEBUGFS_SEQ_FOPS_RO(mdd_lfsck_namespace);
526 static int mdd_lfsck_layout_seq_show(struct seq_file *m, void *data)
528 struct mdd_device *mdd = m->private;
530 LASSERT(mdd != NULL);
532 return lfsck_dump(m, mdd->mdd_bottom, LFSCK_TYPE_LAYOUT);
534 LDEBUGFS_SEQ_FOPS_RO(mdd_lfsck_layout);
536 static struct lprocfs_vars lprocfs_mdd_obd_vars[] = {
537 { .name = "changelog_mask",
538 .fops = &mdd_changelog_mask_fops },
539 { .name = "changelog_users",
540 .fops = &mdd_changelog_users_fops },
541 { .name = "lfsck_namespace",
542 .fops = &mdd_lfsck_namespace_fops },
543 { .name = "lfsck_layout",
544 .fops = &mdd_lfsck_layout_fops },
548 static struct attribute *mdd_attrs[] = {
549 &lustre_attr_uuid.attr,
550 &lustre_attr_atime_diff.attr,
551 &lustre_attr_changelog_size.attr,
552 &lustre_attr_changelog_gc.attr,
553 &lustre_attr_changelog_max_idle_time.attr,
554 &lustre_attr_changelog_max_idle_indexes.attr,
555 &lustre_attr_changelog_min_gc_interval.attr,
556 &lustre_attr_changelog_min_free_cat_entries.attr,
557 &lustre_attr_changelog_deniednext.attr,
558 &lustre_attr_lfsck_async_windows.attr,
559 &lustre_attr_lfsck_speed_limit.attr,
560 &lustre_attr_sync_permission.attr,
564 static void mdd_sysfs_release(struct kobject *kobj)
566 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
568 struct obd_device *obd = mdd2obd_dev(mdd);
570 debugfs_remove_recursive(obd->obd_debugfs_entry);
571 obd->obd_debugfs_entry = NULL;
573 complete(&mdd->mdd_kobj_unregister);
576 int mdd_procfs_init(struct mdd_device *mdd, const char *name)
578 struct obd_device *obd = mdd2obd_dev(mdd);
579 struct obd_type *type;
583 /* at the moment there is no linkage between lu_type
584 * and obd_type, so we lookup obd_type this way
586 type = class_search_type(LUSTRE_MDD_NAME);
588 LASSERT(name != NULL);
589 LASSERT(type != NULL);
590 LASSERT(obd != NULL);
592 mdd->mdd_ktype.default_attrs = mdd_attrs;
593 mdd->mdd_ktype.release = mdd_sysfs_release;
594 mdd->mdd_ktype.sysfs_ops = &lustre_sysfs_ops;
596 init_completion(&mdd->mdd_kobj_unregister);
597 rc = kobject_init_and_add(&mdd->mdd_kobj, &mdd->mdd_ktype,
598 &type->typ_kobj, "%s", name);
602 /* Find the type procroot and add the proc entry for this device */
603 obd->obd_vars = lprocfs_mdd_obd_vars;
604 obd->obd_debugfs_entry = ldebugfs_register(name,
605 type->typ_debugfs_entry,
607 if (IS_ERR_OR_NULL(obd->obd_debugfs_entry)) {
608 rc = obd->obd_debugfs_entry ? PTR_ERR(obd->obd_debugfs_entry)
610 CERROR("Error %d setting up debugfs for %s\n",
612 obd->obd_debugfs_entry = NULL;
614 kobject_put(&mdd->mdd_kobj);
620 void mdd_procfs_fini(struct mdd_device *mdd)
622 kobject_put(&mdd->mdd_kobj);
623 wait_for_completion(&mdd->mdd_kobj_unregister);