From a2ae5cef0d7983fc5b8cec4341a2da660e9833ce Mon Sep 17 00:00:00 2001 From: Qian Yingjin Date: Tue, 14 Sep 2021 16:40:03 +0800 Subject: [PATCH] LU-10499 pcc: keep mtime unchange when attach file into PCC Modifying the timestamps of the files for the attach will cause problems for the cache manager, since all files will appear new at the time they are imported into the cache. And that may also confuse applications if the file mtime has changed just because of attach. In this patch, it keeps the file mtime unchanged when attach it into PCC. EX-bug-id: EX-2859 Signed-off-by: Qian Yingjin Change-Id: I26f0c19c7b6cc1af0d62c192931d0042c9614993 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/54424 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Oleg Drokin Reviewed-by: Andreas Dilger Reviewed-by: jsimmons --- lustre/llite/pcc.c | 13 ++++++++----- lustre/tests/sanity-pcc.sh | 30 ++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/lustre/llite/pcc.c b/lustre/llite/pcc.c index 1f112a7..a5a1207 100644 --- a/lustre/llite/pcc.c +++ b/lustre/llite/pcc.c @@ -3364,7 +3364,8 @@ out: /* * Reset uid, gid or size for the PCC copy masked by @valid. */ -static int pcc_inode_reset_iattr(struct dentry *dentry, unsigned int valid, +static int pcc_inode_reset_iattr(struct inode *lustre_inode, + struct dentry *dentry, unsigned int valid, kuid_t uid, kgid_t gid, loff_t size) { struct inode *inode = dentry->d_inode; @@ -3377,6 +3378,7 @@ static int pcc_inode_reset_iattr(struct dentry *dentry, unsigned int valid, attr.ia_uid = uid; attr.ia_gid = gid; attr.ia_size = size; + attr.ia_mtime = inode_get_mtime(lustre_inode); inode_lock(inode); rc = notify_change(&nop_mnt_idmap, dentry, &attr, NULL); @@ -3502,7 +3504,7 @@ int pcc_inode_create_fini(struct inode *inode, struct pcc_create_attach *pca) if (pcci == NULL) GOTO(out_put, rc = -ENOMEM); - rc = pcc_inode_reset_iattr(pcc_dentry, ATTR_UID | ATTR_GID, + rc = pcc_inode_reset_iattr(inode, pcc_dentry, ATTR_UID | ATTR_GID, old_cred->suid, old_cred->sgid, 0); if (rc) GOTO(out_put, rc); @@ -3658,7 +3660,7 @@ static int pcc_attach_data_archive(struct file *file, struct inode *inode, GOTO(out_dentry, rc); } - rc = pcc_inode_reset_iattr(*dentry, ATTR_UID | ATTR_GID, + rc = pcc_inode_reset_iattr(inode, *dentry, ATTR_UID | ATTR_GID, old_cred->uid, old_cred->gid, 0); if (rc) GOTO(out_fput, rc); @@ -3693,8 +3695,9 @@ static int pcc_attach_data_archive(struct file *file, struct inode *inode, * copy after copy data. Otherwise, it may get wrong file size after * re-attach a file. See LU-13023 for details. */ - rc = pcc_inode_reset_iattr(*dentry, ATTR_SIZE, KUIDT_INIT(0), - KGIDT_INIT(0), ret); + rc = pcc_inode_reset_iattr(inode, *dentry, + ATTR_SIZE | ATTR_MTIME | ATTR_MTIME_SET, + KUIDT_INIT(0), KGIDT_INIT(0), ret); out_fput: fput(pcc_filp); out_dentry: diff --git a/lustre/tests/sanity-pcc.sh b/lustre/tests/sanity-pcc.sh index f2c53c3..6a916e6 100755 --- a/lustre/tests/sanity-pcc.sh +++ b/lustre/tests/sanity-pcc.sh @@ -3612,6 +3612,36 @@ test_46() { } run_test 46 "Verify PCC mode setting works correctly" +test_47() { + local loopfile="$TMP/$tfile" + local mntpt="/mnt/pcc.$tdir" + local hsm_root="$mntpt/$tdir" + local file=$DIR/$tfile + + $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro || + skip "Server does not support PCC-RO" + + setup_loopdev client $loopfile $mntpt 60 + mkdir $hsm_root || error "mkdir $hsm_root failed" + setup_pcc_mapping client \ + "projid={0}\ roid=$HSM_ARCHIVE_NUMBER\ ropcc=1\ mmap_conv=0" + $LCTL pcc list $MOUNT + + local mtime0 + local mtime1 + + echo "QQQQQ" > $file || error "echo $file failed" + mtime0=$(stat -c "%Y" $file); + + sleep 3 + cat $file || error "cat $file failed" + check_lpcc_state $file "readonly" client + mtime1=$(stat -c "%Y" $file) + + (( mtime0 == mtime1 )) || error "mtime changed from $mtime0 to $mtime1" +} +run_test 47 "mtime should be kept once file attached into PCC" + test_96() { local loopfile="$TMP/$tfile" local mntpt="/mnt/pcc.$tdir" -- 1.8.3.1