X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=blobdiff_plain;f=lustre%2Flod%2Flproc_lod.c;h=d2fccdafd84f887317a60d3b4c6a2c73c043851a;hp=52501271722e15ea93290e94e26e484d4477e844;hb=aa4269f5c2e3c834cdff63dc32d7a7183f32374a;hpb=73c12f4d6c98476c0dc5de77a646a157db727eef diff --git a/lustre/lod/lproc_lod.c b/lustre/lod/lproc_lod.c index 5250127..d2fccda 100644 --- a/lustre/lod/lproc_lod.c +++ b/lustre/lod/lproc_lod.c @@ -15,11 +15,7 @@ * * You should have received a copy of the GNU General Public License * version 2 along with this program; If not, see - * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf - * - * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, - * CA 95054 USA or visit www.sun.com if you need additional information or - * have any questions. + * http://www.gnu.org/licenses/gpl-2.0.html * * GPL HEADER END */ @@ -27,7 +23,7 @@ * Copyright 2008 Sun Microsystems, Inc. All rights reserved * Use is subject to license terms. * - * Copyright (c) 2012, 2013, Intel Corporation. + * Copyright (c) 2012, 2017, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -39,388 +35,797 @@ #include #include #include "lod_internal.h" -#include +#include + +/* + * Notice, all the functions below (except for lod_procfs_init() and + * lod_procfs_fini()) are not supposed to be used directly. They are + * called by Linux kernel's procfs. + */ -#ifdef LPROCFS -static int lod_stripesize_seq_show(struct seq_file *m, void *v) +#ifdef CONFIG_PROC_FS + +/** + * Show DoM default stripe size. + */ +static ssize_t dom_stripesize_show(struct kobject *kobj, struct attribute *attr, + char *buf) { - struct obd_device *dev = m->private; - struct lod_device *lod; + struct dt_device *dt = container_of(kobj, struct dt_device, + dd_kobj); + struct lod_device *lod = dt2lod_dev(dt); - LASSERT(dev != NULL); - lod = lu2lod_dev(dev->obd_lu_dev); - return seq_printf(m, LPU64"\n", - lod->lod_desc.ld_default_stripe_size); + return snprintf(buf, PAGE_SIZE, "%u\n", lod->lod_dom_max_stripesize); } -static ssize_t -lod_stripesize_seq_write(struct file *file, const char *buffer, - size_t count, loff_t *off) +/** + * Set DoM default stripe size. + */ +static ssize_t dom_stripesize_store(struct kobject *kobj, + struct attribute *attr, const char *buffer, + size_t count) { - struct seq_file *m = file->private_data; - struct obd_device *dev = m->private; - struct lod_device *lod; - __u64 val; + struct dt_device *dt = container_of(kobj, struct dt_device, + dd_kobj); + struct lod_device *lod = dt2lod_dev(dt); + char tbuf[22] = ""; + s64 val; int rc; - LASSERT(dev != NULL); - lod = lu2lod_dev(dev->obd_lu_dev); - rc = lprocfs_write_u64_helper(buffer, count, &val); + if (count > (sizeof(tbuf) - 1)) + return -EINVAL; + + memcpy(tbuf, buffer, count); + + rc = lu_str_to_s64(tbuf, count, &val, '1'); + if (rc) + return rc; + + if (val < 0) + return -ERANGE; + + /* 1GB is the limit */ + if (val > (1ULL << 30)) + return -ERANGE; + + if (val > 0) { + if (val < LOV_MIN_STRIPE_SIZE) { + LCONSOLE_INFO("Increasing provided stripe size to " + "a minimum value %u\n", + LOV_MIN_STRIPE_SIZE); + val = LOV_MIN_STRIPE_SIZE; + } else if (val & (LOV_MIN_STRIPE_SIZE - 1)) { + val &= ~(LOV_MIN_STRIPE_SIZE - 1); + LCONSOLE_WARN("Changing provided stripe size to %llu " + "(a multiple of minimum %u)\n", + val, LOV_MIN_STRIPE_SIZE); + } + } + + lod->lod_dom_max_stripesize = val; + + return count; +} + +LUSTRE_RW_ATTR(dom_stripesize); + +static ssize_t stripesize_show(struct kobject *kobj, struct attribute *attr, + char *buf) +{ + struct dt_device *dt = container_of(kobj, struct dt_device, + dd_kobj); + struct lod_device *lod = dt2lod_dev(dt); + + return snprintf(buf, PAGE_SIZE, "%llu\n", + lod->lod_ost_descs.ltd_lov_desc.ld_default_stripe_size); +} + +static ssize_t stripesize_store(struct kobject *kobj, struct attribute *attr, + const char *buffer, size_t count) +{ + struct dt_device *dt = container_of(kobj, struct dt_device, + dd_kobj); + struct lod_device *lod = dt2lod_dev(dt); + char tbuf[22] = ""; + s64 val; + int rc; + + if (count > (sizeof(tbuf) - 1)) + return -EINVAL; + + memcpy(tbuf, buffer, count); + + rc = lu_str_to_s64(tbuf, count, &val, '1'); if (rc) return rc; + if (val < 0) + return -ERANGE; + lod_fix_desc_stripe_size(&val); - lod->lod_desc.ld_default_stripe_size = val; + lod->lod_ost_descs.ltd_lov_desc.ld_default_stripe_size = val; + return count; } -LPROC_SEQ_FOPS(lod_stripesize); -static int lod_stripeoffset_seq_show(struct seq_file *m, void *v) +LUSTRE_RW_ATTR(stripesize); + +/** + * Show default stripe offset. + */ +static ssize_t stripeoffset_show(struct kobject *kobj, struct attribute *attr, + char *buf) { - struct obd_device *dev = m->private; - struct lod_device *lod; + struct dt_device *dt = container_of(kobj, struct dt_device, + dd_kobj); + struct lod_device *lod = dt2lod_dev(dt); - LASSERT(dev != NULL); - lod = lu2lod_dev(dev->obd_lu_dev); - return seq_printf(m, LPU64"\n", - lod->lod_desc.ld_default_stripe_offset); + return snprintf(buf, PAGE_SIZE, "%lld\n", + lod->lod_ost_descs.ltd_lov_desc.ld_default_stripe_offset); } -static ssize_t -lod_stripeoffset_seq_write(struct file *file, const char *buffer, - size_t count, loff_t *off) +/** + * Set default stripe offset. + * + * Usually contains -1 allowing Lustre to balance objects among OST + * otherwise may cause severe OST imbalance. + */ +static ssize_t stripeoffset_store(struct kobject *kobj, + struct attribute *attr, + const char *buffer, size_t count) { - struct seq_file *m = file->private_data; - struct obd_device *dev = m->private; - struct lod_device *lod; - __u64 val; + struct dt_device *dt = container_of(kobj, struct dt_device, + dd_kobj); + struct lod_device *lod = dt2lod_dev(dt); + long val; int rc; - LASSERT(dev != NULL); - lod = lu2lod_dev(dev->obd_lu_dev); - rc = lprocfs_write_u64_helper(buffer, count, &val); + rc = kstrtol(buffer, 0, &val); if (rc) return rc; - lod->lod_desc.ld_default_stripe_offset = val; + if (val < -1 || val > LOV_MAX_STRIPE_COUNT) + return -ERANGE; + + lod->lod_ost_descs.ltd_lov_desc.ld_default_stripe_offset = val; + return count; } -LPROC_SEQ_FOPS(lod_stripeoffset); -static int lod_stripetype_seq_show(struct seq_file *m, void *v) +LUSTRE_RW_ATTR(stripeoffset); + +/** + * Show default striping pattern (LOV_PATTERN_*). + */ +static ssize_t __stripetype_show(struct kobject *kobj, struct attribute *attr, + char *buf, bool is_mdt) { - struct obd_device *dev = m->private; - struct lod_device *lod; + struct dt_device *dt = container_of(kobj, struct dt_device, + dd_kobj); + struct lod_device *lod = dt2lod_dev(dt); + struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs : + &lod->lod_ost_descs; - LASSERT(dev != NULL); - lod = lu2lod_dev(dev->obd_lu_dev); - return seq_printf(m, "%u\n", lod->lod_desc.ld_pattern); + return snprintf(buf, PAGE_SIZE, "%u\n", ltd->ltd_lov_desc.ld_pattern); } -static ssize_t -lod_stripetype_seq_write(struct file *file, const char *buffer, - size_t count, loff_t *off) +static ssize_t mdt_stripetype_show(struct kobject *kobj, struct attribute *attr, + char *buf) { - struct seq_file *m = file->private_data; - struct obd_device *dev = m->private; - struct lod_device *lod; - int val, rc; + return __stripetype_show(kobj, attr, buf, true); +} - LASSERT(dev != NULL); - lod = lu2lod_dev(dev->obd_lu_dev); - rc = lprocfs_write_helper(buffer, count, &val); +static ssize_t stripetype_show(struct kobject *kobj, struct attribute *attr, + char *buf) +{ + return __stripetype_show(kobj, attr, buf, false); +} + +/** + * Set default striping pattern (a number, not a human-readable string). + */ +static ssize_t __stripetype_store(struct kobject *kobj, struct attribute *attr, + const char *buffer, size_t count, bool is_mdt) +{ + struct dt_device *dt = container_of(kobj, struct dt_device, + dd_kobj); + struct lod_device *lod = dt2lod_dev(dt); + struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs : + &lod->lod_ost_descs; + u32 pattern; + int rc; + + rc = kstrtouint(buffer, 0, &pattern); if (rc) return rc; - lod_fix_desc_pattern(&val); - lod->lod_desc.ld_pattern = val; + if (is_mdt) + lod_fix_lmv_desc_pattern(&pattern); + else + lod_fix_desc_pattern(&pattern); + + ltd->ltd_lov_desc.ld_pattern = pattern; + return count; } -LPROC_SEQ_FOPS(lod_stripetype); -static int lod_stripecount_seq_show(struct seq_file *m, void *v) +static ssize_t mdt_stripetype_store(struct kobject *kobj, + struct attribute *attr, const char *buffer, + size_t count) { - struct obd_device *dev = m->private; - struct lod_device *lod; + return __stripetype_store(kobj, attr, buffer, count, true); +} - LASSERT(dev != NULL); - lod = lu2lod_dev(dev->obd_lu_dev); - return seq_printf(m, "%d\n", - (__s16)(lod->lod_desc.ld_default_stripe_count + 1) - 1); +static ssize_t stripetype_store(struct kobject *kobj, + struct attribute *attr, const char *buffer, + size_t count) +{ + return __stripetype_store(kobj, attr, buffer, count, false); } -static ssize_t -lod_stripecount_seq_write(struct file *file, const char *buffer, - size_t count, loff_t *off) +LUSTRE_RW_ATTR(mdt_stripetype); +LUSTRE_RW_ATTR(stripetype); + +/** + * Show default number of stripes. + */ +static ssize_t __stripecount_show(struct kobject *kobj, struct attribute *attr, + char *buf, bool is_mdt) { - struct seq_file *m = file->private_data; - struct obd_device *dev = m->private; - struct lod_device *lod; - int val, rc; + struct dt_device *dt = container_of(kobj, struct dt_device, + dd_kobj); + struct lod_device *lod = dt2lod_dev(dt); + struct lov_desc *desc = is_mdt ? &lod->lod_mdt_descs.ltd_lov_desc : + &lod->lod_ost_descs.ltd_lov_desc; + + return snprintf(buf, PAGE_SIZE, "%d\n", + (s16)(desc->ld_default_stripe_count + 1) - 1); +} - LASSERT(dev != NULL); - lod = lu2lod_dev(dev->obd_lu_dev); - rc = lprocfs_write_helper(buffer, count, &val); +static ssize_t mdt_stripecount_show(struct kobject *kobj, + struct attribute *attr, char *buf) +{ + return __stripecount_show(kobj, attr, buf, true); +} + +static ssize_t stripecount_show(struct kobject *kobj, struct attribute *attr, + char *buf) +{ + return __stripecount_show(kobj, attr, buf, false); +} + +/** + * Set default number of stripes. + */ +static ssize_t __stripecount_store(struct kobject *kobj, struct attribute *attr, + const char *buffer, size_t count, + bool is_mdt) +{ + struct dt_device *dt = container_of(kobj, struct dt_device, + dd_kobj); + struct lod_device *lod = dt2lod_dev(dt); + struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs : + &lod->lod_ost_descs; + int stripe_count; + int rc; + + rc = kstrtoint(buffer, 0, &stripe_count); if (rc) return rc; - lod_fix_desc_stripe_count(&val); - lod->lod_desc.ld_default_stripe_count = val; + if (stripe_count < -1) + return -ERANGE; + + lod_fix_desc_stripe_count(&stripe_count); + ltd->ltd_lov_desc.ld_default_stripe_count = stripe_count; + return count; } -LPROC_SEQ_FOPS(lod_stripecount); -static int lod_numobd_seq_show(struct seq_file *m, void *v) +static ssize_t mdt_stripecount_store(struct kobject *kobj, + struct attribute *attr, + const char *buffer, size_t count) { - struct obd_device *dev = m->private; - struct lod_device *lod; + return __stripecount_store(kobj, attr, buffer, count, true); +} - LASSERT(dev != NULL); - lod = lu2lod_dev(dev->obd_lu_dev); - return seq_printf(m, "%u\n", lod->lod_desc.ld_tgt_count); +static ssize_t stripecount_store(struct kobject *kobj, + struct attribute *attr, + const char *buffer, size_t count) +{ + return __stripecount_store(kobj, attr, buffer, count, false); } -LPROC_SEQ_FOPS_RO(lod_numobd); -static int lod_activeobd_seq_show(struct seq_file *m, void *v) +LUSTRE_RW_ATTR(mdt_stripecount); +LUSTRE_RW_ATTR(stripecount); + +/** + * Show number of targets. + */ +static ssize_t __numobd_show(struct kobject *kobj, struct attribute *attr, + char *buf, bool is_mdt) { - struct obd_device *dev = m->private; - struct lod_device *lod; + struct dt_device *dt = container_of(kobj, struct dt_device, + dd_kobj); + struct lod_device *lod = dt2lod_dev(dt); + struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs : + &lod->lod_ost_descs; - LASSERT(dev != NULL); - lod = lu2lod_dev(dev->obd_lu_dev); - return seq_printf(m, "%u\n", lod->lod_desc.ld_active_tgt_count); + return snprintf(buf, PAGE_SIZE, "%u\n", ltd->ltd_lov_desc.ld_tgt_count); } -LPROC_SEQ_FOPS_RO(lod_activeobd); -static int lod_desc_uuid_seq_show(struct seq_file *m, void *v) +static ssize_t mdt_numobd_show(struct kobject *kobj, struct attribute *attr, + char *buf) { - struct obd_device *dev = m->private; - struct lod_device *lod; + return __numobd_show(kobj, attr, buf, true); +} - LASSERT(dev != NULL); - lod = lu2lod_dev(dev->obd_lu_dev); - return seq_printf(m, "%s\n", lod->lod_desc.ld_uuid.uuid); +static ssize_t numobd_show(struct kobject *kobj, struct attribute *attr, + char *buf) +{ + return __numobd_show(kobj, attr, buf, false); } -LPROC_SEQ_FOPS_RO(lod_desc_uuid); -/* free priority (0-255): how badly user wants to choose empty osts */ -static int lod_qos_priofree_seq_show(struct seq_file *m, void *v) +LUSTRE_RO_ATTR(mdt_numobd); +LUSTRE_RO_ATTR(numobd); + +/** + * Show number of active targets. + */ +static ssize_t __activeobd_show(struct kobject *kobj, struct attribute *attr, + char *buf, bool is_mdt) { - struct obd_device *dev = m->private; - struct lod_device *lod = lu2lod_dev(dev->obd_lu_dev); + struct dt_device *dt = container_of(kobj, struct dt_device, + dd_kobj); + struct lod_device *lod = dt2lod_dev(dt); + struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs : + &lod->lod_ost_descs; + + return snprintf(buf, PAGE_SIZE, "%u\n", + ltd->ltd_lov_desc.ld_active_tgt_count); +} - LASSERT(lod != NULL); - return seq_printf(m, "%d%%\n", - (lod->lod_qos.lq_prio_free * 100 + 255) >> 8); +static ssize_t mdt_activeobd_show(struct kobject *kobj, struct attribute *attr, + char *buf) +{ + return __activeobd_show(kobj, attr, buf, true); } -static ssize_t -lod_qos_priofree_seq_write(struct file *file, const char __user *buffer, - size_t count, loff_t *off) +static ssize_t activeobd_show(struct kobject *kobj, struct attribute *attr, + char *buf) { - struct seq_file *m = file->private_data; - struct obd_device *dev = m->private; - struct lod_device *lod; - int val, rc; + return __activeobd_show(kobj, attr, buf, false); +} - LASSERT(dev != NULL); - lod = lu2lod_dev(dev->obd_lu_dev); +LUSTRE_RO_ATTR(mdt_activeobd); +LUSTRE_RO_ATTR(activeobd); - rc = lprocfs_write_helper(buffer, count, &val); +/** + * Show UUID of LOD device. + */ +static ssize_t desc_uuid_show(struct kobject *kobj, struct attribute *attr, + char *buf) +{ + struct dt_device *dt = container_of(kobj, struct dt_device, + dd_kobj); + struct lod_device *lod = dt2lod_dev(dt); + + return snprintf(buf, PAGE_SIZE, "%s\n", + lod->lod_ost_descs.ltd_lov_desc.ld_uuid.uuid); +} +LUSTRE_RO_ATTR(desc_uuid); + +/** + * Show QoS priority parameter. + * + * The printed value is a percentage value (0-100%) indicating the priority + * of free space compared to performance. 0% means select OSTs equally + * regardless of their free space, 100% means select OSTs only by their free + * space even if it results in very imbalanced load on the OSTs. + */ +static ssize_t __qos_prio_free_show(struct kobject *kobj, + struct attribute *attr, char *buf, + bool is_mdt) +{ + struct dt_device *dt = container_of(kobj, struct dt_device, + dd_kobj); + struct lod_device *lod = dt2lod_dev(dt); + struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs : + &lod->lod_ost_descs; + + return snprintf(buf, PAGE_SIZE, "%d%%\n", + (ltd->ltd_qos.lq_prio_free * 100 + 255) >> 8); +} + +static ssize_t mdt_qos_prio_free_show(struct kobject *kobj, + struct attribute *attr, char *buf) +{ + return __qos_prio_free_show(kobj, attr, buf, true); +} + +static ssize_t qos_prio_free_show(struct kobject *kobj, + struct attribute *attr, char *buf) +{ + return __qos_prio_free_show(kobj, attr, buf, false); +} + +/** + * Set QoS free space priority parameter. + * + * Set the relative priority of free OST space compared to OST load when OSTs + * are space imbalanced. See qos_priofree_show() for description of + * this parameter. See qos_threshold_rr_store() and lq_threshold_rr to + * determine what constitutes "space imbalanced" OSTs. + */ +static ssize_t __qos_prio_free_store(struct kobject *kobj, + struct attribute *attr, + const char *buffer, size_t count, + bool is_mdt) +{ + struct dt_device *dt = container_of(kobj, struct dt_device, + dd_kobj); + struct lod_device *lod = dt2lod_dev(dt); + struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs : + &lod->lod_ost_descs; + unsigned int val; + int rc; + + rc = kstrtouint(buffer, 0, &val); if (rc) return rc; if (val > 100) return -EINVAL; - lod->lod_qos.lq_prio_free = (val << 8) / 100; - lod->lod_qos.lq_dirty = 1; - lod->lod_qos.lq_reset = 1; + ltd->ltd_qos.lq_prio_free = (val << 8) / 100; + ltd->ltd_qos.lq_dirty = 1; + ltd->ltd_qos.lq_reset = 1; + return count; } -LPROC_SEQ_FOPS(lod_qos_priofree); -static int lod_qos_thresholdrr_seq_show(struct seq_file *m, void *v) +static ssize_t mdt_qos_prio_free_store(struct kobject *kobj, + struct attribute *attr, + const char *buffer, size_t count) { - struct obd_device *dev = m->private; - struct lod_device *lod; + return __qos_prio_free_store(kobj, attr, buffer, count, true); +} - LASSERT(dev != NULL); - lod = lu2lod_dev(dev->obd_lu_dev); - return seq_printf(m, "%d%%\n", - (lod->lod_qos.lq_threshold_rr * 100 + 255) >> 8); +static ssize_t qos_prio_free_store(struct kobject *kobj, struct attribute *attr, + const char *buffer, size_t count) +{ + return __qos_prio_free_store(kobj, attr, buffer, count, false); } -static ssize_t -lod_qos_thresholdrr_seq_write(struct file *file, const char *buffer, - size_t count, loff_t *off) +LUSTRE_RW_ATTR(mdt_qos_prio_free); +LUSTRE_RW_ATTR(qos_prio_free); + +/** + * Show threshold for "same space on all OSTs" rule. + */ +static ssize_t __qos_threshold_rr_show(struct kobject *kobj, + struct attribute *attr, char *buf, + bool is_mdt) { - struct seq_file *m = file->private_data; - struct obd_device *dev = m->private; - struct lod_device *lod; - int val, rc; + struct dt_device *dt = container_of(kobj, struct dt_device, + dd_kobj); + struct lod_device *lod = dt2lod_dev(dt); + struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs : + &lod->lod_ost_descs; + + return snprintf(buf, PAGE_SIZE, "%d%%\n", + (ltd->ltd_qos.lq_threshold_rr * 100 + 255) >> 8); +} - LASSERT(dev != NULL); - lod = lu2lod_dev(dev->obd_lu_dev); +static ssize_t mdt_qos_threshold_rr_show(struct kobject *kobj, + struct attribute *attr, char *buf) +{ + return __qos_threshold_rr_show(kobj, attr, buf, true); +} - rc = lprocfs_write_helper(buffer, count, &val); +static ssize_t qos_threshold_rr_show(struct kobject *kobj, + struct attribute *attr, char *buf) +{ + return __qos_threshold_rr_show(kobj, attr, buf, false); +} + +/** + * Set threshold for "same space on all OSTs" rule. + * + * This sets the maximum percentage difference of free space between the most + * full and most empty OST in the currently available OSTs. If this percentage + * is exceeded, use the QoS allocator to select OSTs based on their available + * space so that more full OSTs are chosen less often, otherwise use the + * round-robin allocator for efficiency and performance. + */ +static ssize_t __qos_threshold_rr_store(struct kobject *kobj, + struct attribute *attr, + const char *buffer, size_t count, + bool is_mdt) +{ + struct dt_device *dt = container_of(kobj, struct dt_device, + dd_kobj); + struct lod_device *lod = dt2lod_dev(dt); + struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs : + &lod->lod_ost_descs; + char buf[6], *tmp; + unsigned int val; + int rc; + + /* "100%\n\0" should be largest string */ + if (count >= sizeof(buf)) + return -ERANGE; + + strncpy(buf, buffer, sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + tmp = strchr(buf, '%'); + if (tmp) + *tmp = '\0'; + + rc = kstrtouint(buf, 0, &val); if (rc) return rc; - if (val > 100 || val < 0) + if (val > 100) return -EINVAL; + ltd->ltd_qos.lq_threshold_rr = (val << 8) / 100; + ltd->ltd_qos.lq_dirty = 1; - lod->lod_qos.lq_threshold_rr = (val << 8) / 100; - lod->lod_qos.lq_dirty = 1; return count; } -LPROC_SEQ_FOPS(lod_qos_thresholdrr); -static int lod_qos_maxage_seq_show(struct seq_file *m, void *v) +static ssize_t mdt_qos_threshold_rr_store(struct kobject *kobj, + struct attribute *attr, + const char *buffer, size_t count) { - struct obd_device *dev = m->private; - struct lod_device *lod; + return __qos_threshold_rr_store(kobj, attr, buffer, count, true); +} - LASSERT(dev != NULL); - lod = lu2lod_dev(dev->obd_lu_dev); - return seq_printf(m, "%u Sec\n", lod->lod_desc.ld_qos_maxage); +static ssize_t qos_threshold_rr_store(struct kobject *kobj, + struct attribute *attr, + const char *buffer, size_t count) +{ + return __qos_threshold_rr_store(kobj, attr, buffer, count, false); } -static ssize_t -lod_qos_maxage_seq_write(struct file *file, const char *buffer, - size_t count, loff_t *off) +LUSTRE_RW_ATTR(mdt_qos_threshold_rr); +LUSTRE_RW_ATTR(qos_threshold_rr); + +/** + * Show expiration period used to refresh cached statfs data, which + * is used to implement QoS/RR striping allocation algorithm. + */ +static ssize_t __qos_maxage_show(struct kobject *kobj, struct attribute *attr, + char *buf, bool is_mdt) { - struct seq_file *m = file->private_data; - struct obd_device *dev = m->private; - struct lustre_cfg_bufs bufs; - struct lod_device *lod; - struct lu_device *next; - struct lustre_cfg *lcfg; - char str[32]; - unsigned int i; - int val, rc; + struct dt_device *dt = container_of(kobj, struct dt_device, + dd_kobj); + struct lod_device *lod = dt2lod_dev(dt); + struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs : + &lod->lod_ost_descs; + + return snprintf(buf, PAGE_SIZE, "%u Sec\n", + ltd->ltd_lov_desc.ld_qos_maxage); +} - LASSERT(dev != NULL); - lod = lu2lod_dev(dev->obd_lu_dev); +static ssize_t mdt_qos_maxage_show(struct kobject *kobj, struct attribute *attr, + char *buf) +{ + return __qos_maxage_show(kobj, attr, buf, true); +} - rc = lprocfs_write_helper(buffer, count, &val); +static ssize_t qos_maxage_show(struct kobject *kobj, struct attribute *attr, + char *buf) +{ + return __qos_maxage_show(kobj, attr, buf, true); +} + +/** + * Set expiration period used to refresh cached statfs data. + */ +static ssize_t __qos_maxage_store(struct kobject *kobj, struct attribute *attr, + const char *buffer, size_t count, bool is_mdt) +{ + struct dt_device *dt = container_of(kobj, struct dt_device, + dd_kobj); + struct lod_device *lod = dt2lod_dev(dt); + struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs : + &lod->lod_ost_descs; + struct lustre_cfg_bufs bufs; + struct lu_device *next; + struct lustre_cfg *lcfg; + char str[32]; + struct lu_tgt_desc *tgt; + int rc; + u32 val; + + rc = kstrtouint(buffer, 0, &val); if (rc) return rc; if (val <= 0) return -EINVAL; - lod->lod_desc.ld_qos_maxage = val; + + ltd->ltd_lov_desc.ld_qos_maxage = val; /* * propogate the value down to OSPs */ lustre_cfg_bufs_reset(&bufs, NULL); - sprintf(str, "%smaxage=%d", PARAM_OSP, val); + snprintf(str, 32, "%smaxage=%u", PARAM_OSP, val); lustre_cfg_bufs_set_string(&bufs, 1, str); - lcfg = lustre_cfg_new(LCFG_PARAM, &bufs); - lod_getref(&lod->lod_ost_descs); - lod_foreach_ost(lod, i) { - next = &OST_TGT(lod,i)->ltd_ost->dd_lu_dev; + OBD_ALLOC(lcfg, lustre_cfg_len(bufs.lcfg_bufcount, bufs.lcfg_buflen)); + if (lcfg == NULL) + return -ENOMEM; + lustre_cfg_init(lcfg, LCFG_PARAM, &bufs); + + lod_getref(ltd); + ltd_foreach_tgt(ltd, tgt) { + next = &tgt->ltd_tgt->dd_lu_dev; rc = next->ld_ops->ldo_process_config(NULL, next, lcfg); if (rc) - CERROR("can't set maxage on #%d: %d\n", i, rc); + CERROR("can't set maxage on #%d: %d\n", + tgt->ltd_index, rc); } - lod_putref(lod, &lod->lod_ost_descs); - lustre_cfg_free(lcfg); + lod_putref(lod, ltd); + OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens)); return count; } -LPROC_SEQ_FOPS(lod_qos_maxage); -static void *lod_osts_seq_start(struct seq_file *p, loff_t *pos) +static ssize_t mdt_qos_maxage_store(struct kobject *kobj, + struct attribute *attr, + const char *buffer, size_t count) +{ + return __qos_maxage_store(kobj, attr, buffer, count, true); +} + +static ssize_t qos_maxage_store(struct kobject *kobj, struct attribute *attr, + const char *buffer, size_t count) +{ + return __qos_maxage_store(kobj, attr, buffer, count, false); +} + +LUSTRE_RW_ATTR(mdt_qos_maxage); +LUSTRE_RW_ATTR(qos_maxage); + +static void *lod_tgts_seq_start(struct seq_file *p, loff_t *pos, bool is_mdt) { struct obd_device *dev = p->private; - struct lod_device *lod; + struct lod_device *lod = lu2lod_dev(dev->obd_lu_dev); + struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs : + &lod->lod_ost_descs; LASSERT(dev != NULL); - lod = lu2lod_dev(dev->obd_lu_dev); - lod_getref(&lod->lod_ost_descs); /* released in lod_osts_seq_stop */ - if (*pos >= lod->lod_ost_bitmap->size) + lod_getref(ltd); /* released in lod_tgts_seq_stop */ + if (*pos >= ltd->ltd_tgt_bitmap->size) return NULL; - *pos = find_next_bit(lod->lod_ost_bitmap->data, - lod->lod_ost_bitmap->size, *pos); - if (*pos < lod->lod_ost_bitmap->size) - return OST_TGT(lod,*pos); + *pos = find_next_bit(ltd->ltd_tgt_bitmap->data, + ltd->ltd_tgt_bitmap->size, *pos); + if (*pos < ltd->ltd_tgt_bitmap->size) + return LTD_TGT(ltd, *pos); else return NULL; } -static void lod_osts_seq_stop(struct seq_file *p, void *v) +static void *lod_mdts_seq_start(struct seq_file *p, loff_t *pos) +{ + return lod_tgts_seq_start(p, pos, true); +} + +static void *lod_osts_seq_start(struct seq_file *p, loff_t *pos) +{ + return lod_tgts_seq_start(p, pos, false); +} + +static void lod_tgts_seq_stop(struct seq_file *p, void *v, bool is_mdt) { struct obd_device *dev = p->private; - struct lod_device *lod; + struct lod_device *lod = lu2lod_dev(dev->obd_lu_dev); + struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs : + &lod->lod_ost_descs; LASSERT(dev != NULL); - lod = lu2lod_dev(dev->obd_lu_dev); - lod_putref(lod, &lod->lod_ost_descs); + lod_putref(lod, ltd); } -static void *lod_osts_seq_next(struct seq_file *p, void *v, loff_t *pos) +static void lod_mdts_seq_stop(struct seq_file *p, void *v) +{ + lod_tgts_seq_stop(p, v, true); +} + +static void lod_osts_seq_stop(struct seq_file *p, void *v) +{ + lod_tgts_seq_stop(p, v, false); +} + +static void *lod_tgts_seq_next(struct seq_file *p, void *v, loff_t *pos, + bool is_mdt) { struct obd_device *dev = p->private; struct lod_device *lod = lu2lod_dev(dev->obd_lu_dev); + struct lu_tgt_descs *ltd = is_mdt ? &lod->lod_mdt_descs : + &lod->lod_ost_descs; - if (*pos >= lod->lod_ost_bitmap->size - 1) + if (*pos >= ltd->ltd_tgt_bitmap->size - 1) return NULL; - *pos = find_next_bit(lod->lod_ost_bitmap->data, - lod->lod_ost_bitmap->size, *pos + 1); - if (*pos < lod->lod_ost_bitmap->size) - return OST_TGT(lod,*pos); + *pos = find_next_bit(ltd->ltd_tgt_bitmap->data, + ltd->ltd_tgt_bitmap->size, *pos + 1); + if (*pos < ltd->ltd_tgt_bitmap->size) + return LTD_TGT(ltd, *pos); else return NULL; } -static int lod_osts_seq_show(struct seq_file *p, void *v) +static void *lod_mdts_seq_next(struct seq_file *p, void *v, loff_t *pos) { - struct obd_device *obd = p->private; - struct lod_ost_desc *ost_desc = v; - struct lod_device *lod; - int idx, rc, active; - struct dt_device *next; - struct obd_statfs sfs; + return lod_tgts_seq_next(p, v, pos, true); +} + +static void *lod_osts_seq_next(struct seq_file *p, void *v, loff_t *pos) +{ + return lod_tgts_seq_next(p, v, pos, false); +} + +/** + * Show active/inactive status for OST found by lod_osts_seq_next(). + * + * \param[in] m seq file + * \param[in] v unused for single entry + * + * \retval 0 on success + * \retval negative error code if failed + */ +static int lod_tgts_seq_show(struct seq_file *p, void *v) +{ + struct obd_device *obd = p->private; + struct lu_tgt_desc *tgt = v; + struct dt_device *next; + int rc, active; LASSERT(obd->obd_lu_dev); - lod = lu2lod_dev(obd->obd_lu_dev); - idx = ost_desc->ltd_index; - next = OST_TGT(lod,idx)->ltd_ost; - if (next == NULL) + next = tgt->ltd_tgt; + if (!next) return -EINVAL; /* XXX: should be non-NULL env, but it's very expensive */ active = 1; - rc = dt_statfs(NULL, next, &sfs); + rc = dt_statfs(NULL, next, &tgt->ltd_statfs); if (rc == -ENOTCONN) { active = 0; rc = 0; } else if (rc) return rc; - return seq_printf(p, "%d: %s %sACTIVE\n", idx, - obd_uuid2str(&ost_desc->ltd_uuid), - active ? "" : "IN"); + seq_printf(p, "%d: %s %sACTIVE\n", tgt->ltd_index, + obd_uuid2str(&tgt->ltd_uuid), + active ? "" : "IN"); + return 0; } +static const struct seq_operations lod_mdts_sops = { + .start = lod_mdts_seq_start, + .stop = lod_mdts_seq_stop, + .next = lod_mdts_seq_next, + .show = lod_tgts_seq_show, +}; + static const struct seq_operations lod_osts_sops = { .start = lod_osts_seq_start, .stop = lod_osts_seq_stop, .next = lod_osts_seq_next, - .show = lod_osts_seq_show, + .show = lod_tgts_seq_show, }; -static int lod_osts_seq_open(struct inode *inode, struct file *file) +static int lod_mdts_seq_open(struct inode *inode, struct file *file) { struct seq_file *seq; int rc; - rc = seq_open(file, &lod_osts_sops); + rc = seq_open(file, &lod_mdts_sops); if (rc) return rc; @@ -429,88 +834,69 @@ static int lod_osts_seq_open(struct inode *inode, struct file *file) return 0; } -LPROC_SEQ_FOPS_RO_TYPE(lod, uuid); - -LPROC_SEQ_FOPS_RO_TYPE(lod, dt_blksize); -LPROC_SEQ_FOPS_RO_TYPE(lod, dt_kbytestotal); -LPROC_SEQ_FOPS_RO_TYPE(lod, dt_kbytesfree); -LPROC_SEQ_FOPS_RO_TYPE(lod, dt_kbytesavail); -LPROC_SEQ_FOPS_RO_TYPE(lod, dt_filestotal); -LPROC_SEQ_FOPS_RO_TYPE(lod, dt_filesfree); - -static int lod_lmv_failout_seq_show(struct seq_file *m, void *v) +static int lod_osts_seq_open(struct inode *inode, struct file *file) { - struct obd_device *dev = m->private; - struct lod_device *lod; + struct seq_file *seq; + int rc; - LASSERT(dev != NULL); - lod = lu2lod_dev(dev->obd_lu_dev); + rc = seq_open(file, &lod_osts_sops); + if (rc) + return rc; - return seq_printf(m, "%d\n", lod->lod_lmv_failout ? 1 : 0); + seq = file->private_data; + seq->private = PDE_DATA(inode); + return 0; } -static ssize_t -lod_lmv_failout_seq_write(struct file *file, const char *buffer, - size_t count, loff_t *off) +/** + * Show whether special failout mode for testing is enabled or not. + */ +static ssize_t lmv_failout_show(struct kobject *kobj, struct attribute *attr, + char *buf) { - struct seq_file *m = file->private_data; - struct obd_device *dev = m->private; - struct lod_device *lod; - int val = 0; - int rc; + struct dt_device *dt = container_of(kobj, struct dt_device, + dd_kobj); + struct lod_device *lod = dt2lod_dev(dt); - LASSERT(dev != NULL); - lod = lu2lod_dev(dev->obd_lu_dev); + return snprintf(buf, PAGE_SIZE, "%d\n", lod->lod_lmv_failout ? 1 : 0); +} - rc = lprocfs_write_helper(buffer, count, &val); - if (rc != 0) +/** + * Enable/disable a special failout mode for testing. + * + * This determines whether the LMV will try to continue processing a striped + * directory even if it has a (partly) corrupted entry in the master directory, + * or if it will abort upon finding a corrupted slave directory entry. + */ +static ssize_t lmv_failout_store(struct kobject *kobj, struct attribute *attr, + const char *buffer, size_t count) +{ + struct dt_device *dt = container_of(kobj, struct dt_device, + dd_kobj); + struct lod_device *lod = dt2lod_dev(dt); + bool val = 0; + int rc; + + rc = kstrtobool(buffer, &val); + if (rc) return rc; - if (val != 0) - lod->lod_lmv_failout = 1; - else - lod->lod_lmv_failout = 0; + lod->lod_lmv_failout = val; return count; } -LPROC_SEQ_FOPS(lod_lmv_failout); - -static struct lprocfs_seq_vars lprocfs_lod_obd_vars[] = { - { .name = "uuid", - .fops = &lod_uuid_fops }, - { .name = "stripesize", - .fops = &lod_stripesize_fops }, - { .name = "stripeoffset", - .fops = &lod_stripeoffset_fops }, - { .name = "stripecount", - .fops = &lod_stripecount_fops }, - { .name = "stripetype", - .fops = &lod_stripetype_fops }, - { .name = "numobd", - .fops = &lod_numobd_fops }, - { .name = "activeobd", - .fops = &lod_activeobd_fops }, - { .name = "desc_uuid", - .fops = &lod_desc_uuid_fops }, - { .name = "qos_prio_free", - .fops = &lod_qos_priofree_fops }, - { .name = "qos_threshold_rr", - .fops = &lod_qos_thresholdrr_fops }, - { .name = "qos_maxage", - .fops = &lod_qos_maxage_fops }, - { .name = "lmv_failout", - .fops = &lod_lmv_failout_fops }, - { 0 } +LUSTRE_RW_ATTR(lmv_failout); + +static struct lprocfs_vars lprocfs_lod_obd_vars[] = { + { NULL } }; -static struct lprocfs_seq_vars lprocfs_lod_osd_vars[] = { - { "blocksize", &lod_dt_blksize_fops }, - { "kbytestotal", &lod_dt_kbytestotal_fops }, - { "kbytesfree", &lod_dt_kbytesfree_fops }, - { "kbytesavail", &lod_dt_kbytesavail_fops }, - { "filestotal", &lod_dt_filestotal_fops }, - { "filesfree", &lod_dt_filesfree_fops }, - { 0 } +static const struct file_operations lod_proc_mdt_fops = { + .owner = THIS_MODULE, + .open = lod_mdts_seq_open, + .read = seq_read, + .llseek = seq_lseek, + .release = lprocfs_seq_release, }; static const struct file_operations lod_proc_target_fops = { @@ -521,29 +907,73 @@ static const struct file_operations lod_proc_target_fops = { .release = lprocfs_seq_release, }; +static struct attribute *lod_attrs[] = { + &lustre_attr_dom_stripesize.attr, + &lustre_attr_stripesize.attr, + &lustre_attr_stripeoffset.attr, + &lustre_attr_stripecount.attr, + &lustre_attr_stripetype.attr, + &lustre_attr_activeobd.attr, + &lustre_attr_desc_uuid.attr, + &lustre_attr_lmv_failout.attr, + &lustre_attr_numobd.attr, + &lustre_attr_qos_maxage.attr, + &lustre_attr_qos_prio_free.attr, + &lustre_attr_qos_threshold_rr.attr, + &lustre_attr_mdt_stripecount.attr, + &lustre_attr_mdt_stripetype.attr, + &lustre_attr_mdt_activeobd.attr, + &lustre_attr_mdt_numobd.attr, + &lustre_attr_mdt_qos_maxage.attr, + &lustre_attr_mdt_qos_prio_free.attr, + &lustre_attr_mdt_qos_threshold_rr.attr, + NULL, +}; + +/** + * Initialize procfs entries for LOD. + * + * \param[in] lod LOD device + * + * \retval 0 on success + * \retval negative error code if failed + */ int lod_procfs_init(struct lod_device *lod) { - struct obd_device *obd = lod2obd(lod); - struct proc_dir_entry *lov_proc_dir = NULL; - struct obd_type *type; - int rc; + struct lprocfs_vars ldebugfs_obd_vars[] = { { NULL } }; + struct obd_device *obd = lod2obd(lod); + struct obd_type *type; + struct kobject *lov; + int rc; - obd->obd_vars = lprocfs_lod_obd_vars; - rc = lprocfs_obd_setup(obd); + lod->lod_dt_dev.dd_ktype.default_attrs = lod_attrs; + rc = dt_tunables_init(&lod->lod_dt_dev, obd->obd_type, obd->obd_name, + ldebugfs_obd_vars); if (rc) { - CERROR("%s: cannot setup procfs entry: %d\n", + CERROR("%s: failed to setup DT tunables: %d\n", obd->obd_name, rc); RETURN(rc); } - rc = lprocfs_seq_add_vars(obd->obd_proc_entry, lprocfs_lod_osd_vars, - &lod->lod_dt_dev); - if (rc) { - CERROR("%s: cannot setup procfs entry: %d\n", + obd->obd_vars = lprocfs_lod_obd_vars; + obd->obd_proc_entry = lprocfs_register(obd->obd_name, + obd->obd_type->typ_procroot, + obd->obd_vars, obd); + if (IS_ERR(obd->obd_proc_entry)) { + rc = PTR_ERR(obd->obd_proc_entry); + CERROR("%s: error %d setting up lprocfs\n", obd->obd_name, rc); GOTO(out, rc); } + rc = lprocfs_seq_create(obd->obd_proc_entry, "mdt_obd", + 0444, &lod_proc_mdt_fops, obd); + if (rc) { + CWARN("%s: Error adding the target_obd file %d\n", + obd->obd_name, rc); + GOTO(out, rc); + } + rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd", 0444, &lod_proc_target_fops, obd); if (rc) { @@ -552,9 +982,9 @@ int lod_procfs_init(struct lod_device *lod) GOTO(out, rc); } - lod->lod_pool_proc_entry = lprocfs_seq_register("pools", - obd->obd_proc_entry, - NULL, NULL); + lod->lod_pool_proc_entry = lprocfs_register("pools", + obd->obd_proc_entry, + NULL, NULL); if (IS_ERR(lod->lod_pool_proc_entry)) { rc = PTR_ERR(lod->lod_pool_proc_entry); lod->lod_pool_proc_entry = NULL; @@ -563,46 +993,74 @@ int lod_procfs_init(struct lod_device *lod) GOTO(out, rc); } - /* If the real LOV is present which is the case for setups - * with both server and clients on the same node then use - * the LOV's proc root */ - type = class_search_type(LUSTRE_LOV_NAME); - if (type != NULL && type->typ_procroot != NULL) - lov_proc_dir = type->typ_procroot; - else - lov_proc_dir = obd->obd_type->typ_procsym; + lov = kset_find_obj(lustre_kset, "lov"); + if (!lov) { + CERROR("%s: lov subsystem not found\n", obd->obd_name); + GOTO(out, rc = -ENODEV); + } - if (lov_proc_dir == NULL) + rc = sysfs_create_link(lov, &lod->lod_dt_dev.dd_kobj, + obd->obd_name); + if (rc) + CERROR("%s: failed to create LOV sysfs symlink\n", + obd->obd_name); + kobject_put(lov); + + lod->lod_debugfs = ldebugfs_add_symlink(obd->obd_name, "lov", + "../lod/%s", obd->obd_name); + if (!lod->lod_debugfs) + CERROR("%s: failed to create LOV debugfs symlink\n", + obd->obd_name); + + type = container_of(lov, struct obd_type, typ_kobj); + if (!type->typ_procroot) RETURN(0); /* for compatibility we link old procfs's LOV entries to lod ones */ - lod->lod_symlink = lprocfs_add_symlink(obd->obd_name, lov_proc_dir, + lod->lod_symlink = lprocfs_add_symlink(obd->obd_name, + type->typ_procroot, "../lod/%s", obd->obd_name); if (lod->lod_symlink == NULL) - CERROR("could not register LOV symlink for " - "/proc/fs/lustre/lod/%s.", obd->obd_name); + CERROR("cannot create LOV symlink for /proc/fs/lustre/lod/%s\n", + obd->obd_name); RETURN(0); out: - lprocfs_obd_cleanup(obd); + dt_tunables_fini(&lod->lod_dt_dev); return rc; } +/** + * Cleanup procfs entries registred for LOD. + * + * \param[in] lod LOD device + */ void lod_procfs_fini(struct lod_device *lod) { struct obd_device *obd = lod2obd(lod); + struct kobject *lov; - if (lod->lod_symlink != NULL) + if (lod->lod_symlink != NULL) { lprocfs_remove(&lod->lod_symlink); + lod->lod_symlink = NULL; + } - if (lod->lod_pool_proc_entry != NULL) { - lprocfs_remove(&lod->lod_pool_proc_entry); - lod->lod_pool_proc_entry = NULL; + lov = kset_find_obj(lustre_kset, "lov"); + if (lov) { + sysfs_remove_link(lov, obd->obd_name); + kobject_put(lov); } - lprocfs_obd_cleanup(obd); -} + if (!IS_ERR_OR_NULL(lod->lod_debugfs)) + ldebugfs_remove(&lod->lod_debugfs); -#endif /* LPROCFS */ + if (obd->obd_proc_entry) { + lprocfs_remove(&obd->obd_proc_entry); + obd->obd_proc_entry = NULL; + } + + dt_tunables_fini(&lod->lod_dt_dev); +} +#endif /* CONFIG_PROC_FS */