Whamcloud - gitweb
LU-3544 fid: do open-by-fid by default
[fs/lustre-release.git] / lustre / mdt / mdt_open.c
index fd54c2a..d35526e 100644 (file)
@@ -1491,9 +1491,14 @@ int mdt_open_by_fid_lock(struct mdt_thread_info *info, struct ldlm_reply *rep,
        if (flags & MDS_OPEN_RELEASE && !mdt_hsm_release_allow(ma))
                GOTO(out, rc = -EPERM);
 
-       rc = mdt_object_open_lock(info, o, lhc, &ibits);
-        if (rc)
-                GOTO(out_unlock, rc);
+       rc = mdt_check_resent_lock(info, o, lhc);
+       if (rc < 0) {
+               GOTO(out, rc);
+       } else if (rc > 0) {
+               rc = mdt_object_open_lock(info, o, lhc, &ibits);
+               if (rc)
+                       GOTO(out_unlock, rc);
+       }
 
         if (ma->ma_valid & MA_PFID) {
                 parent = mdt_object_find(env, mdt, &ma->ma_pfid);
@@ -1660,23 +1665,16 @@ int mdt_reint_open(struct mdt_thread_info *info, struct mdt_lock_handle *lhc)
                        GOTO(out, result = -EFAULT);
                }
                CDEBUG(D_INFO, "No object(1), continue as regular open.\n");
-       } else if ((!lu_name_is_valid(&rr->rr_name) &&
-                   (create_flags & MDS_OPEN_LOCK)) ||
-                  (create_flags & MDS_OPEN_BY_FID)) {
+       } else if (create_flags & (MDS_OPEN_BY_FID | MDS_OPEN_LOCK)) {
+               /*
+                * MDS_OPEN_LOCK is checked for backward compatibility with 2.1
+                * client.
+                */
                result = mdt_open_by_fid_lock(info, ldlm_rep, lhc);
-               /* If result is 0 then open by FID has found the file
-                * and there is nothing left for us to do here.  More
-                * generally if it is anything other than -ENOENT or
-                * -EREMOTE then we return that now.  If -ENOENT and
-                * MDS_OPEN_CREAT is set then we must create the file
-                * below.  If -EREMOTE then we need to return a LOOKUP
-                * lock to the client, which we do below.  Hence this
-                * odd looking condition.  See LU-2523. */
-               if (!(result == -ENOENT && (create_flags & MDS_OPEN_CREAT)) &&
-                   result != -EREMOTE)
-                       GOTO(out, result);
-
-               CDEBUG(D_INFO, "No object(2), continue as regular open.\n");
+               if (result < 0)
+                       CDEBUG(D_INFO, "no object for "DFID": %d\n",
+                              PFID(rr->rr_fid2), result);
+               GOTO(out, result);
        }
 
         if (OBD_FAIL_CHECK(OBD_FAIL_MDS_OPEN_PACK))
@@ -1811,22 +1809,10 @@ int mdt_reint_open(struct mdt_thread_info *info, struct mdt_lock_handle *lhc)
                          */
                         LASSERT(lhc != NULL);
 
-                        if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
-                                struct ldlm_lock *lock;
-
-                                LASSERT(msg_flags & MSG_RESENT);
-
-                                lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
-                                if (!lock) {
-                                        CERROR("Invalid lock handle "LPX64"\n",
-                                               lhc->mlh_reg_lh.cookie);
-                                        LBUG();
-                                }
-                                LASSERT(fid_res_name_eq(mdt_object_fid(child),
-                                                        &lock->l_resource->lr_name));
-                                LDLM_LOCK_PUT(lock);
-                                rc = 0;
-                        } else {
+                       rc = mdt_check_resent_lock(info, child, lhc);
+                       if (rc < 0) {
+                               GOTO(out_child, result = rc);
+                       } else if (rc > 0) {
                                 mdt_lock_handle_init(lhc);
                                 mdt_lock_reg_init(lhc, LCK_PR);
 
@@ -1856,9 +1842,12 @@ int mdt_reint_open(struct mdt_thread_info *info, struct mdt_lock_handle *lhc)
                }
         }
 
-       if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
+       rc = mdt_check_resent_lock(info, child, lhc);
+       if (rc < 0) {
+               GOTO(out_child, result = rc);
+       } else if (rc == 0) {
                /* the open lock might already be gotten in
-                * mdt_intent_fixup_resent */
+                * ldlm_handle_enqueue() */
                LASSERT(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT);
                if (create_flags & MDS_OPEN_LOCK)
                        mdt_set_disposition(info, ldlm_rep, DISP_OPEN_LOCK);