Whamcloud - gitweb
LU-3467 ofd: use unified handler for OST requests
[fs/lustre-release.git] / lustre / ofd / ofd_trans.c
index 9103704..a14afe2 100644 (file)
@@ -67,7 +67,7 @@ int ofd_trans_start(const struct lu_env *env, struct ofd_device *ofd,
        struct ofd_thread_info  *info = ofd_info(env);
        int                      rc;
 
-       if (info->fti_exp == NULL)
+       if (env->le_ses == NULL || info->fti_exp == NULL)
                return 0;
 
        /* declare last_rcvd update */
@@ -102,109 +102,27 @@ void ofd_trans_stop(const struct lu_env *env, struct ofd_device *ofd,
        dt_trans_stop(env, ofd->ofd_osd, th);
 }
 
-/*
- * last_rcvd & last_committed update callbacks
- */
-static int ofd_last_rcvd_update(struct ofd_thread_info *info,
-                               struct thandle *th)
-{
-       struct ofd_device               *ofd = ofd_exp(info->fti_exp);
-       struct filter_export_data       *fed;
-       struct lsd_client_data          *lcd;
-       __s32                            rc = th->th_result;
-       __u64                           *transno_p;
-       loff_t                           off;
-       int                              err;
-       bool                             lw_client = false;
-
-       ENTRY;
-
-       LASSERT(ofd);
-       LASSERT(info->fti_exp);
-
-       if (exp_connect_flags(info->fti_exp) & OBD_CONNECT_LIGHTWEIGHT)
-               lw_client = true;
-
-       fed = &info->fti_exp->exp_filter_data;
-       LASSERT(fed);
-       lcd = fed->fed_ted.ted_lcd;
-       /* if the export has already been disconnected, we have no last_rcvd
-        * slot, update server data with latest transno then */
-       if (lcd == NULL) {
-               CWARN("commit transaction for disconnected client %s: rc %d\n",
-                     info->fti_exp->exp_client_uuid.uuid, rc);
-               err = tgt_server_data_write(info->fti_env, &ofd->ofd_lut, th);
-               RETURN(err);
-       }
-       /* ofd connect may cause transaction before export has last_rcvd
-        * slot */
-       if (fed->fed_ted.ted_lr_idx < 0 && !lw_client)
-               RETURN(0);
-       off = fed->fed_ted.ted_lr_off;
-
-       transno_p = &lcd->lcd_last_transno;
-       lcd->lcd_last_xid = info->fti_xid;
-
-       /*
-        * When we store zero transno in mcd we can lost last transno value
-        * because mcd contains 0, but msd is not yet written
-        * The server data should be updated also if the latest
-        * transno is rewritten by zero. See the bug 11125 for details.
-        */
-       if (info->fti_transno == 0 &&
-           *transno_p == ofd->ofd_lut.lut_last_transno) {
-               spin_lock(&ofd->ofd_lut.lut_translock);
-               ofd->ofd_lut.lut_lsd.lsd_last_transno =
-                                               ofd->ofd_lut.lut_last_transno;
-               spin_unlock(&ofd->ofd_lut.lut_translock);
-               tgt_server_data_write(info->fti_env, &ofd->ofd_lut, th);
-       }
-
-       *transno_p = info->fti_transno;
-       if (lw_client) {
-               /* Although lightweight (LW) connections have no slot in
-                * last_rcvd, we still want to maintain the in-memory
-                * lsd_client_data structure in order to properly handle reply
-                * reconstruction. */
-               struct lu_target        *tg =&ofd->ofd_lut;
-               bool                     update = false;
-
-               err = 0;
-               /* All operations performed by LW clients are synchronous and
-                * we store the committed transno in the last_rcvd header */
-               spin_lock(&tg->lut_translock);
-               if (info->fti_transno > tg->lut_lsd.lsd_last_transno) {
-                       tg->lut_lsd.lsd_last_transno = info->fti_transno;
-                       update = true;
-               }
-               spin_unlock(&tg->lut_translock);
-               if (update)
-                       err = tgt_server_data_write(info->fti_env, tg, th);
-       } else {
-               LASSERT(fed->fed_ted.ted_lr_off > 0);
-               err = tgt_client_data_write(info->fti_env, &ofd->ofd_lut, lcd,
-                                   &off, th);
-       }
-
-       RETURN(err);
-}
-
 /* Update last_rcvd records with the latest transaction data */
 int ofd_txn_stop_cb(const struct lu_env *env, struct thandle *txn,
                    void *cookie)
 {
-       struct ofd_device *ofd = cookie;
-       struct ofd_thread_info *info;
+       struct ofd_device       *ofd = cookie;
+       struct ofd_thread_info  *info = ofd_info(env);
+       struct dt_object        *obj;
+       struct tgt_session_info *tsi;
+       bool                     echo_client;
+       int                      rc;
 
        ENTRY;
 
-       info = lu_context_key_get(&env->le_ctx, &ofd_thread_key);
+       if (env->le_ses == NULL || info->fti_exp == NULL)
+               RETURN(0);
+
+       tsi = tgt_ses_info(env);
 
-       if (info->fti_exp == NULL)
-                RETURN(0);
+       echo_client = (tgt_ses_req(tsi) == NULL);
 
-       LASSERT(ofd_exp(info->fti_exp) == ofd);
-       if (info->fti_has_trans) {
+       if (info->fti_has_trans && !echo_client) {
                if (info->fti_mult_trans == 0) {
                        CERROR("More than one transaction "LPU64"\n",
                               info->fti_transno);
@@ -216,38 +134,18 @@ int ofd_txn_stop_cb(const struct lu_env *env, struct thandle *txn,
                info->fti_has_trans = 1;
        }
 
-       spin_lock(&ofd->ofd_lut.lut_translock);
-       if (txn->th_result != 0) {
-               if (info->fti_transno != 0) {
-                       CERROR("Replay transno "LPU64" failed: rc %d\n",
-                              info->fti_transno, txn->th_result);
-                       info->fti_transno = 0;
-               }
-       } else if (info->fti_transno == 0) {
-               info->fti_transno = ++ofd->ofd_lut.lut_last_transno;
-       } else {
-               /* should be replay */
-               if (info->fti_transno > ofd->ofd_lut.lut_last_transno)
-                       ofd->ofd_lut.lut_last_transno = info->fti_transno;
-       }
-       spin_unlock(&ofd->ofd_lut.lut_translock);
-
        /** VBR: set new versions */
-       if (txn->th_result == 0 && info->fti_obj != NULL) {
-               dt_version_set(env, ofd_object_child(info->fti_obj),
-                              info->fti_transno, txn);
-               info->fti_obj = NULL;
-       }
-
-       /* filling reply data */
-       CDEBUG(D_INODE, "transno = %llu, last_committed = %llu\n",
-              info->fti_transno, ofd_obd(ofd)->obd_last_committed);
-
-       /* if can't add callback, do sync write */
-       txn->th_sync |= !!tgt_last_commit_cb_add(txn, &ofd->ofd_lut,
-                                                info->fti_exp,
-                                                info->fti_transno);
-
-       return ofd_last_rcvd_update(info, txn);
+       if (info->fti_obj != NULL)
+               obj = ofd_object_child(info->fti_obj);
+       else
+               obj = NULL;
+
+       if (unlikely(echo_client)) /* echo client special case */
+               rc = tgt_last_rcvd_update_echo(env, &ofd->ofd_lut, obj, txn,
+                                              tsi->tsi_exp);
+       else
+               rc = tgt_last_rcvd_update(env, &ofd->ofd_lut, obj, 0, txn,
+                                         tgt_ses_req(tsi));
+       RETURN(rc);
 }