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