Whamcloud - gitweb
LU-11605 osp: max_create_count and create_count changes
[fs/lustre-release.git] / lustre / osp / lproc_osp.c
index dad0b8d..75b7f07 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, 2013, Intel Corporation.
+ * Copyright (c) 2012, 2017, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -35,7 +31,7 @@
  *
  * lustre/osp/lproc_osp.c
  *
- * Lustre OST Proxy Device, procfs functions
+ * Lustre OST Proxy Device (OSP), procfs functions
  *
  * Author: Alex Zhuravlev <alexey.zhuravlev@intel.com>
  */
 
 #include "osp_internal.h"
 
-#ifdef LPROCFS
-static int osp_rd_active(char *page, char **start, off_t off,
-                        int count, int *eof, void *data)
+/**
+ * Show OSP active status
+ *
+ * \param[in] m                seq_file handle
+ * \param[in] data     unused for single entry
+ * \retval             0 on success
+ * \retval             negative number on error
+ */
+static ssize_t active_show(struct kobject *kobj, struct attribute *attr,
+                          char *buf)
 {
-       struct obd_device       *dev = data;
-       int                      rc;
-
-       LPROCFS_CLIMP_CHECK(dev);
-       rc = snprintf(page, count, "%d\n",
-                     !dev->u.cli.cl_import->imp_deactive);
-       LPROCFS_CLIMP_EXIT(dev);
+       struct dt_device *dt = container_of(kobj, struct dt_device,
+                                           dd_kobj);
+       struct lu_device *lu = dt2lu_dev(dt);
+       struct obd_device *obd = lu->ld_obd;
+       int rc;
+
+       LPROCFS_CLIMP_CHECK(obd);
+       rc = sprintf(buf, "%d\n", !obd->u.cli.cl_import->imp_deactive);
+       LPROCFS_CLIMP_EXIT(obd);
        return rc;
 }
 
-static int osp_wr_active(struct file *file, const char *buffer,
-                        unsigned long count, void *data)
+/**
+ * Activate/Deactivate OSP
+ *
+ * \param[in] file     proc file
+ * \param[in] buffer   string, which is "1" or "0" to activate/deactivate OSP
+ * \param[in] count    \a buffer length
+ * \param[in] off      unused for single entry
+ * \retval             \a count on success
+ * \retval             negative number on error
+ */
+static ssize_t active_store(struct kobject *kobj, struct attribute *attr,
+                           const char *buffer, size_t count)
 {
-       struct obd_device       *dev = data;
-       int                      val, rc;
-
-       rc = lprocfs_write_helper(buffer, count, &val);
+       struct dt_device *dt = container_of(kobj, struct dt_device,
+                                           dd_kobj);
+       struct lu_device *lu = dt2lu_dev(dt);
+       struct obd_device *obd = lu->ld_obd;
+       bool val;
+       int rc;
+
+       rc = kstrtobool(buffer, &val);
        if (rc)
                return rc;
-       if (val < 0 || val > 1)
-               return -ERANGE;
 
-       LPROCFS_CLIMP_CHECK(dev);
+       LPROCFS_CLIMP_CHECK(obd);
        /* opposite senses */
-       if (dev->u.cli.cl_import->imp_deactive == val)
-               rc = ptlrpc_set_import_active(dev->u.cli.cl_import, val);
+       if (obd->u.cli.cl_import->imp_deactive == val)
+               rc = ptlrpc_set_import_active(obd->u.cli.cl_import, val);
        else
-               CDEBUG(D_CONFIG, "activate %d: ignoring repeat request\n",
-                      val);
+               CDEBUG(D_CONFIG, "activate %u: ignoring repeat request\n",
+                      (unsigned int)val);
 
-       LPROCFS_CLIMP_EXIT(dev);
+       LPROCFS_CLIMP_EXIT(obd);
        return count;
 }
+LUSTRE_RW_ATTR(active);
 
-static int osp_rd_syn_in_flight(char *page, char **start, off_t off,
-                               int count, int *eof, void *data)
+/**
+ * Show number of RPCs in flight
+ *
+ * \param[in] m                seq_file handle
+ * \param[in] data     unused for single entry
+ * \retval             0 on success
+ * \retval             negative number on error
+ */
+static ssize_t sync_in_flight_show(struct kobject *kobj,
+                                  struct attribute *attr,
+                                  char *buf)
 {
-       struct obd_device       *dev = data;
-       struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
-       int                      rc;
-
-       if (osp == NULL)
-               return -EINVAL;
+       struct dt_device *dt = container_of(kobj, struct dt_device,
+                                           dd_kobj);
+       struct osp_device *osp = dt2osp_dev(dt);
 
-       rc = snprintf(page, count, "%u\n", osp->opd_syn_rpc_in_flight);
-       return rc;
+       return sprintf(buf, "%u\n", atomic_read(&osp->opd_sync_rpcs_in_flight));
 }
+LUSTRE_RO_ATTR(sync_in_flight);
 
-static int osp_rd_syn_in_prog(char *page, char **start, off_t off, int count,
-                             int *eof, void *data)
+/**
+ * Show number of RPCs in processing (including uncommitted by OST)
+ *
+ * \param[in] m                seq_file handle
+ * \param[in] data     unused for single entry
+ * \retval             0 on success
+ * \retval             negative number on error
+ */
+static ssize_t sync_in_progress_show(struct kobject *kobj,
+                                    struct attribute *attr,
+                                    char *buf)
 {
-       struct obd_device       *dev = data;
-       struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
-       int                      rc;
-
-       if (osp == NULL)
-               return -EINVAL;
+       struct dt_device *dt = container_of(kobj, struct dt_device,
+                                           dd_kobj);
+       struct osp_device *osp = dt2osp_dev(dt);
 
-       rc = snprintf(page, count, "%u\n", osp->opd_syn_rpc_in_progress);
-       return rc;
+       return sprintf(buf, "%u\n", atomic_read(&osp->opd_sync_rpcs_in_progress));
 }
+LUSTRE_RO_ATTR(sync_in_progress);
 
-static int osp_rd_syn_changes(char *page, char **start, off_t off,
-                             int count, int *eof, void *data)
+/**
+ * Show number of changes to sync
+ *
+ * \param[in] m                seq_file handle
+ * \param[in] data     unused for single entry
+ * \retval             0 on success
+ * \retval             negative number on error
+ */
+static ssize_t sync_changes_show(struct kobject *kobj,
+                                struct attribute *attr,
+                                char *buf)
 {
-       struct obd_device       *dev = data;
-       struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
-       int                      rc;
-
-       if (osp == NULL)
-               return -EINVAL;
+       struct dt_device *dt = container_of(kobj, struct dt_device,
+                                           dd_kobj);
+       struct osp_device *osp = dt2osp_dev(dt);
 
-       rc = snprintf(page, count, "%lu\n", osp->opd_syn_changes);
-       return rc;
+       return sprintf(buf, "%u\n", atomic_read(&osp->opd_sync_changes));
 }
 
-static int osp_rd_max_rpcs_in_flight(char *page, char **start, off_t off,
-                                    int count, int *eof, void *data)
+/**
+ * Sync changes
+ *
+ * \param[in] file     proc file
+ * \param[in] buffer   unused because any input will do
+ * \param[in] count    \a buffer length
+ * \param[in] off      unused for single entry
+ * \retval             \a count on success
+ * \retval             negative number on error
+ */
+static ssize_t sync_changes_store(struct kobject *kobj, struct attribute *attr,
+                                 const char *buffer, size_t count)
 {
-       struct obd_device       *dev = data;
-       struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
-       int                      rc;
+       struct dt_device *dt = container_of(kobj, struct dt_device,
+                                           dd_kobj);
+       struct osp_device *osp = dt2osp_dev(dt);
+       struct lu_env env;
+       int rc;
+
+       rc = lu_env_init(&env, LCT_LOCAL);
+       if (rc != 0)
+               return rc;
 
-       if (osp == NULL)
-               return -EINVAL;
+       rc = dt_sync(&env, &osp->opd_dt_dev);
+       lu_env_fini(&env);
 
-       rc = snprintf(page, count, "%u\n", osp->opd_syn_max_rpc_in_flight);
-       return rc;
+       return rc == 0 ? count : rc;
 }
+LUSTRE_RW_ATTR(sync_changes);
 
-static int osp_wr_max_rpcs_in_flight(struct file *file, const char *buffer,
-                                    unsigned long count, void *data)
+/**
+ * Show maximum number of RPCs in flight allowed
+ *
+ * \param[in] m                seq_file handle
+ * \param[in] data     unused for single entry
+ * \retval             0 on success
+ * \retval             negative number on error
+ */
+static ssize_t max_rpcs_in_flight_show(struct kobject *kobj,
+                                      struct attribute *attr,
+                                      char *buf)
 {
-       struct obd_device       *dev = data;
-       struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
-       int                      val, rc;
+       struct dt_device *dt = container_of(kobj, struct dt_device,
+                                           dd_kobj);
+       struct osp_device *osp = dt2osp_dev(dt);
 
-       if (osp == NULL)
-               return -EINVAL;
+       return sprintf(buf, "%u\n", osp->opd_sync_max_rpcs_in_flight);
+}
 
-       rc = lprocfs_write_helper(buffer, count, &val);
+/**
+ * Change maximum number of RPCs in flight allowed
+ *
+ * \param[in] file     proc file
+ * \param[in] buffer   string which represents maximum number
+ * \param[in] count    \a buffer length
+ * \param[in] off      unused for single entry
+ * \retval             \a count on success
+ * \retval             negative number on error
+ */
+static ssize_t max_rpcs_in_flight_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 osp_device *osp = dt2osp_dev(dt);
+       unsigned int val;
+       int rc;
+
+       rc = kstrtouint(buffer, 0, &val);
        if (rc)
                return rc;
 
-       if (val < 1)
+       if (val == 0)
                return -ERANGE;
 
-       osp->opd_syn_max_rpc_in_flight = val;
+       osp->opd_sync_max_rpcs_in_flight = val;
        return count;
 }
+LUSTRE_RW_ATTR(max_rpcs_in_flight);
 
-static int osp_rd_max_rpcs_in_prog(char *page, char **start, off_t off,
-                                  int count, int *eof, void *data)
+/**
+ * Show maximum number of RPCs in processing allowed
+ *
+ * \param[in] m                seq_file handle
+ * \param[in] data     unused
+ * \retval             0 on success
+ * \retval             negative number on error
+ */
+static ssize_t max_rpcs_in_progress_show(struct kobject *kobj,
+                                        struct attribute *attr,
+                                        char *buf)
 {
-       struct obd_device       *dev = data;
-       struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
-       int                      rc;
-
-       if (osp == NULL)
-               return -EINVAL;
+       struct dt_device *dt = container_of(kobj, struct dt_device,
+                                           dd_kobj);
+       struct osp_device *osp = dt2osp_dev(dt);
 
-       rc = snprintf(page, count, "%u\n", osp->opd_syn_max_rpc_in_progress);
-       return rc;
+       return sprintf(buf, "%u\n", osp->opd_sync_max_rpcs_in_progress);
 }
 
-static int osp_wr_max_rpcs_in_prog(struct file *file, const char *buffer,
-                                  unsigned long count, void *data)
+/**
+ * Change maximum number of RPCs in processing allowed
+ *
+ * \param[in] file     proc file
+ * \param[in] buffer   string which represents maximum number
+ * \param[in] count    \a buffer length
+ * \param[in] off      unused for single entry
+ * \retval             \a count on success
+ * \retval             negative number on error
+ */
+static ssize_t max_rpcs_in_progress_store(struct kobject *kobj,
+                                         struct attribute *attr,
+                                         const char *buffer,
+                                         size_t count)
 {
-       struct obd_device       *dev = data;
-       struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
-       int                      val, rc;
-
-       if (osp == NULL)
-               return -EINVAL;
+       struct dt_device *dt = container_of(kobj, struct dt_device,
+                                           dd_kobj);
+       struct osp_device *osp = dt2osp_dev(dt);
+       unsigned int val;
+       int rc;
 
-       rc = lprocfs_write_helper(buffer, count, &val);
+       rc = kstrtouint(buffer, 0, &val);
        if (rc)
                return rc;
 
-       if (val < 1)
+       if (val == 0)
                return -ERANGE;
 
-       osp->opd_syn_max_rpc_in_progress = val;
+       osp->opd_sync_max_rpcs_in_progress = val;
 
        return count;
 }
+LUSTRE_RW_ATTR(max_rpcs_in_progress);
 
-static int osp_rd_create_count(char *page, char **start, off_t off, int count,
-                              int *eof, void *data)
+/**
+ * Show number of objects to precreate next time
+ *
+ * \param[in] m                seq_file handle
+ * \param[in] data     unused for single entry
+ * \retval             0 on success
+ * \retval             negative number on error
+ */
+static ssize_t create_count_show(struct kobject *kobj,
+                                struct attribute *attr,
+                                char *buf)
 {
-       struct obd_device *obd = data;
-       struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
+       struct dt_device *dt = container_of(kobj, struct dt_device,
+                                           dd_kobj);
+       struct osp_device *osp = dt2osp_dev(dt);
 
-       if (osp == NULL)
-               return 0;
+       if (!osp->opd_pre)
+               return -EINVAL;
 
-       return snprintf(page, count, "%d\n", osp->opd_pre_grow_count);
+       return sprintf(buf, "%d\n", osp->opd_pre_create_count);
 }
 
-static int osp_wr_create_count(struct file *file, const char *buffer,
-                              unsigned long count, void *data)
+/**
+ * Change number of objects to precreate next time
+ *
+ * \param[in] file     proc file
+ * \param[in] buffer   string which represents number of objects to precreate
+ * \param[in] count    \a buffer length
+ * \param[in] off      unused for single entry
+ * \retval             \a count on success
+ * \retval             negative number on error
+ */
+static ssize_t create_count_store(struct kobject *kobj, struct attribute *attr,
+                                 const char *buffer, size_t count)
 {
-       struct obd_device       *obd = data;
-       struct osp_device       *osp = lu2osp_dev(obd->obd_lu_dev);
-       int                      val, rc, i;
+       struct dt_device *dt = container_of(kobj, struct dt_device,
+                                           dd_kobj);
+       struct osp_device *osp = dt2osp_dev(dt);
+       unsigned int val;
+       int rc, i;
+
+       if (!osp->opd_pre)
+               return -EINVAL;
 
-       if (osp == NULL)
-               return 0;
 
-       rc = lprocfs_write_helper(buffer, count, &val);
+       rc = kstrtouint(buffer, 0, &val);
        if (rc)
                return rc;
 
@@ -233,302 +355,744 @@ static int osp_wr_create_count(struct file *file, const char *buffer,
         * filesystem as a safety measure. */
        if (val < OST_MIN_PRECREATE || val > OST_MAX_PRECREATE)
                return -ERANGE;
-       if (val > osp->opd_pre_max_grow_count)
+       if (val > osp->opd_pre_max_create_count)
                return -ERANGE;
 
        for (i = 1; (i << 1) <= val; i <<= 1)
                ;
-       osp->opd_pre_grow_count = i;
+       osp->opd_pre_create_count = i;
 
        return count;
 }
+LUSTRE_RW_ATTR(create_count);
 
-static int osp_rd_max_create_count(char *page, char **start, off_t off,
-                                  int count, int *eof, void *data)
+/**
+ * Show maximum number of objects to precreate
+ *
+ * \param[in] m                seq_file handle
+ * \param[in] data     unused for single entry
+ * \retval             0 on success
+ * \retval             negative number on error
+ */
+static ssize_t max_create_count_show(struct kobject *kobj,
+                                    struct attribute *attr,
+                                    char *buf)
 {
-       struct obd_device *obd = data;
-       struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
+       struct dt_device *dt = container_of(kobj, struct dt_device,
+                                           dd_kobj);
+       struct osp_device *osp = dt2osp_dev(dt);
 
-       if (osp == NULL)
-               return 0;
+       if (!osp->opd_pre)
+               return -EINVAL;
 
-       return snprintf(page, count, "%d\n", osp->opd_pre_max_grow_count);
+       return sprintf(buf, "%d\n", osp->opd_pre_max_create_count);
 }
 
-static int osp_wr_max_create_count(struct file *file, const char *buffer,
-                                  unsigned long count, void *data)
+/**
+ * Change maximum number of objects to precreate
+ *
+ * \param[in] file     proc file
+ * \param[in] buffer   string which represents maximum number
+ * \param[in] count    \a buffer length
+ * \param[in] off      unused for single entry
+ * \retval             \a count on success
+ * \retval             negative number on error
+ */
+static ssize_t max_create_count_store(struct kobject *kobj,
+                                     struct attribute *attr,
+                                     const char *buffer, size_t count)
 {
-       struct obd_device       *obd = data;
-       struct osp_device       *osp = lu2osp_dev(obd->obd_lu_dev);
-       int                      val, rc;
+       struct dt_device *dt = container_of(kobj, struct dt_device,
+                                           dd_kobj);
+       struct osp_device *osp = dt2osp_dev(dt);
+       unsigned int val;
+       int rc;
 
-       if (osp == NULL)
-               return 0;
+       if (!osp->opd_pre)
+               return -EINVAL;
 
-       rc = lprocfs_write_helper(buffer, count, &val);
+       rc = kstrtouint(buffer, 0, &val);
        if (rc)
                return rc;
 
-       if (val < 0)
-               return -ERANGE;
-       if (val > OST_MAX_PRECREATE)
+       if (val && (val < OST_MIN_PRECREATE ||
+                   val > OST_MAX_PRECREATE))
                return -ERANGE;
 
-       if (osp->opd_pre_grow_count > val)
-               osp->opd_pre_grow_count = val;
+       if (osp->opd_pre_create_count > val)
+               osp->opd_pre_create_count = val;
 
-       osp->opd_pre_max_grow_count = val;
+       /* Can be 0 after setting max_create_count to 0 */
+       if (osp->opd_pre_create_count == 0 && val != 0)
+               osp->opd_pre_create_count = OST_MIN_PRECREATE;
+
+       osp->opd_pre_max_create_count = val;
 
        return count;
 }
+LUSTRE_RW_ATTR(max_create_count);
 
-static int osp_rd_prealloc_next_id(char *page, char **start, off_t off,
-                                  int count, int *eof, void *data)
+/**
+ * Show last id to assign in creation
+ *
+ * \param[in] m                seq_file handle
+ * \param[in] data     unused for single entry
+ * \retval             0 on success
+ * \retval             negative number on error
+ */
+static ssize_t prealloc_next_id_show(struct kobject *kobj,
+                                    struct attribute *attr,
+                                    char *buf)
 {
-       struct obd_device *obd = data;
-       struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
+       struct dt_device *dt = container_of(kobj, struct dt_device,
+                                           dd_kobj);
+       struct osp_device *osp = dt2osp_dev(dt);
+       struct lu_fid *fid;
+       u64 id;
 
-       if (osp == NULL)
-               return 0;
+       if (!osp->opd_pre)
+               return -EINVAL;
 
-       return snprintf(page, count, "%u\n",
-                       fid_oid(&osp->opd_pre_used_fid) + 1);
+       fid = &osp->opd_pre_used_fid;
+       if (fid_is_idif(fid)) {
+               id = fid_idif_id(fid_seq(fid), fid_oid(fid), fid_ver(fid));
+               id++;
+       } else {
+               id = unlikely(fid_oid(fid) == LUSTRE_DATA_SEQ_MAX_WIDTH) ?
+                       1 : fid_oid(fid) + 1;
+       }
+
+       return sprintf(buf, "%llu\n", id);
 }
+LUSTRE_RO_ATTR(prealloc_next_id);
 
-static int osp_rd_prealloc_last_id(char *page, char **start, off_t off,
-                                  int count, int *eof, void *data)
+/**
+ * Show last created id OST reported
+ *
+ * \param[in] m                seq_file handle
+ * \param[in] data     unused for single entry
+ * \retval             0 on success
+ * \retval             negative number on error
+ */
+
+static ssize_t prealloc_last_id_show(struct kobject *kobj,
+                                    struct attribute *attr,
+                                    char *buf)
 {
-       struct obd_device *obd = data;
-       struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
+       struct dt_device *dt = container_of(kobj, struct dt_device,
+                                           dd_kobj);
+       struct osp_device *osp = dt2osp_dev(dt);
+       struct lu_fid *fid;
+       u64 id;
 
-       if (osp == NULL)
-               return 0;
+       if (!osp->opd_pre)
+               return -EINVAL;
 
-       return snprintf(page, count, "%u\n",
-                       fid_oid(&osp->opd_pre_last_created_fid));
+       fid = &osp->opd_pre_last_created_fid;
+       id = fid_is_idif(fid) ?
+                        fid_idif_id(fid_seq(fid), fid_oid(fid), fid_ver(fid)) :
+                        fid_oid(fid);
+
+       return sprintf(buf, "%llu\n", id);
 }
+LUSTRE_RO_ATTR(prealloc_last_id);
 
-static int osp_rd_prealloc_next_seq(char *page, char **start, off_t off,
-                                   int count, int *eof, void *data)
+/**
+ * Show next FID sequence to precreate
+ *
+ * \param[in] m                seq_file handle
+ * \param[in] data     unused for single entry
+ * \retval             0 on success
+ * \retval             negative number on error
+ */
+static ssize_t prealloc_next_seq_show(struct kobject *kobj,
+                                     struct attribute *attr,
+                                     char *buf)
 {
-       struct obd_device *obd = data;
-       struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
+       struct dt_device *dt = container_of(kobj, struct dt_device,
+                                           dd_kobj);
+       struct osp_device *osp = dt2osp_dev(dt);
+       struct lu_fid *fid;
 
-       if (osp == NULL)
-               return 0;
+       if (!osp->opd_pre)
+               return -EINVAL;
 
-       return snprintf(page, count, LPX64"\n",
-                       fid_seq(&osp->opd_pre_used_fid));
+       fid = &osp->opd_pre_used_fid;
+       return sprintf(buf, "%#llx\n", fid_is_idif(fid) ?
+                      fid_seq(fid) & (~0xffff) : fid_seq(fid));
 }
+LUSTRE_RO_ATTR(prealloc_next_seq);
 
-static int osp_rd_prealloc_last_seq(char *page, char **start, off_t off,
-                                   int count, int *eof, void *data)
+/**
+ * Show last created FID sequence OST reported
+ *
+ * \param[in] m                seq_file handle
+ * \param[in] data     unused for single entry
+ * \retval             0 on success
+ * \retval             negative number on error
+ */
+static ssize_t prealloc_last_seq_show(struct kobject *kobj,
+                                     struct attribute *attr,
+                                     char *buf)
 {
-       struct obd_device *obd = data;
-       struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
+       struct dt_device *dt = container_of(kobj, struct dt_device,
+                                           dd_kobj);
+       struct osp_device *osp = dt2osp_dev(dt);
+       struct lu_fid *fid;
 
-       if (osp == NULL)
-               return 0;
+       if (!osp->opd_pre)
+               return -EINVAL;
 
-       return snprintf(page, count, LPX64"\n",
-                       fid_seq(&osp->opd_pre_last_created_fid));
+       fid = &osp->opd_pre_last_created_fid;
+       return sprintf(buf, "%#llx\n", fid_is_idif(fid) ?
+                      fid_seq(fid) & (~0xffff) : fid_seq(fid));
 }
+LUSTRE_RO_ATTR(prealloc_last_seq);
 
-static int osp_rd_prealloc_reserved(char *page, char **start, off_t off,
-                                   int count, int *eof, void *data)
+/**
+ * Show the number of ids reserved by declare
+ *
+ * \param[in] m                seq_file handle
+ * \param[in] data     unused for single entry
+ * \retval             0 on success
+ * \retval             negative number on error
+ */
+static ssize_t prealloc_reserved_show(struct kobject *kobj,
+                                     struct attribute *attr,
+                                     char *buf)
 {
-       struct obd_device *obd = data;
-       struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
+       struct dt_device *dt = container_of(kobj, struct dt_device,
+                                           dd_kobj);
+       struct osp_device *osp = dt2osp_dev(dt);
 
-       if (osp == NULL)
-               return 0;
+       if (!osp->opd_pre)
+               return -EINVAL;
 
-       return snprintf(page, count, LPU64"\n", osp->opd_pre_reserved);
+       return sprintf(buf, "%llu\n", osp->opd_pre_reserved);
 }
+LUSTRE_RO_ATTR(prealloc_reserved);
 
-static int osp_rd_maxage(char *page, char **start, off_t off,
-                        int count, int *eof, void *data)
+/**
+ * Show interval (in seconds) to update statfs data
+ *
+ * \param[in] m                seq_file handle
+ * \param[in] data     unused for single entry
+ * \retval             0 on success
+ * \retval             negative number on error
+ */
+static ssize_t maxage_show(struct kobject *kobj,
+                          struct attribute *attr,
+                          char *buf)
 {
-       struct obd_device       *dev = data;
-       struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
-       int                      rc;
+       struct dt_device *dt = container_of(kobj, struct dt_device,
+                                           dd_kobj);
+       struct osp_device *osp = dt2osp_dev(dt);
 
-       if (osp == NULL)
+       return sprintf(buf, "%lld\n", osp->opd_statfs_maxage);
+}
+
+/**
+ * Change interval to update statfs data
+ *
+ * \param[in] file     proc file
+ * \param[in] buffer   string which represents statfs interval (in seconds)
+ * \param[in] count    \a buffer length
+ * \param[in] off      unused for single entry
+ * \retval             \a count on success
+ * \retval             negative number on error
+ */
+static ssize_t maxage_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 osp_device *osp = dt2osp_dev(dt);
+       unsigned int val;
+       int rc;
+
+       rc = kstrtouint(buffer, 0, &val);
+       if (rc)
+               return rc;
+
+       if (val == 0)
+               return -ERANGE;
+
+       osp->opd_statfs_maxage = val;
+
+       return count;
+}
+LUSTRE_RW_ATTR(maxage);
+
+/**
+ * Show current precreation status: output 0 means success, otherwise negative
+ * number is printed
+ *
+ * \param[in] m                seq_file handle
+ * \param[in] data     unused for single entry
+ * \retval             0 on success
+ * \retval             negative number on error
+ */
+static ssize_t prealloc_status_show(struct kobject *kobj,
+                                   struct attribute *attr,
+                                   char *buf)
+{
+       struct dt_device *dt = container_of(kobj, struct dt_device,
+                                           dd_kobj);
+       struct osp_device *osp = dt2osp_dev(dt);
+
+       if (!osp->opd_pre)
                return -EINVAL;
 
-       rc = snprintf(page, count, "%u\n", osp->opd_statfs_maxage);
+       return sprintf(buf, "%d\n", osp->opd_pre_status);
+}
+LUSTRE_RO_ATTR(prealloc_status);
+
+/**
+ * Show the number of RPCs in processing (including uncommitted by OST) plus
+ * changes to sync, i.e. this is the total number of changes OST needs to apply
+ * and commit.
+ *
+ * This counter is used to determine if OST has space returned. A zero value
+ * indicates that OST storage space consumed by destroyed objects has been freed
+ * on disk, the associated llog records have been cleared, and no synchronous
+ * RPC are being processed.
+ *
+ * \param[in] m                seq_file handle
+ * \param[in] data     unused for single entry
+ * \retval             0 on success
+ * \retval             negative number on error
+ */
+static ssize_t destroys_in_flight_show(struct kobject *kobj,
+                                      struct attribute *attr,
+                                      char *buf)
+{
+       struct dt_device *dt = container_of(kobj, struct dt_device,
+                                           dd_kobj);
+       struct osp_device *osp = dt2osp_dev(dt);
+
+       return sprintf(buf, "%u\n",
+                      atomic_read(&osp->opd_sync_rpcs_in_progress) +
+                      atomic_read(&osp->opd_sync_changes));
+}
+LUSTRE_RO_ATTR(destroys_in_flight);
+
+/**
+ * Show changes synced from previous mount
+ *
+ * \param[in] m                seq_file handle
+ * \param[in] data     unused for single entry
+ * \retval             0 on success
+ * \retval             negative number on error
+ */
+static ssize_t old_sync_processed_show(struct kobject *kobj,
+                                      struct attribute *attr,
+                                      char *buf)
+{
+       struct dt_device *dt = container_of(kobj, struct dt_device,
+                                           dd_kobj);
+       struct osp_device *osp = dt2osp_dev(dt);
+
+       return sprintf(buf, "%d\n", osp->opd_sync_prev_done);
+}
+LUSTRE_RO_ATTR(old_sync_processed);
+
+/**
+ * Show maximum number of RPCs in flight
+ *
+ * \param[in] m                seq_file handle
+ * \param[in] data     unused for single entry
+ * \retval             0 on success
+ * \retval             negative number on error
+ */
+static ssize_t lfsck_max_rpcs_in_flight_show(struct kobject *kobj,
+                                            struct attribute *attr,
+                                            char *buf)
+{
+       struct dt_device *dt = container_of(kobj, struct dt_device,
+                                           dd_kobj);
+       struct lu_device *lu = dt2lu_dev(dt);
+       struct obd_device *obd = lu->ld_obd;
+       u32 max;
+
+       max = obd_get_max_rpcs_in_flight(&obd->u.cli);
+       return sprintf(buf, "%u\n", max);
+}
+
+/**
+ * Change maximum number of RPCs in flight
+ *
+ * \param[in] file     proc file
+ * \param[in] buffer   string which represents maximum number of RPCs in flight
+ * \param[in] count    \a buffer length
+ * \param[in] off      unused for single entry
+ * \retval             \a count on success
+ * \retval             negative number on error
+ */
+static ssize_t lfsck_max_rpcs_in_flight_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 lu_device *lu = dt2lu_dev(dt);
+       struct obd_device *obd = lu->ld_obd;
+       unsigned int val;
+       int rc;
+
+       rc = kstrtouint(buffer, 0, &val);
+       if (rc)
+               return rc;
+
+       rc = obd_set_max_rpcs_in_flight(&obd->u.cli, val);
+       return rc ? rc : count;
+}
+LUSTRE_RW_ATTR(lfsck_max_rpcs_in_flight);
+
+ssize_t ping_show(struct kobject *kobj, struct attribute *attr,
+                 char *buffer)
+{
+       struct dt_device *dt = container_of(kobj, struct dt_device,
+                                           dd_kobj);
+       struct lu_device *lu = dt2lu_dev(dt);
+       struct obd_device *obd = lu->ld_obd;
+       int rc;
+
+       LPROCFS_CLIMP_CHECK(obd);
+       rc = ptlrpc_obd_ping(obd);
+       LPROCFS_CLIMP_EXIT(obd);
+
        return rc;
 }
+LUSTRE_RO_ATTR(ping);
 
-static int osp_wr_maxage(struct file *file, const char *buffer,
-                        unsigned long count, void *data)
+ssize_t osp_conn_uuid_show(struct kobject *kobj, struct attribute *attr,
+                          char *buf)
 {
-       struct obd_device       *dev = data;
+       struct dt_device *dt = container_of(kobj, struct dt_device,
+                                           dd_kobj);
+       struct lu_device *lu = dt2lu_dev(dt);
+       struct obd_device *obd = lu->ld_obd;
+       struct ptlrpc_connection *conn;
+       ssize_t count;
+
+       LPROCFS_CLIMP_CHECK(obd);
+       conn = obd->u.cli.cl_import->imp_connection;
+       if (conn && obd->u.cli.cl_import)
+               count = sprintf(buf, "%s\n", conn->c_remote_uuid.uuid);
+       else
+               count = sprintf(buf, "%s\n", "<none>");
+
+       LPROCFS_CLIMP_EXIT(obd);
+       return count;
+}
+
+LUSTRE_ATTR(ost_conn_uuid, 0444, osp_conn_uuid_show, NULL);
+LUSTRE_ATTR(mdt_conn_uuid, 0444, osp_conn_uuid_show, NULL);
+
+LDEBUGFS_SEQ_FOPS_RO_TYPE(osp, connect_flags);
+LDEBUGFS_SEQ_FOPS_RO_TYPE(osp, server_uuid);
+LDEBUGFS_SEQ_FOPS_RO_TYPE(osp, timeouts);
+
+LPROC_SEQ_FOPS_RW_TYPE(osp, import);
+LDEBUGFS_SEQ_FOPS_RO_TYPE(osp, state);
+
+/**
+ * Show high watermark (in megabytes). If available free space at OST is grater
+ * than high watermark and object allocation for OST is disabled, enable it.
+ *
+ * \param[in] m                seq_file handle
+ * \param[in] data     unused for single entry
+ * \retval             0 on success
+ * \retval             negative number on error
+ */
+static int osp_reserved_mb_high_seq_show(struct seq_file *m, void *data)
+{
+       struct obd_device       *dev = m->private;
        struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
-       int                      val, rc;
 
        if (osp == NULL)
                return -EINVAL;
 
-       rc = lprocfs_write_helper(buffer, count, &val);
+       seq_printf(m, "%u\n", osp->opd_reserved_mb_high);
+       return 0;
+}
+
+/**
+ * Change high watermark
+ *
+ * \param[in] file     proc file
+ * \param[in] buffer   string which represents new value (in megabytes)
+ * \param[in] count    \a buffer length
+ * \param[in] off      unused for single entry
+ * \retval             \a count on success
+ * \retval             negative number on error
+ */
+static ssize_t
+osp_reserved_mb_high_seq_write(struct file *file, const char __user *buffer,
+                       size_t count, loff_t *off)
+{
+       struct seq_file         *m = file->private_data;
+       struct obd_device       *dev = m->private;
+       struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
+       __s64                   val;
+       int                     rc;
+
+       if (osp == NULL || osp->opd_pre == NULL)
+               return -EINVAL;
+
+       rc = lprocfs_str_with_units_to_s64(buffer, count, &val, 'M');
        if (rc)
                return rc;
-
+       val >>= 20;
        if (val < 1)
                return -ERANGE;
 
-       osp->opd_statfs_maxage = val;
+       spin_lock(&osp->opd_pre_lock);
+       osp->opd_reserved_mb_high = val;
+       if (val <= osp->opd_reserved_mb_low)
+               osp->opd_reserved_mb_low = val - 1;
+       spin_unlock(&osp->opd_pre_lock);
 
        return count;
 }
+LDEBUGFS_SEQ_FOPS(osp_reserved_mb_high);
 
-static int osp_rd_pre_status(char *page, char **start, off_t off,
-                            int count, int *eof, void *data)
+/**
+ * Show low watermark (in megabytes). If available free space at OST is less
+ * than low watermark, object allocation for OST is disabled.
+ *
+ * \param[in] m                seq_file handle
+ * \param[in] data     unused for single entry
+ * \retval             0 on success
+ * \retval             negative number on error
+ */
+static int osp_reserved_mb_low_seq_show(struct seq_file *m, void *data)
 {
-       struct obd_device       *dev = data;
+       struct obd_device       *dev = m->private;
        struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
-       int                      rc;
 
        if (osp == NULL)
                return -EINVAL;
 
-       rc = snprintf(page, count, "%d\n", osp->opd_pre_status);
-       return rc;
+       seq_printf(m, "%u\n", osp->opd_reserved_mb_low);
+       return 0;
 }
 
-static int osp_rd_destroys_in_flight(char *page, char **start, off_t off,
-                                    int count, int *eof, void *data)
+/**
+ * Change low watermark
+ *
+ * \param[in] file     proc file
+ * \param[in] buffer   string which represents new value (in megabytes)
+ * \param[in] count    \a buffer length
+ * \param[in] off      unused for single entry
+ * \retval             \a count on success
+ * \retval             negative number on error
+ */
+static ssize_t
+osp_reserved_mb_low_seq_write(struct file *file, const char __user *buffer,
+                       size_t count, loff_t *off)
 {
-       struct obd_device *dev = data;
-       struct osp_device *osp = lu2osp_dev(dev->obd_lu_dev);
+       struct seq_file         *m = file->private_data;
+       struct obd_device       *dev = m->private;
+       struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
+       __s64                   val;
+       int                     rc;
 
-       /*
-        * This counter used to determine if OST has space returned.
-        * Now we need to wait for the following:
-        * - sync changes are zero - no llog records
-        * - sync in progress are zero - no RPCs in flight
-        */
-       return snprintf(page, count, "%lu\n",
-                       osp->opd_syn_rpc_in_progress + osp->opd_syn_changes);
+       if (osp == NULL || osp->opd_pre == NULL)
+               return -EINVAL;
+
+       rc = lprocfs_str_with_units_to_s64(buffer, count, &val, 'M');
+       if (rc)
+               return rc;
+       val >>= 20;
+
+       spin_lock(&osp->opd_pre_lock);
+       osp->opd_reserved_mb_low = val;
+       if (val >= osp->opd_reserved_mb_high)
+               osp->opd_reserved_mb_high = val + 1;
+       spin_unlock(&osp->opd_pre_lock);
+
+       return count;
 }
+LDEBUGFS_SEQ_FOPS(osp_reserved_mb_low);
 
-static int osp_rd_old_sync_processed(char *page, char **start, off_t off,
-                                    int count, int *eof, void *data)
+static ssize_t force_sync_store(struct kobject *kobj, struct attribute *attr,
+                               const char *buffer, size_t count)
 {
-       struct obd_device       *dev = data;
-       struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
-       int                      rc;
+       struct dt_device *dt = container_of(kobj, struct dt_device,
+                                           dd_kobj);
+       struct lu_env env;
+       int rc;
 
-       if (osp == NULL)
-               return -EINVAL;
+       rc = lu_env_init(&env, LCT_LOCAL);
+       if (rc)
+               return rc;
 
-       rc = snprintf(page, count, "%d\n", osp->opd_syn_prev_done);
-       return rc;
+       rc = dt_sync(&env, dt);
+       lu_env_fini(&env);
+
+       return rc == 0 ? count : rc;
 }
+LUSTRE_WO_ATTR(force_sync);
 
 static struct lprocfs_vars lprocfs_osp_obd_vars[] = {
-       { "uuid",               lprocfs_rd_uuid, 0, 0 },
-       { "ping",               0, lprocfs_wr_ping, 0, 0, 0222 },
-       { "connect_flags",      lprocfs_rd_connect_flags, 0, 0 },
-       { "ost_server_uuid",    lprocfs_rd_server_uuid, 0, 0 },
-       { "ost_conn_uuid",      lprocfs_rd_conn_uuid, 0, 0 },
-       { "active",             osp_rd_active, osp_wr_active, 0 },
-       { "max_rpcs_in_flight", osp_rd_max_rpcs_in_flight,
-                               osp_wr_max_rpcs_in_flight, 0 },
-       { "max_rpcs_in_progress", osp_rd_max_rpcs_in_prog,
-                                 osp_wr_max_rpcs_in_prog, 0 },
-       { "create_count",       osp_rd_create_count,
-                               osp_wr_create_count, 0 },
-       { "max_create_count",   osp_rd_max_create_count,
-                               osp_wr_max_create_count, 0 },
-       { "prealloc_next_id",   osp_rd_prealloc_next_id, 0, 0 },
-       { "prealloc_next_seq",  osp_rd_prealloc_next_seq, 0, 0 },
-       { "prealloc_last_id",   osp_rd_prealloc_last_id,  0, 0 },
-       { "prealloc_last_seq",  osp_rd_prealloc_last_seq, 0, 0 },
-       { "prealloc_reserved",  osp_rd_prealloc_reserved, 0, 0 },
-       { "timeouts",           lprocfs_rd_timeouts, 0, 0 },
-       { "import",             lprocfs_rd_import, lprocfs_wr_import, 0 },
-       { "state",              lprocfs_rd_state, 0, 0 },
-       { "maxage",             osp_rd_maxage, osp_wr_maxage, 0 },
-       { "prealloc_status",    osp_rd_pre_status, 0, 0 },
-       { "sync_changes",       osp_rd_syn_changes, 0, 0 },
-       { "sync_in_flight",     osp_rd_syn_in_flight, 0, 0 },
-       { "sync_in_progress",   osp_rd_syn_in_prog, 0, 0 },
-       { "old_sync_processed", osp_rd_old_sync_processed, 0, 0 },
-
-       /* for compatibility reasons */
-       { "destroys_in_flight", osp_rd_destroys_in_flight, 0, 0 },
-       { 0 }
+       { .name =       "connect_flags",
+         .fops =       &osp_connect_flags_fops         },
+       { .name =       "ost_server_uuid",
+         .fops =       &osp_server_uuid_fops           },
+       { .name =       "timeouts",
+         .fops =       &osp_timeouts_fops              },
+       { .name =       "import",
+         .fops =       &osp_import_fops                },
+       { .name =       "state",
+         .fops =       &osp_state_fops                 },
+       { .name =       "reserved_mb_high",
+         .fops =       &osp_reserved_mb_high_fops      },
+       { .name =       "reserved_mb_low",
+         .fops =       &osp_reserved_mb_low_fops       },
+       { NULL }
 };
 
-static struct lprocfs_vars lprocfs_osp_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 }
+static struct lprocfs_vars lprocfs_osp_md_vars[] = {
+       { .name =       "connect_flags",
+         .fops =       &osp_connect_flags_fops         },
+       { .name =       "mdt_server_uuid",
+         .fops =       &osp_server_uuid_fops           },
+       { .name =       "timeouts",
+         .fops =       &osp_timeouts_fops              },
+       { .name =       "import",
+         .fops =       &osp_import_fops                },
+       { .name =       "state",
+         .fops =       &osp_state_fops                 },
+       { NULL }
 };
 
-static struct lprocfs_vars lprocfs_osp_module_vars[] = {
-       { "num_refs",           lprocfs_rd_numrefs, 0, 0 },
-       { 0 }
+static struct attribute *osp_obd_attrs[] = {
+       /* First two for compatiability reasons */
+       &lustre_attr_lfsck_max_rpcs_in_flight.attr,
+       &lustre_attr_destroys_in_flight.attr,
+       &lustre_attr_active.attr,
+       &lustre_attr_max_rpcs_in_flight.attr,
+       &lustre_attr_max_rpcs_in_progress.attr,
+       &lustre_attr_maxage.attr,
+       &lustre_attr_ost_conn_uuid.attr,
+       &lustre_attr_ping.attr,
+       &lustre_attr_prealloc_status.attr,
+       &lustre_attr_prealloc_next_id.attr,
+       &lustre_attr_prealloc_last_id.attr,
+       &lustre_attr_prealloc_next_seq.attr,
+       &lustre_attr_prealloc_last_seq.attr,
+       &lustre_attr_prealloc_reserved.attr,
+       &lustre_attr_sync_in_flight.attr,
+       &lustre_attr_sync_in_progress.attr,
+       &lustre_attr_sync_changes.attr,
+       &lustre_attr_force_sync.attr,
+       &lustre_attr_old_sync_processed.attr,
+       &lustre_attr_create_count.attr,
+       &lustre_attr_max_create_count.attr,
+       NULL,
 };
 
-void lprocfs_osp_init_vars(struct lprocfs_static_vars *lvars)
+static struct attribute *osp_md_attrs[] = {
+       /* First two for compatiability reasons */
+       &lustre_attr_lfsck_max_rpcs_in_flight.attr,
+       &lustre_attr_destroys_in_flight.attr,
+       &lustre_attr_active.attr,
+       &lustre_attr_max_rpcs_in_flight.attr,
+       &lustre_attr_max_rpcs_in_progress.attr,
+       &lustre_attr_maxage.attr,
+       &lustre_attr_mdt_conn_uuid.attr,
+       &lustre_attr_ping.attr,
+       &lustre_attr_prealloc_status.attr,
+       NULL,
+};
+
+void osp_tunables_fini(struct osp_device *osp)
 {
-       lvars->module_vars = lprocfs_osp_module_vars;
-       lvars->obd_vars = lprocfs_osp_obd_vars;
+       struct obd_device *obd = osp->opd_obd;
+       struct kobject *osc;
+
+       osc = kset_find_obj(lustre_kset, "osc");
+       if (osc) {
+               sysfs_remove_link(osc, obd->obd_name);
+               kobject_put(osc);
+       }
+
+       if (!IS_ERR_OR_NULL(osp->opd_debugfs))
+               ldebugfs_remove(&osp->opd_debugfs);
+
+       ptlrpc_lprocfs_unregister_obd(obd);
+
+       if (!IS_ERR_OR_NULL(obd->obd_debugfs_entry))
+               ldebugfs_remove(&obd->obd_debugfs_entry);
+
+       dt_tunables_fini(&osp->opd_dt_dev);
 }
 
-void osp_lprocfs_init(struct osp_device *osp)
+/**
+ * Initialize OSP sysfs / debugfs
+ *
+ * param[in] osp       OSP device
+ */
+void osp_tunables_init(struct osp_device *osp)
 {
-       struct obd_device       *obd = osp->opd_obd;
-       struct proc_dir_entry   *osc_proc_dir;
-       int                      rc;
+       struct obd_device *obd = osp->opd_obd;
+       struct kobject *osc;
+       int rc;
+
+       if (osp->opd_connect_mdt) {
+               osp->opd_dt_dev.dd_ktype.default_attrs = osp_md_attrs;
+               obd->obd_vars = lprocfs_osp_md_vars;
+       } else {
+               osp->opd_dt_dev.dd_ktype.default_attrs = osp_obd_attrs;
+               obd->obd_vars = lprocfs_osp_obd_vars;
+       }
 
-       obd->obd_proc_entry = lprocfs_register(obd->obd_name,
-                                              obd->obd_type->typ_procroot,
-                                              lprocfs_osp_osd_vars,
-                                              &osp->opd_dt_dev);
-       if (IS_ERR(obd->obd_proc_entry)) {
-               CERROR("%s: can't register in lprocfs: %ld\n",
-                      obd->obd_name, PTR_ERR(obd->obd_proc_entry));
-               obd->obd_proc_entry = NULL;
+       rc = dt_tunables_init(&osp->opd_dt_dev, obd->obd_type, obd->obd_name,
+                             NULL);
+       if (rc) {
+               CERROR("%s: failed to setup DT tunables: %d\n",
+                      obd->obd_name, rc);
                return;
        }
 
-       rc = lprocfs_add_vars(obd->obd_proc_entry, lprocfs_osp_obd_vars, obd);
-       if (rc) {
-               CERROR("%s: can't register in lprocfs: %ld\n",
-                      obd->obd_name, PTR_ERR(obd->obd_proc_entry));
+       /* Since we register the obd device with ptlrpc / sptlrpc we
+        * have to register debugfs with obd_device
+        */
+       obd->obd_debugfs_entry = ldebugfs_register(obd->obd_name,
+                                                  obd->obd_type->typ_debugfs_entry,
+                                                  obd->obd_vars, obd);
+       if (IS_ERR_OR_NULL(obd->obd_debugfs_entry)) {
+               rc = obd->obd_debugfs_entry ? PTR_ERR(obd->obd_debugfs_entry)
+                                           : -ENOMEM;
+               CERROR("%s: error %d setting up debugfs\n",
+                      obd->obd_name, rc);
+               obd->obd_debugfs_entry = NULL;
+               dt_tunables_fini(&osp->opd_dt_dev);
                return;
        }
 
+       sptlrpc_lprocfs_cliobd_attach(obd);
        ptlrpc_lprocfs_register_obd(obd);
 
-       /* for compatibility we link old procfs's OSC entries to osp ones */
-       if (!osp->opd_connect_mdt) {
-               osc_proc_dir = lprocfs_srch(proc_lustre_root, "osc");
-               if (osc_proc_dir) {
-                       cfs_proc_dir_entry_t    *symlink = NULL;
-                       char                    *name;
-
-                       OBD_ALLOC(name, strlen(obd->obd_name) + 1);
-                       if (name == NULL)
-                               return;
-
-                       strcpy(name, obd->obd_name);
-                       if (strstr(name, "osc"))
-                               symlink = lprocfs_add_symlink(name,
-                                               osc_proc_dir, "../osp/%s",
-                                               obd->obd_name);
-                       OBD_FREE(name, strlen(obd->obd_name) + 1);
-                       osp->opd_symlink = symlink;
-               }
-       }
-}
+       if (osp->opd_connect_mdt || !strstr(obd->obd_name, "osc"))
+               return;
 
-#endif /* LPROCFS */
+       /* If the real OSC is present which is the case for setups
+        * with both server and clients on the same node then use
+        * the OSC's proc root
+        */
+       osc = kset_find_obj(lustre_kset, "osc");
+       if (osc) {
+               rc = sysfs_create_link(osc, &osp->opd_dt_dev.dd_kobj,
+                                      obd->obd_name);
+               kobject_put(osc);
+       }
 
+       osp->opd_debugfs = ldebugfs_add_symlink(obd->obd_name, "osc",
+                                               "../osp/%s", obd->obd_name);
+       if (!osp->opd_debugfs)
+               CERROR("%s: failed to create OSC debugfs symlink\n",
+                      obd->obd_name);
+}