12a457
From b2c5826fad301bee45a479ee04a1a58770cce44c Mon Sep 17 00:00:00 2001
12a457
From: Raghavendra Talur <rtalur@redhat.com>
12a457
Date: Mon, 13 Apr 2015 17:05:44 +0530
12a457
Subject: [PATCH 187/192] libglusterfs: Even anonymous fds must have fd->flags set
12a457
12a457
        Backport of: http://review.gluster.org/10219
12a457
12a457
We do not set the same flags to anonymous fd that posix uses to open
12a457
an anonymous fd in the backend. If there are any xlators which rely on
12a457
these flags for their operation they may not work well.
12a457
12a457
Add proper flags to anonymous fds at the time of their creation and
12a457
refer to them for subsequent operations.
12a457
12a457
Change-Id: I7ff38f0c7f5e51f204f81bb344e14cde6cff4c0a
12a457
BUG: 1339136
12a457
Signed-off-by: Raghavendra Talur <rtalur@redhat.com>
12a457
Reviewed-on: https://code.engineering.redhat.com/gerrit/75847
12a457
Reviewed-by: Pranith Kumar Karampuri <pkarampu@redhat.com>
12a457
Tested-by: Pranith Kumar Karampuri <pkarampu@redhat.com>
12a457
---
12a457
 libglusterfs/src/fd.c                     |    4 ++--
12a457
 libglusterfs/src/fd.h                     |    5 ++++-
12a457
 xlators/storage/posix/src/posix-helpers.c |   13 ++++---------
12a457
 3 files changed, 10 insertions(+), 12 deletions(-)
12a457
12a457
diff --git a/libglusterfs/src/fd.c b/libglusterfs/src/fd.c
12a457
index 297d703..7d9a0cc 100644
12a457
--- a/libglusterfs/src/fd.c
12a457
+++ b/libglusterfs/src/fd.c
12a457
@@ -314,8 +314,7 @@ gf_fd_put (fdtable_t *fdtable, int32_t fd)
12a457
         fd_t *fdptr = NULL;
12a457
         fdentry_t *fde = NULL;
12a457
 
12a457
-        if (fd == -2)
12a457
-                /* anonymous fd */
12a457
+        if (fd == GF_ANON_FD_NO)
12a457
                 return;
12a457
 
12a457
         if (fdtable == NULL || fd < 0) {
12a457
@@ -786,6 +785,7 @@ __fd_anonymous (inode_t *inode)
12a457
                         return NULL;
12a457
 
12a457
                 fd->anonymous = _gf_true;
12a457
+                fd->flags = GF_ANON_FD_FLAGS;
12a457
 
12a457
                 __fd_bind (fd);
12a457
 
12a457
diff --git a/libglusterfs/src/fd.h b/libglusterfs/src/fd.h
12a457
index 412fcc5..2e93f76 100644
12a457
--- a/libglusterfs/src/fd.h
12a457
+++ b/libglusterfs/src/fd.h
12a457
@@ -25,6 +25,7 @@
12a457
 #include "common-utils.h"
12a457
 
12a457
 #define GF_ANON_FD_NO -2
12a457
+#define GF_ANON_FD_FLAGS (O_RDWR|O_LARGEFILE)
12a457
 
12a457
 struct _inode;
12a457
 struct _dict;
12a457
@@ -52,7 +53,9 @@ struct _fd {
12a457
 	struct _fd_ctx   *_ctx;
12a457
         int               xl_count; /* Number of xl referred in this fd */
12a457
         struct fd_lk_ctx *lk_ctx;
12a457
-        gf_boolean_t      anonymous; /* geo-rep anonymous fd */
12a457
+        gf_boolean_t      anonymous; /* fd which does not have counterpart open
12a457
+                                        fd on backend (server for client, posix
12a457
+                                        for server). */
12a457
 };
12a457
 typedef struct _fd fd_t;
12a457
 
12a457
diff --git a/xlators/storage/posix/src/posix-helpers.c b/xlators/storage/posix/src/posix-helpers.c
12a457
index ba42272..7fb1a24 100644
12a457
--- a/xlators/storage/posix/src/posix-helpers.c
12a457
+++ b/xlators/storage/posix/src/posix-helpers.c
12a457
@@ -1632,19 +1632,14 @@ __posix_fd_ctx_get (fd_t *fd, xlator_t *this, struct posix_fd **pfd_p)
12a457
                 pfd = (void *)(long) tmp_pfd;
12a457
                 goto out;
12a457
         }
12a457
+
12a457
         if (!fd_is_anonymous(fd)) {
12a457
-                gf_msg (this->name, GF_LOG_ERROR, 0,
12a457
-                        P_MSG_READ_FAILED,
12a457
+                gf_msg (this->name, GF_LOG_ERROR, 0, P_MSG_READ_FAILED,
12a457
                         "Failed to get fd context for a non-anonymous fd, "
12a457
-                        "file: %s, gfid: %s", real_path,
12a457
-                        uuid_utoa (fd->inode->gfid));
12a457
+                        "gfid: %s", uuid_utoa (fd->inode->gfid));
12a457
                 goto out;
12a457
         }
12a457
 
12a457
-        if (!fd_is_anonymous(fd))
12a457
-                /* anonymous fd */
12a457
-                goto out;
12a457
-
12a457
         MAKE_HANDLE_PATH (real_path, this, fd->inode->gfid, NULL);
12a457
         if (!real_path) {
12a457
                 gf_msg (this->name, GF_LOG_ERROR, 0,
12a457
@@ -1672,7 +1667,7 @@ __posix_fd_ctx_get (fd_t *fd, xlator_t *this, struct posix_fd **pfd_p)
12a457
         }
12a457
 
12a457
         if (fd->inode->ia_type == IA_IFREG) {
12a457
-                _fd = open (real_path, O_RDWR|O_LARGEFILE);
12a457
+                _fd = open (real_path, fd->flags);
12a457
                 if (_fd == -1) {
12a457
                         POSIX_GET_FILE_UNLINK_PATH (priv->base_path,
12a457
                                                     fd->inode->gfid,
12a457
-- 
12a457
1.7.1
12a457