a3470f
From 1a5680e36331d10be2b677f7a5a085e706297c96 Mon Sep 17 00:00:00 2001
a3470f
From: Ashish Pandey <aspandey@redhat.com>
a3470f
Date: Thu, 17 May 2018 15:55:44 +0530
a3470f
Subject: [PATCH 288/305] feature/locks: Unwind response based on clinet
a3470f
 version
a3470f
a3470f
upstream patch:
a3470f
https://review.gluster.org/#/c/20031/
a3470f
a3470f
>Change-Id: I6fc7755cca0d6f61cb775363618036228925842c
a3470f
a3470f
Change-Id: I6fc7755cca0d6f61cb775363618036228925842c
a3470f
BUG: 1558948
a3470f
Signed-off-by: Ashish Pandey <aspandey@redhat.com>
a3470f
Reviewed-on: https://code.engineering.redhat.com/gerrit/140080
a3470f
Tested-by: RHGS Build Bot <nigelb@redhat.com>
a3470f
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
a3470f
---
a3470f
 xlators/features/locks/src/posix.c | 142 +++++++++++++++++++++++--------------
a3470f
 1 file changed, 88 insertions(+), 54 deletions(-)
a3470f
a3470f
diff --git a/xlators/features/locks/src/posix.c b/xlators/features/locks/src/posix.c
a3470f
index ef4bebf..63bcf31 100644
a3470f
--- a/xlators/features/locks/src/posix.c
a3470f
+++ b/xlators/features/locks/src/posix.c
a3470f
@@ -39,6 +39,43 @@ static int format_brickname(char *);
a3470f
 int pl_lockinfo_get_brickname (xlator_t *, inode_t *, int32_t *);
a3470f
 static int fetch_pathinfo(xlator_t *, inode_t *, int32_t *, char **);
a3470f
 
a3470f
+#define PL_STACK_UNWIND_AND_FREE(__local, fop, frame, op_ret, params ...)   \
a3470f
+        do {                                                                \
a3470f
+                frame->local = NULL;                                        \
a3470f
+                STACK_UNWIND_STRICT (fop, frame, op_ret, params);           \
a3470f
+                if (__local) {                                              \
a3470f
+                        if (__local->inodelk_dom_count_req)                 \
a3470f
+                                data_unref (__local->inodelk_dom_count_req);\
a3470f
+                        loc_wipe (&__local->loc[0]);                        \
a3470f
+                        loc_wipe (&__local->loc[1]);                        \
a3470f
+                        if (__local->fd)                                    \
a3470f
+                                fd_unref (__local->fd);                     \
a3470f
+                        mem_put (__local);                                  \
a3470f
+                }                                                           \
a3470f
+        } while (0)
a3470f
+
a3470f
+/*
a3470f
+ * The client is always requesting data, but older
a3470f
+ * servers were not returning it. Newer ones are, so
a3470f
+ * the client is receiving a mix of NULL and non-NULL
a3470f
+ * xdata in the answers when bricks are of different
a3470f
+ * versions. This triggers a bug in older clients.
a3470f
+ * To prevent that, we avoid returning extra xdata to
a3470f
+ * older clients (making the newer brick to behave as
a3470f
+ * an old brick).
a3470f
+ */
a3470f
+#define PL_STACK_UNWIND_FOR_CLIENT(fop, xdata, frame, op_ret, params ...)     \
a3470f
+        do {                                                                  \
a3470f
+                pl_local_t *__local = NULL;                                   \
a3470f
+                if (frame->root->client &&                                    \
a3470f
+                    (frame->root->client->opversion < GD_OP_VERSION_3_12_0)) {\
a3470f
+                        __local = frame->local;                               \
a3470f
+                        PL_STACK_UNWIND_AND_FREE (__local, fop, frame, op_ret, params);\
a3470f
+                } else {                                                      \
a3470f
+                        PL_STACK_UNWIND (fop, xdata, frame, op_ret, params);  \
a3470f
+                }                                                             \
a3470f
+        } while (0)
a3470f
+
a3470f
 #define PL_STACK_UNWIND(fop, xdata, frame, op_ret, params ...)          \
a3470f
         do {                                                            \
a3470f
                 pl_local_t *__local = NULL;                             \
a3470f
@@ -68,17 +105,7 @@ static int fetch_pathinfo(xlator_t *, inode_t *, int32_t *, char **);
a3470f
                                 }                                       \
a3470f
                         }                                               \
a3470f
                 }                                                       \
a3470f
-                frame->local = NULL;                                    \
a3470f
-                STACK_UNWIND_STRICT (fop, frame, op_ret, params);       \
a3470f
-                if (__local) {                                          \
a3470f
-                        if (__local->inodelk_dom_count_req)             \
a3470f
-                                data_unref (__local->inodelk_dom_count_req);\
a3470f
-                        loc_wipe (&__local->loc[0]);                    \
a3470f
-                        loc_wipe (&__local->loc[1]);                    \
a3470f
-                        if (__local->fd)                                \
a3470f
-                                fd_unref (__local->fd);                 \
a3470f
-                        mem_put (__local);                              \
a3470f
-                }                                                       \
a3470f
+                PL_STACK_UNWIND_AND_FREE (__local, fop, frame, op_ret, params);\
a3470f
                 if (__unref)                                            \
a3470f
                         dict_unref (__unref);                           \
a3470f
         } while (0)
a3470f
@@ -1492,7 +1519,8 @@ int32_t
a3470f
 pl_fsetxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
a3470f
                   int32_t op_ret, int32_t op_errno, dict_t *xdata)
a3470f
 {
a3470f
-        PL_STACK_UNWIND (fsetxattr, xdata, frame, op_ret, op_errno, xdata);
a3470f
+        PL_STACK_UNWIND_FOR_CLIENT (fsetxattr, xdata, frame,
a3470f
+                                    op_ret, op_errno, xdata);
a3470f
         return 0;
a3470f
 }
a3470f
 
a3470f
@@ -1564,12 +1592,8 @@ pl_flush_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
a3470f
               int32_t op_ret, int32_t op_errno, dict_t *xdata)
a3470f
 {
a3470f
 
a3470f
-        if (frame->root->client &&
a3470f
-            (frame->root->client->opversion < GD_OP_VERSION_3_12_0)) {
a3470f
-                STACK_UNWIND_STRICT (flush, frame, op_ret, op_errno, xdata);
a3470f
-        } else {
a3470f
-                PL_STACK_UNWIND (flush, xdata, frame, op_ret, op_errno, xdata);
a3470f
-        }
a3470f
+        PL_STACK_UNWIND_FOR_CLIENT (flush, xdata, frame,
a3470f
+                                    op_ret, op_errno, xdata);
a3470f
 
a3470f
         return 0;
a3470f
 }
a3470f
@@ -3081,7 +3105,8 @@ int32_t
a3470f
 pl_setxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
a3470f
                  int32_t op_ret, int32_t op_errno, dict_t *xdata)
a3470f
 {
a3470f
-        PL_STACK_UNWIND (setxattr, xdata, frame, op_ret, op_errno, xdata);
a3470f
+        PL_STACK_UNWIND_FOR_CLIENT (setxattr, xdata, frame,
a3470f
+                                    op_ret, op_errno, xdata);
a3470f
         return 0;
a3470f
 }
a3470f
 
a3470f
@@ -3107,8 +3132,8 @@ pl_setxattr (call_frame_t *frame, xlator_t *this,
a3470f
                 goto usual;
a3470f
         }
a3470f
 
a3470f
-        PL_STACK_UNWIND (setxattr, xdata_rsp, frame, op_ret, op_errno,
a3470f
-                         xdata_rsp);
a3470f
+        PL_STACK_UNWIND_FOR_CLIENT (setxattr, xdata_rsp, frame,
a3470f
+                                    op_ret, op_errno, xdata_rsp);
a3470f
         return 0;
a3470f
 
a3470f
 usual:
a3470f
@@ -3937,8 +3962,8 @@ pl_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
a3470f
               struct iatt *buf, struct iatt *preparent,
a3470f
               struct iatt *postparent, dict_t *xdata)
a3470f
 {
a3470f
-        PL_STACK_UNWIND (mkdir, xdata, frame, op_ret, op_errno,
a3470f
-                         inode, buf, preparent, postparent, xdata);
a3470f
+        PL_STACK_UNWIND_FOR_CLIENT (mkdir, xdata, frame, op_ret, op_errno,
a3470f
+                                    inode, buf, preparent, postparent, xdata);
a3470f
         return 0;
a3470f
 }
a3470f
 
a3470f
@@ -3958,7 +3983,8 @@ pl_stat_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
a3470f
              int32_t op_ret, int32_t op_errno, struct iatt *buf,
a3470f
              dict_t *xdata)
a3470f
 {
a3470f
-        PL_STACK_UNWIND (stat, xdata, frame, op_ret, op_errno, buf, xdata);
a3470f
+        PL_STACK_UNWIND_FOR_CLIENT (stat, xdata, frame,
a3470f
+                                    op_ret, op_errno, buf, xdata);
a3470f
         return 0;
a3470f
 }
a3470f
 
a3470f
@@ -3978,8 +4004,8 @@ pl_mknod_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
a3470f
               struct iatt *buf, struct iatt *preparent,
a3470f
               struct iatt *postparent, dict_t *xdata)
a3470f
 {
a3470f
-        PL_STACK_UNWIND (mknod, xdata, frame, op_ret, op_errno,
a3470f
-                         inode, buf, preparent, postparent, xdata);
a3470f
+        PL_STACK_UNWIND_FOR_CLIENT (mknod, xdata, frame, op_ret, op_errno,
a3470f
+                                    inode, buf, preparent, postparent, xdata);
a3470f
         return 0;
a3470f
 }
a3470f
 
a3470f
@@ -4000,8 +4026,8 @@ pl_rmdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
a3470f
               int32_t op_ret, int32_t op_errno, struct iatt *preparent,
a3470f
               struct iatt *postparent, dict_t *xdata)
a3470f
 {
a3470f
-        PL_STACK_UNWIND (rmdir, xdata, frame, op_ret, op_errno,
a3470f
-                         preparent, postparent, xdata);
a3470f
+        PL_STACK_UNWIND_FOR_CLIENT (rmdir, xdata, frame, op_ret, op_errno,
a3470f
+                                    preparent, postparent, xdata);
a3470f
         return 0;
a3470f
 }
a3470f
 
a3470f
@@ -4022,8 +4048,8 @@ pl_symlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
a3470f
                 struct iatt *buf, struct iatt *preparent,
a3470f
                 struct iatt *postparent, dict_t *xdata)
a3470f
 {
a3470f
-        PL_STACK_UNWIND (symlink, xdata, frame, op_ret, op_errno,
a3470f
-                         inode, buf, preparent, postparent, xdata);
a3470f
+        PL_STACK_UNWIND_FOR_CLIENT (symlink, xdata, frame, op_ret, op_errno,
a3470f
+                                    inode, buf, preparent, postparent, xdata);
a3470f
         return 0;
a3470f
 }
a3470f
 
a3470f
@@ -4045,8 +4071,8 @@ pl_link_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
a3470f
              struct iatt *buf, struct iatt *preparent,
a3470f
              struct iatt *postparent, dict_t *xdata)
a3470f
 {
a3470f
-        PL_STACK_UNWIND (link, xdata, frame, op_ret, op_errno,
a3470f
-                         inode, buf, preparent, postparent, xdata);
a3470f
+        PL_STACK_UNWIND_FOR_CLIENT (link, xdata, frame, op_ret, op_errno,
a3470f
+                                    inode, buf, preparent, postparent, xdata);
a3470f
         return 0;
a3470f
 }
a3470f
 
a3470f
@@ -4066,8 +4092,8 @@ pl_fsync_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
a3470f
               struct iatt *postbuf,
a3470f
               dict_t *xdata)
a3470f
 {
a3470f
-        PL_STACK_UNWIND (fsync, xdata, frame, op_ret, op_errno,
a3470f
-                         prebuf, postbuf, xdata);
a3470f
+        PL_STACK_UNWIND_FOR_CLIENT (fsync, xdata, frame, op_ret, op_errno,
a3470f
+                                    prebuf, postbuf, xdata);
a3470f
         return 0;
a3470f
 }
a3470f
 
a3470f
@@ -4086,8 +4112,8 @@ pl_readdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
a3470f
                 int32_t op_ret, int32_t op_errno, gf_dirent_t *entries,
a3470f
                 dict_t *xdata)
a3470f
 {
a3470f
-        PL_STACK_UNWIND (readdir, xdata, frame, op_ret, op_errno,
a3470f
-                         entries, xdata);
a3470f
+        PL_STACK_UNWIND_FOR_CLIENT (readdir, xdata, frame, op_ret, op_errno,
a3470f
+                                    entries, xdata);
a3470f
         return 0;
a3470f
 }
a3470f
 
a3470f
@@ -4108,7 +4134,8 @@ int32_t
a3470f
 pl_fsyncdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
a3470f
                  int32_t op_ret, int32_t op_errno, dict_t *xdata)
a3470f
 {
a3470f
-        PL_STACK_UNWIND (fsyncdir, xdata, frame, op_ret, op_errno, xdata);
a3470f
+        PL_STACK_UNWIND_FOR_CLIENT (fsyncdir, xdata, frame,
a3470f
+                                    op_ret, op_errno, xdata);
a3470f
         return 0;
a3470f
 }
a3470f
 
a3470f
@@ -4128,7 +4155,8 @@ pl_statfs_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
a3470f
                int32_t op_ret, int32_t op_errno, struct statvfs *buf,
a3470f
                dict_t *xdata)
a3470f
 {
a3470f
-        PL_STACK_UNWIND (statfs, xdata, frame, op_ret, op_errno, buf, xdata);
a3470f
+        PL_STACK_UNWIND_FOR_CLIENT (statfs, xdata, frame,
a3470f
+                                    op_ret, op_errno, buf, xdata);
a3470f
         return 0;
a3470f
 }
a3470f
 
a3470f
@@ -4146,7 +4174,8 @@ int32_t
a3470f
 pl_removexattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
a3470f
                     int32_t op_ret, int32_t op_errno, dict_t *xdata)
a3470f
 {
a3470f
-        PL_STACK_UNWIND (removexattr, xdata, frame, op_ret, op_errno, xdata);
a3470f
+        PL_STACK_UNWIND_FOR_CLIENT (removexattr, xdata, frame,
a3470f
+                                    op_ret, op_errno, xdata);
a3470f
         return 0;
a3470f
 }
a3470f
 
a3470f
@@ -4164,7 +4193,8 @@ int32_t
a3470f
 pl_fremovexattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
a3470f
                      int32_t op_ret, int32_t op_errno, dict_t *xdata)
a3470f
 {
a3470f
-        PL_STACK_UNWIND (fremovexattr, xdata, frame, op_ret, op_errno, xdata);
a3470f
+        PL_STACK_UNWIND_FOR_CLIENT (fremovexattr, xdata, frame,
a3470f
+                                    op_ret, op_errno, xdata);
a3470f
         return 0;
a3470f
 }
a3470f
 
a3470f
@@ -4183,8 +4213,8 @@ pl_rchecksum_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
a3470f
                   int32_t op_ret, int32_t op_errno, uint32_t weak_cksum,
a3470f
                   uint8_t *strong_cksum, dict_t *xdata)
a3470f
 {
a3470f
-        PL_STACK_UNWIND (rchecksum, xdata, frame, op_ret, op_errno,
a3470f
-                         weak_cksum, strong_cksum, xdata);
a3470f
+        PL_STACK_UNWIND_FOR_CLIENT (rchecksum, xdata, frame, op_ret, op_errno,
a3470f
+                                    weak_cksum, strong_cksum, xdata);
a3470f
         return 0;
a3470f
 }
a3470f
 
a3470f
@@ -4204,7 +4234,8 @@ pl_xattrop_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
a3470f
                 int32_t op_ret, int32_t op_errno, dict_t *dict,
a3470f
                 dict_t *xdata)
a3470f
 {
a3470f
-        PL_STACK_UNWIND (xattrop, xdata, frame, op_ret, op_errno, dict, xdata);
a3470f
+        PL_STACK_UNWIND_FOR_CLIENT (xattrop, xdata, frame,
a3470f
+                                    op_ret, op_errno, dict, xdata);
a3470f
         return 0;
a3470f
 }
a3470f
 
a3470f
@@ -4225,7 +4256,8 @@ pl_fxattrop_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
a3470f
                  int32_t op_ret, int32_t op_errno, dict_t *dict,
a3470f
                  dict_t *xdata)
a3470f
 {
a3470f
-        PL_STACK_UNWIND (fxattrop, xdata, frame, op_ret, op_errno, dict, xdata);
a3470f
+        PL_STACK_UNWIND_FOR_CLIENT (fxattrop, xdata, frame,
a3470f
+                                    op_ret, op_errno, dict, xdata);
a3470f
         return 0;
a3470f
 }
a3470f
 
a3470f
@@ -4247,8 +4279,8 @@ pl_setattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
a3470f
                 struct iatt *statpost,
a3470f
                 dict_t *xdata)
a3470f
 {
a3470f
-        PL_STACK_UNWIND (setattr, xdata, frame, op_ret, op_errno,
a3470f
-                         statpre, statpost, xdata);
a3470f
+        PL_STACK_UNWIND_FOR_CLIENT (setattr, xdata, frame, op_ret, op_errno,
a3470f
+                                    statpre, statpost, xdata);
a3470f
         return 0;
a3470f
 }
a3470f
 
a3470f
@@ -4267,8 +4299,8 @@ pl_fsetattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
a3470f
                  int32_t op_ret, int32_t op_errno, struct iatt *statpre,
a3470f
                  struct iatt *statpost, dict_t *xdata)
a3470f
 {
a3470f
-        PL_STACK_UNWIND (fsetattr, xdata, frame, op_ret, op_errno,
a3470f
-                         statpre, statpost, xdata);
a3470f
+        PL_STACK_UNWIND_FOR_CLIENT (fsetattr, xdata, frame, op_ret, op_errno,
a3470f
+                                    statpre, statpost, xdata);
a3470f
         return 0;
a3470f
 }
a3470f
 
a3470f
@@ -4287,8 +4319,8 @@ pl_fallocate_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
a3470f
                   int32_t op_ret, int32_t op_errno, struct iatt *pre,
a3470f
                   struct iatt *post, dict_t *xdata)
a3470f
 {
a3470f
-        PL_STACK_UNWIND (fallocate, xdata, frame, op_ret, op_errno,
a3470f
-                         pre, post, xdata);
a3470f
+        PL_STACK_UNWIND_FOR_CLIENT (fallocate, xdata, frame, op_ret, op_errno,
a3470f
+                                    pre, post, xdata);
a3470f
         return 0;
a3470f
 }
a3470f
 
a3470f
@@ -4309,8 +4341,8 @@ pl_readlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
a3470f
                  int32_t op_ret, int32_t op_errno, const char *path,
a3470f
                  struct iatt *buf, dict_t *xdata)
a3470f
 {
a3470f
-        PL_STACK_UNWIND (readlink, xdata, frame, op_ret, op_errno,
a3470f
-                         path, buf, xdata);
a3470f
+        PL_STACK_UNWIND_FOR_CLIENT (readlink, xdata, frame, op_ret, op_errno,
a3470f
+                                    path, buf, xdata);
a3470f
         return 0;
a3470f
 }
a3470f
 
a3470f
@@ -4328,7 +4360,8 @@ int32_t
a3470f
 pl_access_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
a3470f
                int32_t op_ret, int32_t op_errno, dict_t *xdata)
a3470f
 {
a3470f
-        PL_STACK_UNWIND (access, xdata, frame, op_ret, op_errno, xdata);
a3470f
+        PL_STACK_UNWIND_FOR_CLIENT (access, xdata, frame,
a3470f
+                                    op_ret, op_errno, xdata);
a3470f
         return 0;
a3470f
 }
a3470f
 
a3470f
@@ -4347,7 +4380,8 @@ pl_seek_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
a3470f
              int32_t op_ret, int32_t op_errno, off_t offset,
a3470f
              dict_t *xdata)
a3470f
 {
a3470f
-        PL_STACK_UNWIND (seek, xdata, frame, op_ret, op_errno, offset, xdata);
a3470f
+        PL_STACK_UNWIND_FOR_CLIENT (seek, xdata, frame,
a3470f
+                                    op_ret, op_errno, offset, xdata);
a3470f
         return 0;
a3470f
 }
a3470f
 
a3470f
-- 
a3470f
1.8.3.1
a3470f