In order to simplify truncate operation on the file which only has lower, we skip restoring mtime on copy-up for regular file. Signed-off-by: Chengguang Xu <cgxu519@xxxxxxxxxxxx> --- fs/overlayfs/copy_up.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/fs/overlayfs/copy_up.c b/fs/overlayfs/copy_up.c index 0fed532efa68..8b92b3ba3c46 100644 --- a/fs/overlayfs/copy_up.c +++ b/fs/overlayfs/copy_up.c @@ -241,12 +241,17 @@ static int ovl_set_size(struct dentry *upperdentry, struct kstat *stat) static int ovl_set_timestamps(struct dentry *upperdentry, struct kstat *stat) { - struct iattr attr = { - .ia_valid = - ATTR_ATIME | ATTR_MTIME | ATTR_ATIME_SET | ATTR_MTIME_SET, - .ia_atime = stat->atime, - .ia_mtime = stat->mtime, - }; + struct iattr attr; + + if (S_ISREG(upperdentry->d_inode->i_mode)) { + attr.ia_valid = ATTR_ATIME | ATTR_ATIME_SET; + attr.ia_atime = stat->atime; + } else { + attr.ia_valid = ATTR_ATIME | ATTR_MTIME | + ATTR_ATIME_SET | ATTR_MTIME_SET; + attr.ia_atime = stat->atime; + attr.ia_mtime = stat->mtime; + } return notify_change(upperdentry, &attr, NULL); } -- 2.27.0