From 22035d5e37db748cbdee2596d99006cea6b5282e Mon Sep 17 00:00:00 2001 From: Xavier Hernandez Date: Sat, 8 Nov 2014 21:46:41 +0100 Subject: ec: Fix posix compliance failures This patch solves some problems that caused dispersed volumes to not pass posix smoke tests: * Problems in open/create with O_WRONLY Opening files with -w- permissions using O_WRONLY returned an EACCES error because internally O_WRONLY was replaced with O_RDWR. * Problems with entrylk on renames. When source and destination were the same, ec tried to acquire the same entrylk twice, causing a deadlock. * Overwrite of a variable when reordering locks. On a rename, if the second lock needed to be placed at the beggining of the list, the 'lock' variable was overwritten and later its timer was cancelled, cancelling the incorrect one. * Handle O_TRUNC in open. When O_TRUNC was received in an open call, it was blindly propagated to child subvolumes. This caused a discrepancy between real file size and the size stored into trusted.ec.size xattr. This has been solved by removing O_TRUNC from open and later calling ftruncate. This is a backport of http://review.gluster.org/9420 Change-Id: I20c3d6e1c11be314be86879be54b728e01013798 BUG: 1159471 Signed-off-by: Xavier Hernandez Reviewed-on: http://review.gluster.org/9501 Tested-by: Gluster Build System Reviewed-by: Dan Lambright Reviewed-by: Pranith Kumar Karampuri Reviewed-by: Raghavendra Bhat --- tests/bugs/bug-1161886/bug-1161886.c | 53 ++++++++++++++++++++++++++++++++++++ tests/bugs/bug-1161886/bug-1161886.t | 44 ++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 tests/bugs/bug-1161886/bug-1161886.c create mode 100644 tests/bugs/bug-1161886/bug-1161886.t (limited to 'tests') diff --git a/tests/bugs/bug-1161886/bug-1161886.c b/tests/bugs/bug-1161886/bug-1161886.c new file mode 100644 index 00000000000..036f4ad1cc7 --- /dev/null +++ b/tests/bugs/bug-1161886/bug-1161886.c @@ -0,0 +1,53 @@ + +#include +#include "glfs.h" +#include "glfs-handles.h" + +int +main (int argc, char *argv[]) +{ + glfs_t *fs = NULL; + glfs_fd_t *fd = NULL; + int ret = 1; + + if (argc != 4) { + fprintf (stderr, "Syntax: %s \n", argv[0]); + return 1; + } + + fs = glfs_new (argv[2]); + if (!fs) { + fprintf (stderr, "glfs_new: returned NULL\n"); + return 1; + } + + ret = glfs_set_volfile_server (fs, "tcp", argv[1], 24007); + if (ret != 0) { + fprintf (stderr, "glfs_set_volfile_server: retuned %d\n", ret); + goto out; + } + ret = glfs_set_logging (fs, "/dev/null", 7); + if (ret != 0) { + fprintf (stderr, "glfs_set_logging: returned %d\n", ret); + goto out; + } + ret = glfs_init (fs); + if (ret != 0) { + fprintf (stderr, "glfs_init: returned %d\n", ret); + goto out; + } + + fd = glfs_open (fs, argv[3], O_RDWR | O_TRUNC); + if (fd == NULL) { + fprintf (stderr, "glfs_open: returned NULL\n"); + goto out; + } + glfs_close(fd); + + ret = 0; + +out: + glfs_fini (fs); + + return ret; +} diff --git a/tests/bugs/bug-1161886/bug-1161886.t b/tests/bugs/bug-1161886/bug-1161886.t new file mode 100644 index 00000000000..3911038cd5f --- /dev/null +++ b/tests/bugs/bug-1161886/bug-1161886.t @@ -0,0 +1,44 @@ +#!/bin/bash + +. $(dirname $0)/../../include.rc +. $(dirname $0)/../../volume.rc + +function check_ec_size +{ + local res + + for i in {0..2}; do + res=$(( `getfattr -n trusted.ec.size -e hex $B0/$V0$i/$1 | sed -n "s/^trusted.ec.size=//p"` )) + if [ "x$res" == "x" -o "$res" != "$2" ]; then + echo "N" + return 0 + fi + done + echo "Y" + return 0 +} + +cleanup + +TEST glusterd +TEST pidof glusterd +TEST $CLI volume create $V0 redundancy 1 $H0:$B0/${V0}{0..2} +EXPECT "Created" volinfo_field $V0 'Status' +TEST $CLI volume start $V0 +EXPECT_WITHIN $PROCESS_UP_TIMEOUT "Started" volinfo_field $V0 'Status' +TEST glusterfs --entry-timeout=0 --attribute-timeout=0 --volfile-id=/$V0 --volfile-server=$H0 $M0 +EXPECT_WITHIN $CHILD_UP_TIMEOUT "3" ec_child_up_count $V0 0 + +TEST dd if=/dev/zero of=$M0/file1 bs=4k count=1 +TEST mv $M0/file1 $M0/file2 +TEST ! stat $M0/file1 +TEST stat $M0/file2 + +TEST gcc -Wall -O2 -I api/src -o $(dirname $0)/bug-1161886 $(dirname $0)/bug-1161886.c -lgfapi +TEST $(dirname $0)/bug-1161886 $H0 $V0 /file2 +EXPECT "^0$" stat -c "%s" $M0/file2 +EXPECT "^Y$" check_ec_size file2 0 + +rm -f $(dirname $0)/bug-1161886 + +cleanup -- cgit