Whamcloud - gitweb
LU-12624 lod: alloc dir stripes by QoS
[fs/lustre-release.git] / lustre / mdt / mdt_reint.c
index b0cc3a2..81c148f 100644 (file)
@@ -250,17 +250,25 @@ static int mdt_unlock_slaves(struct mdt_thread_info *mti,
 static inline int mdt_object_striped(struct mdt_thread_info *mti,
                                     struct mdt_object *obj)
 {
+       struct lu_device *bottom_dev;
+       struct lu_object *bottom_obj;
        int rc;
 
        if (!S_ISDIR(obj->mot_header.loh_attr))
                return 0;
 
-       rc = mo_xattr_get(mti->mti_env, mdt_object_child(obj), &LU_BUF_NULL,
+       /* getxattr from bottom obj to avoid reading in shard FIDs */
+       bottom_dev = dt2lu_dev(mti->mti_mdt->mdt_bottom);
+       bottom_obj = lu_object_find_slice(mti->mti_env, bottom_dev,
+                                         mdt_object_fid(obj), NULL);
+       if (IS_ERR(bottom_obj))
+               return PTR_ERR(bottom_obj);
+
+       rc = dt_xattr_get(mti->mti_env, lu2dt(bottom_obj), &LU_BUF_NULL,
                          XATTR_NAME_LMV);
-       if (rc <= 0)
-               return rc == -ENODATA ? 0 : rc;
+       lu_object_put(mti->mti_env, bottom_obj);
 
-       return 1;
+       return (rc > 0) ? 1 : (rc == -ENODATA) ? 0 : rc;
 }
 
 /**
@@ -355,8 +363,8 @@ static int mdt_create(struct mdt_thread_info *info)
        int rc;
        ENTRY;
 
-       DEBUG_REQ(D_INODE, mdt_info_req(info), "Create  ("DNAME"->"DFID") "
-                 "in "DFID,
+       DEBUG_REQ(D_INODE, mdt_info_req(info),
+                 "Create ("DNAME"->"DFID") in "DFID,
                  PNAME(&rr->rr_name), PFID(rr->rr_fid2), PFID(rr->rr_fid1));
 
        if (!fid_is_md_operative(rr->rr_fid1))
@@ -641,6 +649,8 @@ static int mdt_reint_setattr(struct mdt_thread_info *info,
        if (info->mti_dlm_req)
                ldlm_request_cancel(req, info->mti_dlm_req, 0, LATF_SKIP);
 
+       OBD_RACE(OBD_FAIL_PTLRPC_RESEND_RACE);
+
        repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
        mo = mdt_object_find(info->mti_env, mdt, rr->rr_fid1);
        if (IS_ERR(mo))
@@ -681,13 +691,23 @@ static int mdt_reint_setattr(struct mdt_thread_info *info,
 
                /* LU-10286: compatibility check for FLR.
                 * Please check the comment in mdt_finish_open() for details */
-               if (!exp_connect_flr(info->mti_exp)) {
+               if (!exp_connect_flr(info->mti_exp) ||
+                   !exp_connect_overstriping(info->mti_exp)) {
                        rc = mdt_big_xattr_get(info, mo, XATTR_NAME_LOV);
                        if (rc < 0 && rc != -ENODATA)
                                GOTO(out_put, rc);
 
-                       if (rc > 0 && mdt_lmm_is_flr(info->mti_big_lmm))
-                               GOTO(out_put, rc = -EOPNOTSUPP);
+                       if (!exp_connect_flr(info->mti_exp)) {
+                               if (rc > 0 &&
+                                   mdt_lmm_is_flr(info->mti_big_lmm))
+                                       GOTO(out_put, rc = -EOPNOTSUPP);
+                       }
+
+                       if (!exp_connect_overstriping(info->mti_exp)) {
+                               if (rc > 0 &&
+                                   mdt_lmm_is_overstriping(info->mti_big_lmm))
+                                       GOTO(out_put, rc = -EOPNOTSUPP);
+                       }
                }
 
                /* For truncate, the file size sent from client
@@ -718,6 +738,8 @@ static int mdt_reint_setattr(struct mdt_thread_info *info,
                struct lu_buf *buf = &info->mti_buf;
                struct lu_ucred *uc = mdt_ucred(info);
                struct mdt_lock_handle *lh;
+               const char *name;
+               __u64 lockpart = MDS_INODELOCK_XATTR;
 
                /* reject if either remote or striped dir is disabled */
                if (ma->ma_valid & MA_LMV) {
@@ -731,27 +753,35 @@ static int mdt_reint_setattr(struct mdt_thread_info *info,
                                GOTO(out_put, rc = -EPERM);
                }
 
+               if (!S_ISDIR(lu_object_attr(&mo->mot_obj)))
+                       GOTO(out_put, rc = -ENOTDIR);
+
                if (ma->ma_attr.la_valid != 0)
                        GOTO(out_put, rc = -EPROTO);
 
-               lh = &info->mti_lh[MDT_LH_PARENT];
-               mdt_lock_reg_init(lh, LCK_PW);
-
-               rc = mdt_object_lock(info, mo, lh, MDS_INODELOCK_XATTR);
-               if (rc != 0)
-                       GOTO(out_put, rc);
-
                if (ma->ma_valid & MA_LOV) {
                        buf->lb_buf = ma->ma_lmm;
                        buf->lb_len = ma->ma_lmm_size;
+                       name = XATTR_NAME_LOV;
                } else {
-                       buf->lb_buf = ma->ma_lmv;
+                       struct lmv_user_md *lmu = &ma->ma_lmv->lmv_user_md;
+
+                       buf->lb_buf = lmu;
                        buf->lb_len = ma->ma_lmv_size;
+                       name = XATTR_NAME_DEFAULT_LMV;
+                       /* force client to update dir default layout */
+                       lockpart |= MDS_INODELOCK_LOOKUP;
                }
+
+               lh = &info->mti_lh[MDT_LH_PARENT];
+               mdt_lock_reg_init(lh, LCK_PW);
+
+               rc = mdt_object_lock(info, mo, lh, lockpart);
+               if (rc != 0)
+                       GOTO(out_put, rc);
+
                rc = mo_xattr_set(info->mti_env, mdt_object_child(mo), buf,
-                                 (ma->ma_valid & MA_LOV) ?
-                                       XATTR_NAME_LOV : XATTR_NAME_DEFAULT_LMV,
-                                 0);
+                                 name, 0);
 
                mdt_object_unlock(info, mo, lh, rc);
                if (rc)
@@ -844,7 +874,7 @@ static int mdt_reint_unlink(struct mdt_thread_info *info,
        struct mdt_lock_handle *child_lh;
        struct ldlm_enqueue_info *einfo = &info->mti_einfo[0];
        __u64 lock_ibits;
-       bool cos_incompat = false, discard = false;
+       bool cos_incompat = false;
        int no_name = 0;
        int rc;
 
@@ -921,7 +951,7 @@ relock:
        if (!cos_incompat) {
                rc = mdt_object_striped(info, mc);
                if (rc < 0)
-                       GOTO(unlock_parent, rc);
+                       GOTO(put_child, rc);
 
                cos_incompat = rc;
                if (cos_incompat) {
@@ -1025,8 +1055,8 @@ relock:
                rc = mdt_attr_get_complex(info, mc, ma);
                if (rc)
                        GOTO(out_stat, rc);
-       } else {
-               discard = mdt_dom_check_for_discard(info, mc);
+       } else if (mdt_dom_check_for_discard(info, mc)) {
+               mdt_dom_discard_data(info, mc);
        }
        mdt_handle_last_unlink(info, mc, ma);
 
@@ -1060,13 +1090,7 @@ unlock_parent:
        mdt_object_unlock(info, mp, parent_lh, rc);
 put_parent:
        mdt_object_put(info->mti_env, mp);
-
-       /* discard is just a PW DOM lock to drop the data on a client
-        * no need to keep objects being get and locked, do that after all.
-        */
-       if (discard)
-               mdt_dom_discard_data(info, child_fid);
-
+       CFS_RACE_WAKEUP(OBD_FAIL_OBD_ZERO_NLINK_RACE);
         return rc;
 }
 
@@ -1094,6 +1118,11 @@ static int mdt_reint_link(struct mdt_thread_info *info,
        if (OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_LINK))
                RETURN(err_serious(-ENOENT));
 
+       if (OBD_FAIL_PRECHECK(OBD_FAIL_PTLRPC_RESEND_RACE)) {
+               req->rq_no_reply = 1;
+               RETURN(err_serious(-ENOENT));
+       }
+
        if (info->mti_dlm_req)
                ldlm_request_cancel(req, info->mti_dlm_req, 0, LATF_SKIP);
 
@@ -1639,6 +1668,9 @@ static int mdt_lock_remote_slaves(struct mdt_thread_info *info,
        for (i = 0; i < le32_to_cpu(lmv->lmv_stripe_count); i++) {
                fid_le_to_cpu(fid, &lmv->lmv_stripe_fids[i]);
 
+               if (!fid_is_sane(fid))
+                       continue;
+
                slave = mdt_object_find(info->mti_env, mdt, fid);
                if (IS_ERR(slave))
                        GOTO(out, rc = PTR_ERR(slave));
@@ -1915,7 +1947,7 @@ static int mdd_migrate_close(struct mdt_thread_info *info,
         * cancelled, it's okay to cancel it now as we've held mot_open_sem.
         */
        ldlm_lock_cancel(lease);
-       ldlm_reprocess_all(lease->l_resource);
+       ldlm_reprocess_all(lease->l_resource, lease);
        LDLM_LOCK_PUT(lease);
 
 close:
@@ -2139,7 +2171,11 @@ unlock_open_sem:
        if (open_sem_locked)
                up_write(&sobj->mot_open_sem);
 unlock_links:
-       mdt_unlock_list(info, &link_locks, do_sync ?: rc);
+       /* if we've got too many locks to save into RPC,
+        * then just commit before the locks are released */
+       if (!rc && do_sync)
+               mdt_device_sync(env, mdt);
+       mdt_unlock_list(info, &link_locks, do_sync ? 1 : rc);
 put_source:
        mdt_object_put(env, sobj);
        mdt_object_put(env, spobj);
@@ -2152,9 +2188,6 @@ unlock_rename:
        if (lustre_handle_is_used(&rename_lh))
                mdt_rename_unlock(&rename_lh);
 
-       if (!rc && do_sync)
-               mdt_device_sync(env, mdt);
-
        return rc;
 }
 
@@ -2273,20 +2306,10 @@ static int mdt_rename_determine_lock_order(struct mdt_thread_info *info,
  * 2 - srcdir child; 3 - tgtdir child.
  * Update on disk version of srcdir child.
  */
-/**
- * For DNE phase I, only these renames are allowed
- *     mv src_p/src_c tgt_p/tgt_c
- * 1. src_p/src_c/tgt_p/tgt_c are in the same MDT.
- * 2. src_p and tgt_p are same directory, and tgt_c does not
- *    exists. In this case, all of modification will happen
- *    in the MDT where ithesource parent is, only one remote
- *    update is needed, i.e. set c_time/m_time on the child.
- *    And tgt_c will be still in the same MDT as the original
- *    src_c.
- */
 static int mdt_reint_rename(struct mdt_thread_info *info,
                            struct mdt_lock_handle *unused)
 {
+       struct mdt_device *mdt = info->mti_mdt;
        struct mdt_reint_record *rr = &info->mti_rr;
        struct md_attr *ma = &info->mti_attr;
        struct ptlrpc_request *req = mdt_info_req(info);
@@ -2302,8 +2325,8 @@ static int mdt_reint_rename(struct mdt_thread_info *info,
        struct lu_fid *old_fid = &info->mti_tmp_fid1;
        struct lu_fid *new_fid = &info->mti_tmp_fid2;
        __u64 lock_ibits;
-       bool reverse = false;
-       bool cos_incompat, discard = false;
+       bool reverse = false, discard = false;
+       bool cos_incompat;
        int rc;
        ENTRY;
 
@@ -2318,25 +2341,10 @@ static int mdt_reint_rename(struct mdt_thread_info *info,
            !fid_is_md_operative(rr->rr_fid2))
                RETURN(-EPERM);
 
-       /*
-        * Note: do not enqueue rename lock for replay request, because
-        * if other MDT holds rename lock, but being blocked to wait for
-        * this MDT to finish its recovery, and the failover MDT can not
-        * get rename lock, which will cause deadlock.
-        */
-       if (!req_is_replay(req)) {
-               rc = mdt_rename_lock(info, &rename_lh);
-               if (rc != 0) {
-                       CERROR("%s: can't lock FS for rename: rc = %d\n",
-                              mdt_obd_name(info->mti_mdt), rc);
-                       RETURN(rc);
-               }
-       }
-
        /* find both parents. */
        msrcdir = mdt_parent_find_check(info, rr->rr_fid1, 0);
        if (IS_ERR(msrcdir))
-               GOTO(out_unlock_rename, rc = PTR_ERR(msrcdir));
+               RETURN(PTR_ERR(msrcdir));
 
        OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RENAME3, 5);
 
@@ -2349,9 +2357,36 @@ static int mdt_reint_rename(struct mdt_thread_info *info,
                        GOTO(out_put_srcdir, rc = PTR_ERR(mtgtdir));
        }
 
+       /*
+        * Note: do not enqueue rename lock for replay request, because
+        * if other MDT holds rename lock, but being blocked to wait for
+        * this MDT to finish its recovery, and the failover MDT can not
+        * get rename lock, which will cause deadlock.
+        */
+       if (!req_is_replay(req)) {
+               /*
+                * Normally rename RPC is handled on the MDT with the target
+                * directory (if target exists, it's on the MDT with the
+                * target), if the source directory is remote, it's a hint that
+                * source is remote too (this may not be true, but it won't
+                * cause any issue), return -EXDEV early to avoid taking
+                * rename_lock.
+                */
+               if (!mdt->mdt_enable_remote_rename &&
+                   mdt_object_remote(msrcdir))
+                       GOTO(out_put_tgtdir, rc = -EXDEV);
+
+               rc = mdt_rename_lock(info, &rename_lh);
+               if (rc != 0) {
+                       CERROR("%s: can't lock FS for rename: rc = %d\n",
+                              mdt_obd_name(mdt), rc);
+                       GOTO(out_put_tgtdir, rc);
+               }
+       }
+
        rc = mdt_rename_determine_lock_order(info, msrcdir, mtgtdir);
        if (rc < 0)
-               GOTO(out_put_tgtdir, rc);
+               GOTO(out_unlock_rename, rc);
 
        reverse = rc;
 
@@ -2376,7 +2411,7 @@ relock:
                rc = mdt_object_lock_save(info, mtgtdir, lh_tgtdirp, 1,
                                          cos_incompat);
                if (rc)
-                       GOTO(out_put_tgtdir, rc);
+                       GOTO(out_unlock_rename, rc);
 
                OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RENAME, 5);
 
@@ -2384,20 +2419,21 @@ relock:
                                          cos_incompat);
                if (rc != 0) {
                        mdt_object_unlock(info, mtgtdir, lh_tgtdirp, rc);
-                       GOTO(out_put_tgtdir, rc);
+                       GOTO(out_unlock_rename, rc);
                }
        } else {
                rc = mdt_object_lock_save(info, msrcdir, lh_srcdirp, 0,
                                          cos_incompat);
                if (rc)
-                       GOTO(out_put_tgtdir, rc);
+                       GOTO(out_unlock_rename, rc);
 
                OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RENAME, 5);
 
                if (mtgtdir != msrcdir) {
                        rc = mdt_object_lock_save(info, mtgtdir, lh_tgtdirp, 1,
                                                  cos_incompat);
-               } else if (lh_srcdirp->mlh_pdo_hash !=
+               } else if (!mdt_object_remote(mtgtdir) &&
+                          lh_srcdirp->mlh_pdo_hash !=
                           lh_tgtdirp->mlh_pdo_hash) {
                        rc = mdt_pdir_hash_lock(info, lh_tgtdirp, mtgtdir,
                                                MDS_INODELOCK_UPDATE,
@@ -2406,7 +2442,7 @@ relock:
                }
                if (rc != 0) {
                        mdt_object_unlock(info, msrcdir, lh_srcdirp, rc);
-                       GOTO(out_put_tgtdir, rc);
+                       GOTO(out_unlock_rename, rc);
                }
        }
 
@@ -2436,6 +2472,9 @@ relock:
                GOTO(out_put_old, rc = -ENOENT);
        }
 
+       if (mdt_object_remote(mold) && !mdt->mdt_enable_remote_rename)
+               GOTO(out_put_old, rc = -EXDEV);
+
        /* Check if @mtgtdir is subdir of @mold, before locking child
         * to avoid reverse locking. */
        if (mtgtdir != msrcdir) {
@@ -2610,7 +2649,6 @@ relock:
                        mdt_handle_last_unlink(info, mnew, ma);
                        discard = mdt_dom_check_for_discard(info, mnew);
                }
-
                mdt_rename_counter_tally(info, info->mti_mdt, req,
                                         msrcdir, mtgtdir);
        }
@@ -2621,28 +2659,30 @@ relock:
 out_unlock_old:
        mdt_object_unlock(info, mold, lh_oldp, rc);
 out_put_new:
-       if (mnew != NULL)
+       if (mnew && !discard)
                mdt_object_put(info->mti_env, mnew);
 out_put_old:
        mdt_object_put(info->mti_env, mold);
 out_unlock_parents:
        mdt_object_unlock(info, mtgtdir, lh_tgtdirp, rc);
        mdt_object_unlock(info, msrcdir, lh_srcdirp, rc);
+out_unlock_rename:
+       if (lustre_handle_is_used(&rename_lh))
+               mdt_rename_unlock(&rename_lh);
 out_put_tgtdir:
        mdt_object_put(info->mti_env, mtgtdir);
 out_put_srcdir:
        mdt_object_put(info->mti_env, msrcdir);
-out_unlock_rename:
-       if (lustre_handle_is_used(&rename_lh))
-               mdt_rename_unlock(&rename_lh);
 
-       /* If 'discard' is set then new_fid must exits.
-        * DOM data discard need neither object nor lock,
-        * so do this at the end.
+       /* The DoM discard can be done right in the place above where it is
+        * assigned, meanwhile it is done here after rename unlock due to
+        * compatibility with old clients, for them the discard blocks
+        * the main thread until completion. Check LU-11359 for details.
         */
-       if (discard)
-               mdt_dom_discard_data(info, new_fid);
-
+       if (discard) {
+               mdt_dom_discard_data(info, mnew);
+               mdt_object_put(info->mti_env, mnew);
+       }
        return rc;
 }
 
@@ -2650,17 +2690,18 @@ static int mdt_reint_resync(struct mdt_thread_info *info,
                            struct mdt_lock_handle *lhc)
 {
        struct mdt_reint_record *rr = &info->mti_rr;
-       struct ptlrpc_request   *req = mdt_info_req(info);
-       struct md_attr          *ma = &info->mti_attr;
-       struct mdt_object       *mo;
-       struct ldlm_lock        *lease;
-       struct mdt_body         *repbody;
-       struct md_layout_change  layout = { .mlc_mirror_id = rr->rr_mirror_id };
-       bool                     lease_broken;
-       int                      rc, rc2;
+       struct ptlrpc_request *req = mdt_info_req(info);
+       struct md_attr *ma = &info->mti_attr;
+       struct mdt_object *mo;
+       struct ldlm_lock *lease;
+       struct mdt_body *repbody;
+       struct md_layout_change layout = { .mlc_mirror_id = rr->rr_mirror_id };
+       bool lease_broken;
+       int rc, rc2;
+
        ENTRY;
 
-       DEBUG_REQ(D_INODE, req, DFID": FLR file resync\n", PFID(rr->rr_fid1));
+       DEBUG_REQ(D_INODE, req, DFID", FLR file resync", PFID(rr->rr_fid1));
 
        if (info->mti_dlm_req)
                ldlm_request_cancel(req, info->mti_dlm_req, 0, LATF_SKIP);
@@ -2697,10 +2738,13 @@ static int mdt_reint_resync(struct mdt_thread_info *info,
 
        /* the file has yet opened by anyone else after we took the lease. */
        layout.mlc_opc = MD_LAYOUT_RESYNC;
-       rc = mdt_layout_change(info, mo, &layout);
+       lhc = &info->mti_lh[MDT_LH_LOCAL];
+       rc = mdt_layout_change(info, mo, lhc, &layout);
        if (rc)
                GOTO(out_unlock, rc);
 
+       mdt_object_unlock(info, mo, lhc, 0);
+
        ma->ma_need = MA_INODE;
        ma->ma_valid = 0;
        rc = mdt_attr_get_complex(info, mo, ma);