Whamcloud - gitweb
LU-14462 gss: fix support for namespace in lgss_keyring
[fs/lustre-release.git] / lustre / mdd / mdd_lproc.c
index f4fa19b..e80a90c 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 (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2012, 2014, Intel Corporation.
+ * Copyright (c) 2012, 2017, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
 #include <libcfs/libcfs_string.h>
 #include "mdd_internal.h"
 
-static ssize_t
-mdd_atime_diff_seq_write(struct file *file, const char *buffer,
-                        size_t count, loff_t *off)
+static ssize_t uuid_show(struct kobject *kobj, struct attribute *attr,
+                        char *buf)
 {
-       struct seq_file *m = file->private_data;
-       struct mdd_device *mdd = m->private;
-       char kernbuf[20], *end;
-       unsigned long diff = 0;
-
-        if (count > (sizeof(kernbuf) - 1))
-                return -EINVAL;
-
-       if (copy_from_user(kernbuf, buffer, count))
-                return -EFAULT;
+       struct mdd_device *mdd = container_of(kobj, struct mdd_device,
+                                             mdd_kobj);
+       struct obd_device *obd = mdd2obd_dev(mdd);
 
-        kernbuf[count] = '\0';
+       return sprintf(buf, "%s\n", obd->obd_uuid.uuid);
+}
+LUSTRE_RO_ATTR(uuid);
 
-        diff = simple_strtoul(kernbuf, &end, 0);
-        if (kernbuf == end)
-                return -EINVAL;
+static ssize_t atime_diff_show(struct kobject *kobj, struct attribute *attr,
+                              char *buf)
+{
+       struct mdd_device *mdd = container_of(kobj, struct mdd_device,
+                                             mdd_kobj);
 
-        mdd->mdd_atime_diff = diff;
-        return count;
+       return sprintf(buf, "%lld\n", mdd->mdd_atime_diff);
 }
 
-static int mdd_atime_diff_seq_show(struct seq_file *m, void *data)
+static ssize_t atime_diff_store(struct kobject *kobj,
+                               struct attribute *attr,
+                               const char *buffer, size_t count)
 {
-       struct mdd_device *mdd = m->private;
+       struct mdd_device *mdd = container_of(kobj, struct mdd_device,
+                                             mdd_kobj);
+       time64_t diff = 0;
+       int rc;
 
-       return seq_printf(m, "%lu\n", mdd->mdd_atime_diff);
+       rc = kstrtoll(buffer, 10, &diff);
+       if (rc)
+               return rc;
+
+        mdd->mdd_atime_diff = diff;
+        return count;
 }
-LPROC_SEQ_FOPS(mdd_atime_diff);
+LUSTRE_RW_ATTR(atime_diff);
 
 /**** changelogs ****/
 static int mdd_changelog_mask_seq_show(struct seq_file *m, void *data)
@@ -89,15 +90,16 @@ static int mdd_changelog_mask_seq_show(struct seq_file *m, void *data)
        int i = 0;
 
        while (i < CL_LAST) {
-               if (mdd->mdd_cl.mc_mask & (1 << i))
+               if (mdd->mdd_cl.mc_mask & BIT(i))
                        seq_printf(m, "%s ", changelog_type2str(i));
                i++;
        }
+       seq_putc(m, '\n');
        return 0;
 }
 
 static ssize_t
-mdd_changelog_mask_seq_write(struct file *file, const char *buffer,
+mdd_changelog_mask_seq_write(struct file *file, const char __user *buffer,
                             size_t count, loff_t *off)
 {
        struct seq_file *m = file->private_data;
@@ -106,9 +108,9 @@ mdd_changelog_mask_seq_write(struct file *file, const char *buffer,
        int rc;
        ENTRY;
 
-       if (count >= PAGE_CACHE_SIZE)
+       if (count >= PAGE_SIZE)
                RETURN(-EINVAL);
-       OBD_ALLOC(kernbuf, PAGE_CACHE_SIZE);
+       OBD_ALLOC(kernbuf, PAGE_SIZE);
        if (kernbuf == NULL)
                RETURN(-ENOMEM);
        if (copy_from_user(kernbuf, buffer, count))
@@ -120,10 +122,10 @@ mdd_changelog_mask_seq_write(struct file *file, const char *buffer,
        if (rc == 0)
                rc = count;
 out:
-       OBD_FREE(kernbuf, PAGE_CACHE_SIZE);
+       OBD_FREE(kernbuf, PAGE_SIZE);
        return rc;
 }
-LPROC_SEQ_FOPS(mdd_changelog_mask);
+LDEBUGFS_SEQ_FOPS(mdd_changelog_mask);
 
 static int lprocfs_changelog_users_cb(const struct lu_env *env,
                                      struct llog_handle *llh,
@@ -136,8 +138,9 @@ static int lprocfs_changelog_users_cb(const struct lu_env *env,
 
        rec = (struct llog_changelog_user_rec *)hdr;
 
-       seq_printf(m, CHANGELOG_USER_PREFIX"%-3d "LPU64"\n",
-                  rec->cur_id, rec->cur_endrec);
+       seq_printf(m, CHANGELOG_USER_PREFIX"%-3d %llu (%u)\n",
+                  rec->cur_id, rec->cur_endrec, (__u32)get_seconds() -
+                                                rec->cur_time);
        return 0;
 }
 
@@ -165,8 +168,8 @@ static int mdd_changelog_users_seq_show(struct seq_file *m, void *data)
        cur = mdd->mdd_cl.mc_index;
        spin_unlock(&mdd->mdd_cl.mc_lock);
 
-       seq_printf(m, "current index: "LPU64"\n", cur);
-       seq_printf(m, "%-5s %s\n", "ID", "index");
+       seq_printf(m, "current index: %llu\n", cur);
+       seq_printf(m, "%-5s %s %s\n", "ID", "index", "(idle seconds)");
 
        llog_cat_process(&env, ctxt->loc_handle, lprocfs_changelog_users_cb,
                         m, 0, 0);
@@ -175,86 +178,340 @@ static int mdd_changelog_users_seq_show(struct seq_file *m, void *data)
        llog_ctxt_put(ctxt);
        return 0;
 }
-LPROC_SEQ_FOPS_RO(mdd_changelog_users);
+LDEBUGFS_SEQ_FOPS_RO(mdd_changelog_users);
 
-static int mdd_sync_perm_seq_show(struct seq_file *m, void *data)
+static int mdd_changelog_size_ctxt(const struct lu_env *env,
+                                  struct mdd_device *mdd,
+                                  int index, __u64 *val)
 {
-       struct mdd_device *mdd = m->private;
+       struct llog_ctxt        *ctxt;
 
-       LASSERT(mdd != NULL);
-       return seq_printf(m, "%d\n", mdd->mdd_sync_permission);
+       ctxt = llog_get_context(mdd2obd_dev(mdd),
+                               index);
+       if (ctxt == NULL)
+               return -ENXIO;
+
+       if (!(ctxt->loc_handle->lgh_hdr->llh_flags & LLOG_F_IS_CAT)) {
+               CERROR("%s: ChangeLog has wrong flags: rc = %d\n",
+                      ctxt->loc_obd->obd_name, -EINVAL);
+               llog_ctxt_put(ctxt);
+               return -EINVAL;
+       }
+
+       *val += llog_cat_size(env, ctxt->loc_handle);
+
+       llog_ctxt_put(ctxt);
+
+       return 0;
 }
 
-static ssize_t
-mdd_sync_perm_seq_write(struct file *file, const char *buffer,
-                       size_t count, loff_t *off)
+static ssize_t changelog_size_show(struct kobject *kobj,
+                                  struct attribute *attr,
+                                  char *buf)
 {
-       struct seq_file *m = file->private_data;
-       struct mdd_device *mdd = m->private;
-        int val, rc;
+       struct mdd_device *mdd = container_of(kobj, struct mdd_device,
+                                             mdd_kobj);
+       struct lu_env env;
+       u64 tmp = 0;
+       int rc;
 
-        LASSERT(mdd != NULL);
-        rc = lprocfs_write_helper(buffer, count, &val);
-        if (rc)
-                return rc;
+       rc = lu_env_init(&env, LCT_LOCAL);
+       if (rc)
+               return rc;
 
-        mdd->mdd_sync_permission = !!val;
-        return count;
+       rc = mdd_changelog_size_ctxt(&env, mdd, LLOG_CHANGELOG_ORIG_CTXT, &tmp);
+       if (rc) {
+               lu_env_fini(&env);
+               return rc;
+       }
+
+       rc = mdd_changelog_size_ctxt(&env, mdd, LLOG_CHANGELOG_USER_ORIG_CTXT,
+                                    &tmp);
+
+       rc = sprintf(buf, "%llu\n", tmp);
+       lu_env_fini(&env);
+       return rc;
 }
-LPROC_SEQ_FOPS(mdd_sync_perm);
+LUSTRE_RO_ATTR(changelog_size);
 
-static int mdd_lfsck_speed_limit_seq_show(struct seq_file *m, void *data)
+static ssize_t changelog_gc_show(struct kobject *kobj,
+                                struct attribute *attr,
+                                char *buf)
 {
-       struct mdd_device *mdd = m->private;
+       struct mdd_device *mdd = container_of(kobj, struct mdd_device,
+                                             mdd_kobj);
 
-       LASSERT(mdd != NULL);
-       return lfsck_get_speed(m, mdd->mdd_bottom);
+       return sprintf(buf, "%u\n", mdd->mdd_changelog_gc);
 }
 
-static ssize_t
-mdd_lfsck_speed_limit_seq_write(struct file *file, const char *buffer,
-                               size_t count, loff_t *off)
+static ssize_t changelog_gc_store(struct kobject *kobj,
+                                 struct attribute *attr,
+                                 const char *buffer, size_t count)
 {
-       struct seq_file *m = file->private_data;
-       struct mdd_device *mdd = m->private;
-       __u32 val;
+       struct mdd_device *mdd = container_of(kobj, struct mdd_device,
+                                             mdd_kobj);
+       bool val;
+       int rc;
+
+       rc = kstrtobool(buffer, &val);
+       if (rc)
+               return rc;
+
+       mdd->mdd_changelog_gc = val;
+
+       return count;
+}
+LUSTRE_RW_ATTR(changelog_gc);
+
+static ssize_t changelog_max_idle_time_show(struct kobject *kobj,
+                                           struct attribute *attr,
+                                           char *buf)
+{
+       struct mdd_device *mdd = container_of(kobj, struct mdd_device,
+                                             mdd_kobj);
+
+       return sprintf(buf, "%lld\n", mdd->mdd_changelog_max_idle_time);
+}
+
+static ssize_t changelog_max_idle_time_store(struct kobject *kobj,
+                                            struct attribute *attr,
+                                            const char *buffer, size_t count)
+{
+       struct mdd_device *mdd = container_of(kobj, struct mdd_device,
+                                             mdd_kobj);
+       time64_t val;
+       int rc;
+
+       rc = kstrtoll(buffer, 10, &val);
+       if (rc)
+               return rc;
+
+       /* as it sounds reasonable, do not allow a user to be idle since
+        * more than about 68 years, this will allow to use 32bits
+        * timestamps for comparison
+        */
+       if (val < 1 || val > INT_MAX)
+               return -ERANGE;
+
+       mdd->mdd_changelog_max_idle_time = val;
+
+       return count;
+}
+LUSTRE_RW_ATTR(changelog_max_idle_time);
+
+static ssize_t changelog_max_idle_indexes_show(struct kobject *kobj,
+                                              struct attribute *attr,
+                                              char *buf)
+{
+       struct mdd_device *mdd = container_of(kobj, struct mdd_device,
+                                             mdd_kobj);
+
+       return sprintf(buf, "%lu\n", mdd->mdd_changelog_max_idle_indexes);
+}
+
+static ssize_t changelog_max_idle_indexes_store(struct kobject *kobj,
+                                               struct attribute *attr,
+                                               const char *buffer,
+                                               size_t count)
+{
+       struct mdd_device *mdd = container_of(kobj, struct mdd_device,
+                                             mdd_kobj);
+       unsigned long val;
        int rc;
 
        LASSERT(mdd != NULL);
-       rc = lprocfs_write_helper(buffer, count, &val);
+       rc = kstrtoul(buffer, 0, &val);
+       if (rc)
+               return rc;
+
+       /* XXX may need to limit/check with reasonable elapsed/idle indexes */
+       /* XXX may better allow to specify a % of full ChangeLogs */
+
+       mdd->mdd_changelog_max_idle_indexes = val;
+
+       return count;
+}
+LUSTRE_RW_ATTR(changelog_max_idle_indexes);
+
+static ssize_t changelog_min_gc_interval_show(struct kobject *kobj,
+                                             struct attribute *attr,
+                                             char *buf)
+{
+       struct mdd_device *mdd = container_of(kobj, struct mdd_device,
+                                             mdd_kobj);
+
+       return sprintf(buf, "%lld\n", mdd->mdd_changelog_min_gc_interval);
+}
+
+static ssize_t changelog_min_gc_interval_store(struct kobject *kobj,
+                                              struct attribute *attr,
+                                              const char *buffer,
+                                              size_t count)
+{
+       struct mdd_device *mdd = container_of(kobj, struct mdd_device,
+                                             mdd_kobj);
+       time64_t val;
+       int rc;
+
+       rc = kstrtoll(buffer, 10, &val);
+       if (rc)
+               return rc;
+
+       /* XXX may need to limit with reasonable elapsed/interval times */
+       if (val < 1)
+               return -ERANGE;
+
+       mdd->mdd_changelog_min_gc_interval = val;
+
+       return count;
+}
+LUSTRE_RW_ATTR(changelog_min_gc_interval);
+
+static ssize_t changelog_min_free_cat_entries_show(struct kobject *kobj,
+                                                  struct attribute *attr,
+                                                  char *buf)
+{
+       struct mdd_device *mdd = container_of(kobj, struct mdd_device,
+                                             mdd_kobj);
+
+       return sprintf(buf, "%u\n", mdd->mdd_changelog_min_free_cat_entries);
+}
+
+static ssize_t changelog_min_free_cat_entries_store(struct kobject *kobj,
+                                                   struct attribute *attr,
+                                                   const char *buffer,
+                                                   size_t count)
+{
+       struct mdd_device *mdd = container_of(kobj, struct mdd_device,
+                                             mdd_kobj);
+       unsigned int val;
+       int rc;
+
+       rc = kstrtouint(buffer, 10, &val);
+       if (rc)
+               return rc;
+
+       /* XXX may need to limit with more reasonable number of free entries */
+       if (val < 1)
+               return -ERANGE;
+
+       mdd->mdd_changelog_min_free_cat_entries = val;
+
+       return count;
+}
+LUSTRE_RW_ATTR(changelog_min_free_cat_entries);
+
+static ssize_t changelog_deniednext_show(struct kobject *kobj,
+                                        struct attribute *attr,
+                                        char *buf)
+{
+       struct mdd_device *mdd = container_of(kobj, struct mdd_device,
+                                             mdd_kobj);
+
+       return sprintf(buf, "%u\n", mdd->mdd_cl.mc_deniednext);
+}
+
+static ssize_t changelog_deniednext_store(struct kobject *kobj,
+                                         struct attribute *attr,
+                                         const char *buffer,
+                                         size_t count)
+{
+       struct mdd_device *mdd = container_of(kobj, struct mdd_device,
+                                             mdd_kobj);
+       unsigned int time = 0;
+       int rc;
+
+       rc = kstrtouint(buffer, 0, &time);
+       if (rc)
+               return rc;
+
+       mdd->mdd_cl.mc_deniednext = time;
+       return count;
+}
+LUSTRE_RW_ATTR(changelog_deniednext);
+
+static ssize_t sync_permission_show(struct kobject *kobj,
+                                   struct attribute *attr, char *buf)
+{
+       struct mdd_device *mdd = container_of(kobj, struct mdd_device,
+                                             mdd_kobj);
+
+       return sprintf(buf, "%d\n", mdd->mdd_sync_permission);
+}
+
+static ssize_t sync_permission_store(struct kobject *kobj,
+                                    struct attribute *attr,
+                                    const char *buffer, size_t count)
+{
+       struct mdd_device *mdd = container_of(kobj, struct mdd_device,
+                                             mdd_kobj);
+       bool val;
+       int rc;
+
+       rc = kstrtobool(buffer, &val);
+       if (rc)
+               return rc;
+
+       mdd->mdd_sync_permission = val;
+
+       return count;
+}
+LUSTRE_RW_ATTR(sync_permission);
+
+static ssize_t lfsck_speed_limit_show(struct kobject *kobj,
+                                     struct attribute *attr, char *buf)
+{
+       struct mdd_device *mdd = container_of(kobj, struct mdd_device,
+                                             mdd_kobj);
+
+       return lfsck_get_speed(buf, mdd->mdd_bottom);
+}
+
+static ssize_t lfsck_speed_limit_store(struct kobject *kobj,
+                                      struct attribute *attr,
+                                      const char *buffer, size_t count)
+{
+       struct mdd_device *mdd = container_of(kobj, struct mdd_device,
+                                             mdd_kobj);
+       unsigned int val;
+       int rc;
+
+       rc = kstrtouint(buffer, 10, &val);
        if (rc != 0)
                return rc;
 
        rc = lfsck_set_speed(mdd->mdd_bottom, val);
        return rc != 0 ? rc : count;
 }
-LPROC_SEQ_FOPS(mdd_lfsck_speed_limit);
+LUSTRE_RW_ATTR(lfsck_speed_limit);
 
-static int mdd_lfsck_async_windows_seq_show(struct seq_file *m, void *data)
+static ssize_t lfsck_async_windows_show(struct kobject *kobj,
+                                       struct attribute *attr, char *buf)
 {
-       struct mdd_device *mdd = m->private;
+       struct mdd_device *mdd = container_of(kobj, struct mdd_device,
+                                             mdd_kobj);
 
-       LASSERT(mdd != NULL);
-       return lfsck_get_windows(m, mdd->mdd_bottom);
+       return lfsck_get_windows(buf, mdd->mdd_bottom);
 }
 
-static ssize_t
-mdd_lfsck_async_windows_seq_write(struct file *file, const char *buffer,
-                                 size_t count, loff_t *off)
+static ssize_t lfsck_async_windows_store(struct kobject *kobj,
+                                        struct attribute *attr,
+                                        const char *buffer, size_t count)
 {
-       struct seq_file   *m = file->private_data;
-       struct mdd_device *mdd = m->private;
-       __u32              val;
-       int                rc;
+       struct mdd_device *mdd = container_of(kobj, struct mdd_device,
+                                             mdd_kobj);
+       unsigned int val;
+       int rc;
 
-       LASSERT(mdd != NULL);
-       rc = lprocfs_write_helper(buffer, count, &val);
-       if (rc == 0)
-               rc = lfsck_set_windows(mdd->mdd_bottom, val);
+       rc = kstrtouint(buffer, 10, &val);
+       if (rc)
+               return rc;
+
+       rc = lfsck_set_windows(mdd->mdd_bottom, val);
 
        return rc != 0 ? rc : count;
 }
-LPROC_SEQ_FOPS(mdd_lfsck_async_windows);
+LUSTRE_RW_ATTR(lfsck_async_windows);
 
 static int mdd_lfsck_namespace_seq_show(struct seq_file *m, void *data)
 {
@@ -264,7 +521,7 @@ static int mdd_lfsck_namespace_seq_show(struct seq_file *m, void *data)
 
        return lfsck_dump(m, mdd->mdd_bottom, LFSCK_TYPE_NAMESPACE);
 }
-LPROC_SEQ_FOPS_RO(mdd_lfsck_namespace);
+LDEBUGFS_SEQ_FOPS_RO(mdd_lfsck_namespace);
 
 static int mdd_lfsck_layout_seq_show(struct seq_file *m, void *data)
 {
@@ -274,64 +531,201 @@ static int mdd_lfsck_layout_seq_show(struct seq_file *m, void *data)
 
        return lfsck_dump(m, mdd->mdd_bottom, LFSCK_TYPE_LAYOUT);
 }
-LPROC_SEQ_FOPS_RO(mdd_lfsck_layout);
+LDEBUGFS_SEQ_FOPS_RO(mdd_lfsck_layout);
+
+/**
+ * Show default number of stripes for O_APPEND files.
+ *
+ * \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 append_stripe_count_show(struct kobject *kobj,
+                                       struct attribute *attr, char *buf)
+{
+       struct mdd_device *mdd = container_of(kobj, struct mdd_device,
+                                             mdd_kobj);
+
+       return scnprintf(buf, PAGE_SIZE, "%d\n", mdd->mdd_append_stripe_count);
+}
+
+/**
+ * Set default number of stripes for O_APPEND files.
+ *
+ * \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 append_stripe_count_store(struct kobject *kobj,
+                                        struct attribute *attr,
+                                        const char *buffer, size_t count)
+{
+       struct mdd_device *mdd = container_of(kobj, struct mdd_device,
+                                             mdd_kobj);
+       int stripe_count;
+       int rc;
+
+       rc = kstrtoint(buffer, 0, &stripe_count);
+       if (rc)
+               return rc;
+
+       if (stripe_count < -1)
+               return -ERANGE;
+
+       mdd->mdd_append_stripe_count = stripe_count;
+
+       return count;
+}
+LUSTRE_RW_ATTR(append_stripe_count);
+
+/**
+ * Show default OST pool for O_APPEND files.
+ *
+ * \param[in] kobject  proc object
+ * \param[in] attribute proc attribute
+ * \param[in] buf      output buffer
+ *
+ * \retval 0           on success,
+ * \retval negative    error code if failed
+ */
+static ssize_t append_pool_show(struct kobject *kobj,
+                               struct attribute *attr, char *buf)
+{
+       struct mdd_device *mdd = container_of(kobj, struct mdd_device,
+                                             mdd_kobj);
+
+       return scnprintf(buf, PAGE_SIZE, "%s\n", mdd->mdd_append_pool);
+}
+
+/**
+ * Set default OST pool for O_APPEND files.
+ *
+ * \param[in] kobject  proc object
+ * \param[in] attribute proc attribute
+ * \param[in] buffer   user inputted pool name
+ * \param[in] count    @buffer length
+ *
+ * \retval @count      on success
+ * \retval negative    error code otherwise
+ */
+static ssize_t append_pool_store(struct kobject *kobj, struct attribute *attr,
+                                const char *buffer, size_t count)
+{
+       struct mdd_device *mdd = container_of(kobj, struct mdd_device,
+                                             mdd_kobj);
+
+       if (!count || count > LOV_MAXPOOLNAME + 1)
+               return -EINVAL;
+
+       /* clear previous value */
+       memset(mdd->mdd_append_pool, 0, LOV_MAXPOOLNAME + 1);
+
+       /* entering "none" clears the pool, otherwise copy the new pool */
+       if (strncmp("none", buffer, 4)) {
+               memcpy(mdd->mdd_append_pool, buffer, count);
+
+               /* Trim the trailing '\n' if any */
+               if (mdd->mdd_append_pool[count - 1] == '\n') {
+                       /* Don't echo just a newline */
+                       if (count == 1)
+                               return -EINVAL;
+                       mdd->mdd_append_pool[count - 1] = 0;
+               }
+       }
+
+       return count;
+}
+LUSTRE_RW_ATTR(append_pool);
 
-static struct lprocfs_seq_vars lprocfs_mdd_obd_vars[] = {
-       { .name =       "atime_diff",
-         .fops =       &mdd_atime_diff_fops            },
+static struct ldebugfs_vars ldebugfs_mdd_obd_vars[] = {
        { .name =       "changelog_mask",
          .fops =       &mdd_changelog_mask_fops        },
        { .name =       "changelog_users",
          .fops =       &mdd_changelog_users_fops       },
-       { .name =       "sync_permission",
-         .fops =       &mdd_sync_perm_fops             },
-       { .name =       "lfsck_speed_limit",
-         .fops =       &mdd_lfsck_speed_limit_fops     },
-       { .name =       "lfsck_async_windows",
-         .fops =       &mdd_lfsck_async_windows_fops   },
        { .name =       "lfsck_namespace",
          .fops =       &mdd_lfsck_namespace_fops       },
        { .name =       "lfsck_layout",
          .fops =       &mdd_lfsck_layout_fops          },
-       { 0 }
+       { NULL }
 };
 
+static struct attribute *mdd_attrs[] = {
+       &lustre_attr_uuid.attr,
+       &lustre_attr_atime_diff.attr,
+       &lustre_attr_changelog_size.attr,
+       &lustre_attr_changelog_gc.attr,
+       &lustre_attr_changelog_max_idle_time.attr,
+       &lustre_attr_changelog_max_idle_indexes.attr,
+       &lustre_attr_changelog_min_gc_interval.attr,
+       &lustre_attr_changelog_min_free_cat_entries.attr,
+       &lustre_attr_changelog_deniednext.attr,
+       &lustre_attr_lfsck_async_windows.attr,
+       &lustre_attr_lfsck_speed_limit.attr,
+       &lustre_attr_sync_permission.attr,
+       &lustre_attr_append_stripe_count.attr,
+       &lustre_attr_append_pool.attr,
+       NULL,
+};
+
+static void mdd_sysfs_release(struct kobject *kobj)
+{
+       struct mdd_device *mdd = container_of(kobj, struct mdd_device,
+                                             mdd_kobj);
+       struct obd_device *obd = mdd2obd_dev(mdd);
+
+       debugfs_remove_recursive(obd->obd_debugfs_entry);
+       obd->obd_debugfs_entry = NULL;
+
+       complete(&mdd->mdd_kobj_unregister);
+}
+
 int mdd_procfs_init(struct mdd_device *mdd, const char *name)
 {
-       struct obd_device *obd = class_name2obd(name);
-       struct obd_type   *type;
-       int                rc;
-       ENTRY;
+       struct obd_device *obd = mdd2obd_dev(mdd);
+       struct obd_type *type;
+       int rc;
 
+       ENTRY;
        /* at the moment there is no linkage between lu_type
-        * and obd_type, so we lookup obd_type this way */
+        * and obd_type, so we lookup obd_type this way
+        */
        type = class_search_type(LUSTRE_MDD_NAME);
 
        LASSERT(name != NULL);
        LASSERT(type != NULL);
        LASSERT(obd  != NULL);
 
-       /* Find the type procroot and add the proc entry for this device */
-       obd->obd_vars = lprocfs_mdd_obd_vars;
-       mdd->mdd_proc_entry = lprocfs_seq_register(name, type->typ_procroot,
-                                                  obd->obd_vars, mdd);
-       if (IS_ERR(mdd->mdd_proc_entry)) {
-               rc = PTR_ERR(mdd->mdd_proc_entry);
-               CERROR("Error %d setting up lprocfs for %s\n",
-                      rc, name);
-               mdd->mdd_proc_entry = NULL;
-               GOTO(out, rc);
-       }
-       rc = 0;
-       EXIT;
-out:
+       /* put reference taken by class_search_type */
+       kobject_put(&type->typ_kobj);
+
+       mdd->mdd_ktype.default_attrs = mdd_attrs;
+       mdd->mdd_ktype.release = mdd_sysfs_release;
+       mdd->mdd_ktype.sysfs_ops = &lustre_sysfs_ops;
+
+       init_completion(&mdd->mdd_kobj_unregister);
+       rc = kobject_init_and_add(&mdd->mdd_kobj, &mdd->mdd_ktype,
+                                 &type->typ_kobj, "%s", name);
        if (rc)
-               mdd_procfs_fini(mdd);
-       return rc;
+               return rc;
+
+       /* Find the type procroot and add the proc entry for this device */
+       obd->obd_debugfs_vars = ldebugfs_mdd_obd_vars;
+       obd->obd_debugfs_entry = debugfs_create_dir(name,
+                                                    type->typ_debugfs_entry);
+       ldebugfs_add_vars(obd->obd_debugfs_entry, obd->obd_debugfs_vars, mdd);
+
+       RETURN(rc);
 }
 
 void mdd_procfs_fini(struct mdd_device *mdd)
 {
-       if (mdd->mdd_proc_entry)
-               lprocfs_remove(&mdd->mdd_proc_entry);
+       kobject_put(&mdd->mdd_kobj);
+       wait_for_completion(&mdd->mdd_kobj_unregister);
 }