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