diff options
Diffstat (limited to 'tests/bugs/io-cache')
| -rw-r--r-- | tests/bugs/io-cache/bug-858242.c | 84 | ||||
| -rwxr-xr-x | tests/bugs/io-cache/bug-858242.t | 28 | ||||
| -rw-r--r-- | tests/bugs/io-cache/bug-read-hang.c | 125 | ||||
| -rwxr-xr-x | tests/bugs/io-cache/bug-read-hang.t | 34 |
4 files changed, 271 insertions, 0 deletions
diff --git a/tests/bugs/io-cache/bug-858242.c b/tests/bugs/io-cache/bug-858242.c new file mode 100644 index 00000000000..ac87a15533e --- /dev/null +++ b/tests/bugs/io-cache/bug-858242.c @@ -0,0 +1,84 @@ +#define _GNU_SOURCE + +#include <stdio.h> +#include <errno.h> +#include <string.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <stdlib.h> +#include <unistd.h> + +int +main(int argc, char *argv[]) +{ + char *filename = NULL, *volname = NULL, *cmd = NULL; + char buffer[1024] = { + 0, + }; + int fd = -1; + int ret = -1; + struct stat statbuf = { + 0, + }; + + if (argc != 3) { + fprintf(stderr, "usage: %s <file-name> <volname>\n", argv[0]); + goto out; + } + + filename = argv[1]; + volname = argv[2]; + + fd = open(filename, O_RDWR | O_CREAT, 0); + if (fd < 0) { + fprintf(stderr, "open (%s) failed (%s)\n", filename, strerror(errno)); + goto out; + } + + ret = write(fd, "test-content", 12); + if (ret < 0) { + fprintf(stderr, "write failed (%s)", strerror(errno)); + goto out; + } + + ret = fsync(fd); + if (ret < 0) { + fprintf(stderr, "fsync failed (%s)", strerror(errno)); + goto out; + } + + ret = fstat(fd, &statbuf); + if (ret < 0) { + fprintf(stderr, "fstat failed (%s)", strerror(errno)); + goto out; + } + + ret = asprintf(&cmd, "gluster --mode=script volume stop %s force", volname); + if (ret < 0) { + fprintf(stderr, "cannot construct cli command string (%s)", + strerror(errno)); + goto out; + } + + ret = system(cmd); + if (ret < 0) { + fprintf(stderr, "stopping volume (%s) failed", volname); + goto out; + } + + sleep(3); + + ret = read(fd, buffer, 1024); + if (ret >= 0) { + fprintf(stderr, + "read should've returned error, " + "but is successful\n"); + ret = -1; + goto out; + } + + ret = 0; +out: + return ret; +} diff --git a/tests/bugs/io-cache/bug-858242.t b/tests/bugs/io-cache/bug-858242.t new file mode 100755 index 00000000000..0c8ffb6ab30 --- /dev/null +++ b/tests/bugs/io-cache/bug-858242.t @@ -0,0 +1,28 @@ +#!/bin/bash + +. $(dirname $0)/../../include.rc + +cleanup; + +TEST glusterd +TEST pidof glusterd +TEST $CLI volume info; + +TEST $CLI volume create $V0 $H0:$B0/brick1; +EXPECT 'Created' volinfo_field $V0 'Status'; + +TEST $CLI volume start $V0; +EXPECT 'Started' volinfo_field $V0 'Status'; + +TEST $CLI volume set $V0 performance.quick-read off + +#mount on a random dir +TEST glusterfs --entry-timeout=3600 --attribute-timeout=3600 -s $H0 --volfile-id=$V0 $M0 --direct-io-mode=yes + +build_tester $(dirname $0)/bug-858242.c + +TEST $(dirname $0)/bug-858242 $M0/testfile $V0 + +TEST rm -rf $(dirname $0)/858242 +cleanup; + diff --git a/tests/bugs/io-cache/bug-read-hang.c b/tests/bugs/io-cache/bug-read-hang.c new file mode 100644 index 00000000000..e1fae97e7e8 --- /dev/null +++ b/tests/bugs/io-cache/bug-read-hang.c @@ -0,0 +1,125 @@ +#include <glusterfs/api/glfs.h> +#include <glusterfs/api/glfs-handles.h> +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#define NO_INIT 1 + +int count = 0; +void +read_cbk(glfs_fd_t *fd, ssize_t ret, void *data) +{ + count++; +} + +glfs_t * +setup_new_client(char *hostname, char *volname, char *log_file, int flag) +{ + int ret = 0; + glfs_t *fs = NULL; + + fs = glfs_new(volname); + if (!fs) { + fprintf(stderr, "\nglfs_new: returned NULL (%s)\n", strerror(errno)); + goto error; + } + + ret = glfs_set_volfile_server(fs, "tcp", hostname, 24007); + if (ret < 0) { + fprintf(stderr, "\nglfs_set_volfile_server failed ret:%d (%s)\n", ret, + strerror(errno)); + goto error; + } + + ret = glfs_set_logging(fs, log_file, 7); + if (ret < 0) { + fprintf(stderr, "\nglfs_set_logging failed with ret: %d (%s)\n", ret, + strerror(errno)); + goto error; + } + + if (flag == NO_INIT) + goto out; + + ret = glfs_init(fs); + if (ret < 0) { + fprintf(stderr, "\nglfs_init failed with ret: %d (%s)\n", ret, + strerror(errno)); + goto error; + } + +out: + return fs; +error: + return NULL; +} + +int +main(int argc, char *argv[]) +{ + int ret = 0; + glfs_t *fs = NULL; + struct glfs_fd *fd = NULL; + char *volname = NULL; + char *log_file = NULL; + char *hostname = NULL; + char *buf = NULL; + struct stat stat; + + if (argc != 4) { + fprintf( + stderr, + "Expect following args %s <hostname> <Vol> <log file location>\n", + argv[0]); + return -1; + } + + hostname = argv[1]; + volname = argv[2]; + log_file = argv[3]; + + fs = setup_new_client(hostname, volname, log_file, 0); + if (!fs) { + fprintf(stderr, "\nsetup_new_client: returned NULL (%s)\n", + strerror(errno)); + goto error; + } + + fd = glfs_opendir(fs, "/"); + if (!fd) { + fprintf(stderr, "/: %s\n", strerror(errno)); + return -1; + } + + glfs_readdirplus(fd, &stat); + + fd = glfs_open(fs, "/test", O_RDWR); + if (fd == NULL) { + fprintf(stderr, "glfs_open: returned NULL\n"); + goto error; + } + + buf = (char *)malloc(5); + + ret = glfs_pread(fd, buf, 5, 0, 0, NULL); + if (ret < 0) { + fprintf(stderr, "Read(%s): %d (%s)\n", "test", ret, strerror(errno)); + return ret; + } + + free(buf); + glfs_close(fd); + + ret = glfs_fini(fs); + if (ret < 0) { + fprintf(stderr, "glfs_fini failed with ret: %d (%s)\n", ret, + strerror(errno)); + return -1; + } + + return 0; +error: + return -1; +} diff --git a/tests/bugs/io-cache/bug-read-hang.t b/tests/bugs/io-cache/bug-read-hang.t new file mode 100755 index 00000000000..f8efe281723 --- /dev/null +++ b/tests/bugs/io-cache/bug-read-hang.t @@ -0,0 +1,34 @@ +#!/bin/bash + +. $(dirname $0)/../../include.rc +#. $(dirname $0)/../../volume.rc + +cleanup; + +#Basic checks +TEST glusterd +TEST pidof glusterd +TEST $CLI volume info + +TEST $CLI volume create $V0 replica 2 $H0:$B0/${V0}{1..2}; + +TEST $CLI volume set $V0 features.cache-invalidation on +TEST $CLI volume set $V0 features.cache-invalidation-timeout 600 +TEST $CLI volume set $V0 performance.cache-invalidation on +TEST $CLI volume set $V0 performance.md-cache-timeout 600 +TEST $CLI volume set $V0 performance.cache-samba-metadata on +TEST $CLI volume set $V0 open-behind off + +logdir=`gluster --print-logdir` + +TEST $CLI volume start $V0 + +TEST glusterfs --volfile-id=/$V0 --volfile-server=$H0 $M0 +echo "Hello" > $M0/test + +TEST build_tester $(dirname $0)/bug-read-hang.c -lgfapi +TEST $(dirname $0)/bug-read-hang $H0 $V0 $logdir/bug-read-hang.log + +cleanup_tester $(dirname $0)/bug-read-hang + +cleanup; |
