From 2f43a1a4b567ec02ec03847b6eaec5ac59e68808 Mon Sep 17 00:00:00 2001 From: Pranith Kumar K Date: Thu, 10 Oct 2019 09:37:24 +0530 Subject: cluster/afr: Add afr_seek to fops table fixes: bz#1760189 Change-Id: Iffbf8d6f4c50b8e2de8364658697bdbe96549f5d Signed-off-by: Pranith Kumar K --- tests/basic/afr/afr-seek.t | 55 ++++++++++++++ tests/basic/ec/ec-seek.t | 3 +- tests/basic/ec/seek.c | 182 --------------------------------------------- tests/basic/seek.c | 182 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 239 insertions(+), 183 deletions(-) create mode 100644 tests/basic/afr/afr-seek.t delete mode 100644 tests/basic/ec/seek.c create mode 100644 tests/basic/seek.c (limited to 'tests/basic') diff --git a/tests/basic/afr/afr-seek.t b/tests/basic/afr/afr-seek.t new file mode 100644 index 00000000000..c12ee011660 --- /dev/null +++ b/tests/basic/afr/afr-seek.t @@ -0,0 +1,55 @@ +#!/bin/bash + +. $(dirname $0)/../../include.rc +. $(dirname $0)/../../volume.rc + +cleanup + +SEEK=$(dirname $0)/seek +build_tester $(dirname $0)/../seek.c -o ${SEEK} + +TEST glusterd +TEST pidof glusterd +TEST $CLI volume info + +TEST mkdir -p $B0/${V0}{0..2} +TEST $CLI volume create $V0 replica 3 $H0:$B0/${V0}{0..2} + +TEST $CLI volume start $V0 + +TEST $GFS -s $H0 --volfile-id $V0 $M0 +EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1" afr_child_up_status $V0 0 +EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1" afr_child_up_status $V0 1 +EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1" afr_child_up_status $V0 2 + +TEST ${SEEK} create ${M0}/test 0 1 1048576 1 +# Determine underlying filesystem allocation block size +BSIZE="$(($(${SEEK} scan ${M0}/test hole 0) * 2))" + +TEST ${SEEK} create ${M0}/test 0 ${BSIZE} $((${BSIZE} * 4 + 512)) ${BSIZE} + +EXPECT "^0$" ${SEEK} scan ${M0}/test data 0 +EXPECT "^$((${BSIZE} / 2))$" ${SEEK} scan ${M0}/test data $((${BSIZE} / 2)) +EXPECT "^$((${BSIZE} - 1))$" ${SEEK} scan ${M0}/test data $((${BSIZE} - 1)) +EXPECT "^$((${BSIZE} * 4))$" ${SEEK} scan ${M0}/test data ${BSIZE} +EXPECT "^$((${BSIZE} * 4))$" ${SEEK} scan ${M0}/test data $((${BSIZE} * 4)) +EXPECT "^$((${BSIZE} * 5))$" ${SEEK} scan ${M0}/test data $((${BSIZE} * 5)) +EXPECT "^$((${BSIZE} * 5 + 511))$" ${SEEK} scan ${M0}/test data $((${BSIZE} * 5 + 511)) +EXPECT "^ENXIO$" ${SEEK} scan ${M0}/test data $((${BSIZE} * 5 + 512)) +EXPECT "^ENXIO$" ${SEEK} scan ${M0}/test data $((${BSIZE} * 6)) + +EXPECT "^${BSIZE}$" ${SEEK} scan ${M0}/test hole 0 +EXPECT "^${BSIZE}$" ${SEEK} scan ${M0}/test hole $((${BSIZE} / 2)) +EXPECT "^${BSIZE}$" ${SEEK} scan ${M0}/test hole $((${BSIZE} - 1)) +EXPECT "^${BSIZE}$" ${SEEK} scan ${M0}/test hole ${BSIZE} +EXPECT "^$((${BSIZE} * 5 + 512))$" ${SEEK} scan ${M0}/test hole $((${BSIZE} * 4)) +EXPECT "^$((${BSIZE} * 5 + 512))$" ${SEEK} scan ${M0}/test hole $((${BSIZE} * 5)) +EXPECT "^$((${BSIZE} * 5 + 512))$" ${SEEK} scan ${M0}/test hole $((${BSIZE} * 5 + 511)) +EXPECT "^ENXIO$" ${SEEK} scan ${M0}/test hole $((${BSIZE} * 5 + 512)) +EXPECT "^ENXIO$" ${SEEK} scan ${M0}/test hole $((${BSIZE} * 6)) + +rm -f ${SEEK} +cleanup + +# Centos6 regression slaves seem to not support SEEK_DATA/SEEK_HOLE +#G_TESTDEF_TEST_STATUS_CENTOS6=BAD_TEST,BUG=000000 diff --git a/tests/basic/ec/ec-seek.t b/tests/basic/ec/ec-seek.t index 6a0060870c8..5a7d31b9f8f 100644 --- a/tests/basic/ec/ec-seek.t +++ b/tests/basic/ec/ec-seek.t @@ -6,7 +6,7 @@ cleanup SEEK=$(dirname $0)/seek -build_tester $(dirname $0)/seek.c -o ${SEEK} +build_tester $(dirname $0)/../seek.c -o ${SEEK} TEST glusterd TEST pidof glusterd @@ -51,6 +51,7 @@ EXPECT "^$((${BSIZE} * 5 + 512))$" ${SEEK} scan ${M0}/test hole $((${BSIZE} * 5 EXPECT "^ENXIO$" ${SEEK} scan ${M0}/test hole $((${BSIZE} * 5 + 512)) EXPECT "^ENXIO$" ${SEEK} scan ${M0}/test hole $((${BSIZE} * 6)) +rm -f ${SEEK} cleanup # Centos6 regression slaves seem to not support SEEK_DATA/SEEK_HOLE diff --git a/tests/basic/ec/seek.c b/tests/basic/ec/seek.c deleted file mode 100644 index 54fa6f463af..00000000000 --- a/tests/basic/ec/seek.c +++ /dev/null @@ -1,182 +0,0 @@ - -#define _GNU_SOURCE - -#include -#include -#include -#include -#include -#include -#include -#include - -static char buffer[65536]; - -static int -parse_int(const char *text, size_t *value) -{ - char *ptr; - size_t val; - - val = strtoul(text, &ptr, 0); - if (*ptr != 0) { - return 0; - } - - *value = val; - - return 1; -} - -static int -fill_area(int fd, off_t offset, size_t size) -{ - size_t len; - ssize_t res; - - while (size > 0) { - len = sizeof(buffer); - if (len > size) { - len = size; - } - res = pwrite(fd, buffer, len, offset); - if (res < 0) { - fprintf(stderr, "pwrite(%d, %p, %lu, %lu) failed: %d\n", fd, buffer, - size, offset, errno); - return 0; - } - if (res != len) { - fprintf(stderr, - "pwrite(%d, %p, %lu, %lu) didn't wrote all " - "data: %lu/%lu\n", - fd, buffer, size, offset, res, len); - return 0; - } - offset += len; - size -= len; - } - - return 1; -} - -static void -syntax(void) -{ - fprintf(stderr, "Syntax: seek create [...]\n"); - fprintf(stderr, " seek scan data|hole \n"); -} - -static int -seek_create(const char *path, int argc, char *argv[]) -{ - size_t off, size; - int fd; - int ret = 1; - - fd = open(path, O_CREAT | O_TRUNC | O_RDWR, 0644); - if (fd < 0) { - fprintf(stderr, "Failed to create the file\n"); - goto out; - } - - while (argc > 0) { - if (!parse_int(argv[0], &off) || !parse_int(argv[1], &size)) { - syntax(); - goto out_close; - } - if (!fill_area(fd, off, size)) { - goto out_close; - } - argv += 2; - argc -= 2; - } - - ret = 0; - -out_close: - close(fd); -out: - return ret; -} - -static int -seek_scan(const char *path, const char *type, const char *pos) -{ - size_t off, res; - int fd, whence; - int ret = 1; - - if (strcmp(type, "data") == 0) { - whence = SEEK_DATA; - } else if (strcmp(type, "hole") == 0) { - whence = SEEK_HOLE; - } else { - syntax(); - goto out; - } - - if (!parse_int(pos, &off)) { - syntax(); - goto out; - } - - fd = open(path, O_RDWR); - if (fd < 0) { - fprintf(stderr, "Failed to open the file\n"); - goto out; - } - - res = lseek(fd, off, whence); - if (res == (off_t)-1) { - if (errno != ENXIO) { - fprintf(stderr, "seek(%d, %lu, %d) failed: %d\n", fd, off, whence, - errno); - goto out_close; - } - fprintf(stdout, "ENXIO\n"); - } else { - fprintf(stdout, "%lu\n", res); - } - - ret = 0; - -out_close: - close(fd); -out: - return ret; -} - -int -main(int argc, char *argv[]) -{ - int ret = 1; - - memset(buffer, 0x55, sizeof(buffer)); - - if (argc < 3) { - syntax(); - goto out; - } - - if (strcmp(argv[1], "create") == 0) { - if (((argc - 3) & 1) != 0) { - syntax(); - goto out; - } - ret = seek_create(argv[2], argc - 3, argv + 3); - } else if (strcmp(argv[1], "scan") == 0) { - if (argc != 5) { - syntax(); - goto out; - } - ret = seek_scan(argv[2], argv[3], argv[4]); - } else { - syntax(); - goto out; - } - - ret = 0; - -out: - return ret; -} diff --git a/tests/basic/seek.c b/tests/basic/seek.c new file mode 100644 index 00000000000..54fa6f463af --- /dev/null +++ b/tests/basic/seek.c @@ -0,0 +1,182 @@ + +#define _GNU_SOURCE + +#include +#include +#include +#include +#include +#include +#include +#include + +static char buffer[65536]; + +static int +parse_int(const char *text, size_t *value) +{ + char *ptr; + size_t val; + + val = strtoul(text, &ptr, 0); + if (*ptr != 0) { + return 0; + } + + *value = val; + + return 1; +} + +static int +fill_area(int fd, off_t offset, size_t size) +{ + size_t len; + ssize_t res; + + while (size > 0) { + len = sizeof(buffer); + if (len > size) { + len = size; + } + res = pwrite(fd, buffer, len, offset); + if (res < 0) { + fprintf(stderr, "pwrite(%d, %p, %lu, %lu) failed: %d\n", fd, buffer, + size, offset, errno); + return 0; + } + if (res != len) { + fprintf(stderr, + "pwrite(%d, %p, %lu, %lu) didn't wrote all " + "data: %lu/%lu\n", + fd, buffer, size, offset, res, len); + return 0; + } + offset += len; + size -= len; + } + + return 1; +} + +static void +syntax(void) +{ + fprintf(stderr, "Syntax: seek create [...]\n"); + fprintf(stderr, " seek scan data|hole \n"); +} + +static int +seek_create(const char *path, int argc, char *argv[]) +{ + size_t off, size; + int fd; + int ret = 1; + + fd = open(path, O_CREAT | O_TRUNC | O_RDWR, 0644); + if (fd < 0) { + fprintf(stderr, "Failed to create the file\n"); + goto out; + } + + while (argc > 0) { + if (!parse_int(argv[0], &off) || !parse_int(argv[1], &size)) { + syntax(); + goto out_close; + } + if (!fill_area(fd, off, size)) { + goto out_close; + } + argv += 2; + argc -= 2; + } + + ret = 0; + +out_close: + close(fd); +out: + return ret; +} + +static int +seek_scan(const char *path, const char *type, const char *pos) +{ + size_t off, res; + int fd, whence; + int ret = 1; + + if (strcmp(type, "data") == 0) { + whence = SEEK_DATA; + } else if (strcmp(type, "hole") == 0) { + whence = SEEK_HOLE; + } else { + syntax(); + goto out; + } + + if (!parse_int(pos, &off)) { + syntax(); + goto out; + } + + fd = open(path, O_RDWR); + if (fd < 0) { + fprintf(stderr, "Failed to open the file\n"); + goto out; + } + + res = lseek(fd, off, whence); + if (res == (off_t)-1) { + if (errno != ENXIO) { + fprintf(stderr, "seek(%d, %lu, %d) failed: %d\n", fd, off, whence, + errno); + goto out_close; + } + fprintf(stdout, "ENXIO\n"); + } else { + fprintf(stdout, "%lu\n", res); + } + + ret = 0; + +out_close: + close(fd); +out: + return ret; +} + +int +main(int argc, char *argv[]) +{ + int ret = 1; + + memset(buffer, 0x55, sizeof(buffer)); + + if (argc < 3) { + syntax(); + goto out; + } + + if (strcmp(argv[1], "create") == 0) { + if (((argc - 3) & 1) != 0) { + syntax(); + goto out; + } + ret = seek_create(argv[2], argc - 3, argv + 3); + } else if (strcmp(argv[1], "scan") == 0) { + if (argc != 5) { + syntax(); + goto out; + } + ret = seek_scan(argv[2], argv[3], argv[4]); + } else { + syntax(); + goto out; + } + + ret = 0; + +out: + return ret; +} -- cgit