Whamcloud - gitweb
LU-10499 pcc: keep mtime unchange when attach file into PCC 24/54424/7
authorQian Yingjin <qian@ddn.com>
Tue, 14 Sep 2021 08:40:03 +0000 (16:40 +0800)
committerOleg Drokin <green@whamcloud.com>
Fri, 23 Aug 2024 21:57:48 +0000 (21:57 +0000)
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 <qian@ddn.com>
Change-Id: I26f0c19c7b6cc1af0d62c192931d0042c9614993
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/54424
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: jsimmons <jsimmons@infradead.org>
lustre/llite/pcc.c
lustre/tests/sanity-pcc.sh

index 1f112a7..a5a1207 100644 (file)
@@ -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:
index f2c53c3..6a916e6 100755 (executable)
@@ -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"