summaryrefslogtreecommitdiffstats
path: root/xlators/storage/posix/src/posix-helpers.c
diff options
context:
space:
mode:
authorKotresh HR <khiremat@redhat.com>2018-05-21 12:57:45 -0400
committerKotresh HR <khiremat@redhat.com>2018-05-24 03:42:39 -0400
commit833808f42247bcb8db1be917f1ffd7841d9e226f (patch)
treea547480be5533bdb97ccd831a1ea92f395277409 /xlators/storage/posix/src/posix-helpers.c
parent096983831d11901daca0cb33b87bc5c1471a1ebf (diff)
posix/ctime: Fix gfid heal on first lookup
With ctime feature enabled, the gfid is not healing on first lookup. The fresh file logic depends on ctime and it was fetching from backend instead of xattr with ctime feature enabled. Fixed the same. Also fixed a possible hang with inode lock Backport of: > Patch: https://review.gluster.org/20052 > BUG: 1580532 > Change-Id: I020875c0462b284d6fa0e68304a422fa3d6a3e73 > Signed-off-by: Kotresh HR <khiremat@redhat.com> fixes: bz#1582080 Change-Id: I020875c0462b284d6fa0e68304a422fa3d6a3e73 Signed-off-by: Kotresh HR <khiremat@redhat.com>
Diffstat (limited to 'xlators/storage/posix/src/posix-helpers.c')
-rw-r--r--xlators/storage/posix/src/posix-helpers.c52
1 files changed, 42 insertions, 10 deletions
diff --git a/xlators/storage/posix/src/posix-helpers.c b/xlators/storage/posix/src/posix-helpers.c
index 0ca9169e2f4..00118b2d123 100644
--- a/xlators/storage/posix/src/posix-helpers.c
+++ b/xlators/storage/posix/src/posix-helpers.c
@@ -1620,14 +1620,14 @@ unlock:
}
static int
-is_fresh_file (struct stat *stat)
+is_fresh_file (int64_t ctime_sec)
{
struct timeval tv;
gettimeofday (&tv, NULL);
- if ((stat->st_ctime >= (tv.tv_sec - 1))
- && (stat->st_ctime <= tv.tv_sec))
+ if ((ctime_sec >= (tv.tv_sec - 1))
+ && (ctime_sec <= tv.tv_sec))
return 1;
return 0;
@@ -1665,19 +1665,51 @@ posix_gfid_heal (xlator_t *this, const char *path, loc_t *loc, dict_t *xattr_req
uuid_t uuid_curr;
int ret = 0;
struct stat stat = {0, };
+ struct iatt stbuf = {0, };
+ struct posix_private *priv = NULL;
+
+ priv = this->private;
if (!xattr_req)
return 0;
- if (sys_lstat (path, &stat) != 0) {
- return -errno;
- }
-
- ret = sys_lgetxattr (path, GFID_XATTR_KEY, uuid_curr, 16);
- if (ret != 16) {
- if (is_fresh_file (&stat)) {
+ if (loc->inode && priv->ctime) {
+ if (sys_lstat (path, &stat) != 0) {
+ return -errno;
+ }
+ /* stbuf is only to compare ctime, don't use it to access
+ * other fields as they are zero. */
+ ret = posix_get_mdata_xattr (this, path, -1, loc->inode,
+ &stbuf);
+ if (ret) {
+ gf_msg (this->name, GF_LOG_WARNING, errno,
+ P_MSG_GETMDATA_FAILED,
+ "posix get mdata failed on gfid: %s",
+ uuid_utoa(loc->inode->gfid));
return -ENOENT;
}
+ ret = sys_lgetxattr (path, GFID_XATTR_KEY, uuid_curr, 16);
+ if (ret != 16) {
+ if (is_fresh_file (stbuf.ia_ctime)) {
+ gf_msg (this->name, GF_LOG_ERROR, ENOENT,
+ P_MSG_FRESHFILE,
+ "Fresh file: %s", path);
+ return -ENOENT;
+ }
+ }
+ } else {
+ if (sys_lstat (path, &stat) != 0) {
+ return -errno;
+ }
+ ret = sys_lgetxattr (path, GFID_XATTR_KEY, uuid_curr, 16);
+ if (ret != 16) {
+ if (is_fresh_file (stat.st_ctime)) {
+ gf_msg (this->name, GF_LOG_ERROR, ENOENT,
+ P_MSG_FRESHFILE,
+ "Fresh file: %s", path);
+ return -ENOENT;
+ }
+ }
}
posix_gfid_set (this, path, loc, xattr_req);