Whamcloud - gitweb
LU-3670 mdt: cancel MDS_INODELOCK_XATTR on MDS updates 86/7186/3
authorAndrew Perepechko <andrew_perepechko@xyratex.com>
Wed, 31 Jul 2013 00:23:20 +0000 (04:23 +0400)
committerOleg Drokin <oleg.drokin@intel.com>
Thu, 26 Sep 2013 19:46:51 +0000 (19:46 +0000)
In some cases, MDS updates extended attributes
on its own rather than on a client request.
MDS_INODELOCK_XATTR should be taken for this purpose.

Signed-off-by: Andrew Perepechko <andrew_perepechko@xyratex.com>
Change-Id: I8d5e947cc05ce5f25c8f128b01ab7458636b55ba
Reviewed-on: http://review.whamcloud.com/7186
Tested-by: Hudson
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Reviewed-by: wangdi <di.wang@intel.com>
lustre/mdt/mdt_handler.c
lustre/mdt/mdt_hsm.c
lustre/mdt/mdt_open.c
lustre/mdt/mdt_reint.c
lustre/tests/sanityn.sh

index 6044ea3..3ac51d7 100644 (file)
@@ -1116,13 +1116,13 @@ int mdt_swap_layouts(struct mdt_thread_info *info)
        lh2 = &info->mti_lh[MDT_LH_OLD];
        mdt_lock_reg_init(lh2, LCK_EX);
 
-       rc = mdt_object_lock(info, o1, lh1, MDS_INODELOCK_LAYOUT,
-                            MDT_LOCAL_LOCK);
+       rc = mdt_object_lock(info, o1, lh1, MDS_INODELOCK_LAYOUT |
+                            MDS_INODELOCK_XATTR, MDT_LOCAL_LOCK);
        if (rc < 0)
                GOTO(put, rc);
 
-       rc = mdt_object_lock(info, o2, lh2, MDS_INODELOCK_LAYOUT,
-                            MDT_LOCAL_LOCK);
+       rc = mdt_object_lock(info, o2, lh2, MDS_INODELOCK_LAYOUT |
+                            MDS_INODELOCK_XATTR, MDT_LOCAL_LOCK);
        if (rc < 0)
                GOTO(unlock1, rc);
 
index 510c737..a7a39dc 100644 (file)
@@ -235,8 +235,8 @@ int mdt_hsm_state_set(struct mdt_thread_info *info)
 
        lh = &info->mti_lh[MDT_LH_CHILD];
        mdt_lock_reg_init(lh, LCK_PW);
-       rc = mdt_object_lock(info, obj, lh, MDS_INODELOCK_LOOKUP,
-                            MDT_LOCAL_LOCK);
+       rc = mdt_object_lock(info, obj, lh, MDS_INODELOCK_LOOKUP |
+                            MDS_INODELOCK_XATTR, MDT_LOCAL_LOCK);
        if (rc)
                RETURN(rc);
 
index 947023c..0cb4d93 100644 (file)
@@ -2089,22 +2089,25 @@ static int mdt_hsm_release(struct mdt_thread_info *info, struct mdt_object *o,
        ma->ma_hsm.mh_flags |= HS_RELEASED;
        lustre_hsm2buf(buf->lb_buf, &ma->ma_hsm);
        ma->ma_hsm.mh_flags &= ~HS_RELEASED;
+
+       mdt_lock_reg_init(lh, LCK_EX);
+       rc = mdt_object_lock(info, o, lh, MDS_INODELOCK_LAYOUT |
+                            MDS_INODELOCK_XATTR, MDT_LOCAL_LOCK);
+       if (rc != 0)
+               GOTO(out_close, rc);
+
        rc = mo_xattr_set(info->mti_env, mdt_object_child(orphan), buf,
                          XATTR_NAME_HSM, 0);
-       if (rc < 0)
-               GOTO(out_close, rc);
 
-       mdt_lock_reg_init(lh, LCK_EX);
-       rc = mdt_object_lock(info, o, lh, MDS_INODELOCK_LAYOUT, MDT_LOCAL_LOCK);
-       if (rc == 0) {
+       if (rc == 0)
                /* Swap layout with orphan object */
                rc = mo_swap_layouts(info->mti_env, mdt_object_child(o),
                                     mdt_object_child(orphan),
                                     SWAP_LAYOUTS_MDS_HSM);
 
-               /* Release exclusive LL */
-               mdt_object_unlock(info, o, lh, 1);
-       }
+       /* Release exclusive LL */
+       mdt_object_unlock(info, o, lh, 1);
+
        EXIT;
 
 out_close:
index a1bd60b..909091c 100644 (file)
@@ -469,14 +469,21 @@ int mdt_add_dirty_flag(struct mdt_thread_info *info, struct mdt_object *mo,
        /* If an up2date copy exists in the backend, add dirty flag */
        if ((ma->ma_valid & MA_HSM) && (ma->ma_hsm.mh_flags & HS_EXISTS)
            && !(ma->ma_hsm.mh_flags & (HS_DIRTY|HS_RELEASED))) {
+               struct mdt_lock_handle  *lh = &info->mti_lh[MDT_LH_CHILD];
 
                ma->ma_hsm.mh_flags |= HS_DIRTY;
+
+               mdt_lock_reg_init(lh, LCK_PW);
+               rc = mdt_object_lock(info, mo, lh, MDS_INODELOCK_XATTR,
+                                    MDT_LOCAL_LOCK);
+               if (rc != 0)
+                       RETURN(rc);
+
                rc = mdt_hsm_attr_set(info, mo, &ma->ma_hsm);
-               if (rc) {
+               if (rc)
                        CERROR("file attribute change error for "DFID": %d\n",
                                PFID(mdt_object_fid(mo)), rc);
-                       RETURN(rc);
-               }
+               mdt_object_unlock(info, mo, lh, rc);
        }
 
        RETURN(rc);
@@ -943,8 +950,8 @@ static int mdt_reint_link(struct mdt_thread_info *info,
                GOTO(out_unlock_parent, rc = -EXDEV);
        }
 
-        rc = mdt_object_lock(info, ms, lhs, MDS_INODELOCK_UPDATE,
-                            MDT_CROSS_LOCK);
+       rc = mdt_object_lock(info, ms, lhs, MDS_INODELOCK_UPDATE |
+                            MDS_INODELOCK_XATTR, MDT_CROSS_LOCK);
         if (rc != 0) {
                 mdt_object_put(info->mti_env, ms);
                 GOTO(out_unlock_parent, rc);
@@ -1235,8 +1242,8 @@ static int mdt_reint_rename(struct mdt_thread_info *info,
 
         lh_oldp = &info->mti_lh[MDT_LH_OLD];
         mdt_lock_reg_init(lh_oldp, LCK_EX);
-        rc = mdt_object_lock(info, mold, lh_oldp, MDS_INODELOCK_LOOKUP,
-                             MDT_CROSS_LOCK);
+       rc = mdt_object_lock(info, mold, lh_oldp, MDS_INODELOCK_LOOKUP |
+                            MDS_INODELOCK_XATTR, MDT_CROSS_LOCK);
         if (rc != 0) {
                 mdt_object_put(info->mti_env, mold);
                 GOTO(out_unlock_target, rc);
index 63321ae..21f56fa 100644 (file)
@@ -2479,6 +2479,8 @@ run_test 71 "correct file map just after write operation is finished"
 
 test_72() {
        local p="$TMP/sanityN-$TESTNAME.parameters"
+       local tlink1
+       local tlink2
        save_lustre_params client "llite.*.xattr_cache" > $p
        lctl set_param llite.*.xattr_cache 1 ||
                { skip "xattr cache is not supported"; return 0; }
@@ -2492,6 +2494,14 @@ test_72() {
                error "setfattr2 failed"
        getfattr -n user.attr1 $DIR1/$tfile | grep value2 ||
                error "getfattr2 failed"
+
+       # check that trusted.link is consistent
+       tlink1=$(getfattr -n trusted.link $DIR1/$tfile | md5sum)
+       ln $DIR2/$tfile $DIR2/$tfile-2 || error "failed to link"
+       tlink2=$(getfattr -n trusted.link $DIR1/$tfile | md5sum)
+       echo "$tlink1 $tlink2"
+       [ "$tlink1" = "$tlink2" ] && error "trusted.link should have changed!"
+
        rm -f $DIR2/$tfile
 
        restore_lustre_params < $p