summaryrefslogtreecommitdiffstats
path: root/tests/basic/ec
diff options
context:
space:
mode:
Diffstat (limited to 'tests/basic/ec')
-rw-r--r--tests/basic/ec/ec-fast-fgetxattr.c191
-rw-r--r--tests/basic/ec/seek.c235
2 files changed, 209 insertions, 217 deletions
diff --git a/tests/basic/ec/ec-fast-fgetxattr.c b/tests/basic/ec/ec-fast-fgetxattr.c
index b40dda65de5..bf982151861 100644
--- a/tests/basic/ec/ec-fast-fgetxattr.c
+++ b/tests/basic/ec/ec-fast-fgetxattr.c
@@ -12,123 +12,118 @@
int cbk_complete = 0;
ssize_t cbk_ret_val = 0;
int
-fill_iov (struct iovec *iov, char fillchar, int count)
+fill_iov(struct iovec *iov, char fillchar, int count)
{
- int ret = -1;
-
- iov->iov_base = malloc (count + 1);
- if (iov->iov_base == NULL) {
- return ret;
- } else {
- iov->iov_len = count;
- ret = 0;
- }
- memset (iov->iov_base, fillchar, count);
- memset (iov->iov_base + count, '\0', 1);
+ int ret = -1;
+ iov->iov_base = malloc(count + 1);
+ if (iov->iov_base == NULL) {
return ret;
+ } else {
+ iov->iov_len = count;
+ ret = 0;
+ }
+ memset(iov->iov_base, fillchar, count);
+ memset(iov->iov_base + count, '\0', 1);
+
+ return ret;
}
void
-write_async_cbk (glfs_fd_t *fd, ssize_t ret, struct stat *prestat,
- struct stat *poststat, void *cookie)
+write_async_cbk(glfs_fd_t *fd, ssize_t ret, struct stat *prestat,
+ struct stat *poststat, void *cookie)
{
-
- if (ret < 0) {
- fprintf (stderr, "glfs_write failed");
- }
- cbk_ret_val = ret;
- cbk_complete = 1;
+ if (ret < 0) {
+ fprintf(stderr, "glfs_write failed");
+ }
+ cbk_ret_val = ret;
+ cbk_complete = 1;
}
int
-write_async (glfs_t *fs, glfs_fd_t *glfd, int char_count)
+write_async(glfs_t *fs, glfs_fd_t *glfd, int char_count)
{
- ssize_t ret = -1;
- int flags = O_RDWR;
- struct iovec iov = {0};
-
-
+ ssize_t ret = -1;
+ int flags = O_RDWR;
+ struct iovec iov = {0};
- ret = fill_iov (&iov, 'a', char_count);
- if (ret) {
- fprintf (stderr, "failed to create iov");
- goto out;
- }
+ ret = fill_iov(&iov, 'a', char_count);
+ if (ret) {
+ fprintf(stderr, "failed to create iov");
+ goto out;
+ }
- ret = glfs_pwritev_async (glfd, &iov, 1, 0, flags, write_async_cbk,
- NULL);
+ ret = glfs_pwritev_async(glfd, &iov, 1, 0, flags, write_async_cbk, NULL);
out:
- if (ret < 0) {
- fprintf (stderr, "glfs_pwritev async failed");
- }
- return ret;
-
+ if (ret < 0) {
+ fprintf(stderr, "glfs_pwritev async failed");
+ }
+ return ret;
}
int
-main (int argc, char *argv[])
+main(int argc, char *argv[])
{
- glfs_t *fs = NULL;
- glfs_fd_t *fd = NULL;
- int ret = 1;
- char buf[1024] = {0};
-
- if (argc != 4) {
- fprintf (stderr, "Syntax: %s <host> <volname> <file>\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: returned %d\n", ret);
- goto out;
- }
- ret = glfs_set_logging (fs, "/tmp/ec-fgetxattr.log", 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;
- }
-
- ret = write_async (fs, fd, 16);
- if (ret) {
- fprintf (stderr, "write_async failed\n");
- }
-
- sleep (1);
- ret = glfs_fgetxattr (fd, "trusted.glusterfs.abc", buf, sizeof buf);
- while (cbk_complete != 1) {
- /* ret will be -ve as xattr doesn't exist, and fgetxattr should
- * return waaaayyy before writev */
- ret = 0;
- sleep (1);
- }
- if (cbk_ret_val < 0) {
- fprintf (stderr, "cbk_ret_val is -ve\n");
- ret = -1;
- }
- glfs_close(fd);
+ glfs_t *fs = NULL;
+ glfs_fd_t *fd = NULL;
+ int ret = 1;
+ char buf[1024] = {0};
+
+ if (argc != 4) {
+ fprintf(stderr, "Syntax: %s <host> <volname> <file>\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: returned %d\n", ret);
+ goto out;
+ }
+ ret = glfs_set_logging(fs, "/tmp/ec-fgetxattr.log", 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;
+ }
+
+ ret = write_async(fs, fd, 16);
+ if (ret) {
+ fprintf(stderr, "write_async failed\n");
+ }
+
+ sleep(1);
+ ret = glfs_fgetxattr(fd, "trusted.glusterfs.abc", buf, sizeof buf);
+ while (cbk_complete != 1) {
+ /* ret will be -ve as xattr doesn't exist, and fgetxattr should
+ * return waaaayyy before writev */
+ ret = 0;
+ sleep(1);
+ }
+ if (cbk_ret_val < 0) {
+ fprintf(stderr, "cbk_ret_val is -ve\n");
+ ret = -1;
+ }
+ glfs_close(fd);
out:
- unlink ("/tmp/ec-fgetxattr.log");
- glfs_fini (fs);
+ unlink("/tmp/ec-fgetxattr.log");
+ glfs_fini(fs);
- return ret;
+ return ret;
}
diff --git a/tests/basic/ec/seek.c b/tests/basic/ec/seek.c
index 67036ad4e75..54fa6f463af 100644
--- a/tests/basic/ec/seek.c
+++ b/tests/basic/ec/seek.c
@@ -15,171 +15,168 @@ static char buffer[65536];
static int
parse_int(const char *text, size_t *value)
{
- char *ptr;
- size_t val;
+ char *ptr;
+ size_t val;
- val = strtoul(text, &ptr, 0);
- if (*ptr != 0) {
- return 0;
- }
+ val = strtoul(text, &ptr, 0);
+ if (*ptr != 0) {
+ return 0;
+ }
- *value = val;
+ *value = val;
- return 1;
+ 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;
+ 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;
+ return 1;
}
static void
syntax(void)
{
- fprintf(stderr, "Syntax: seek create <path> <offset> <size> [...]\n");
- fprintf(stderr, " seek scan <path> data|hole <offset>\n");
+ fprintf(stderr, "Syntax: seek create <path> <offset> <size> [...]\n");
+ fprintf(stderr, " seek scan <path> data|hole <offset>\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;
+ 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;
}
-
- 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;
+ if (!fill_area(fd, off, size)) {
+ goto out_close;
}
+ argv += 2;
+ argc -= 2;
+ }
- ret = 0;
+ ret = 0;
out_close:
- close(fd);
+ close(fd);
out:
- return ret;
+ 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;
+ 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);
+ }
- 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;
+ ret = 0;
out_close:
- close(fd);
+ close(fd);
out:
- return ret;
+ return ret;
}
int
main(int argc, char *argv[])
{
- int ret = 1;
+ int ret = 1;
- memset(buffer, 0x55, sizeof(buffer));
+ memset(buffer, 0x55, sizeof(buffer));
- if (argc < 3) {
- syntax();
- goto out;
- }
+ 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;
+ 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;
+ ret = 0;
out:
- return ret;
+ return ret;
}
-