Whamcloud - gitweb
LU-8066 lod: replace class_process_proc_param()
[fs/lustre-release.git] / lustre / lod / lproc_lod.c
index e976063..80c6d44 100644 (file)
  *
  * 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/
 #include <obd_class.h>
 #include <linux/seq_file.h>
 #include "lod_internal.h"
-#include <lustre_param.h>
+#include <uapi/linux/lustre/lustre_param.h>
+
+/*
+ * 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 CONFIG_PROC_FS
 
-#ifdef LPROCFS
-static int lod_rd_stripesize(char *page, char **start, off_t off, int count,
-                            int *eof, void *data)
+/**
+ * Show default stripe size.
+ *
+ * \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_dom_stripesize_seq_show(struct seq_file *m, void *v)
 {
-       struct obd_device *dev  = (struct obd_device *)data;
+       struct obd_device *dev = m->private;
        struct lod_device *lod;
 
        LASSERT(dev != NULL);
-       lod  = lu2lod_dev(dev->obd_lu_dev);
-       *eof = 1;
-       return snprintf(page, count, LPU64"\n",
-                       lod->lod_desc.ld_default_stripe_size);
+       lod = lu2lod_dev(dev->obd_lu_dev);
+       seq_printf(m, "%u\n", lod->lod_dom_max_stripesize);
+       return 0;
 }
 
-static int lod_wr_stripesize(struct file *file, const char *buffer,
-                            unsigned long count, void *data)
+/**
+ * Set default stripe size.
+ *
+ * \param[in] file     proc file
+ * \param[in] buffer   string containing the maximum number of bytes stored in
+ *                     each object before moving to the next object in the
+ *                     layout (if any)
+ * \param[in] count    @buffer length
+ * \param[in] off      unused for single entry
+ *
+ * \retval @count      on success
+ * \retval negative    error code if failed
+ */
+static ssize_t
+lod_dom_stripesize_seq_write(struct file *file, const char __user *buffer,
+                             size_t count, loff_t *off)
 {
-       struct obd_device *dev = (struct obd_device *)data;
+       struct seq_file *m = file->private_data;
+       struct obd_device *dev = m->private;
        struct lod_device *lod;
-       __u64 val;
+       s64 val;
        int rc;
 
        LASSERT(dev != NULL);
-       lod  = lu2lod_dev(dev->obd_lu_dev);
-       rc = lprocfs_write_u64_helper(buffer, count, &val);
+       lod = lu2lod_dev(dev->obd_lu_dev);
+       rc = lprocfs_str_with_units_to_s64(buffer, count, &val, '1');
        if (rc)
                return rc;
+       if (val < 0)
+               return -ERANGE;
+
+       /* 1GB is the limit */
+       if (val > (1ULL << 30))
+               return -ERANGE;
+       else 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;
 
-       lod_fix_desc_stripe_size(&val);
-       lod->lod_desc.ld_default_stripe_size = val;
        return count;
 }
+LPROC_SEQ_FOPS(lod_dom_stripesize);
 
-static int lod_rd_stripeoffset(char *page, char **start, off_t off, int count,
-                              int *eof, void *data)
+/**
+ * Show default stripe size.
+ *
+ * \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_stripesize_seq_show(struct seq_file *m, void *v)
 {
-       struct obd_device *dev = (struct obd_device *)data;
+       struct obd_device *dev = m->private;
        struct lod_device *lod;
 
        LASSERT(dev != NULL);
        lod  = lu2lod_dev(dev->obd_lu_dev);
-       *eof = 1;
-       return snprintf(page, count, LPU64"\n",
-                       lod->lod_desc.ld_default_stripe_offset);
+       seq_printf(m, "%llu\n",
+                  lod->lod_desc.ld_default_stripe_size);
+       return 0;
 }
 
-static int lod_wr_stripeoffset(struct file *file, const char *buffer,
-                              unsigned long count, void *data)
+/**
+ * Set default stripe size.
+ *
+ * \param[in] file     proc file
+ * \param[in] buffer   string containing the maximum number of bytes stored in
+ *                     each object before moving to the next object in the
+ *                     layout (if any)
+ * \param[in] count    @buffer length
+ * \param[in] off      unused for single entry
+ *
+ * \retval @count      on success
+ * \retval negative    error code if failed
+ */
+static ssize_t
+lod_stripesize_seq_write(struct file *file, const char __user *buffer,
+                        size_t count, loff_t *off)
 {
-       struct obd_device *dev = (struct obd_device *)data;
+       struct seq_file *m = file->private_data;
+       struct obd_device *dev = m->private;
        struct lod_device *lod;
-       __u64 val;
+       s64 val;
        int rc;
 
        LASSERT(dev != NULL);
        lod  = lu2lod_dev(dev->obd_lu_dev);
-       rc = lprocfs_write_u64_helper(buffer, count, &val);
+       rc = lprocfs_str_with_units_to_s64(buffer, 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_desc.ld_default_stripe_offset = val;
        return count;
 }
+LPROC_SEQ_FOPS(lod_stripesize);
 
-static int lod_rd_stripetype(char *page, char **start, off_t off, int count,
-                            int *eof, void *data)
+/**
+ * Show default stripe offset.
+ *
+ * \param[in] m                seq file
+ * \param[in] v                unused for single entry
+ *
+ * \retval 0           on success
+ * \retval negative    error code if failed
+ */
+static ssize_t stripeoffset_show(struct kobject *kobj, struct attribute *attr,
+                                char *buf)
 {
-       struct obd_device *dev = (struct obd_device *)data;
-       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);
-       *eof = 1;
-       return snprintf(page, count, "%u\n", lod->lod_desc.ld_pattern);
+       return sprintf(buf, "%lld\n", lod->lod_desc.ld_default_stripe_offset);
 }
 
-static int lod_wr_stripetype(struct file *file, const char *buffer,
-                            unsigned long count, void *data)
+/**
+ * Set default stripe offset.
+ *
+ * Usually contains -1 allowing Lustre to balance objects among OST
+ * otherwise may cause severe OST imbalance.
+ *
+ * \param[in] file     proc file
+ * \param[in] buffer   string describing starting OST index for new files
+ * \param[in] count    @buffer length
+ * \param[in] off      unused for single entry
+ *
+ * \retval @count      on success
+ * \retval negative    error code if failed
+ */
+static ssize_t stripeoffset_store(struct kobject *kobj, struct attribute *attr,
+                                 const char *buffer, size_t count)
 {
-       struct obd_device *dev = (struct obd_device *)data;
-       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);
+       long val;
+       int rc;
 
-       LASSERT(dev != NULL);
-       lod  = lu2lod_dev(dev->obd_lu_dev);
-       rc = lprocfs_write_helper(buffer, count, &val);
+       rc = kstrtol(buffer, 0, &val);
        if (rc)
                return rc;
 
-       lod_fix_desc_pattern(&val);
-       lod->lod_desc.ld_pattern = val;
+       if (val < -1 || val > LOV_MAX_STRIPE_COUNT)
+               return -ERANGE;
+
+       lod->lod_desc.ld_default_stripe_offset = val;
+
        return count;
 }
+LUSTRE_RW_ATTR(stripeoffset);
 
-static int lod_rd_stripecount(char *page, char **start, off_t off, int count,
-                             int *eof, void *data)
+/**
+ * Show default striping pattern (LOV_PATTERN_*).
+ *
+ * \param[in] m                seq file
+ * \param[in] v                unused for single entry
+ *
+ * \retval 0           on success
+ * \retval negative    error code if failed
+ */
+static ssize_t stripetype_show(struct kobject *kobj, struct attribute *attr,
+                              char *buf)
 {
-       struct obd_device *dev = (struct obd_device *)data;
-       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);
-       *eof = 1;
-       return snprintf(page, count, "%d\n",
-                       (__s16)(lod->lod_desc.ld_default_stripe_count + 1) - 1);
+       return sprintf(buf, "%u\n", lod->lod_desc.ld_pattern);
 }
 
-static int lod_wr_stripecount(struct file *file, const char *buffer,
-                             unsigned long count, void *data)
+/**
+ * Set default striping pattern (a number, not a human-readable string).
+ *
+ * \param[in] file     proc file
+ * \param[in] buffer   string containing the default striping pattern for new
+ *                     files. This is an integer LOV_PATTERN_* value
+ * \param[in] count    @buffer length
+ * \param[in] off      unused for single entry
+ *
+ * \retval @count      on success
+ * \retval negative    error code if failed
+ */
+static ssize_t stripetype_store(struct kobject *kobj, struct attribute *attr,
+                               const char *buffer, size_t count)
 {
-       struct obd_device *dev = (struct obd_device *)data;
-       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);
+       u32 pattern;
+       int rc;
 
-       LASSERT(dev != NULL);
-       lod  = lu2lod_dev(dev->obd_lu_dev);
-       rc = lprocfs_write_helper(buffer, count, &val);
+       rc = kstrtouint(buffer, 0, &pattern);
        if (rc)
                return rc;
 
-       lod_fix_desc_stripe_count(&val);
-       lod->lod_desc.ld_default_stripe_count = val;
+       lod_fix_desc_pattern(&pattern);
+       lod->lod_desc.ld_pattern = pattern;
+
        return count;
 }
+LUSTRE_RW_ATTR(stripetype);
 
-static int lod_rd_numobd(char *page, char **start, off_t off, int count,
-                        int *eof, void *data)
+/**
+ * Show default number of stripes.
+ *
+ * \param[in] m                seq file
+ * \param[in] v                unused for single entry
+ *
+ * \retval 0           on success,
+ * \retval negative    error code if failed
+ */
+static ssize_t stripecount_show(struct kobject *kobj, struct attribute *attr,
+                               char *buf)
 {
-       struct obd_device *dev = (struct obd_device*)data;
-       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);
-       *eof = 1;
-       return snprintf(page, count, "%u\n", lod->lod_desc.ld_tgt_count);
+       return sprintf(buf, "%d\n",
+                      (s16)(lod->lod_desc.ld_default_stripe_count + 1) - 1);
+}
 
+/**
+ * Set default number of stripes.
+ *
+ * \param[in] file     proc file
+ * \param[in] buffer   string containing the default number of stripes
+ *                     for new files
+ * \param[in] count    @buffer length
+ * \param[in] off      unused for single entry
+ *
+ * \retval @count      on success
+ * \retval negative    error code otherwise
+ */
+static ssize_t stripecount_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);
+       int stripe_count;
+       int rc;
+
+       rc = kstrtoint(buffer, 0, &stripe_count);
+       if (rc)
+               return rc;
+
+       if (stripe_count < -1)
+               return -ERANGE;
+
+       lod_fix_desc_stripe_count(&stripe_count);
+       lod->lod_desc.ld_default_stripe_count = stripe_count;
+
+       return count;
 }
+LUSTRE_RW_ATTR(stripecount);
 
-static int lod_rd_activeobd(char *page, char **start, off_t off, int count,
-                           int *eof, void *data)
+/**
+ * Show number of targets.
+ *
+ * \param[in] m                seq file
+ * \param[in] v                unused for single entry
+ *
+ * \retval 0           on success
+ * \retval negative    error code if failed
+ */
+static ssize_t numobd_show(struct kobject *kobj, struct attribute *attr,
+                          char *buf)
 {
-       struct obd_device* dev = (struct obd_device*)data;
-       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);
-       *eof = 1;
-       return snprintf(page, count, "%u\n",
-                       lod->lod_desc.ld_active_tgt_count);
+       return sprintf(buf, "%u\n", lod->lod_desc.ld_tgt_count);
 }
+LUSTRE_RO_ATTR(numobd);
 
-static int lod_rd_desc_uuid(char *page, char **start, off_t off, int count,
-                           int *eof, void *data)
+/**
+ * Show number of active targets.
+ *
+ * \param[in] m                seq file
+ * \param[in] v                unused for single entry
+ *
+ * \retval 0           on success
+ * \retval negative    error code if failed
+ */
+static ssize_t activeobd_show(struct kobject *kobj, struct attribute *attr,
+                             char *buf)
 {
-       struct obd_device *dev = (struct obd_device*) data;
-       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);
-       *eof = 1;
-       return snprintf(page, count, "%s\n", lod->lod_desc.ld_uuid.uuid);
+       return sprintf(buf, "%u\n", lod->lod_desc.ld_active_tgt_count);
 }
+LUSTRE_RO_ATTR(activeobd);
 
-/* free priority (0-255): how badly user wants to choose empty osts */
-static int lod_rd_qos_priofree(char *page, char **start, off_t off, int count,
-                              int *eof, void *data)
+/**
+ * Show UUID of LOD device.
+ *
+ * \param[in] m                seq file
+ * \param[in] v                unused for single entry
+ *
+ * \retval 0           on success
+ * \retval negative    error code if failed
+ */
+static ssize_t desc_uuid_show(struct kobject *kobj, struct attribute *attr,
+                             char *buf)
 {
-       struct obd_device *dev = (struct obd_device*) data;
-       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);
 
-       LASSERT(lod != NULL);
-       *eof = 1;
-       return snprintf(page, count, "%d%%\n",
-                       (lod->lod_qos.lq_prio_free * 100 + 255) >> 8);
+       return sprintf(buf, "%s\n", lod->lod_desc.ld_uuid.uuid);
 }
+LUSTRE_RO_ATTR(desc_uuid);
 
-static int lod_wr_qos_priofree(struct file *file, const char *buffer,
-                              unsigned long count, void *data)
+/**
+ * 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.
+ *
+ * \param[in] m                seq file
+ * \param[in] v                unused for single entry
+ *
+ * \retval 0           on success
+ * \retval negative    error code if failed
+ */
+static ssize_t qos_prio_free_show(struct kobject *kobj, struct attribute *attr,
+                                 char *buf)
 {
-       struct obd_device *dev = (struct obd_device *)data;
-       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);
 
-       LASSERT(dev != NULL);
-       lod = lu2lod_dev(dev->obd_lu_dev);
+       return sprintf(buf, "%d%%\n",
+                      (lod->lod_qos.lq_prio_free * 100 + 255) >> 8);
+}
 
-       rc = lprocfs_write_helper(buffer, count, &val);
+/**
+ * Set QoS free space priority parameter.
+ *
+ * Set the relative priority of free OST space compared to OST load when OSTs
+ * are space imbalanced.  See lod_qos_priofree_seq_show() for description of
+ * this parameter.  See lod_qos_thresholdrr_seq_write() and lq_threshold_rr to
+ * determine what constitutes "space imbalanced" OSTs.
+ *
+ * \param[in] file     proc file
+ * \param[in] buffer   string which contains the free space priority (0-100)
+ * \param[in] count    @buffer length
+ * \param[in] off      unused for single entry
+ *
+ * \retval @count      on success
+ * \retval negative    error code if failed
+ */
+static ssize_t qos_prio_free_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);
+       unsigned int val;
+       int rc;
+
+       rc = kstrtouint(buffer, 0, &val);
        if (rc)
                return rc;
 
@@ -236,33 +458,63 @@ static int lod_wr_qos_priofree(struct file *file, const char *buffer,
        lod->lod_qos.lq_prio_free = (val << 8) / 100;
        lod->lod_qos.lq_dirty = 1;
        lod->lod_qos.lq_reset = 1;
+
        return count;
 }
+LUSTRE_RW_ATTR(qos_prio_free);
 
-static int lod_rd_qos_thresholdrr(char *page, char **start, off_t off,
-                                 int count, int *eof, void *data)
+/**
+ * Show threshold for "same space on all OSTs" rule.
+ *
+ * \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_qos_thresholdrr_seq_show(struct seq_file *m, void *v)
 {
-       struct obd_device *dev = (struct obd_device*) data;
+       struct obd_device *dev = m->private;
        struct lod_device *lod;
 
        LASSERT(dev != NULL);
        lod = lu2lod_dev(dev->obd_lu_dev);
-       *eof = 1;
-       return snprintf(page, count, "%d%%\n",
-                       (lod->lod_qos.lq_threshold_rr * 100 + 255) >> 8);
+       seq_printf(m, "%d%%\n",
+                  (lod->lod_qos.lq_threshold_rr * 100 + 255) >> 8);
+       return 0;
 }
 
-static int lod_wr_qos_thresholdrr(struct file *file, const char *buffer,
-                                 unsigned long count, void *data)
+/**
+ * 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.
+
+ * \param[in] file     proc file
+ * \param[in] buffer   string containing percentage difference of free space
+ * \param[in] count    @buffer length
+ * \param[in] off      unused for single entry
+ *
+ * \retval @count      on success
+ * \retval negative    error code if failed
+ */
+static ssize_t
+lod_qos_thresholdrr_seq_write(struct file *file, const char __user *buffer,
+                             size_t count, loff_t *off)
 {
-       struct obd_device *dev = (struct obd_device *)data;
+       struct seq_file *m = file->private_data;
+       struct obd_device *dev = m->private;
        struct lod_device *lod;
-       int val, rc;
+       int rc;
+       __s64 val;
 
        LASSERT(dev != NULL);
        lod = lu2lod_dev(dev->obd_lu_dev);
 
-       rc = lprocfs_write_helper(buffer, count, &val);
+       rc = lprocfs_str_with_units_to_s64(buffer, count, &val, '%');
        if (rc)
                return rc;
 
@@ -271,36 +523,57 @@ static int lod_wr_qos_thresholdrr(struct file *file, const char *buffer,
 
        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_rd_qos_maxage(char *page, char **start, off_t off, int count,
-                            int *eof, void *data)
+/**
+ * Show expiration period used to refresh cached statfs data, which
+ * is used to implement QoS/RR striping allocation algorithm.
+ *
+ * \param[in] m                seq file
+ * \param[in] v                unused for single entry
+ *
+ * \retval 0           on success
+ * \retval negative    error code if failed
+ */
+static ssize_t qos_maxage_show(struct kobject *kobj, struct attribute *attr,
+                              char *buf)
 {
-       struct obd_device *dev = (struct obd_device*) data;
-       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);
-       *eof = 1;
-       return snprintf(page, count, "%u Sec\n", lod->lod_desc.ld_qos_maxage);
+       return sprintf(buf, "%u Sec\n", lod->lod_desc.ld_qos_maxage);
 }
 
-static int lod_wr_qos_maxage(struct file *file, const char *buffer,
-                            unsigned long count, void *data)
+/**
+ * Set expiration period used to refresh cached statfs data.
+ *
+ * \param[in] file     proc file
+ * \param[in] buffer   string contains maximum age of statfs data in seconds
+ * \param[in] count    @buffer length
+ * \param[in] off      unused for single entry
+ *
+ * \retval @count      on success
+ * \retval negative    error code if failed
+ */
+static ssize_t qos_maxage_store(struct kobject *kobj, struct attribute *attr,
+                               const char *buffer, size_t count)
 {
-       struct obd_device       *dev = (struct obd_device *)data;
-       struct lustre_cfg_bufs   bufs;
-       struct lod_device       *lod;
-       struct lu_device        *next;
-       struct lustre_cfg       *lcfg;
-       char                     str[32];
-       int                      val, rc, i;
-
-       LASSERT(dev != NULL);
-       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 lustre_cfg_bufs bufs;
+       struct lu_device *next;
+       struct lustre_cfg *lcfg;
+       char str[32];
+       unsigned int i;
+       int rc;
+       u32 val;
 
-       rc = lprocfs_write_helper(buffer, count, &val);
+       rc = kstrtouint(buffer, 0, &val);
        if (rc)
                return rc;
 
@@ -312,9 +585,13 @@ static int lod_wr_qos_maxage(struct file *file, const char *buffer,
         * 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);
+       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(&lod->lod_ost_descs);
        lod_foreach_ost(lod, i) {
                next = &OST_TGT(lod,i)->ltd_ost->dd_lu_dev;
@@ -323,10 +600,11 @@ static int lod_wr_qos_maxage(struct file *file, const char *buffer,
                        CERROR("can't set maxage on #%d: %d\n", i, rc);
        }
        lod_putref(lod, &lod->lod_ost_descs);
-       lustre_cfg_free(lcfg);
+       OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens));
 
        return count;
 }
+LUSTRE_RW_ATTR(qos_maxage);
 
 static void *lod_osts_seq_start(struct seq_file *p, loff_t *pos)
 {
@@ -374,6 +652,15 @@ static void *lod_osts_seq_next(struct seq_file *p, void *v, loff_t *pos)
                return NULL;
 }
 
+/**
+ * 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_osts_seq_show(struct seq_file *p, void *v)
 {
        struct obd_device   *obd = p->private;
@@ -400,9 +687,10 @@ static int lod_osts_seq_show(struct seq_file *p, void *v)
        } 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", idx,
+                  obd_uuid2str(&ost_desc->ltd_uuid),
+                  active ? "" : "IN");
+       return 0;
 }
 
 static const struct seq_operations lod_osts_sops = {
@@ -414,55 +702,80 @@ static const struct seq_operations lod_osts_sops = {
 
 static int lod_osts_seq_open(struct inode *inode, struct file *file)
 {
-       struct proc_dir_entry *dp = PDE(inode);
        struct seq_file *seq;
        int rc;
 
-       LPROCFS_ENTRY_CHECK(dp);
        rc = seq_open(file, &lod_osts_sops);
        if (rc)
                return rc;
 
        seq = file->private_data;
-       seq->private = dp->data;
+       seq->private = PDE_DATA(inode);
        return 0;
 }
 
-static struct lprocfs_vars lprocfs_lod_obd_vars[] = {
-       { "uuid",         lprocfs_rd_uuid,        0, 0 },
-       { "stripesize",   lod_rd_stripesize,      lod_wr_stripesize, 0 },
-       { "stripeoffset", lod_rd_stripeoffset,    lod_wr_stripeoffset, 0 },
-       { "stripecount",  lod_rd_stripecount,     lod_wr_stripecount, 0 },
-       { "stripetype",   lod_rd_stripetype,      lod_wr_stripetype, 0 },
-       { "numobd",       lod_rd_numobd,          0, 0 },
-       { "activeobd",    lod_rd_activeobd,       0, 0 },
-       { "desc_uuid",    lod_rd_desc_uuid,       0, 0 },
-       { "qos_prio_free",lod_rd_qos_priofree,    lod_wr_qos_priofree, 0 },
-       { "qos_threshold_rr",  lod_rd_qos_thresholdrr, lod_wr_qos_thresholdrr, 0 },
-       { "qos_maxage",   lod_rd_qos_maxage,      lod_wr_qos_maxage, 0 },
-       { 0 }
-};
-
-static struct lprocfs_vars lprocfs_lod_osd_vars[] = {
-       { "blocksize",    lprocfs_dt_rd_blksize, 0, 0 },
-       { "kbytestotal",  lprocfs_dt_rd_kbytestotal, 0, 0 },
-       { "kbytesfree",   lprocfs_dt_rd_kbytesfree, 0, 0 },
-       { "kbytesavail",  lprocfs_dt_rd_kbytesavail, 0, 0 },
-       { "filestotal",   lprocfs_dt_rd_filestotal, 0, 0 },
-       { "filesfree",    lprocfs_dt_rd_filesfree, 0, 0 },
-       { 0 }
-};
+/**
+ * Show whether special failout mode for testing is enabled or not.
+ *
+ * \param[in] m                seq file
+ * \param[in] v                unused for single entry
+ *
+ * \retval 0           on success
+ * \retval negative    error code if failed
+ */
+static ssize_t lmv_failout_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);
 
-static struct lprocfs_vars lprocfs_lod_module_vars[] = {
-       { "num_refs",     lprocfs_rd_numrefs,     0, 0 },
-       { 0 }
-};
+       return sprintf(buf, "%d\n", lod->lod_lmv_failout ? 1 : 0);
+}
 
-void lprocfs_lod_init_vars(struct lprocfs_static_vars *lvars)
+/**
+ * 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.
+ *
+ * \param[in] file     proc file
+ * \param[in] buffer   string: 0 or non-zero to disable or enable LMV failout
+ * \param[in] count    @buffer length
+ * \param[in] off      unused for single entry
+ *
+ * \retval @count      on success
+ * \retval negative    error code if failed
+ */
+static ssize_t lmv_failout_store(struct kobject *kobj, struct attribute *attr,
+                                const char *buffer, size_t count)
 {
-       lvars->module_vars      = lprocfs_lod_module_vars;
-       lvars->obd_vars         = lprocfs_lod_obd_vars;
+       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;
+
+       lod->lod_lmv_failout = val;
+
+       return count;
 }
+LUSTRE_RW_ATTR(lmv_failout);
+
+static struct lprocfs_vars lprocfs_lod_obd_vars[] = {
+       { .name =       "stripesize",
+         .fops =       &lod_stripesize_fops    },
+       { .name =       "qos_threshold_rr",
+         .fops =       &lod_qos_thresholdrr_fops },
+       { .name =       "dom_stripesize",
+         .fops =       &lod_dom_stripesize_fops        },
+       { NULL }
+};
 
 static const struct file_operations lod_proc_target_fops = {
        .owner   = THIS_MODULE,
@@ -472,25 +785,51 @@ static const struct file_operations lod_proc_target_fops = {
        .release = lprocfs_seq_release,
 };
 
+static struct attribute *lod_attrs[] = {
+       &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,
+       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 lprocfs_static_vars lvars;
-       cfs_proc_dir_entry_t *lov_proc_dir;
+       struct proc_dir_entry *lov_proc_dir;
+       struct obd_type *type;
+       struct kobject *lov;
        int rc;
 
-       lprocfs_lod_init_vars(&lvars);
-       rc = lprocfs_obd_setup(obd, lvars.obd_vars);
+       lod->lod_dt_dev.dd_ktype.default_attrs = lod_attrs;
+       rc = dt_tunables_init(&lod->lod_dt_dev, obd->obd_type, obd->obd_name,
+                             NULL);
        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_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);
        }
@@ -514,36 +853,76 @@ int lod_procfs_init(struct lod_device *lod)
                GOTO(out, rc);
        }
 
-       /* for compatibility we link old procfs's OSC entries to osp ones */
-       lov_proc_dir = lprocfs_srch(proc_lustre_root, "lov");
-       if (lov_proc_dir != NULL && strstr(obd->obd_name, "lov") != NULL)
-               lod->lod_symlink = lprocfs_add_symlink(obd->obd_name,
-                                                      lov_proc_dir,
-                                                      "../lod/%s",
-                                                      obd->obd_name);
+       lov = kset_find_obj(lustre_kset, "lov");
+       if (lov) {
+               rc = sysfs_create_link(lov, &lod->lod_dt_dev.dd_kobj,
+                                      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);
+
+       /* 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;
 
+       if (lov_proc_dir == NULL)
+               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/%s", obd->obd_name);
+       if (lod->lod_symlink == NULL)
+               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);
+       }
+
+       if (!IS_ERR_OR_NULL(lod->lod_debugfs))
+               ldebugfs_remove(&lod->lod_debugfs);
+
+       if (obd->obd_proc_entry) {
+               lprocfs_remove(&obd->obd_proc_entry);
+               obd->obd_proc_entry = NULL;
        }
 
-       lprocfs_obd_cleanup(obd);
+       dt_tunables_fini(&lod->lod_dt_dev);
 }
 
-#endif /* LPROCFS */
+#endif /* CONFIG_PROC_FS */