summaryrefslogtreecommitdiffstats
path: root/xlators/storage/posix/src/posix-helpers.c
diff options
context:
space:
mode:
authorXavier Hernandez <jahernan@redhat.com>2018-01-19 12:18:13 +0100
committerAmar Tumballi <amarts@redhat.com>2019-04-29 07:30:56 +0000
commitd23e918d954e985b13295ba00353e4f47759e59e (patch)
tree0bdf47d24269f7aaa766a251c0b8d74f74893280 /xlators/storage/posix/src/posix-helpers.c
parent45b19d569e9f61410e4a700950e3cf4d7e6838f1 (diff)
storage/posix: fix fresh file detection delay
Current implementation made it possible to consider that a file was not fresh even if it was created less than a second ago. This patch fixes the way in which the delay is computed to ensure that at least one second has elapsed. Change-Id: I05f7b99e7e8dd97e31f7ebaaec6c39eecf98b00f Updates: bz#1193929 Signed-off-by: Xavier Hernandez <jahernan@redhat.com>
Diffstat (limited to 'xlators/storage/posix/src/posix-helpers.c')
-rw-r--r--xlators/storage/posix/src/posix-helpers.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/xlators/storage/posix/src/posix-helpers.c b/xlators/storage/posix/src/posix-helpers.c
index d0fd45a..401f8ca 100644
--- a/xlators/storage/posix/src/posix-helpers.c
+++ b/xlators/storage/posix/src/posix-helpers.c
@@ -1641,14 +1641,26 @@ unlock:
}
static int
-is_fresh_file(int64_t ctime_sec)
+is_fresh_file(int64_t sec, int64_t ns)
{
struct timeval tv;
+ int64_t elapsed;
gettimeofday(&tv, NULL);
- if ((ctime_sec >= (tv.tv_sec - 1)) && (ctime_sec <= tv.tv_sec))
+ elapsed = (tv.tv_sec - sec) * 1000000L;
+ elapsed += tv.tv_usec - (ns / 1000L);
+ if (elapsed < 0) {
+ /* The file has been modified in the future !!!
+ * Is it fresh ? previous implementation considered this as a
+ * non-fresh file, so maintaining the same behavior. */
+ return 0;
+ }
+
+ /* If the file is newer than a second, we consider it fresh. */
+ if (elapsed < 1000000) {
return 1;
+ }
return 0;
}
@@ -1711,7 +1723,9 @@ posix_gfid_heal(xlator_t *this, const char *path, loc_t *loc, dict_t *xattr_req)
}
ret = sys_lgetxattr(path, GFID_XATTR_KEY, uuid_curr, 16);
if (ret != 16) {
- if (is_fresh_file(stbuf.ia_ctime)) {
+ /* TODO: This is a very hacky way of doing this, and very prone to
+ * errors and unexpected behavior. This should be changed. */
+ if (is_fresh_file(stbuf.ia_ctime, stbuf.ia_ctime_nsec)) {
gf_msg(this->name, GF_LOG_ERROR, ENOENT, P_MSG_FRESHFILE,
"Fresh file: %s", path);
return -ENOENT;
@@ -1723,7 +1737,9 @@ posix_gfid_heal(xlator_t *this, const char *path, loc_t *loc, dict_t *xattr_req)
}
ret = sys_lgetxattr(path, GFID_XATTR_KEY, uuid_curr, 16);
if (ret != 16) {
- if (is_fresh_file(stat.st_ctime)) {
+ /* TODO: This is a very hacky way of doing this, and very prone to
+ * errors and unexpected behavior. This should be changed. */
+ if (is_fresh_file(stat.st_ctim.tv_sec, stat.st_ctim.tv_nsec)) {
gf_msg(this->name, GF_LOG_ERROR, ENOENT, P_MSG_FRESHFILE,
"Fresh file: %s", path);
return -ENOENT;