Whamcloud - gitweb
LU-5759 tests: use lfs getstripe -M instead of get_mds_num
[fs/lustre-release.git] / lustre / osp / osp_trans.c
index 7d4ace8..449a474 100644 (file)
@@ -63,6 +63,8 @@
 
 struct osp_async_update_args {
        struct dt_update_request *oaua_update;
+       atomic_t                 *oaua_count;
+       wait_queue_head_t        *oaua_waitq;
        bool                      oaua_flow_control;
 };
 
@@ -195,6 +197,9 @@ static int osp_async_update_interpret(const struct lu_env *env,
                index++;
        }
 
+       if (oaua->oaua_count != NULL && atomic_dec_and_test(oaua->oaua_count))
+               wake_up_all(oaua->oaua_waitq);
+
        dt_update_request_destroy(dt_update);
 
        return 0;
@@ -238,6 +243,9 @@ int osp_unplug_async_request(const struct lu_env *env,
 
                args = ptlrpc_req_async_args(req);
                args->oaua_update = update;
+               args->oaua_count = NULL;
+               args->oaua_waitq = NULL;
+               args->oaua_flow_control = false;
                req->rq_interpret_reply = osp_async_update_interpret;
                ptlrpcd_add_req(req, PDL_POLICY_LOCAL, -1);
        }
@@ -287,8 +295,8 @@ osp_find_or_create_async_update_request(struct osp_device *osp)
  * \param[in] env              pointer to the thread context
  * \param[in] op               operation type, see 'enum update_type'
  * \param[in] obj              pointer to the operation target
- * \param[in] count            array size of the subsequent @lens and @bufs
- * \param[in] lens             buffer length array for the subsequent @bufs
+ * \param[in] count            array size of the subsequent \a lens and \a bufs
+ * \param[in] lens             buffer length array for the subsequent \a bufs
  * \param[in] bufs             the buffers to compose the request
  * \param[in] data             pointer to the data used by the interpreter
  * \param[in] interpreter      pointer to the interpreter function
@@ -413,9 +421,9 @@ out:
 /**
  * Trigger the request for remote updates.
  *
- * If the transaction is a remote transaction, then related remote updates
- * will be sent asynchronously; otherwise, the cross MDTs transaction will
- * be synchronized.
+ * If the transaction is not a remote one or it is required to be sync mode
+ * (th->th_sync is set), then it will be sent synchronously; otherwise, the
+ * RPC will be sent asynchronously.
  *
  * Please refer to osp_trans_create() for transaction type.
  *
@@ -442,14 +450,30 @@ static int osp_trans_trigger(const struct lu_env *env, struct osp_device *osp,
                struct ptlrpc_request           *req;
 
                list_del_init(&dt_update->dur_list);
+               if (th->th_sync) {
+                       rc = out_remote_sync(env, osp->opd_obd->u.cli.cl_import,
+                                            dt_update, NULL);
+                       dt_update_request_destroy(dt_update);
+
+                       return rc;
+               }
+
                rc = out_prep_update_req(env, osp->opd_obd->u.cli.cl_import,
                                         dt_update->dur_buf.ub_req, &req);
                if (rc == 0) {
+                       down_read(&osp->opd_async_updates_rwsem);
+
                        args = ptlrpc_req_async_args(req);
                        args->oaua_update = dt_update;
+                       args->oaua_count = &osp->opd_async_updates_count;
+                       args->oaua_waitq = &osp->opd_syn_barrier_waitq;
                        args->oaua_flow_control = flow_control;
                        req->rq_interpret_reply =
                                osp_async_update_interpret;
+
+                       atomic_inc(args->oaua_count);
+                       up_read(&osp->opd_async_updates_rwsem);
+
                        ptlrpcd_add_req(req, PDL_POLICY_LOCAL, -1);
                } else {
                        dt_update_request_destroy(dt_update);
@@ -538,6 +562,7 @@ int osp_trans_stop(const struct lu_env *env, struct dt_device *dt,
        struct thandle_update           *tu = th->th_update;
        struct dt_update_request        *dt_update;
        int                              rc = 0;
+       ENTRY;
 
        LASSERT(tu != NULL);
        LASSERT(tu != LP_POISON);
@@ -546,14 +571,15 @@ int osp_trans_stop(const struct lu_env *env, struct dt_device *dt,
        dt_update = out_find_update(tu, dt);
        if (dt_update == NULL) {
                if (!is_only_remote_trans(th))
-                       return rc;
-               goto put;
+                       RETURN(rc);
+
+               GOTO(put, rc);
        }
 
        if (dt_update->dur_buf.ub_req == NULL ||
            dt_update->dur_buf.ub_req->ourq_count == 0) {
                dt_update_request_destroy(dt_update);
-               goto put;
+               GOTO(put, rc);
        }
 
        if (is_only_remote_trans(th)) {
@@ -562,7 +588,7 @@ int osp_trans_stop(const struct lu_env *env, struct dt_device *dt,
                        struct client_obd *cli = &osp->opd_obd->u.cli;
 
                        rc = obd_get_request_slot(cli);
-                       if (!osp->opd_imp_active || osp->opd_got_disconnected) {
+                       if (!osp->opd_imp_active || !osp->opd_imp_connected) {
                                if (rc == 0)
                                        obd_put_request_slot(cli);
 
@@ -571,7 +597,7 @@ int osp_trans_stop(const struct lu_env *env, struct dt_device *dt,
 
                        if (rc != 0) {
                                dt_update_request_destroy(dt_update);
-                               goto put;
+                               GOTO(put, rc);
                        }
 
                        rc = osp_trans_trigger(env, dt2osp_dev(dt),
@@ -590,6 +616,8 @@ int osp_trans_stop(const struct lu_env *env, struct dt_device *dt,
                dt_update_request_destroy(dt_update);
        }
 
+       GOTO(put, rc);
+
 put:
        thandle_put(th);
        return rc;