From e36d5c6b8c1c3800ef89a0251854bd2b7e2af924 Mon Sep 17 00:00:00 2001 From: Kotresh HR Date: Tue, 22 May 2018 00:34:48 -0400 Subject: posix/ctime: Fix updating mtime to older time With ctime feature enabled, the mtime is not updated when it's set to time older than the existing one. Fixed the same. But the ctime is not allowed to change to older dates. Backport of: > Patch: https://review.gluster.org/#/c/20055/ > BUG: 1581035 > Change-Id: If520922df42d6ce084c8df3046c138f8367164e5 (cherry picked from commit e9e3699456e738635685c9f42d1c4206c6177510) fixes: bz#1582531 Change-Id: If520922df42d6ce084c8df3046c138f8367164e5 Signed-off-by: Kotresh HR (cherry picked from commit e9e3699456e738635685c9f42d1c4206c6177510) --- xlators/storage/posix/src/posix-metadata.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/xlators/storage/posix/src/posix-metadata.c b/xlators/storage/posix/src/posix-metadata.c index 045ad25b21f..5da46d6bd99 100644 --- a/xlators/storage/posix/src/posix-metadata.c +++ b/xlators/storage/posix/src/posix-metadata.c @@ -346,6 +346,7 @@ posix_compare_timespec (struct timespec *first, struct timespec *second) return first->tv_sec - second->tv_sec; } + /* posix_set_mdata_xattr updates the posix_mdata_t based on the flag * in inode context and stores it on disk */ @@ -419,16 +420,21 @@ posix_set_mdata_xattr (xlator_t *this, const char *real_path, int fd, (uint64_t *)&mdata); } } + + /* Earlier, mdata was updated only if the existing time is less + * than the time to be updated. This would fail the scenarios + * where mtime can be set to any time using the syscall. Hence + * just updating without comparison. But the ctime is not + * allowed to changed to older date. + */ if (flag->ctime && - posix_compare_timespec (time, &mdata->ctime) > 0) { + posix_compare_timespec (time, &mdata->ctime) > 0) { mdata->ctime = *time; } - if (flag->mtime && - posix_compare_timespec (time, &mdata->mtime) > 0) { + if (flag->mtime) { mdata->mtime = *time; } - if (flag->atime && - posix_compare_timespec (time, &mdata->atime) > 0) { + if (flag->atime) { mdata->atime = *time; } -- cgit