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);
537 * Show default number of stripes for O_APPEND files.
539 * \param[in] m seq file
540 * \param[in] v unused for single entry
542 * \retval 0 on success,
543 * \retval negative error code if failed
545 static ssize_t append_stripe_count_show(struct kobject *kobj,
546 struct attribute *attr, char *buf)
548 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
551 return snprintf(buf, PAGE_SIZE, "%d\n", mdd->mdd_append_stripe_count);
555 * Set default number of stripes for O_APPEND files.
557 * \param[in] file proc file
558 * \param[in] buffer string containing the default number of stripes
560 * \param[in] count @buffer length
561 * \param[in] off unused for single entry
563 * \retval @count on success
564 * \retval negative error code otherwise
566 static ssize_t append_stripe_count_store(struct kobject *kobj,
567 struct attribute *attr,
568 const char *buffer, size_t count)
570 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
575 rc = kstrtoint(buffer, 0, &stripe_count);
579 if (stripe_count < -1)
582 mdd->mdd_append_stripe_count = stripe_count;
586 LUSTRE_RW_ATTR(append_stripe_count);
589 * Show default OST pool for O_APPEND files.
591 * \param[in] kobject proc object
592 * \param[in] attribute proc attribute
593 * \param[in] buf output buffer
595 * \retval 0 on success,
596 * \retval negative error code if failed
598 static ssize_t append_pool_show(struct kobject *kobj,
599 struct attribute *attr, char *buf)
601 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
604 return snprintf(buf, LOV_MAXPOOLNAME + 1, "%s\n", mdd->mdd_append_pool);
608 * Set default OST pool for O_APPEND files.
610 * \param[in] kobject proc object
611 * \param[in] attribute proc attribute
612 * \param[in] buffer user inputted pool name
613 * \param[in] count @buffer length
615 * \retval @count on success
616 * \retval negative error code otherwise
618 static ssize_t append_pool_store(struct kobject *kobj, struct attribute *attr,
619 const char *buffer, size_t count)
621 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
624 if (!count || count > LOV_MAXPOOLNAME + 1)
627 /* clear previous value */
628 memset(mdd->mdd_append_pool, 0, LOV_MAXPOOLNAME + 1);
630 /* entering "none" clears the pool, otherwise copy the new pool */
631 if (strncmp("none", buffer, 4)) {
632 memcpy(mdd->mdd_append_pool, buffer, count);
634 /* Trim the trailing '\n' if any */
635 if (mdd->mdd_append_pool[count - 1] == '\n') {
636 /* Don't echo just a newline */
639 mdd->mdd_append_pool[count - 1] = 0;
645 LUSTRE_RW_ATTR(append_pool);
647 static struct lprocfs_vars lprocfs_mdd_obd_vars[] = {
648 { .name = "changelog_mask",
649 .fops = &mdd_changelog_mask_fops },
650 { .name = "changelog_users",
651 .fops = &mdd_changelog_users_fops },
652 { .name = "lfsck_namespace",
653 .fops = &mdd_lfsck_namespace_fops },
654 { .name = "lfsck_layout",
655 .fops = &mdd_lfsck_layout_fops },
659 static struct attribute *mdd_attrs[] = {
660 &lustre_attr_uuid.attr,
661 &lustre_attr_atime_diff.attr,
662 &lustre_attr_changelog_size.attr,
663 &lustre_attr_changelog_gc.attr,
664 &lustre_attr_changelog_max_idle_time.attr,
665 &lustre_attr_changelog_max_idle_indexes.attr,
666 &lustre_attr_changelog_min_gc_interval.attr,
667 &lustre_attr_changelog_min_free_cat_entries.attr,
668 &lustre_attr_changelog_deniednext.attr,
669 &lustre_attr_lfsck_async_windows.attr,
670 &lustre_attr_lfsck_speed_limit.attr,
671 &lustre_attr_sync_permission.attr,
672 &lustre_attr_append_stripe_count.attr,
673 &lustre_attr_append_pool.attr,
677 static void mdd_sysfs_release(struct kobject *kobj)
679 struct mdd_device *mdd = container_of(kobj, struct mdd_device,
681 struct obd_device *obd = mdd2obd_dev(mdd);
683 debugfs_remove_recursive(obd->obd_debugfs_entry);
684 obd->obd_debugfs_entry = NULL;
686 complete(&mdd->mdd_kobj_unregister);
689 int mdd_procfs_init(struct mdd_device *mdd, const char *name)
691 struct obd_device *obd = mdd2obd_dev(mdd);
692 struct obd_type *type;
696 /* at the moment there is no linkage between lu_type
697 * and obd_type, so we lookup obd_type this way
699 type = class_search_type(LUSTRE_MDD_NAME);
701 LASSERT(name != NULL);
702 LASSERT(type != NULL);
703 LASSERT(obd != NULL);
705 /* put reference taken by class_search_type */
706 kobject_put(&type->typ_kobj);
708 mdd->mdd_ktype.default_attrs = mdd_attrs;
709 mdd->mdd_ktype.release = mdd_sysfs_release;
710 mdd->mdd_ktype.sysfs_ops = &lustre_sysfs_ops;
712 init_completion(&mdd->mdd_kobj_unregister);
713 rc = kobject_init_and_add(&mdd->mdd_kobj, &mdd->mdd_ktype,
714 &type->typ_kobj, "%s", name);
718 /* Find the type procroot and add the proc entry for this device */
719 obd->obd_vars = lprocfs_mdd_obd_vars;
720 obd->obd_debugfs_entry = debugfs_create_dir(name,
721 type->typ_debugfs_entry);
722 ldebugfs_add_vars(obd->obd_debugfs_entry, obd->obd_vars, mdd);
727 void mdd_procfs_fini(struct mdd_device *mdd)
729 kobject_put(&mdd->mdd_kobj);
730 wait_for_completion(&mdd->mdd_kobj_unregister);