From: Jian Yu Date: Mon, 10 Sep 2018 05:10:30 +0000 (-0700) Subject: LU-10660 mdt: revoke lease lock for truncate X-Git-Tag: 2.11.56~82 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=e4c168165df201f8800118a4913bbb02e0bad3c1;p=fs%2Flustre-release.git LU-10660 mdt: revoke lease lock for truncate 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 Reviewed-on: https://review.whamcloud.com/33093 Tested-by: Jenkins Reviewed-by: Andreas Dilger Reviewed-by: Jinshan Xiong Tested-by: Maloo Reviewed-by: Oleg Drokin --- diff --git a/lustre/include/uapi/linux/lustre/lustre_idl.h b/lustre/include/uapi/linux/lustre/lustre_idl.h index 44daeef..8d7b58c 100644 --- a/lustre/include/uapi/linux/lustre/lustre_idl.h +++ b/lustre/include/uapi/linux/lustre/lustre_idl.h @@ -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 | \ diff --git a/lustre/llite/llite_lib.c b/lustre/llite/llite_lib.c index b73aa4d..df8eca9 100644 --- a/lustre/llite/llite_lib.c +++ b/lustre/llite/llite_lib.c @@ -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); diff --git a/lustre/mdt/mdt_lib.c b/lustre/mdt/mdt_lib.c index 7d58428..d929b67 100644 --- a/lustre/mdt/mdt_lib.c +++ b/lustre/mdt/mdt_lib.c @@ -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); } diff --git a/lustre/mdt/mdt_reint.c b/lustre/mdt/mdt_reint.c index d2dfd3f..ff7718c 100644 --- a/lustre/mdt/mdt_reint.c +++ b/lustre/mdt/mdt_reint.c @@ -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)