Whamcloud - gitweb
LU-13366 lod: check for extension size at instantiation time
[fs/lustre-release.git] / lustre / osp / osp_dev.c
index 546b6ba..04ad620 100644 (file)
@@ -23,7 +23,7 @@
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2012, 2016, Intel Corporation.
+ * Copyright (c) 2012, 2017, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
 
 #include <linux/kthread.h>
 
-#include <uapi/linux/lustre_ioctl.h>
+#include <uapi/linux/lustre/lustre_ioctl.h>
 #include <lustre_log.h>
 #include <lustre_obdo.h>
-#include <uapi/linux/lustre_param.h>
+#include <uapi/linux/lustre/lustre_param.h>
 #include <obd_class.h>
 
 #include "osp_internal.h"
@@ -258,20 +258,23 @@ static int osp_init_last_objid(const struct lu_env *env, struct osp_device *osp)
        if (IS_ERR(dto))
                RETURN(PTR_ERR(dto));
 
+       osp_objid_buf_prep(&osi->osi_lb, &osi->osi_off, &osp->opd_last_id,
+                          osp->opd_index);
+
        /* object will be released in device cleanup path */
-       if (osi->osi_attr.la_size >=
-           sizeof(osi->osi_id) * (osp->opd_index + 1)) {
-               osp_objid_buf_prep(&osi->osi_lb, &osi->osi_off, &fid->f_oid,
-                                  osp->opd_index);
+       if (osi->osi_attr.la_size >= (osi->osi_off + osi->osi_lb.lb_len)) {
                rc = dt_record_read(env, dto, &osi->osi_lb, &osi->osi_off);
                if (rc != 0 && rc != -EFAULT)
                        GOTO(out, rc);
+               /* In case of idif bits 32-48 go to f_seq
+                * (see osp_init_last_seq). So don't care
+                * about u64->u32 convertion. */
+               fid->f_oid = osp->opd_last_id;
        }
 
        if (rc == -EFAULT) { /* fresh LAST_ID */
+               osp->opd_last_id = 0;
                fid->f_oid = 0;
-               osp_objid_buf_prep(&osi->osi_lb, &osi->osi_off, &fid->f_oid,
-                                  osp->opd_index);
                rc = osp_write_local_file(env, osp, dto, &osi->osi_lb,
                                          osi->osi_off);
                if (rc != 0)
@@ -315,20 +318,21 @@ static int osp_init_last_seq(const struct lu_env *env, struct osp_device *osp)
        if (IS_ERR(dto))
                RETURN(PTR_ERR(dto));
 
+       osp_objseq_buf_prep(&osi->osi_lb, &osi->osi_off, &fid->f_seq,
+                          osp->opd_index);
+
        /* object will be released in device cleanup path */
-       if (osi->osi_attr.la_size >=
-           sizeof(osi->osi_id) * (osp->opd_index + 1)) {
-               osp_objseq_buf_prep(&osi->osi_lb, &osi->osi_off, &fid->f_seq,
-                                  osp->opd_index);
+       if (osi->osi_attr.la_size >= (osi->osi_off + osi->osi_lb.lb_len)) {
                rc = dt_record_read(env, dto, &osi->osi_lb, &osi->osi_off);
                if (rc != 0 && rc != -EFAULT)
                        GOTO(out, rc);
+               if (fid_is_idif(fid))
+                       fid->f_seq = fid_idif_seq(osp->opd_last_id,
+                                                 osp->opd_index);
        }
 
        if (rc == -EFAULT) { /* fresh OSP */
                fid->f_seq = 0;
-               osp_objseq_buf_prep(&osi->osi_lb, &osi->osi_off, &fid->f_seq,
-                                   osp->opd_index);
                rc = osp_write_local_file(env, osp, dto, &osi->osi_lb,
                                          osi->osi_off);
                if (rc != 0)
@@ -374,7 +378,7 @@ static int osp_last_used_init(const struct lu_env *env, struct osp_device *osp)
 
        rc = osp_init_last_seq(env, osp);
        if (rc < 0) {
-               CERROR("%s: Can not get ids %d from old objid!\n",
+               CERROR("%s: Can not get sequence %d from old objseq!\n",
                       osp->opd_obd->obd_name, rc);
                GOTO(out, rc);
        }
@@ -405,6 +409,7 @@ static int osp_last_used_init(const struct lu_env *env, struct osp_device *osp)
                GOTO(out, rc = -EINVAL);
        }
 
+       osp_fid_to_obdid(&osp->opd_last_used_fid, &osp->opd_last_id);
        CDEBUG(D_INFO, "%s: Init last used fid "DFID"\n",
               osp->opd_obd->obd_name, PFID(&osp->opd_last_used_fid));
 out:
@@ -496,8 +501,8 @@ static int osp_disconnect(struct osp_device *d)
  */
 static int osp_update_init(struct osp_device *osp)
 {
-       struct l_wait_info      lwi = { 0 };
-       struct task_struct      *task;
+       struct task_struct *task;
+       int rc;
 
        ENTRY;
 
@@ -510,7 +515,6 @@ static int osp_update_init(struct osp_device *osp)
        if (osp->opd_update == NULL)
                RETURN(-ENOMEM);
 
-       init_waitqueue_head(&osp->opd_update_thread.t_ctl_waitq);
        init_waitqueue_head(&osp->opd_update->ou_waitq);
        spin_lock_init(&osp->opd_update->ou_lock);
        INIT_LIST_HEAD(&osp->opd_update->ou_list);
@@ -518,12 +522,22 @@ static int osp_update_init(struct osp_device *osp)
        osp->opd_update->ou_version = 1;
        osp->opd_update->ou_generation = 0;
 
+       rc = lu_env_init(&osp->opd_update->ou_env,
+                        osp->opd_dt_dev.dd_lu_dev.ld_type->ldt_ctx_tags);
+       if (rc < 0) {
+               CERROR("%s: init env error: rc = %d\n", osp->opd_obd->obd_name,
+                      rc);
+               OBD_FREE_PTR(osp->opd_update);
+               osp->opd_update = NULL;
+               RETURN(rc);
+       }
        /* start thread handling sending updates to the remote MDT */
-       task = kthread_run(osp_send_update_thread, osp,
-                          "osp_up%u-%u", osp->opd_index, osp->opd_group);
+       task = kthread_create(osp_send_update_thread, osp,
+                             "osp_up%u-%u", osp->opd_index, osp->opd_group);
        if (IS_ERR(task)) {
                int rc = PTR_ERR(task);
 
+               lu_env_fini(&osp->opd_update->ou_env);
                OBD_FREE_PTR(osp->opd_update);
                osp->opd_update = NULL;
                CERROR("%s: can't start precreate thread: rc = %d\n",
@@ -531,9 +545,8 @@ static int osp_update_init(struct osp_device *osp)
                RETURN(rc);
        }
 
-       l_wait_event(osp->opd_update_thread.t_ctl_waitq,
-                    osp_send_update_thread_running(osp) ||
-                    osp_send_update_thread_stopped(osp), &lwi);
+       osp->opd_update->ou_update_task = task;
+       wake_up_process(task);
 
        RETURN(0);
 }
@@ -555,11 +568,8 @@ static void osp_update_fini(const struct lu_env *env, struct osp_device *osp)
        if (ou == NULL)
                return;
 
-       osp->opd_update_thread.t_flags = SVC_STOPPING;
-       wake_up(&ou->ou_waitq);
-
-       wait_event(osp->opd_update_thread.t_ctl_waitq,
-                  osp->opd_update_thread.t_flags & SVC_STOPPED);
+       kthread_stop(ou->ou_update_task);
+       lu_env_fini(&ou->ou_env);
 
        /* Remove the left osp thandle from the list */
        spin_lock(&ou->ou_lock);
@@ -596,6 +606,8 @@ static int osp_shutdown(const struct lu_env *env, struct osp_device *d)
 
        rc = osp_disconnect(d);
 
+       osp_statfs_fini(d);
+
        if (!d->opd_connect_mdt) {
                /* stop sync thread */
                osp_sync_fini(d);
@@ -629,9 +641,11 @@ static int osp_shutdown(const struct lu_env *env, struct osp_device *d)
 static int osp_process_config(const struct lu_env *env,
                              struct lu_device *dev, struct lustre_cfg *lcfg)
 {
-       struct osp_device               *d = lu2osp_dev(dev);
-       struct obd_device               *obd = d->opd_obd;
-       int                              rc;
+       struct osp_device *d = lu2osp_dev(dev);
+       struct dt_device *dt = lu2dt_dev(dev);
+       struct obd_device *obd = d->opd_obd;
+       ssize_t count;
+       int rc;
 
        ENTRY;
 
@@ -647,22 +661,20 @@ static int osp_process_config(const struct lu_env *env,
                rc = osp_shutdown(env, d);
                break;
        case LCFG_PARAM:
-               LASSERT(obd);
-               rc = class_process_proc_param(d->opd_connect_mdt ?
-                                             PARAM_OSP : PARAM_OSC,
-                                             obd->obd_vars, lcfg, obd);
-               if (rc > 0)
-                       rc = 0;
-               if (rc == -ENOSYS) {
-                       /* class_process_proc_param() haven't found matching
-                        * parameter and returned ENOSYS so that layer(s)
+               count = class_modify_config(lcfg, d->opd_connect_mdt ?
+                                                 PARAM_OSP : PARAM_OSC,
+                                           &dt->dd_kobj);
+               if (count < 0) {
+                       /* class_modify_config() haven't found matching
+                        * parameter and returned an error so that layer(s)
                         * below could use that. But OSP is the bottom, so
-                        * just ignore it */
+                        * just ignore it
+                        */
                        CERROR("%s: unknown param %s\n",
                               (char *)lustre_cfg_string(lcfg, 0),
                               (char *)lustre_cfg_string(lcfg, 1));
-                       rc = 0;
                }
+               rc = 0;
                break;
        default:
                CERROR("%s: unknown command %u\n",
@@ -699,10 +711,41 @@ static int osp_recovery_complete(const struct lu_env *env,
        RETURN(0);
 }
 
+/**
+ * Implementation of lu_device_operations::ldo_fid_alloc() for OSP
+ *
+ * Allocate FID from remote MDT.
+ *
+ * see include/lu_object.h for the details.
+ */
+static int osp_fid_alloc(const struct lu_env *env, struct lu_device *d,
+                        struct lu_fid *fid, struct lu_object *parent,
+                        const struct lu_name *name)
+{
+       struct osp_device *osp = lu2osp_dev(d);
+       struct client_obd *cli = &osp->opd_obd->u.cli;
+       struct lu_client_seq *seq = cli->cl_seq;
+       int rc;
+
+       ENTRY;
+
+       /* Sigh, fid client is not ready yet */
+       if (!osp->opd_obd->u.cli.cl_seq)
+               RETURN(-ENOTCONN);
+
+       if (!osp->opd_obd->u.cli.cl_seq->lcs_exp)
+               RETURN(-ENOTCONN);
+
+       rc = seq_client_alloc_fid(env, seq, fid);
+
+       RETURN(rc);
+}
+
 const struct lu_device_operations osp_lu_ops = {
        .ldo_object_alloc       = osp_object_alloc,
        .ldo_process_config     = osp_process_config,
        .ldo_recovery_complete  = osp_recovery_complete,
+       .ldo_fid_alloc          = osp_fid_alloc,
 };
 
 /**
@@ -723,7 +766,7 @@ const struct lu_device_operations osp_lu_ops = {
  * \retval negative    negative errno if get statfs failed.
  */
 static int osp_statfs(const struct lu_env *env, struct dt_device *dev,
-                     struct obd_statfs *sfs)
+                     struct obd_statfs *sfs, struct obd_statfs_info *info)
 {
        struct osp_device *d = dt2osp_dev(dev);
        struct obd_import *imp = d->opd_obd->u.cli.cl_import;
@@ -736,37 +779,43 @@ static int osp_statfs(const struct lu_env *env, struct dt_device *dev,
        if (unlikely(d->opd_imp_active == 0))
                RETURN(-ENOTCONN);
 
+       /* return recently updated data */
+       *sfs = d->opd_statfs;
+       if (info) {
+               info->os_reserved_mb_low = d->opd_reserved_mb_low;
+               info->os_reserved_mb_high = d->opd_reserved_mb_high;
+       }
+
        if (d->opd_pre == NULL)
                RETURN(0);
 
-       /* return recently updated data */
-       *sfs = d->opd_statfs;
+       CDEBUG(D_OTHER, "%s: %llu blocks, %llu free, %llu avail, "
+              "%u bsize, %u reserved mb low, %u reserved mb high, "
+              "%llu files, %llu free files\n", d->opd_obd->obd_name,
+              sfs->os_blocks, sfs->os_bfree, sfs->os_bavail, sfs->os_bsize,
+              d->opd_reserved_mb_low, d->opd_reserved_mb_high,
+              sfs->os_files, sfs->os_ffree);
+
+
+       if (info && !info->os_enable_pre)
+               RETURN(0);
 
        /*
-        * layer above osp (usually lod) can use ffree to estimate
-        * how many objects are available for immediate creation
+        * The layer above osp (usually lod) can use f_precreated to
+        * estimate how many objects are available for immediate usage.
         */
        spin_lock(&d->opd_pre_lock);
-       sfs->os_fprecreated = osp_objs_precreated(env, d);
+       sfs->os_fprecreated = osp_fid_diff(&d->opd_pre_last_created_fid,
+                                          &d->opd_pre_used_fid);
        sfs->os_fprecreated -= d->opd_pre_reserved;
        LASSERTF(sfs->os_fprecreated <= OST_MAX_PRECREATE * 2,
                 "last_created "DFID", next_fid "DFID", reserved %llu\n",
                 PFID(&d->opd_pre_last_created_fid), PFID(&d->opd_pre_used_fid),
                 d->opd_pre_reserved);
        spin_unlock(&d->opd_pre_lock);
-
-       CDEBUG(D_OTHER, "%s: %llu blocks, %llu free, %llu avail, "
-              "%llu files, %llu free files\n", d->opd_obd->obd_name,
-              sfs->os_blocks, sfs->os_bfree, sfs->os_bavail,
-              sfs->os_files, sfs->os_ffree);
        RETURN(0);
 }
 
-static int osp_sync_timeout(void *data)
-{
-       return 1;
-}
-
 /**
  * Implementation of dt_device_operations::dt_sync
  *
@@ -782,56 +831,59 @@ static int osp_sync_timeout(void *data)
 static int osp_sync(const struct lu_env *env, struct dt_device *dev)
 {
        struct osp_device *d = dt2osp_dev(dev);
-       cfs_time_t         expire;
-       struct l_wait_info lwi = { 0 };
-       unsigned long      id, old;
-       int                rc = 0;
-       unsigned long      start = cfs_time_current();
+       time64_t start = ktime_get_seconds();
+       int recs, rc = 0;
+       u64 old;
+
        ENTRY;
 
        /* No Sync between MDTs yet. */
        if (d->opd_connect_mdt)
                RETURN(0);
 
+       recs = atomic_read(&d->opd_sync_changes);
+       old = atomic64_read(&d->opd_sync_processed_recs);
+
+       osp_sync_force(env, dt2osp_dev(dev));
+
        if (unlikely(d->opd_imp_active == 0))
                RETURN(-ENOTCONN);
 
-       id = d->opd_sync_last_used_id;
        down_write(&d->opd_async_updates_rwsem);
 
        CDEBUG(D_OTHER, "%s: async updates %d\n", d->opd_obd->obd_name,
               atomic_read(&d->opd_async_updates_count));
 
        /* make sure the connection is fine */
-       expire = cfs_time_shift(obd_timeout);
-       lwi = LWI_TIMEOUT(expire - cfs_time_current(), osp_sync_timeout, d);
-       rc = l_wait_event(d->opd_sync_barrier_waitq,
-                         atomic_read(&d->opd_async_updates_count) == 0,
-                         &lwi);
+       rc = wait_event_idle_timeout(
+               d->opd_sync_barrier_waitq,
+               atomic_read(&d->opd_async_updates_count) == 0,
+               cfs_time_seconds(obd_timeout));
+       if (rc > 0)
+               rc = 0;
+       else if (rc == 0)
+               rc = -ETIMEDOUT;
+
        up_write(&d->opd_async_updates_rwsem);
        if (rc != 0)
                GOTO(out, rc);
 
-       CDEBUG(D_CACHE, "%s: id: used %lu, processed %llu\n",
-              d->opd_obd->obd_name, id, d->opd_sync_last_processed_id);
-
-       /* wait till all-in-line are processed */
-       while (d->opd_sync_last_processed_id < id) {
-
-               old = d->opd_sync_last_processed_id;
+       CDEBUG(D_CACHE, "%s: processed %llu\n", d->opd_obd->obd_name,
+              (unsigned long long)atomic64_read(&d->opd_sync_processed_recs));
 
+       while (atomic64_read(&d->opd_sync_processed_recs) < old + recs) {
+               __u64 last = atomic64_read(&d->opd_sync_processed_recs);
                /* make sure the connection is fine */
-               expire = cfs_time_shift(obd_timeout);
-               lwi = LWI_TIMEOUT(expire - cfs_time_current(),
-                                 osp_sync_timeout, d);
-               l_wait_event(d->opd_sync_barrier_waitq,
-                            d->opd_sync_last_processed_id >= id,
-                            &lwi);
-
-               if (d->opd_sync_last_processed_id >= id)
+               wait_event_idle_timeout(
+                       d->opd_sync_barrier_waitq,
+                       atomic64_read(&d->opd_sync_processed_recs)
+                            >= old + recs,
+                       cfs_time_seconds(obd_timeout));
+
+               if (atomic64_read(&d->opd_sync_processed_recs) >= old + recs)
                        break;
 
-               if (d->opd_sync_last_processed_id != old) {
+               if (atomic64_read(&d->opd_sync_processed_recs) != last) {
                        /* some progress have been made,
                         * keep trying... */
                        continue;
@@ -854,12 +906,10 @@ static int osp_sync(const struct lu_env *env, struct dt_device *dev)
        while (atomic_read(&d->opd_sync_rpcs_in_flight) > 0) {
                old = atomic_read(&d->opd_sync_rpcs_in_flight);
 
-               expire = cfs_time_shift(obd_timeout);
-               lwi = LWI_TIMEOUT(expire - cfs_time_current(),
-                                 osp_sync_timeout, d);
-               l_wait_event(d->opd_sync_barrier_waitq,
-                            atomic_read(&d->opd_sync_rpcs_in_flight) == 0,
-                            &lwi);
+               wait_event_idle_timeout(
+                       d->opd_sync_barrier_waitq,
+                       atomic_read(&d->opd_sync_rpcs_in_flight) == 0,
+                       cfs_time_seconds(obd_timeout));
 
                if (atomic_read(&d->opd_sync_rpcs_in_flight) == 0)
                        break;
@@ -878,8 +928,8 @@ out:
        atomic_dec(&d->opd_sync_barrier);
        osp_sync_check_for_work(d);
 
-       CDEBUG(D_CACHE, "%s: done in %lu: rc = %d\n", d->opd_obd->obd_name,
-              cfs_time_current() - start, rc);
+       CDEBUG(D_CACHE, "%s: done in %lld: rc = %d\n", d->opd_obd->obd_name,
+              ktime_get_seconds() - start, rc);
 
        RETURN(rc);
 }
@@ -999,10 +1049,10 @@ static int osp_init0(const struct lu_env *env, struct osp_device *osp,
 {
        struct obd_device       *obd;
        struct obd_import       *imp;
-       class_uuid_t            uuid;
-       char                    *src, *tgt, *mdt, *osdname = NULL;
+       char *src, *tgt, *osdname = NULL;
+       const char *mdt;
        int                     rc;
-       long                    idx;
+       u32 idx;
 
        ENTRY;
 
@@ -1049,8 +1099,8 @@ static int osp_init0(const struct lu_env *env, struct osp_device *osp,
                        RETURN(-EINVAL);
                }
 
-               idx = simple_strtol(tgt + 4, &mdt, 16);
-               if (mdt[0] != '-' || idx > INT_MAX || idx < 0) {
+               rc = target_name2index(tgt + 1, &idx, &mdt);
+               if (rc < 0 || rc & LDD_F_SV_ALL || mdt[0] != '-') {
                        CERROR("%s: invalid OST index in '%s': rc = %d\n",
                               osp->opd_obd->obd_name, src, -EINVAL);
                        RETURN(-EINVAL);
@@ -1068,8 +1118,8 @@ static int osp_init0(const struct lu_env *env, struct osp_device *osp,
                        RETURN(-EINVAL);
                }
 
-               idx = simple_strtol(tgt + 4, &mdt, 16);
-               if (*mdt != '\0' || idx > INT_MAX || idx < 0) {
+               rc = target_name2index(tgt + 1, &idx, &mdt);
+               if (rc < 0 || rc & LDD_F_SV_ALL || *mdt != '\0') {
                        CERROR("%s: invalid OST index in '%s': rc = %d\n",
                               osp->opd_obd->obd_name, src, -EINVAL);
                        RETURN(-EINVAL);
@@ -1088,8 +1138,8 @@ static int osp_init0(const struct lu_env *env, struct osp_device *osp,
                if (strncmp(tgt - 12, "-MDT", 4) == 0)
                        osp->opd_connect_mdt = 1;
 
-               idx = simple_strtol(tgt - 8, &mdt, 16);
-               if (mdt[0] != '-' || idx > INT_MAX || idx < 0) {
+               rc = target_name2index(tgt - 11, &idx, &mdt);
+               if (rc < 0 || rc & LDD_F_SV_ALL || mdt[0] != '-') {
                        CERROR("%s: invalid OST index in '%s': rc =%d\n",
                               osp->opd_obd->obd_name, src, -EINVAL);
                        RETURN(-EINVAL);
@@ -1120,14 +1170,7 @@ static int osp_init0(const struct lu_env *env, struct osp_device *osp,
        strcat(osdname, "-osd");
        CDEBUG(D_HA, "%s: connect to %s (%s)\n", obd->obd_name, osdname, src);
 
-       if (osp->opd_connect_mdt) {
-               struct client_obd *cli = &osp->opd_obd->u.cli;
-
-               OBD_ALLOC(cli->cl_rpc_lock, sizeof(*cli->cl_rpc_lock));
-               if (!cli->cl_rpc_lock)
-                       GOTO(out_fini, rc = -ENOMEM);
-               osp_init_rpc_lock(cli->cl_rpc_lock);
-       }
+       osp_init_rpc_lock(osp);
 
        osp->opd_dt_dev.dd_lu_dev.ld_ops = &osp_lu_ops;
        osp->opd_dt_dev.dd_ops = &osp_dt_ops;
@@ -1149,7 +1192,7 @@ static int osp_init0(const struct lu_env *env, struct osp_device *osp,
                GOTO(out_ref, rc);
        }
 
-       osp_lprocfs_init(osp);
+       osp_tunables_init(osp);
 
        rc = obd_fid_init(osp->opd_obd, NULL, osp->opd_connect_mdt ?
                          LUSTRE_SEQ_METADATA : LUSTRE_SEQ_DATA);
@@ -1183,19 +1226,21 @@ static int osp_init0(const struct lu_env *env, struct osp_device *osp,
                if (rc < 0)
                        GOTO(out_precreat, rc);
        } else {
+               osp->opd_got_disconnected = 1;
                rc = osp_update_init(osp);
                if (rc != 0)
                        GOTO(out_fid, rc);
        }
 
+       rc = osp_init_statfs(osp);
+       if (rc)
+               GOTO(out_precreat, rc);
+
        ns_register_cancel(obd->obd_namespace, osp_cancel_weight);
 
        /*
         * Initiate connect to OST
         */
-       ll_generate_random_uuid(uuid);
-       class_uuid_unparse(uuid, &osp->opd_cluuid);
-
        imp = obd->u.cli.cl_import;
 
        rc = ptlrpc_init_import(imp);
@@ -1221,21 +1266,11 @@ out_last_used:
 out_fid:
        obd_fid_fini(osp->opd_obd);
 out_proc:
-       ptlrpc_lprocfs_unregister_obd(obd);
-       lprocfs_obd_cleanup(obd);
-       if (osp->opd_symlink)
-               lprocfs_remove(&osp->opd_symlink);
+       osp_tunables_fini(osp);
        client_obd_cleanup(obd);
 out_ref:
        ptlrpcd_decref();
 out_disconnect:
-       if (osp->opd_connect_mdt) {
-               struct client_obd *cli = &osp->opd_obd->u.cli;
-               if (cli->cl_rpc_lock != NULL) {
-                       OBD_FREE_PTR(cli->cl_rpc_lock);
-                       cli->cl_rpc_lock = NULL;
-               }
-       }
        obd_disconnect(osp->opd_storage_exp);
 out_fini:
        if (osdname)
@@ -1259,10 +1294,8 @@ static struct lu_device *osp_device_free(const struct lu_env *env,
 {
        struct osp_device *osp = lu2osp_dev(lu);
 
-       if (atomic_read(&lu->ld_ref) && lu->ld_site) {
-               LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, D_ERROR, NULL);
-               lu_site_print(env, lu->ld_site, &msgdata, lu_cdebug_printer);
-       }
+       lu_site_print(env, lu->ld_site, &lu->ld_ref, D_ERROR,
+                     lu_cdebug_printer);
        dt_device_fini(&osp->opd_dt_dev);
        OBD_FREE_PTR(osp);
 
@@ -1331,23 +1364,14 @@ static struct lu_device *osp_device_fini(const struct lu_env *env,
                osp->opd_async_requests = NULL;
        }
 
-       if (osp->opd_storage_exp)
+       if (osp->opd_storage_exp) {
+               /* wait for the commit callbacks to complete */
+               wait_event(osp->opd_sync_waitq,
+                         atomic_read(&osp->opd_commits_registered) == 0);
                obd_disconnect(osp->opd_storage_exp);
-
-       if (osp->opd_symlink)
-               lprocfs_remove(&osp->opd_symlink);
+       }
 
        LASSERT(osp->opd_obd);
-       ptlrpc_lprocfs_unregister_obd(osp->opd_obd);
-       lprocfs_obd_cleanup(osp->opd_obd);
-
-       if (osp->opd_connect_mdt) {
-               struct client_obd *cli = &osp->opd_obd->u.cli;
-               if (cli->cl_rpc_lock != NULL) {
-                       OBD_FREE_PTR(cli->cl_rpc_lock);
-                       cli->cl_rpc_lock = NULL;
-               }
-       }
 
        rc = client_obd_cleanup(osp->opd_obd);
        if (rc != 0) {
@@ -1355,6 +1379,8 @@ static struct lu_device *osp_device_fini(const struct lu_env *env,
                RETURN(ERR_PTR(rc));
        }
 
+       osp_tunables_fini(osp);
+
        ptlrpcd_decref();
 
        RETURN(NULL);
@@ -1500,7 +1526,7 @@ static int osp_obd_disconnect(struct obd_export *exp)
  * \retval negative    negative errno if statfs failed.
  */
 static int osp_obd_statfs(const struct lu_env *env, struct obd_export *exp,
-                         struct obd_statfs *osfs, __u64 unused, __u32 flags)
+                         struct obd_statfs *osfs, time64_t unused, __u32 flags)
 {
        struct obd_statfs       *msfs;
        struct ptlrpc_request   *req;
@@ -1614,12 +1640,10 @@ static int osp_import_event(struct obd_device *obd, struct obd_import *imp,
                d->opd_imp_connected = 1;
                d->opd_imp_seen_connected = 1;
                d->opd_obd->obd_inactive = 0;
+               wake_up(&d->opd_pre_waitq);
                if (d->opd_connect_mdt)
                        break;
 
-               if (d->opd_pre != NULL)
-                       wake_up(&d->opd_pre_waitq);
-
                osp_sync_check_for_work(d);
                CDEBUG(D_HA, "got connected\n");
                break;
@@ -1690,12 +1714,9 @@ static int osp_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
                rc = ptlrpc_set_import_active(obd->u.cli.cl_import,
                                              data->ioc_offset);
                break;
-       case OBD_IOC_PING_TARGET:
-               rc = ptlrpc_obd_ping(obd);
-               break;
        default:
                CERROR("%s: unrecognized ioctl %#x by %s\n", obd->obd_name,
-                      cmd, current_comm());
+                      cmd, current->comm);
                rc = -ENOTTY;
        }
        module_put(THIS_MODULE);
@@ -1797,44 +1818,6 @@ static int osp_obd_set_info_async(const struct lu_env *env,
        RETURN(0);
 }
 
-/**
- * Implementation of obd_ops: o_fid_alloc
- *
- * Allocate a FID. There are two cases in which OSP performs
- * FID allocation.
- *
- * 1. FID precreation for data objects, which is done in
- *    osp_precreate_fids() instead of this function.
- * 2. FID allocation for each sub-stripe of a striped directory.
- *    Similar to other FID clients, OSP requests the sequence
- *    from its corresponding remote MDT, which in turn requests
- *    sequences from the sequence controller (MDT0).
- *
- * \param[in] env      execution environment
- * \param[in] exp      export of the OSP
- * \param[out] fid     FID being allocated
- * \param[in] unused   necessary for the interface but unused.
- *
- * \retval 0           0 FID allocated successfully.
- * \retval 1           1 FID allocated successfully and new sequence
- *                      requested from seq meta server
- * \retval negative    negative errno if FID allocation failed.
- */
-static int osp_fid_alloc(const struct lu_env *env, struct obd_export *exp,
-                        struct lu_fid *fid, struct md_op_data *unused)
-{
-       struct client_obd       *cli = &exp->exp_obd->u.cli;
-       struct osp_device       *osp = lu2osp_dev(exp->exp_obd->obd_lu_dev);
-       struct lu_client_seq    *seq = cli->cl_seq;
-       ENTRY;
-
-       LASSERT(osp->opd_obd->u.cli.cl_seq != NULL);
-       /* Sigh, fid client is not ready yet */
-       LASSERT(osp->opd_obd->u.cli.cl_seq->lcs_exp != NULL);
-
-       RETURN(seq_client_alloc_fid(env, seq, fid));
-}
-
 /* context key constructor/destructor: mdt_key_init, mdt_key_fini */
 LU_KEY_INIT_FINI(osp, struct osp_thread_info);
 static void osp_key_exit(const struct lu_context *ctx,
@@ -1856,7 +1839,7 @@ struct lu_context_key osp_thread_key = {
 LU_KEY_INIT_FINI(osp_txn, struct osp_txn_info);
 
 struct lu_context_key osp_txn_key = {
-       .lct_tags = LCT_OSP_THREAD | LCT_TX_HANDLE,
+       .lct_tags = LCT_OSP_THREAD,
        .lct_init = osp_txn_key_init,
        .lct_fini = osp_txn_key_fini
 };
@@ -1882,7 +1865,7 @@ static struct lu_device_type osp_device_type = {
        .ldt_ctx_tags = LCT_MD_THREAD | LCT_DT_THREAD,
 };
 
-static struct obd_ops osp_obd_device_ops = {
+static const struct obd_ops osp_obd_device_ops = {
        .o_owner        = THIS_MODULE,
        .o_add_conn     = client_import_add_conn,
        .o_del_conn     = client_import_del_conn,
@@ -1896,11 +1879,8 @@ static struct obd_ops osp_obd_device_ops = {
        .o_statfs       = osp_obd_statfs,
        .o_fid_init     = client_fid_init,
        .o_fid_fini     = client_fid_fini,
-       .o_fid_alloc    = osp_fid_alloc,
 };
 
-struct llog_operations osp_mds_ost_orig_logops;
-
 /**
  * Initialize OSP module.
  *
@@ -1915,22 +1895,21 @@ struct llog_operations osp_mds_ost_orig_logops;
  */
 static int __init osp_init(void)
 {
-       struct obd_type *type;
+       struct obd_type *sym;
        int rc;
 
        rc = lu_kmem_init(osp_caches);
        if (rc)
                return rc;
 
-
-       rc = class_register_type(&osp_obd_device_ops, NULL, true, NULL,
+       rc = class_register_type(&osp_obd_device_ops, NULL, false, NULL,
                                 LUSTRE_OSP_NAME, &osp_device_type);
        if (rc != 0) {
                lu_kmem_fini(osp_caches);
                return rc;
        }
 
-       rc = class_register_type(&lwp_obd_device_ops, NULL, true, NULL,
+       rc = class_register_type(&lwp_obd_device_ops, NULL, false, NULL,
                                 LUSTRE_LWP_NAME, &lwp_device_type);
        if (rc != 0) {
                class_unregister_type(LUSTRE_OSP_NAME);
@@ -1938,24 +1917,15 @@ static int __init osp_init(void)
                return rc;
        }
 
-       /* Note: add_rec/delcare_add_rec will be only used by catalogs */
-       osp_mds_ost_orig_logops = llog_osd_ops;
-       osp_mds_ost_orig_logops.lop_add = llog_cat_add_rec;
-       osp_mds_ost_orig_logops.lop_declare_add = llog_cat_declare_add_rec;
-
-       /* create "osc" entry in procfs for compatibility purposes */
-       type = class_search_type(LUSTRE_OSC_NAME);
-       if (type != NULL && type->typ_procroot != NULL)
-               return rc;
-
-       type = class_search_type(LUSTRE_OSP_NAME);
-       type->typ_procsym = lprocfs_register("osc", proc_lustre_root,
-                                            NULL, NULL);
-       if (IS_ERR(type->typ_procsym)) {
-               CERROR("osp: can't create compat entry \"osc\": %d\n",
-                      (int) PTR_ERR(type->typ_procsym));
-               type->typ_procsym = NULL;
+       /* create "osc" entry for compatibility purposes */
+       sym = class_add_symlinks(LUSTRE_OSC_NAME, true);
+       if (IS_ERR(sym)) {
+               rc = PTR_ERR(sym);
+               /* does real "osc" already exist ? */
+               if (rc == -EEXIST)
+                       rc = 0;
        }
+
        return rc;
 }
 
@@ -1967,6 +1937,19 @@ static int __init osp_init(void)
  */
 static void __exit osp_exit(void)
 {
+       struct obd_type *sym = class_search_type(LUSTRE_OSC_NAME);
+
+       /* if this was never fully initialized by the osc layer
+        * then we are responsible for freeing this obd_type
+        */
+       if (sym) {
+               /* final put if we manage this obd type */
+               if (sym->typ_sym_filter)
+                       kobject_put(&sym->typ_kobj);
+               /* put reference taken by class_search_type */
+               kobject_put(&sym->typ_kobj);
+       }
+
        class_unregister_type(LUSTRE_LWP_NAME);
        class_unregister_type(LUSTRE_OSP_NAME);
        lu_kmem_fini(osp_caches);