a3470f
From 5b628662aa823770179c5592c182dd8b6acc9b1d Mon Sep 17 00:00:00 2001
a3470f
From: N Balachandran <nbalacha@redhat.com>
a3470f
Date: Thu, 23 Aug 2018 18:38:01 +0530
a3470f
Subject: [PATCH 359/359] storage/posix: Increment trusted.pgfid in posix_mknod
a3470f
a3470f
The value of trusted.pgfid.xx was always set to 1
a3470f
in posix_mknod. This is incorrect if posix_mknod
a3470f
calls posix_create_link_if_gfid_exists.
a3470f
a3470f
upstream patch: https://review.gluster.org/#/c/glusterfs/+/20875/
a3470f
a3470f
> Change-Id: Ibe87ca6f155846b9a7c7abbfb1eb8b6a99a5eb68
a3470f
> fixes: bz#1619720
a3470f
> Signed-off-by: N Balachandran <nbalacha@redhat.com>
a3470f
a3470f
Change-Id: Iaa7ad44b918eed28718f62c312f2d8edf01b9256
a3470f
BUG: 1620765
a3470f
Signed-off-by: N Balachandran <nbalacha@redhat.com>
a3470f
Reviewed-on: https://code.engineering.redhat.com/gerrit/147891
a3470f
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
a3470f
Tested-by: RHGS Build Bot <nigelb@redhat.com>
a3470f
---
a3470f
 tests/bugs/posix/bug-1619720.t    | 57 +++++++++++++++++++++++++++++++++++++++
a3470f
 xlators/storage/posix/src/posix.c | 18 ++++++++++---
a3470f
 2 files changed, 71 insertions(+), 4 deletions(-)
a3470f
 create mode 100755 tests/bugs/posix/bug-1619720.t
a3470f
a3470f
diff --git a/tests/bugs/posix/bug-1619720.t b/tests/bugs/posix/bug-1619720.t
a3470f
new file mode 100755
a3470f
index 0000000..5e0d0f7
a3470f
--- /dev/null
a3470f
+++ b/tests/bugs/posix/bug-1619720.t
a3470f
@@ -0,0 +1,57 @@
a3470f
+#!/bin/bash
a3470f
+
a3470f
+. $(dirname $0)/../../include.rc
a3470f
+. $(dirname $0)/../../dht.rc
a3470f
+
a3470f
+cleanup;
a3470f
+
a3470f
+
a3470f
+# Test steps:
a3470f
+# The test checks to make sure that the trusted.pgfid.xx xattr is set on
a3470f
+# both the linkto and data files post the final rename.
a3470f
+# The test creates files file-1 and file-3 so that src_hashed = dst_hashed,
a3470f
+# src_cached = dst_cached and xxx_hashed != xxx_cached.
a3470f
+# It then renames file-1 to file-3 which triggers the posix_mknod call
a3470f
+# which updates the trusted.pgfid.xx xattr.
a3470f
+
a3470f
+
a3470f
+TEST glusterd
a3470f
+TEST pidof glusterd
a3470f
+
a3470f
+TEST $CLI volume create $V0 $H0:$B0/${V0}0 $H0:$B0/${V0}1
a3470f
+TEST $CLI volume start $V0
a3470f
+TEST $CLI volume set $V0 storage.build-pgfid on
a3470f
+
a3470f
+## Mount FUSE
a3470f
+TEST glusterfs -s $H0 --volfile-id $V0 $M0;
a3470f
+
a3470f
+TEST mkdir $M0/tmp
a3470f
+
a3470f
+
a3470f
+
a3470f
+# Not the best way to do this but I need files which hash to the same subvol and
a3470f
+# whose cached subvols are the same.
a3470f
+# In a 2 subvol distributed volume, file-{1,3} hash to the same subvol.
a3470f
+# file-2 will hash to the other subvol
a3470f
+
a3470f
+TEST touch $M0/tmp/file-2
a3470f
+pgfid_xattr_name=$(getfattr -m "trusted.pgfid.*" $B0/${V0}1/tmp/file-2 | grep "trusted.pgfid")
a3470f
+echo $pgfid_xattr_name
a3470f
+
a3470f
+
a3470f
+TEST mv $M0/tmp/file-2 $M0/tmp/file-1
a3470f
+TEST touch $M0/tmp/file-2
a3470f
+TEST mv $M0/tmp/file-2 $M0/tmp/file-3
a3470f
+
a3470f
+# At this point, both the file-1 and file-3 data files exist on one subvol
a3470f
+# and both linkto files on the other
a3470f
+
a3470f
+TEST mv -f $M0/tmp/file-1 $M0/tmp/file-3
a3470f
+
a3470f
+TEST getfattr -n $pgfid_xattr_name $B0/${V0}0/tmp/file-3
a3470f
+TEST getfattr -n $pgfid_xattr_name $B0/${V0}1/tmp/file-3
a3470f
+
a3470f
+# Not required for the test but an extra check if required.
a3470f
+# The linkto file was not renamed Without the fix.
a3470f
+#TEST mv $M0/tmp/file-3 $M0/tmp/file-6
a3470f
+cleanup;
a3470f
diff --git a/xlators/storage/posix/src/posix.c b/xlators/storage/posix/src/posix.c
a3470f
index 28d2e6f..5088469 100644
a3470f
--- a/xlators/storage/posix/src/posix.c
a3470f
+++ b/xlators/storage/posix/src/posix.c
a3470f
@@ -1427,6 +1427,7 @@ posix_mknod (call_frame_t *frame, xlator_t *this,
a3470f
         gf_boolean_t          entry_created   = _gf_false, gfid_set = _gf_false;
a3470f
         gf_boolean_t          linked          = _gf_false;
a3470f
         gf_loglevel_t         level           = GF_LOG_NONE;
a3470f
+        posix_inode_ctx_t     *ctx            = NULL;
a3470f
 
a3470f
         DECLARE_OLD_FS_ID_VAR;
a3470f
 
a3470f
@@ -1556,10 +1557,20 @@ post_op:
a3470f
         if (priv->update_pgfid_nlinks) {
a3470f
                 MAKE_PGFID_XATTR_KEY (pgfid_xattr_key, PGFID_XATTR_KEY_PREFIX,
a3470f
                                       loc->pargfid);
a3470f
-                nlink_samepgfid = 1;
a3470f
+                op_ret = posix_inode_ctx_get_all (loc->inode, this, &ctx;;
a3470f
+                if (op_ret < 0) {
a3470f
+                        op_errno = ENOMEM;
a3470f
+                        goto out;
a3470f
+                }
a3470f
 
a3470f
-                SET_PGFID_XATTR (real_path, pgfid_xattr_key, nlink_samepgfid,
a3470f
-                                 XATTR_CREATE, op_ret, this, ignore);
a3470f
+                pthread_mutex_lock (&ctx->pgfid_lock);
a3470f
+                {
a3470f
+                        LINK_MODIFY_PGFID_XATTR (real_path, pgfid_xattr_key,
a3470f
+                                                 nlink_samepgfid, 0, op_ret,
a3470f
+                                                 this, unlock);
a3470f
+                }
a3470f
+unlock:
a3470f
+                pthread_mutex_unlock (&ctx->pgfid_lock);
a3470f
         }
a3470f
 
a3470f
         if (priv->gfid2path) {
a3470f
@@ -1567,7 +1578,6 @@ post_op:
a3470f
                                            loc->name);
a3470f
         }
a3470f
 
a3470f
-ignore:
a3470f
         op_ret = posix_entry_create_xattr_set (this, real_path, xdata);
a3470f
         if (op_ret) {
a3470f
                 if (errno != EEXIST)
a3470f
-- 
a3470f
1.8.3.1
a3470f