Whamcloud - gitweb
LU-10660 mdt: revoke lease lock for truncate 93/33093/6
authorJian Yu <yujian@whamcloud.com>
Mon, 10 Sep 2018 05:10:30 +0000 (22:10 -0700)
committerOleg Drokin <green@whamcloud.com>
Sun, 16 Sep 2018 06:41:42 +0000 (06:41 +0000)
Lustre lease lock is usually used to protect file data
against concurrent access. Open lock used on MDT side
is for this purpose. However, truncate will change
file data but it doesn't revoke lease lock.

This patch fixes the issue by acquiring open sem,
checking lease count and revoking lease if there exists
any pending lease on the file.

Change-Id: Ia55457c6d7e1e76f98b41feef39577822304513b
Signed-off-by: Jian Yu <yujian@whamcloud.com>
Reviewed-on: https://review.whamcloud.com/33093
Tested-by: Jenkins
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Jinshan Xiong <jinshan.xiong@gmail.com>
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/include/uapi/linux/lustre/lustre_idl.h
lustre/llite/llite_lib.c
lustre/mdt/mdt_lib.c
lustre/mdt/mdt_reint.c

index 44daeef..8d7b58c 100644 (file)
@@ -1924,6 +1924,7 @@ enum mds_op_bias {
        MDS_CLOSE_LAYOUT_MERGE  = 1 << 15,
        MDS_CLOSE_RESYNC_DONE   = 1 << 16,
        MDS_CLOSE_LAYOUT_SPLIT  = 1 << 17,
+       MDS_TRUNC_KEEP_LEASE    = 1 << 18,
 };
 
 #define MDS_CLOSE_INTENT (MDS_HSM_RELEASE | MDS_CLOSE_LAYOUT_SWAP |         \
index b73aa4d..df8eca9 100644 (file)
@@ -1683,6 +1683,13 @@ int ll_setattr_raw(struct dentry *dentry, struct iattr *attr, bool hsm_import)
                ll_file_clear_flag(lli, LLIF_DATA_MODIFIED);
        }
 
+       if (attr->ia_valid & ATTR_FILE) {
+               struct ll_file_data *fd = LUSTRE_FPRIVATE(attr->ia_file);
+
+               if (fd->fd_lease_och)
+                       op_data->op_bias |= MDS_TRUNC_KEEP_LEASE;
+       }
+
        op_data->op_attr = *attr;
 
        rc = ll_md_setattr(dentry, op_data);
index 7d58428..d929b67 100644 (file)
@@ -1110,13 +1110,8 @@ static int mdt_setattr_unpack_rec(struct mdt_thread_info *info)
        la->la_mtime = rec->sa_mtime;
        ma->ma_valid = MA_INODE;
 
-       if (rec->sa_bias & MDS_DATA_MODIFIED)
-               ma->ma_attr_flags |= MDS_DATA_MODIFIED;
-       else
-               ma->ma_attr_flags &= ~MDS_DATA_MODIFIED;
-
-       ma->ma_attr_flags &= ~MDS_CLOSE_INTENT;
-       ma->ma_attr_flags |= rec->sa_bias & MDS_CLOSE_INTENT;
+       ma->ma_attr_flags |= rec->sa_bias & (MDS_CLOSE_INTENT |
+                               MDS_DATA_MODIFIED | MDS_TRUNC_KEEP_LEASE);
        RETURN(0);
 }
 
index d2dfd3f..ff7718c 100644 (file)
@@ -692,6 +692,28 @@ static int mdt_reint_setattr(struct mdt_thread_info *info,
        if (mdt_object_remote(mo))
                GOTO(out_put, rc = -EREMOTE);
 
+       /* revoke lease lock if size is going to be changed */
+       if (unlikely(ma->ma_attr.la_valid & LA_SIZE &&
+                    !(ma->ma_attr_flags & MDS_TRUNC_KEEP_LEASE) &&
+                    atomic_read(&mo->mot_lease_count) > 0)) {
+               down_read(&mo->mot_open_sem);
+
+               if (atomic_read(&mo->mot_lease_count) > 0) { /* lease exists */
+                       lhc = &info->mti_lh[MDT_LH_LOCAL];
+                       mdt_lock_reg_init(lhc, LCK_CW);
+
+                       rc = mdt_object_lock(info, mo, lhc, MDS_INODELOCK_OPEN);
+                       if (rc != 0) {
+                               up_read(&mo->mot_open_sem);
+                               GOTO(out_put, rc);
+                       }
+
+                       /* revoke lease lock */
+                       mdt_object_unlock(info, mo, lhc, 1);
+               }
+               up_read(&mo->mot_open_sem);
+       }
+
        if (ma->ma_attr.la_valid & LA_SIZE || rr->rr_flags & MRF_OPEN_TRUNC) {
                /* Check write access for the O_TRUNC case */
                if (mdt_write_read(mo) < 0)