Whamcloud - gitweb
- fixed using not initialized ctxt with pop_ctxt() in mds_lock_and_check_slave()
[fs/lustre-release.git] / lustre / mds / mds_lmv.c
index 2093a19..0287b11 100644 (file)
@@ -1153,7 +1153,14 @@ int mds_lock_and_check_slave(int offset, struct ptlrpc_request *req,
         }
         cleanup_phase = 1;
 
-        LASSERT(S_ISDIR(dentry->d_inode->i_mode));
+        /* 
+         * handling the case when remote MDS checks if dir is empty before
+         * rename. But it also does it for all entries, because inode is stored
+         * here and remote MDS does not know if rename point to dir or to reg
+         * file. So we check it here.
+         */
+       if (!S_ISDIR(dentry->d_inode->i_mode))
+               GOTO(cleanup, rc = 0);
 
         rc = mds_init_ucred(&uc, rsd);
         if (rc) {
@@ -1162,11 +1169,10 @@ int mds_lock_and_check_slave(int offset, struct ptlrpc_request *req,
         }
 
         push_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
+       rc = mds_is_dir_empty(obd, dentry) ? 0 : -ENOTEMPTY;
+        pop_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
 
-        rc = 0;
-        if (!mds_is_dir_empty(obd, dentry))
-                rc = -ENOTEMPTY;
-
+        mds_exit_ucred(&uc);
         EXIT;
 cleanup:
         switch(cleanup_phase) {
@@ -1174,8 +1180,6 @@ cleanup:
                 if (rc)
                         ldlm_lock_decref(lockh, LCK_EX);
                 l_dput(dentry);
-                pop_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
-                mds_exit_ucred(&uc);
         default:
                 break;
         }