Blob Blame History Raw
From b2c5826fad301bee45a479ee04a1a58770cce44c Mon Sep 17 00:00:00 2001
From: Raghavendra Talur <rtalur@redhat.com>
Date: Mon, 13 Apr 2015 17:05:44 +0530
Subject: [PATCH 187/192] libglusterfs: Even anonymous fds must have fd->flags set

        Backport of: http://review.gluster.org/10219

We do not set the same flags to anonymous fd that posix uses to open
an anonymous fd in the backend. If there are any xlators which rely on
these flags for their operation they may not work well.

Add proper flags to anonymous fds at the time of their creation and
refer to them for subsequent operations.

Change-Id: I7ff38f0c7f5e51f204f81bb344e14cde6cff4c0a
BUG: 1339136
Signed-off-by: Raghavendra Talur <rtalur@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/75847
Reviewed-by: Pranith Kumar Karampuri <pkarampu@redhat.com>
Tested-by: Pranith Kumar Karampuri <pkarampu@redhat.com>
---
 libglusterfs/src/fd.c                     |    4 ++--
 libglusterfs/src/fd.h                     |    5 ++++-
 xlators/storage/posix/src/posix-helpers.c |   13 ++++---------
 3 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/libglusterfs/src/fd.c b/libglusterfs/src/fd.c
index 297d703..7d9a0cc 100644
--- a/libglusterfs/src/fd.c
+++ b/libglusterfs/src/fd.c
@@ -314,8 +314,7 @@ gf_fd_put (fdtable_t *fdtable, int32_t fd)
         fd_t *fdptr = NULL;
         fdentry_t *fde = NULL;
 
-        if (fd == -2)
-                /* anonymous fd */
+        if (fd == GF_ANON_FD_NO)
                 return;
 
         if (fdtable == NULL || fd < 0) {
@@ -786,6 +785,7 @@ __fd_anonymous (inode_t *inode)
                         return NULL;
 
                 fd->anonymous = _gf_true;
+                fd->flags = GF_ANON_FD_FLAGS;
 
                 __fd_bind (fd);
 
diff --git a/libglusterfs/src/fd.h b/libglusterfs/src/fd.h
index 412fcc5..2e93f76 100644
--- a/libglusterfs/src/fd.h
+++ b/libglusterfs/src/fd.h
@@ -25,6 +25,7 @@
 #include "common-utils.h"
 
 #define GF_ANON_FD_NO -2
+#define GF_ANON_FD_FLAGS (O_RDWR|O_LARGEFILE)
 
 struct _inode;
 struct _dict;
@@ -52,7 +53,9 @@ struct _fd {
 	struct _fd_ctx   *_ctx;
         int               xl_count; /* Number of xl referred in this fd */
         struct fd_lk_ctx *lk_ctx;
-        gf_boolean_t      anonymous; /* geo-rep anonymous fd */
+        gf_boolean_t      anonymous; /* fd which does not have counterpart open
+                                        fd on backend (server for client, posix
+                                        for server). */
 };
 typedef struct _fd fd_t;
 
diff --git a/xlators/storage/posix/src/posix-helpers.c b/xlators/storage/posix/src/posix-helpers.c
index ba42272..7fb1a24 100644
--- a/xlators/storage/posix/src/posix-helpers.c
+++ b/xlators/storage/posix/src/posix-helpers.c
@@ -1632,19 +1632,14 @@ __posix_fd_ctx_get (fd_t *fd, xlator_t *this, struct posix_fd **pfd_p)
                 pfd = (void *)(long) tmp_pfd;
                 goto out;
         }
+
         if (!fd_is_anonymous(fd)) {
-                gf_msg (this->name, GF_LOG_ERROR, 0,
-                        P_MSG_READ_FAILED,
+                gf_msg (this->name, GF_LOG_ERROR, 0, P_MSG_READ_FAILED,
                         "Failed to get fd context for a non-anonymous fd, "
-                        "file: %s, gfid: %s", real_path,
-                        uuid_utoa (fd->inode->gfid));
+                        "gfid: %s", uuid_utoa (fd->inode->gfid));
                 goto out;
         }
 
-        if (!fd_is_anonymous(fd))
-                /* anonymous fd */
-                goto out;
-
         MAKE_HANDLE_PATH (real_path, this, fd->inode->gfid, NULL);
         if (!real_path) {
                 gf_msg (this->name, GF_LOG_ERROR, 0,
@@ -1672,7 +1667,7 @@ __posix_fd_ctx_get (fd_t *fd, xlator_t *this, struct posix_fd **pfd_p)
         }
 
         if (fd->inode->ia_type == IA_IFREG) {
-                _fd = open (real_path, O_RDWR|O_LARGEFILE);
+                _fd = open (real_path, fd->flags);
                 if (_fd == -1) {
                         POSIX_GET_FILE_UNLINK_PATH (priv->base_path,
                                                     fd->inode->gfid,
-- 
1.7.1