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