233933
From d5f931b334ac7abccaf30d277ce3ca9cfae0da5b Mon Sep 17 00:00:00 2001
233933
From: Pranith Kumar K <pkarampu@redhat.com>
233933
Date: Mon, 29 Jul 2019 14:08:37 +0530
233933
Subject: [PATCH 273/276] cluster/ec: Fix reopen flags to avoid misbehavior
233933
233933
Problem:
233933
when a file needs to be re-opened O_APPEND and O_EXCL
233933
flags are not filtered in EC.
233933
233933
- O_APPEND should be filtered because EC doesn't send O_APPEND below EC for
233933
open to make sure writes happen on the individual fragments instead of at the
233933
end of the file.
233933
233933
- O_EXCL should be filtered because shd could have created the file so even
233933
when file exists open should succeed
233933
233933
- O_CREAT should be filtered because open happens with gfid as parameter. So
233933
open fop will create just the gfid which will lead to problems.
233933
233933
Fix:
233933
Filter out these two flags in reopen.
233933
233933
Upstream-patch:https://review.gluster.org/#/c/glusterfs/+/23121/
233933
Change-Id: Ia280470fcb5188a09caa07bf665a2a94bce23bc4
233933
fixes: bz#1735514
233933
Signed-off-by: Pranith Kumar K <pkarampu@redhat.com>
233933
Reviewed-on: https://code.engineering.redhat.com/gerrit/177977
233933
Tested-by: RHGS Build Bot <nigelb@redhat.com>
233933
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
233933
---
233933
 xlators/cluster/ec/src/ec-common.c      | 4 +++-
233933
 xlators/cluster/ec/src/ec-inode-write.c | 7 +++++--
233933
 2 files changed, 8 insertions(+), 3 deletions(-)
233933
233933
diff --git a/xlators/cluster/ec/src/ec-common.c b/xlators/cluster/ec/src/ec-common.c
233933
index 28b31c9..5fb4610 100644
233933
--- a/xlators/cluster/ec/src/ec-common.c
233933
+++ b/xlators/cluster/ec/src/ec-common.c
233933
@@ -101,6 +101,7 @@ ec_fix_open(ec_fop_data_t *fop, uintptr_t mask)
233933
 {
233933
     uintptr_t need_open = 0;
233933
     int ret = 0;
233933
+    int32_t flags = 0;
233933
     loc_t loc = {
233933
         0,
233933
     };
233933
@@ -121,6 +122,7 @@ ec_fix_open(ec_fop_data_t *fop, uintptr_t mask)
233933
         goto out;
233933
     }
233933
 
233933
+    flags = fop->fd->flags & (~(O_TRUNC | O_APPEND | O_CREAT | O_EXCL));
233933
     if (IA_IFDIR == fop->fd->inode->ia_type) {
233933
         ec_opendir(fop->frame, fop->xl, need_open,
233933
                    EC_MINIMUM_ONE | EC_FOP_NO_PROPAGATE_ERROR, NULL, NULL,
233933
@@ -128,7 +130,7 @@ ec_fix_open(ec_fop_data_t *fop, uintptr_t mask)
233933
     } else {
233933
         ec_open(fop->frame, fop->xl, need_open,
233933
                 EC_MINIMUM_ONE | EC_FOP_NO_PROPAGATE_ERROR, NULL, NULL, &loc,
233933
-                fop->fd->flags & (~O_TRUNC), fop->fd, NULL);
233933
+                flags, fop->fd, NULL);
233933
     }
233933
 
233933
 out:
233933
diff --git a/xlators/cluster/ec/src/ec-inode-write.c b/xlators/cluster/ec/src/ec-inode-write.c
233933
index 4f35b6d..2f28e11 100644
233933
--- a/xlators/cluster/ec/src/ec-inode-write.c
233933
+++ b/xlators/cluster/ec/src/ec-inode-write.c
233933
@@ -1985,10 +1985,13 @@ ec_get_lock_good_mask(inode_t *inode, xlator_t *xl)
233933
     LOCK(&inode->lock);
233933
     {
233933
         ictx = __ec_inode_get(inode, xl);
233933
-        lock = ictx->inode_lock;
233933
+        if (ictx)
233933
+            lock = ictx->inode_lock;
233933
     }
233933
     UNLOCK(&inode->lock);
233933
-    return lock->good_mask;
233933
+    if (lock)
233933
+        return lock->good_mask;
233933
+    return 0;
233933
 }
233933
 
233933
 void
233933
-- 
233933
1.8.3.1
233933