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/
31 * lustre/mdd/mdd_lproc.c
33 * Lustre Metadata Server (mdd) routines
35 * Author: Wang Di <wangdi@clusterfs.com>
38 #define DEBUG_SUBSYSTEM S_MDS
41 #include <obd_class.h>
42 #include <obd_support.h>
43 #include <lprocfs_status.h>
44 #include <libcfs/libcfs_string.h>
45 #include "mdd_internal.h"
47 static ssize_t uuid_show(struct kobject *kobj, struct attribute *attr,
50 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
52 struct obd_device *obd = mdd2obd_dev(mdd);
54 return sprintf(buf, "%s\n", obd->obd_uuid.uuid);
58 static ssize_t atime_diff_show(struct kobject *kobj, struct attribute *attr,
61 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
64 return sprintf(buf, "%lld\n", mdd->mdd_atime_diff);
67 static ssize_t atime_diff_store(struct kobject *kobj,
68 struct attribute *attr,
69 const char *buffer, size_t count)
71 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
76 rc = kstrtoll(buffer, 10, &diff);
80 mdd->mdd_atime_diff = diff;
83 LUSTRE_RW_ATTR(atime_diff);
85 /**** changelogs ****/
86 static int mdd_changelog_current_mask_seq_show(struct seq_file *m, void *data)
88 struct mdd_device *mdd = m->private;
92 if (mdd->mdd_cl.mc_current_mask & BIT(i))
93 seq_printf(m, "%s ", changelog_type2str(i));
99 LDEBUGFS_SEQ_FOPS_RO(mdd_changelog_current_mask);
101 static int mdd_changelog_mask_seq_show(struct seq_file *m, void *data)
103 struct mdd_device *mdd = m->private;
106 while (i < CL_LAST) {
107 if (mdd->mdd_cl.mc_proc_mask & BIT(i))
108 seq_printf(m, "%s ", changelog_type2str(i));
116 mdd_changelog_mask_seq_write(struct file *file, const char __user *buffer,
117 size_t count, loff_t *off)
119 struct seq_file *m = file->private_data;
120 struct mdd_device *mdd = m->private;
123 int oldmask = mdd->mdd_cl.mc_proc_mask;
124 int newmask = oldmask;
128 if (count >= PAGE_SIZE)
130 OBD_ALLOC(kernbuf, PAGE_SIZE);
133 if (copy_from_user(kernbuf, buffer, count))
134 GOTO(out, rc = -EFAULT);
137 /* if the new mask is relative and proc mask is minimal then assume
138 * it is relative to DEFMASK, otherwise apply new mask on the current
141 if (oldmask == CHANGELOG_MINMASK) {
144 while (isspace(*str))
146 if (*str == '+' || *str == '-')
147 newmask = CHANGELOG_DEFMASK;
150 rc = cfs_str2mask(kernbuf, changelog_type2str, &newmask,
151 CHANGELOG_MINMASK, CHANGELOG_ALLMASK,
156 mdd->mdd_cl.mc_proc_mask = newmask;
158 /* if oldmask is not MINMASK and newmask keeps all bits from oldmask
159 * then just extend the current mask, otherwise the current mask
160 * should be recalculated through all user masks.
162 if (oldmask != CHANGELOG_MINMASK && (newmask & oldmask) == oldmask) {
163 spin_lock(&mdd->mdd_cl.mc_user_lock);
164 mdd->mdd_cl.mc_current_mask |= newmask;
165 spin_unlock(&mdd->mdd_cl.mc_user_lock);
169 rc = lu_env_init(&env, LCT_LOCAL);
173 mdd_changelog_recalc_mask(&env, mdd);
181 OBD_FREE(kernbuf, PAGE_SIZE);
184 LDEBUGFS_SEQ_FOPS(mdd_changelog_mask);
186 static int lprocfs_changelog_users_cb(const struct lu_env *env,
187 struct llog_handle *llh,
188 struct llog_rec_hdr *hdr, void *data)
190 struct llog_changelog_user_rec2 *rec;
191 struct seq_file *m = data;
192 char user_name[CHANGELOG_USER_NAMELEN_FULL];
194 LASSERT(llh->lgh_hdr->llh_flags & LLOG_F_IS_PLAIN);
196 rec = container_of(hdr, typeof(*rec), cur_hdr);
198 seq_printf(m, "%-24s %10llu (%u)",
199 mdd_chlg_username(rec, user_name, sizeof(user_name)),
201 (__u32)ktime_get_real_seconds() - rec->cur_time);
202 if (mdd_chlg_usermask(rec)) {
206 seq_puts(m, " mask=");
207 for (i = 0; i < CL_LAST; i++) {
208 if (!(mdd_chlg_usermask(rec) & BIT(i)))
212 seq_puts(m, changelog_type2str(i));
221 static int mdd_changelog_users_seq_show(struct seq_file *m, void *data)
224 struct mdd_device *mdd = m->private;
225 struct llog_ctxt *ctxt;
229 ctxt = llog_get_context(mdd2obd_dev(mdd),
230 LLOG_CHANGELOG_USER_ORIG_CTXT);
233 LASSERT(ctxt->loc_handle->lgh_hdr->llh_flags & LLOG_F_IS_CAT);
235 rc = lu_env_init(&env, LCT_LOCAL);
241 spin_lock(&mdd->mdd_cl.mc_lock);
242 cur = mdd->mdd_cl.mc_index;
243 spin_unlock(&mdd->mdd_cl.mc_lock);
245 seq_printf(m, "current_index: %llu\n", cur);
246 seq_printf(m, "%-24s %10s %s %s\n", "ID", "index", "(idle)", "mask");
248 llog_cat_process(&env, ctxt->loc_handle, lprocfs_changelog_users_cb,
255 LDEBUGFS_SEQ_FOPS_RO(mdd_changelog_users);
257 static int mdd_changelog_size_ctxt(const struct lu_env *env,
258 struct mdd_device *mdd,
259 int index, __u64 *val)
261 struct llog_ctxt *ctxt;
263 ctxt = llog_get_context(mdd2obd_dev(mdd),
268 if (!(ctxt->loc_handle->lgh_hdr->llh_flags & LLOG_F_IS_CAT)) {
269 CERROR("%s: ChangeLog has wrong flags: rc = %d\n",
270 ctxt->loc_obd->obd_name, -EINVAL);
275 *val += llog_cat_size(env, ctxt->loc_handle);
282 static ssize_t changelog_size_show(struct kobject *kobj,
283 struct attribute *attr,
286 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
292 rc = lu_env_init(&env, LCT_LOCAL);
296 rc = mdd_changelog_size_ctxt(&env, mdd, LLOG_CHANGELOG_ORIG_CTXT, &tmp);
302 rc = mdd_changelog_size_ctxt(&env, mdd, LLOG_CHANGELOG_USER_ORIG_CTXT,
305 rc = sprintf(buf, "%llu\n", tmp);
309 LUSTRE_RO_ATTR(changelog_size);
311 static ssize_t changelog_gc_show(struct kobject *kobj,
312 struct attribute *attr,
315 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
318 return sprintf(buf, "%u\n", mdd->mdd_changelog_gc);
321 static ssize_t changelog_gc_store(struct kobject *kobj,
322 struct attribute *attr,
323 const char *buffer, size_t count)
325 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
330 rc = kstrtobool(buffer, &val);
334 mdd->mdd_changelog_gc = val;
338 LUSTRE_RW_ATTR(changelog_gc);
340 static ssize_t changelog_free_space_gc_show(struct kobject *kobj,
341 struct attribute *attr, char *buf)
343 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
346 return sprintf(buf, "%u\n", mdd->mdd_changelog_free_space_gc);
349 static ssize_t changelog_free_space_gc_store(struct kobject *kobj,
350 struct attribute *attr,
351 const char *buffer, size_t count)
353 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
358 rc = kstrtobool(buffer, &val);
362 mdd->mdd_changelog_free_space_gc = val;
366 LUSTRE_RW_ATTR(changelog_free_space_gc);
368 static ssize_t changelog_max_idle_time_show(struct kobject *kobj,
369 struct attribute *attr,
372 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
375 return sprintf(buf, "%lld\n", mdd->mdd_changelog_max_idle_time);
378 static ssize_t changelog_max_idle_time_store(struct kobject *kobj,
379 struct attribute *attr,
380 const char *buffer, size_t count)
382 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
387 rc = kstrtoll(buffer, 10, &val);
391 /* as it sounds reasonable, do not allow a user to be idle since
392 * more than about 68 years, this will allow to use 32bits
393 * timestamps for comparison
395 if (val < 1 || val > INT_MAX)
398 mdd->mdd_changelog_max_idle_time = val;
402 LUSTRE_RW_ATTR(changelog_max_idle_time);
404 static ssize_t changelog_max_idle_indexes_show(struct kobject *kobj,
405 struct attribute *attr,
408 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
411 return sprintf(buf, "%lu\n", mdd->mdd_changelog_max_idle_indexes);
414 static ssize_t changelog_max_idle_indexes_store(struct kobject *kobj,
415 struct attribute *attr,
419 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
424 LASSERT(mdd != NULL);
425 rc = kstrtoul(buffer, 0, &val);
429 /* XXX may need to limit/check with reasonable elapsed/idle indexes */
430 /* XXX may better allow to specify a % of full ChangeLogs */
432 mdd->mdd_changelog_max_idle_indexes = val;
436 LUSTRE_RW_ATTR(changelog_max_idle_indexes);
438 static ssize_t changelog_min_gc_interval_show(struct kobject *kobj,
439 struct attribute *attr,
442 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
445 return sprintf(buf, "%lld\n", mdd->mdd_changelog_min_gc_interval);
448 static ssize_t changelog_min_gc_interval_store(struct kobject *kobj,
449 struct attribute *attr,
453 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
458 rc = kstrtoll(buffer, 10, &val);
462 /* XXX may need to limit with reasonable elapsed/interval times */
466 mdd->mdd_changelog_min_gc_interval = val;
470 LUSTRE_RW_ATTR(changelog_min_gc_interval);
472 static ssize_t changelog_min_free_cat_entries_show(struct kobject *kobj,
473 struct attribute *attr,
476 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
479 return sprintf(buf, "%u\n", mdd->mdd_changelog_min_free_cat_entries);
482 static ssize_t changelog_min_free_cat_entries_store(struct kobject *kobj,
483 struct attribute *attr,
487 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
492 rc = kstrtouint(buffer, 10, &val);
496 /* XXX may need to limit with more reasonable number of free entries */
500 mdd->mdd_changelog_min_free_cat_entries = val;
504 LUSTRE_RW_ATTR(changelog_min_free_cat_entries);
506 static ssize_t changelog_deniednext_show(struct kobject *kobj,
507 struct attribute *attr,
510 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
513 return sprintf(buf, "%u\n", mdd->mdd_cl.mc_deniednext);
516 static ssize_t changelog_deniednext_store(struct kobject *kobj,
517 struct attribute *attr,
521 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
523 unsigned int time = 0;
526 rc = kstrtouint(buffer, 0, &time);
530 mdd->mdd_cl.mc_deniednext = time;
533 LUSTRE_RW_ATTR(changelog_deniednext);
535 static ssize_t enable_shard_pfid_show(struct kobject *kobj,
536 struct attribute *attr, char *buf)
538 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
541 return scnprintf(buf, PAGE_SIZE, "%d\n",
542 mdd->mdd_cl.mc_enable_shard_pfid);
545 static ssize_t enable_shard_pfid_store(struct kobject *kobj,
546 struct attribute *attr,
547 const char *buffer, size_t count)
549 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
554 rc = kstrtou8(buffer, 10, &val);
558 mdd->mdd_cl.mc_enable_shard_pfid = !!val;
561 LUSTRE_RW_ATTR(enable_shard_pfid);
563 static ssize_t sync_permission_show(struct kobject *kobj,
564 struct attribute *attr, char *buf)
566 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
569 return sprintf(buf, "%d\n", mdd->mdd_sync_permission);
572 static ssize_t sync_permission_store(struct kobject *kobj,
573 struct attribute *attr,
574 const char *buffer, size_t count)
576 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
581 rc = kstrtobool(buffer, &val);
585 mdd->mdd_sync_permission = val;
589 LUSTRE_RW_ATTR(sync_permission);
591 static ssize_t lfsck_speed_limit_show(struct kobject *kobj,
592 struct attribute *attr, char *buf)
594 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
597 return lfsck_get_speed(buf, mdd->mdd_bottom);
600 static ssize_t lfsck_speed_limit_store(struct kobject *kobj,
601 struct attribute *attr,
602 const char *buffer, size_t count)
604 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
609 rc = kstrtouint(buffer, 10, &val);
613 rc = lfsck_set_speed(mdd->mdd_bottom, val);
614 return rc != 0 ? rc : count;
616 LUSTRE_RW_ATTR(lfsck_speed_limit);
618 static ssize_t lfsck_async_windows_show(struct kobject *kobj,
619 struct attribute *attr, char *buf)
621 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
624 return lfsck_get_windows(buf, mdd->mdd_bottom);
627 static ssize_t lfsck_async_windows_store(struct kobject *kobj,
628 struct attribute *attr,
629 const char *buffer, size_t count)
631 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
636 rc = kstrtouint(buffer, 10, &val);
640 rc = lfsck_set_windows(mdd->mdd_bottom, val);
642 return rc != 0 ? rc : count;
644 LUSTRE_RW_ATTR(lfsck_async_windows);
646 static int mdd_lfsck_namespace_seq_show(struct seq_file *m, void *data)
648 struct mdd_device *mdd = m->private;
650 LASSERT(mdd != NULL);
652 return lfsck_dump(m, mdd->mdd_bottom, LFSCK_TYPE_NAMESPACE);
654 LDEBUGFS_SEQ_FOPS_RO(mdd_lfsck_namespace);
656 static int mdd_lfsck_layout_seq_show(struct seq_file *m, void *data)
658 struct mdd_device *mdd = m->private;
660 LASSERT(mdd != NULL);
662 return lfsck_dump(m, mdd->mdd_bottom, LFSCK_TYPE_LAYOUT);
664 LDEBUGFS_SEQ_FOPS_RO(mdd_lfsck_layout);
667 * Show default number of stripes for O_APPEND files.
669 * \param[in] m seq file
670 * \param[in] v unused for single entry
672 * \retval 0 on success,
673 * \retval negative error code if failed
675 static ssize_t append_stripe_count_show(struct kobject *kobj,
676 struct attribute *attr, char *buf)
678 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
681 return scnprintf(buf, PAGE_SIZE, "%d\n", mdd->mdd_append_stripe_count);
685 * Set default number of stripes for O_APPEND files.
687 * \param[in] file proc file
688 * \param[in] buffer string containing the default number of stripes
690 * \param[in] count @buffer length
691 * \param[in] off unused for single entry
693 * \retval @count on success
694 * \retval negative error code otherwise
696 static ssize_t append_stripe_count_store(struct kobject *kobj,
697 struct attribute *attr,
698 const char *buffer, size_t count)
700 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
705 rc = kstrtoint(buffer, 0, &stripe_count);
709 if (stripe_count < -1)
712 mdd->mdd_append_stripe_count = stripe_count;
716 LUSTRE_RW_ATTR(append_stripe_count);
719 * Show default OST pool for O_APPEND files.
721 * \param[in] kobject proc object
722 * \param[in] attribute proc attribute
723 * \param[in] buf output buffer
725 * \retval 0 on success,
726 * \retval negative error code if failed
728 static ssize_t append_pool_show(struct kobject *kobj,
729 struct attribute *attr, char *buf)
731 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
734 return scnprintf(buf, PAGE_SIZE, "%s\n", mdd->mdd_append_pool);
738 * Set default OST pool for O_APPEND files.
740 * \param[in] kobject proc object
741 * \param[in] attribute proc attribute
742 * \param[in] buffer user inputted pool name
743 * \param[in] count @buffer length
745 * \retval @count on success
746 * \retval negative error code otherwise
748 static ssize_t append_pool_store(struct kobject *kobj, struct attribute *attr,
749 const char *buffer, size_t count)
751 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
754 if (!count || count > LOV_MAXPOOLNAME + 1 || buffer[0] == '\n')
757 strscpy(mdd->mdd_append_pool, buffer, LOV_MAXPOOLNAME + 1);
758 if (mdd->mdd_append_pool[count - 1] == '\n')
759 mdd->mdd_append_pool[count - 1] = '\0';
761 /* clears the pool for "none", "inherit" or "ignore" */
762 if (lov_pool_is_reserved(mdd->mdd_append_pool))
763 memset(mdd->mdd_append_pool, 0, LOV_MAXPOOLNAME + 1);
767 LUSTRE_RW_ATTR(append_pool);
769 static struct ldebugfs_vars ldebugfs_mdd_obd_vars[] = {
770 { .name = "changelog_mask",
771 .fops = &mdd_changelog_mask_fops },
772 { .name = "changelog_current_mask",
773 .fops = &mdd_changelog_current_mask_fops },
774 { .name = "changelog_users",
775 .fops = &mdd_changelog_users_fops },
776 { .name = "lfsck_namespace",
777 .fops = &mdd_lfsck_namespace_fops },
778 { .name = "lfsck_layout",
779 .fops = &mdd_lfsck_layout_fops },
783 static struct attribute *mdd_attrs[] = {
784 &lustre_attr_uuid.attr,
785 &lustre_attr_atime_diff.attr,
786 &lustre_attr_changelog_size.attr,
787 &lustre_attr_changelog_gc.attr,
788 &lustre_attr_changelog_free_space_gc.attr,
789 &lustre_attr_changelog_max_idle_time.attr,
790 &lustre_attr_changelog_max_idle_indexes.attr,
791 &lustre_attr_changelog_min_gc_interval.attr,
792 &lustre_attr_changelog_min_free_cat_entries.attr,
793 &lustre_attr_changelog_deniednext.attr,
794 &lustre_attr_enable_shard_pfid.attr,
795 &lustre_attr_lfsck_async_windows.attr,
796 &lustre_attr_lfsck_speed_limit.attr,
797 &lustre_attr_sync_permission.attr,
798 &lustre_attr_append_stripe_count.attr,
799 &lustre_attr_append_pool.attr,
803 KOBJ_ATTRIBUTE_GROUPS(mdd); /* creates mdd_groups */
805 static void mdd_sysfs_release(struct kobject *kobj)
807 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
809 struct obd_device *obd = mdd2obd_dev(mdd);
811 debugfs_remove_recursive(obd->obd_debugfs_entry);
812 obd->obd_debugfs_entry = NULL;
814 complete(&mdd->mdd_kobj_unregister);
817 int mdd_procfs_init(struct mdd_device *mdd, const char *name)
819 struct obd_device *obd = mdd2obd_dev(mdd);
820 struct obd_type *type;
824 /* at the moment there is no linkage between lu_type
825 * and obd_type, so we lookup obd_type this way
827 type = class_search_type(LUSTRE_MDD_NAME);
829 LASSERT(name != NULL);
830 LASSERT(type != NULL);
831 LASSERT(obd != NULL);
833 /* put reference taken by class_search_type */
834 kobject_put(&type->typ_kobj);
836 mdd->mdd_ktype.default_groups = KOBJ_ATTR_GROUPS(mdd);
837 mdd->mdd_ktype.release = mdd_sysfs_release;
838 mdd->mdd_ktype.sysfs_ops = &lustre_sysfs_ops;
840 init_completion(&mdd->mdd_kobj_unregister);
841 rc = kobject_init_and_add(&mdd->mdd_kobj, &mdd->mdd_ktype,
842 &type->typ_kobj, "%s", name);
846 /* Find the type procroot and add the proc entry for this device */
847 obd->obd_debugfs_vars = ldebugfs_mdd_obd_vars;
848 obd->obd_debugfs_entry = debugfs_create_dir(name,
849 type->typ_debugfs_entry);
850 ldebugfs_add_vars(obd->obd_debugfs_entry, obd->obd_debugfs_vars, mdd);
855 void mdd_procfs_fini(struct mdd_device *mdd)
857 kobject_put(&mdd->mdd_kobj);
858 wait_for_completion(&mdd->mdd_kobj_unregister);