Whamcloud - gitweb
LU-13366 lod: check for extension size at instantiation time
[fs/lustre-release.git] / lustre / osp / osp_dev.c
index ba348ef..04ad620 100644 (file)
@@ -501,7 +501,8 @@ static int osp_disconnect(struct osp_device *d)
  */
 static int osp_update_init(struct osp_device *osp)
 {
-       struct task_struct      *task;
+       struct task_struct *task;
+       int rc;
 
        ENTRY;
 
@@ -514,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);
@@ -522,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",
@@ -535,9 +545,8 @@ static int osp_update_init(struct osp_device *osp)
                RETURN(rc);
        }
 
-       wait_event_idle(osp->opd_update_thread.t_ctl_waitq,
-                       osp_send_update_thread_running(osp) ||
-                       osp_send_update_thread_stopped(osp));
+       osp->opd_update->ou_update_task = task;
+       wake_up_process(task);
 
        RETURN(0);
 }
@@ -559,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);
@@ -705,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,
 };
 
 /**
@@ -753,9 +790,9 @@ static int osp_statfs(const struct lu_env *env, struct dt_device *dev,
                RETURN(0);
 
        CDEBUG(D_OTHER, "%s: %llu blocks, %llu free, %llu avail, "
-              "%u reserved mb low, %u reserved mb high,"
+              "%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_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);
 
@@ -779,11 +816,6 @@ static int osp_statfs(const struct lu_env *env, struct dt_device *dev,
        RETURN(0);
 }
 
-static int osp_sync_timeout(void *data)
-{
-       return 1;
-}
-
 /**
  * Implementation of dt_device_operations::dt_sync
  *
@@ -799,7 +831,6 @@ 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);
-       struct l_wait_info lwi = { 0 };
        time64_t start = ktime_get_seconds();
        int recs, rc = 0;
        u64 old;
@@ -824,10 +855,15 @@ static int osp_sync(const struct lu_env *env, struct dt_device *dev)
               atomic_read(&d->opd_async_updates_count));
 
        /* make sure the connection is fine */
-       lwi = LWI_TIMEOUT(cfs_time_seconds(obd_timeout), 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);
@@ -838,11 +874,11 @@ static int osp_sync(const struct lu_env *env, struct dt_device *dev)
        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 */
-               lwi = LWI_TIMEOUT(cfs_time_seconds(obd_timeout),
-                                 osp_sync_timeout, d);
-               l_wait_event(d->opd_sync_barrier_waitq,
-                            atomic64_read(&d->opd_sync_processed_recs)
-                            >= old + recs, &lwi);
+               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;
@@ -870,11 +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);
 
-               lwi = LWI_TIMEOUT(cfs_time_seconds(obd_timeout),
-                                 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;
@@ -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);
 
@@ -1683,7 +1716,7 @@ static int osp_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
                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);
@@ -1785,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,
@@ -1870,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,
@@ -1884,7 +1879,6 @@ 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,
 };
 
 /**