summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKotresh HR <khiremat@redhat.com>2018-05-22 00:34:48 -0400
committerKotresh HR <khiremat@redhat.com>2018-05-25 13:52:47 +0000
commite36d5c6b8c1c3800ef89a0251854bd2b7e2af924 (patch)
treef12c73c26853ff914f8535789972092e61d8e0ce
parentc6f21697a52200bbbf9af05dff2b9c3ae0a99b43 (diff)
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 <khiremat@redhat.com> (cherry picked from commit e9e3699456e738635685c9f42d1c4206c6177510)
-rw-r--r--xlators/storage/posix/src/posix-metadata.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/xlators/storage/posix/src/posix-metadata.c b/xlators/storage/posix/src/posix-metadata.c
index 045ad25..5da46d6 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;
}