summaryrefslogtreecommitdiffstats
path: root/tests/basic
diff options
context:
space:
mode:
authorGluster Ant <bugzilla-bot@gluster.org>2018-09-12 17:52:45 +0530
committerNigel Babu <nigelb@redhat.com>2018-09-12 17:52:45 +0530
commite16868dede6455cab644805af6fe1ac312775e13 (patch)
tree15aebdb4fff2d87cf8a72f836816b3aa634da58d /tests/basic
parent45a71c0548b6fd2c757aa2e7b7671a1411948894 (diff)
Land part 2 of clang-format changes
Change-Id: Ia84cc24c8924e6d22d02ac15f611c10e26db99b4 Signed-off-by: Nigel Babu <nigelb@redhat.com>
Diffstat (limited to 'tests/basic')
-rw-r--r--tests/basic/ctime/ctime-glfs-init.c85
-rw-r--r--tests/basic/ec/ec-fast-fgetxattr.c191
-rw-r--r--tests/basic/ec/seek.c235
-rw-r--r--tests/basic/fops-sanity.c1811
-rw-r--r--tests/basic/fuse/seek.c102
-rw-r--r--tests/basic/gfapi/anonymous_fd_read_write.c177
-rw-r--r--tests/basic/gfapi/bug-1241104.c141
-rw-r--r--tests/basic/gfapi/bug1283983.c205
-rw-r--r--tests/basic/gfapi/bug1291259.c300
-rw-r--r--tests/basic/gfapi/bug1613098.c157
-rw-r--r--tests/basic/gfapi/gfapi-async-calls-test.c272
-rw-r--r--tests/basic/gfapi/gfapi-dup.c144
-rw-r--r--tests/basic/gfapi/gfapi-load-volfile.c64
-rw-r--r--tests/basic/gfapi/gfapi-ssl-test.c194
-rw-r--r--tests/basic/gfapi/gfapi-trunc.c151
-rw-r--r--tests/basic/gfapi/glfd-lkowner.c350
-rw-r--r--tests/basic/gfapi/glfs_sysrq.c93
-rw-r--r--tests/basic/gfapi/glfs_xreaddirplus_r.c346
-rw-r--r--tests/basic/gfapi/libgfapi-fini-hang.c97
-rw-r--r--tests/basic/gfapi/mandatory-lock-optimal.c765
-rw-r--r--tests/basic/gfapi/seek.c138
-rw-r--r--tests/basic/gfapi/upcall-cache-invalidate.c359
-rw-r--r--tests/basic/gfapi/upcall-register-api.c477
-rw-r--r--tests/basic/logchecks.c350
-rw-r--r--tests/basic/posix/zero-fill-enospace.c100
-rw-r--r--tests/basic/quota.c107
-rw-r--r--tests/basic/tier/file_lock.c127
27 files changed, 3806 insertions, 3732 deletions
diff --git a/tests/basic/ctime/ctime-glfs-init.c b/tests/basic/ctime/ctime-glfs-init.c
index 57a3dc7820e..e4f197b8f30 100644
--- a/tests/basic/ctime/ctime-glfs-init.c
+++ b/tests/basic/ctime/ctime-glfs-init.c
@@ -10,58 +10,59 @@
#include <glusterfs/api/glfs.h>
#include <glusterfs/api/glfs-handles.h>
-#define LOG_ERR(msg) do { \
- fprintf (stderr, "%s : Error (%s)\n", msg, strerror (errno)); \
- } while (0)
+#define LOG_ERR(msg) \
+ do { \
+ fprintf(stderr, "%s : Error (%s)\n", msg, strerror(errno)); \
+ } while (0)
int
-main (int argc, char *argv[])
+main(int argc, char *argv[])
{
- int ret = 0;
- char *hostname = NULL;
- char *volname = NULL;
- char *logfile = NULL;
- glfs_t *fs = NULL;
+ int ret = 0;
+ char *hostname = NULL;
+ char *volname = NULL;
+ char *logfile = NULL;
+ glfs_t *fs = NULL;
- if (argc != 4) {
- fprintf (stderr, "Invalid argument\n");
- exit(1);
- }
+ if (argc != 4) {
+ fprintf(stderr, "Invalid argument\n");
+ exit(1);
+ }
- hostname = argv[1];
- volname = argv[2];
- logfile = argv[3];
+ hostname = argv[1];
+ volname = argv[2];
+ logfile = argv[3];
- fs = glfs_new (volname);
- if (!fs) {
- LOG_ERR ("glfs_new failed");
- return -1;
- }
+ fs = glfs_new(volname);
+ if (!fs) {
+ LOG_ERR("glfs_new failed");
+ return -1;
+ }
- ret = glfs_set_volfile_server (fs, "tcp", hostname, 24007);
- if (ret < 0) {
- LOG_ERR ("glfs_set_volfile_server failed");
- goto err;
- }
+ ret = glfs_set_volfile_server(fs, "tcp", hostname, 24007);
+ if (ret < 0) {
+ LOG_ERR("glfs_set_volfile_server failed");
+ goto err;
+ }
- ret = glfs_set_logging (fs, logfile, 7);
- if (ret < 0) {
- LOG_ERR ("glfs_set_logging failed");
- goto err;
- }
+ ret = glfs_set_logging(fs, logfile, 7);
+ if (ret < 0) {
+ LOG_ERR("glfs_set_logging failed");
+ goto err;
+ }
- ret = glfs_init (fs);
- if (ret < 0) {
- LOG_ERR ("glfs_init failed");
- goto err;
- }
+ ret = glfs_init(fs);
+ if (ret < 0) {
+ LOG_ERR("glfs_init failed");
+ goto err;
+ }
- glfs_fini (fs);
- fs = NULL;
- return 0;
+ glfs_fini(fs);
+ fs = NULL;
+ return 0;
err:
- glfs_fini (fs);
- fs = NULL;
+ glfs_fini(fs);
+ fs = NULL;
- return -1;
+ return -1;
}
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;
}
-
diff --git a/tests/basic/fops-sanity.c b/tests/basic/fops-sanity.c
index 1e2ccde6bd8..aff72d89ca1 100644
--- a/tests/basic/fops-sanity.c
+++ b/tests/basic/fops-sanity.c
@@ -34,858 +34,904 @@
#endif
/* for fd based fops after unlink */
-int fd_based_fops_1 (char *filename);
+int
+fd_based_fops_1(char *filename);
/* for fd based fops before unlink */
-int fd_based_fops_2 (char *filename);
+int
+fd_based_fops_2(char *filename);
/* fops based on fd after dup */
-int dup_fd_based_fops (char *filename);
+int
+dup_fd_based_fops(char *filename);
/* for fops based on path */
-int path_based_fops (char *filename);
+int
+path_based_fops(char *filename);
/* for fops which operate on directory */
-int dir_based_fops (char *filename);
+int
+dir_based_fops(char *filename);
/* for fops which operate in link files (symlinks) */
-int link_based_fops (char *filename);
+int
+link_based_fops(char *filename);
/* to test open syscall with open modes available. */
-int test_open_modes (char *filename);
+int
+test_open_modes(char *filename);
/* generic function which does open write and read. */
-int generic_open_read_write (char *filename, int flag, mode_t mode);
+int
+generic_open_read_write(char *filename, int flag, mode_t mode);
-#define OPEN_MODE 0666
+#define OPEN_MODE 0666
int
-main (int argc, char *argv[])
+main(int argc, char *argv[])
{
- int ret = -1;
- int result = 0;
- char filename[255] = {0,};
-
- if (argc > 1)
- strcpy(filename, argv[1]);
- else
- strcpy(filename, "temp-xattr-test-file");
-
- ret = fd_based_fops_1 (strcat(filename, "_1"));
- if (ret < 0) {
- fprintf (stderr, "fd based file operation 1 failed\n");
- result |= ret;
- } else {
- fprintf (stdout, "fd based file operation 1 passed\n");
- }
-
- ret = fd_based_fops_2 (strcat(filename, "_2"));
- if (ret < 0) {
- result |= ret;
- fprintf (stderr, "fd based file operation 2 failed\n");
- } else {
- fprintf (stdout, "fd based file operation 2 passed\n");
- }
-
- ret = dup_fd_based_fops (strcat (filename, "_3"));
- if (ret < 0) {
- result |= ret;
- fprintf (stderr, "dup fd based file operation failed\n");
- } else {
- fprintf (stdout, "dup fd based file operation passed\n");
- }
-
- ret = path_based_fops (strcat (filename, "_4"));
- if (ret < 0) {
- result |= ret;
- fprintf (stderr, "path based file operation failed\n");
- } else {
- fprintf (stdout, "path based file operation passed\n");
- }
-
- ret = dir_based_fops (strcat (filename, "_5"));
- if (ret < 0) {
- result |= ret;
- fprintf (stderr, "directory based file operation failed\n");
- } else {
- fprintf (stdout, "directory based file operation passed\n");
- }
-
- ret = link_based_fops (strcat (filename, "_5"));
- if (ret < 0) {
- result |= ret;
- fprintf (stderr, "link based file operation failed\n");
- } else {
- fprintf (stdout, "link based file operation passed\n");
- }
-
- ret = test_open_modes (strcat (filename, "_5"));
- if (ret < 0) {
- result |= ret;
- fprintf (stderr, "testing modes of `open' call failed\n");
- } else {
- fprintf (stdout, "testing modes of `open' call passed\n");
- }
- return result;
+ int ret = -1;
+ int result = 0;
+ char filename[255] = {
+ 0,
+ };
+
+ if (argc > 1)
+ strcpy(filename, argv[1]);
+ else
+ strcpy(filename, "temp-xattr-test-file");
+
+ ret = fd_based_fops_1(strcat(filename, "_1"));
+ if (ret < 0) {
+ fprintf(stderr, "fd based file operation 1 failed\n");
+ result |= ret;
+ } else {
+ fprintf(stdout, "fd based file operation 1 passed\n");
+ }
+
+ ret = fd_based_fops_2(strcat(filename, "_2"));
+ if (ret < 0) {
+ result |= ret;
+ fprintf(stderr, "fd based file operation 2 failed\n");
+ } else {
+ fprintf(stdout, "fd based file operation 2 passed\n");
+ }
+
+ ret = dup_fd_based_fops(strcat(filename, "_3"));
+ if (ret < 0) {
+ result |= ret;
+ fprintf(stderr, "dup fd based file operation failed\n");
+ } else {
+ fprintf(stdout, "dup fd based file operation passed\n");
+ }
+
+ ret = path_based_fops(strcat(filename, "_4"));
+ if (ret < 0) {
+ result |= ret;
+ fprintf(stderr, "path based file operation failed\n");
+ } else {
+ fprintf(stdout, "path based file operation passed\n");
+ }
+
+ ret = dir_based_fops(strcat(filename, "_5"));
+ if (ret < 0) {
+ result |= ret;
+ fprintf(stderr, "directory based file operation failed\n");
+ } else {
+ fprintf(stdout, "directory based file operation passed\n");
+ }
+
+ ret = link_based_fops(strcat(filename, "_5"));
+ if (ret < 0) {
+ result |= ret;
+ fprintf(stderr, "link based file operation failed\n");
+ } else {
+ fprintf(stdout, "link based file operation passed\n");
+ }
+
+ ret = test_open_modes(strcat(filename, "_5"));
+ if (ret < 0) {
+ result |= ret;
+ fprintf(stderr, "testing modes of `open' call failed\n");
+ } else {
+ fprintf(stdout, "testing modes of `open' call passed\n");
+ }
+ return result;
}
/* Execute all possible fops on a fd which is unlinked */
int
-fd_based_fops_1 (char *filename)
+fd_based_fops_1(char *filename)
{
- int fd = 0;
- int ret = -1;
- int result = 0;
- struct stat stbuf = {0,};
- char wstr[50] = {0,};
- char rstr[50] = {0,};
-
- fd = open (filename, O_RDWR|O_CREAT, OPEN_MODE);
- if (fd < 0) {
- fprintf (stderr, "open failed : %s\n", strerror (errno));
- return ret;
- }
-
- ret = unlink (filename);
- if (ret < 0) {
- fprintf (stderr, "unlink failed : %s\n", strerror (errno));
- result |= ret;
- }
-
- strcpy (wstr, "This is my string\n");
- ret = write (fd, wstr, strlen(wstr));
- if (ret <= 0) {
- fprintf (stderr, "write failed: %s\n", strerror (errno));
- result |= ret;
- }
-
- ret = lseek (fd, 0, SEEK_SET);
- if (ret < 0) {
- fprintf (stderr, "lseek failed: %s\n", strerror (errno));
- result |= ret;
- }
-
- ret = read (fd, rstr, strlen(wstr));
- if (ret <= 0) {
- fprintf (stderr, "read failed: %s\n", strerror (errno));
- result |= ret;
- }
-
- ret = memcmp (rstr, wstr, strlen (wstr));
- if (ret != 0) {
- fprintf (stderr, "read returning junk\n");
- result |= ret;
- }
-
- ret = ftruncate (fd, 0);
- if (ret < 0) {
- fprintf (stderr, "ftruncate failed : %s\n", strerror (errno));
- result |= ret;
- }
-
- ret = fstat (fd, &stbuf);
- if (ret < 0) {
- fprintf (stderr, "fstat failed : %s\n", strerror (errno));
- result |= ret;
- }
-
- ret = fsync (fd);
- if (ret < 0) {
- fprintf (stderr, "fsync failed : %s\n", strerror (errno));
- result |= ret;
- }
-
- ret = fdatasync (fd);
- if (ret < 0) {
- fprintf (stderr, "fdatasync failed : %s\n", strerror (errno));
- result |= ret;
- }
-
-/*
- * These metadata operations fail at the moment because kernel doesn't
- * pass the client fd in the operation.
- * The following bug tracks this change.
- * https://bugzilla.redhat.com/show_bug.cgi?id=1084422
- * ret = fchmod (fd, 0640);
- * if (ret < 0) {
- * fprintf (stderr, "fchmod failed : %s\n", strerror (errno));
- * result |= ret;
- * }
-
- * ret = fchown (fd, 10001, 10001);
- * if (ret < 0) {
- * fprintf (stderr, "fchown failed : %s\n", strerror (errno));
- * result |= ret;
- * }
-
- * ret = fsetxattr (fd, "trusted.xattr-test", "working", 8, 0);
- * if (ret < 0) {
- * fprintf (stderr, "fsetxattr failed : %s\n", strerror (errno));
- * result |= ret;
- * }
-
- * ret = flistxattr (fd, NULL, 0);
- * if (ret <= 0) {
- * fprintf (stderr, "flistxattr failed : %s\n", strerror (errno));
- * result |= ret;
- * }
-
- * ret = fgetxattr (fd, "trusted.xattr-test", NULL, 0);
- * if (ret <= 0) {
- * fprintf (stderr, "fgetxattr failed : %s\n", strerror (errno));
- * result |= ret;
- * }
-
- * ret = fremovexattr (fd, "trusted.xattr-test");
- * if (ret < 0) {
- * fprintf (stderr, "fremovexattr failed : %s\n", strerror (errno));
- * result |= ret;
- * }
- */
-
- if (fd)
- close(fd);
- return result;
+ int fd = 0;
+ int ret = -1;
+ int result = 0;
+ struct stat stbuf = {
+ 0,
+ };
+ char wstr[50] = {
+ 0,
+ };
+ char rstr[50] = {
+ 0,
+ };
+
+ fd = open(filename, O_RDWR | O_CREAT, OPEN_MODE);
+ if (fd < 0) {
+ fprintf(stderr, "open failed : %s\n", strerror(errno));
+ return ret;
+ }
+
+ ret = unlink(filename);
+ if (ret < 0) {
+ fprintf(stderr, "unlink failed : %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ strcpy(wstr, "This is my string\n");
+ ret = write(fd, wstr, strlen(wstr));
+ if (ret <= 0) {
+ fprintf(stderr, "write failed: %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = lseek(fd, 0, SEEK_SET);
+ if (ret < 0) {
+ fprintf(stderr, "lseek failed: %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = read(fd, rstr, strlen(wstr));
+ if (ret <= 0) {
+ fprintf(stderr, "read failed: %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = memcmp(rstr, wstr, strlen(wstr));
+ if (ret != 0) {
+ fprintf(stderr, "read returning junk\n");
+ result |= ret;
+ }
+
+ ret = ftruncate(fd, 0);
+ if (ret < 0) {
+ fprintf(stderr, "ftruncate failed : %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = fstat(fd, &stbuf);
+ if (ret < 0) {
+ fprintf(stderr, "fstat failed : %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = fsync(fd);
+ if (ret < 0) {
+ fprintf(stderr, "fsync failed : %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = fdatasync(fd);
+ if (ret < 0) {
+ fprintf(stderr, "fdatasync failed : %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ /*
+ * These metadata operations fail at the moment because kernel doesn't
+ * pass the client fd in the operation.
+ * The following bug tracks this change.
+ * https://bugzilla.redhat.com/show_bug.cgi?id=1084422
+ * ret = fchmod (fd, 0640);
+ * if (ret < 0) {
+ * fprintf (stderr, "fchmod failed : %s\n", strerror (errno));
+ * result |= ret;
+ * }
+
+ * ret = fchown (fd, 10001, 10001);
+ * if (ret < 0) {
+ * fprintf (stderr, "fchown failed : %s\n", strerror (errno));
+ * result |= ret;
+ * }
+
+ * ret = fsetxattr (fd, "trusted.xattr-test", "working", 8, 0);
+ * if (ret < 0) {
+ * fprintf (stderr, "fsetxattr failed : %s\n", strerror
+ (errno));
+ * result |= ret;
+ * }
+
+ * ret = flistxattr (fd, NULL, 0);
+ * if (ret <= 0) {
+ * fprintf (stderr, "flistxattr failed : %s\n", strerror
+ (errno));
+ * result |= ret;
+ * }
+
+ * ret = fgetxattr (fd, "trusted.xattr-test", NULL, 0);
+ * if (ret <= 0) {
+ * fprintf (stderr, "fgetxattr failed : %s\n", strerror
+ (errno));
+ * result |= ret;
+ * }
+
+ * ret = fremovexattr (fd, "trusted.xattr-test");
+ * if (ret < 0) {
+ * fprintf (stderr, "fremovexattr failed : %s\n", strerror
+ (errno));
+ * result |= ret;
+ * }
+ */
+
+ if (fd)
+ close(fd);
+ return result;
}
-
int
-fd_based_fops_2 (char *filename)
+fd_based_fops_2(char *filename)
{
- int fd = 0;
- int ret = -1;
- int result = 0;
- struct stat stbuf = {0,};
- char wstr[50] = {0,};
- char rstr[50] = {0,};
-
- fd = open (filename, O_RDWR|O_CREAT, OPEN_MODE);
- if (fd < 0) {
- fprintf (stderr, "open failed : %s\n", strerror (errno));
- return ret;
- }
-
- ret = ftruncate (fd, 0);
- if (ret < 0) {
- fprintf (stderr, "ftruncate failed : %s\n", strerror (errno));
- result |= ret;
- }
-
- strcpy (wstr, "This is my second string\n");
- ret = write (fd, wstr, strlen (wstr));
- if (ret < 0) {
- fprintf (stderr, "write failed: %s\n", strerror (errno));
- result |= ret;
- }
-
- lseek (fd, 0, SEEK_SET);
- if (ret < 0) {
- fprintf (stderr, "lseek failed: %s\n", strerror (errno));
- result |= ret;
- }
-
- ret = read (fd, rstr, strlen (wstr));
- if (ret <= 0) {
- fprintf (stderr, "read failed: %s\n", strerror (errno));
- result |= ret;
- }
-
- ret = memcmp (rstr, wstr, strlen (wstr));
- if (ret != 0) {
- fprintf (stderr, "read returning junk\n");
- result |= ret;
- }
-
- ret = fstat (fd, &stbuf);
- if (ret < 0) {
- fprintf (stderr, "fstat failed : %s\n", strerror (errno));
- result |= ret;
- }
-
- ret = fchmod (fd, 0640);
- if (ret < 0) {
- fprintf (stderr, "fchmod failed : %s\n", strerror (errno));
- result |= ret;
- }
-
- ret = fchown (fd, 10001, 10001);
- if (ret < 0) {
- fprintf (stderr, "fchown failed : %s\n", strerror (errno));
- result |= ret;
- }
-
- ret = fsync (fd);
- if (ret < 0) {
- fprintf (stderr, "fsync failed : %s\n", strerror (errno));
- result |= ret;
- }
-
- ret = fsetxattr (fd, "trusted.xattr-test", "working", 8, 0);
- if (ret < 0) {
- fprintf (stderr, "fsetxattr failed : %s\n", strerror (errno));
- result |= ret;
- }
-
- ret = fdatasync (fd);
- if (ret < 0) {
- fprintf (stderr, "fdatasync failed : %s\n", strerror (errno));
- result |= ret;
- }
-
- ret = flistxattr (fd, NULL, 0);
- if (ret <= 0) {
- fprintf (stderr, "flistxattr failed : %s\n", strerror (errno));
- result |= ret;
- }
-
- ret = fgetxattr (fd, "trusted.xattr-test", NULL, 0);
- if (ret <= 0) {
- fprintf (stderr, "fgetxattr failed : %s\n", strerror (errno));
- result |= ret;
- }
-
- ret = fremovexattr (fd, "trusted.xattr-test");
- if (ret < 0) {
- fprintf (stderr, "fremovexattr failed : %s\n", strerror (errno));
- result |= ret;
- }
-
- if (fd)
- close (fd);
- unlink (filename);
-
- return result;
+ int fd = 0;
+ int ret = -1;
+ int result = 0;
+ struct stat stbuf = {
+ 0,
+ };
+ char wstr[50] = {
+ 0,
+ };
+ char rstr[50] = {
+ 0,
+ };
+
+ fd = open(filename, O_RDWR | O_CREAT, OPEN_MODE);
+ if (fd < 0) {
+ fprintf(stderr, "open failed : %s\n", strerror(errno));
+ return ret;
+ }
+
+ ret = ftruncate(fd, 0);
+ if (ret < 0) {
+ fprintf(stderr, "ftruncate failed : %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ strcpy(wstr, "This is my second string\n");
+ ret = write(fd, wstr, strlen(wstr));
+ if (ret < 0) {
+ fprintf(stderr, "write failed: %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ lseek(fd, 0, SEEK_SET);
+ if (ret < 0) {
+ fprintf(stderr, "lseek failed: %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = read(fd, rstr, strlen(wstr));
+ if (ret <= 0) {
+ fprintf(stderr, "read failed: %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = memcmp(rstr, wstr, strlen(wstr));
+ if (ret != 0) {
+ fprintf(stderr, "read returning junk\n");
+ result |= ret;
+ }
+
+ ret = fstat(fd, &stbuf);
+ if (ret < 0) {
+ fprintf(stderr, "fstat failed : %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = fchmod(fd, 0640);
+ if (ret < 0) {
+ fprintf(stderr, "fchmod failed : %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = fchown(fd, 10001, 10001);
+ if (ret < 0) {
+ fprintf(stderr, "fchown failed : %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = fsync(fd);
+ if (ret < 0) {
+ fprintf(stderr, "fsync failed : %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = fsetxattr(fd, "trusted.xattr-test", "working", 8, 0);
+ if (ret < 0) {
+ fprintf(stderr, "fsetxattr failed : %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = fdatasync(fd);
+ if (ret < 0) {
+ fprintf(stderr, "fdatasync failed : %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = flistxattr(fd, NULL, 0);
+ if (ret <= 0) {
+ fprintf(stderr, "flistxattr failed : %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = fgetxattr(fd, "trusted.xattr-test", NULL, 0);
+ if (ret <= 0) {
+ fprintf(stderr, "fgetxattr failed : %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = fremovexattr(fd, "trusted.xattr-test");
+ if (ret < 0) {
+ fprintf(stderr, "fremovexattr failed : %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ if (fd)
+ close(fd);
+ unlink(filename);
+
+ return result;
}
int
-path_based_fops (char *filename)
+path_based_fops(char *filename)
{
- int ret = -1;
- int fd = 0;
- int result = 0;
- struct stat stbuf = {0,};
- char newfilename[255] = {0,};
- char *hardlink = "linkfile-hard.txt";
- char *symlnk = "linkfile-soft.txt";
- char buf[1024] = {0,};
-
- fd = creat (filename, 0644);
- if (fd < 0) {
- fprintf (stderr, "creat failed: %s\n", strerror (errno));
- return ret;
- }
-
- ret = truncate (filename, 0);
- if (ret < 0) {
- fprintf (stderr, "truncate failed: %s\n", strerror (errno));
- result |= ret;
- }
-
- ret = stat (filename, &stbuf);
- if (ret < 0) {
- fprintf (stderr, "stat failed: %s\n", strerror (errno));
- result |= ret;
- }
-
- ret = chmod (filename, 0640);
- if (ret < 0) {
- fprintf (stderr, "chmod failed: %s\n", strerror (errno));
- result |= ret;
- }
-
- ret = chown (filename, 10001, 10001);
- if (ret < 0) {
- fprintf (stderr, "chown failed: %s\n", strerror (errno));
- result |= ret;
- }
-
- ret = setxattr (filename, "trusted.xattr-test", "working", 8, 0);
- if (ret < 0) {
- fprintf (stderr, "setxattr failed: %s\n", strerror (errno));
- result |= ret;
- }
-
- ret = listxattr (filename, NULL, 0);
- if (ret <= 0) {
- ret = -1;
- fprintf (stderr, "listxattr failed: %s\n", strerror (errno));
- result |= ret;
- }
-
- ret = getxattr (filename, "trusted.xattr-test", NULL, 0);
- if (ret <= 0) {
- fprintf (stderr, "getxattr failed: %s\n", strerror (errno));
- result |= ret;
- }
-
- ret = removexattr (filename, "trusted.xattr-test");
- if (ret < 0) {
- fprintf (stderr, "removexattr failed: %s\n", strerror (errno));
- result |= ret;
- }
-
- ret = access (filename, R_OK|W_OK);
- if (ret < 0) {
- fprintf (stderr, "access failed: %s\n", strerror (errno));
- result |= ret;
- }
-
- ret = link (filename, hardlink);
- if (ret < 0) {
- fprintf (stderr, "link failed: %s\n", strerror(errno));
- result |= ret;
- }
- unlink(hardlink);
-
- ret = symlink (filename, symlnk);
- if (ret < 0) {
- fprintf (stderr, "symlink failed: %s\n", strerror(errno));
- result |= ret;
- }
-
- ret = readlink (symlnk, buf, sizeof(buf));
- if (ret < 0) {
- fprintf (stderr, "readlink failed: %s\n", strerror(errno));
- result |= ret;
- }
- unlink(symlnk);
-
- /* Create a character special file */
- ret = mknod ("cspecial", S_IFCHR|S_IRWXU|S_IRWXG, makedev(2,3));
- if (ret < 0) {
- fprintf (stderr, "cpsecial mknod failed: %s\n",
- strerror(errno));
- result |= ret;
- }
- unlink("cspecial");
-
- ret = mknod ("bspecial", S_IFBLK|S_IRWXU|S_IRWXG, makedev(4,5));
- if (ret < 0) {
- fprintf (stderr, "bspecial mknod failed: %s\n",
- strerror(errno));
- result |= ret;
- }
- unlink("bspecial");
+ int ret = -1;
+ int fd = 0;
+ int result = 0;
+ struct stat stbuf = {
+ 0,
+ };
+ char newfilename[255] = {
+ 0,
+ };
+ char *hardlink = "linkfile-hard.txt";
+ char *symlnk = "linkfile-soft.txt";
+ char buf[1024] = {
+ 0,
+ };
+
+ fd = creat(filename, 0644);
+ if (fd < 0) {
+ fprintf(stderr, "creat failed: %s\n", strerror(errno));
+ return ret;
+ }
+
+ ret = truncate(filename, 0);
+ if (ret < 0) {
+ fprintf(stderr, "truncate failed: %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = stat(filename, &stbuf);
+ if (ret < 0) {
+ fprintf(stderr, "stat failed: %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = chmod(filename, 0640);
+ if (ret < 0) {
+ fprintf(stderr, "chmod failed: %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = chown(filename, 10001, 10001);
+ if (ret < 0) {
+ fprintf(stderr, "chown failed: %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = setxattr(filename, "trusted.xattr-test", "working", 8, 0);
+ if (ret < 0) {
+ fprintf(stderr, "setxattr failed: %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = listxattr(filename, NULL, 0);
+ if (ret <= 0) {
+ ret = -1;
+ fprintf(stderr, "listxattr failed: %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = getxattr(filename, "trusted.xattr-test", NULL, 0);
+ if (ret <= 0) {
+ fprintf(stderr, "getxattr failed: %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = removexattr(filename, "trusted.xattr-test");
+ if (ret < 0) {
+ fprintf(stderr, "removexattr failed: %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = access(filename, R_OK | W_OK);
+ if (ret < 0) {
+ fprintf(stderr, "access failed: %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = link(filename, hardlink);
+ if (ret < 0) {
+ fprintf(stderr, "link failed: %s\n", strerror(errno));
+ result |= ret;
+ }
+ unlink(hardlink);
+
+ ret = symlink(filename, symlnk);
+ if (ret < 0) {
+ fprintf(stderr, "symlink failed: %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = readlink(symlnk, buf, sizeof(buf));
+ if (ret < 0) {
+ fprintf(stderr, "readlink failed: %s\n", strerror(errno));
+ result |= ret;
+ }
+ unlink(symlnk);
+
+ /* Create a character special file */
+ ret = mknod("cspecial", S_IFCHR | S_IRWXU | S_IRWXG, makedev(2, 3));
+ if (ret < 0) {
+ fprintf(stderr, "cpsecial mknod failed: %s\n", strerror(errno));
+ result |= ret;
+ }
+ unlink("cspecial");
+
+ ret = mknod("bspecial", S_IFBLK | S_IRWXU | S_IRWXG, makedev(4, 5));
+ if (ret < 0) {
+ fprintf(stderr, "bspecial mknod failed: %s\n", strerror(errno));
+ result |= ret;
+ }
+ unlink("bspecial");
#ifdef linux
- ret = mknod ("fifo", S_IFIFO|S_IRWXU|S_IRWXG, 0);
+ ret = mknod("fifo", S_IFIFO | S_IRWXU | S_IRWXG, 0);
#else
- ret = mkfifo ("fifo", 0);
+ ret = mkfifo("fifo", 0);
#endif
- if (ret < 0) {
- fprintf (stderr, "fifo mknod failed: %s\n",
- strerror(errno));
- result |= ret;
- }
- unlink("fifo");
+ if (ret < 0) {
+ fprintf(stderr, "fifo mknod failed: %s\n", strerror(errno));
+ result |= ret;
+ }
+ unlink("fifo");
#ifdef linux
- ret = mknod ("sock", S_IFSOCK|S_IRWXU|S_IRWXG, 0);
- if (ret < 0) {
- fprintf (stderr, "sock mknod failed: %s\n",
- strerror(errno));
- result |= ret;
- }
+ ret = mknod("sock", S_IFSOCK | S_IRWXU | S_IRWXG, 0);
+ if (ret < 0) {
+ fprintf(stderr, "sock mknod failed: %s\n", strerror(errno));
+ result |= ret;
+ }
#else
- {
- int s;
- const char *pathname = "sock";
- struct sockaddr_un addr;
-
- s = socket(PF_LOCAL, SOCK_STREAM, 0);
- memset(&addr, 0, sizeof(addr));
- strncpy(addr.sun_path, pathname, sizeof(addr.sun_path));
- ret = bind(s, (const struct sockaddr *)&addr, SUN_LEN(&addr));
- if (ret < 0) {
- fprintf (stderr, "fifo mknod failed: %s\n",
- strerror(errno));
- result |= ret;
- }
- close(s);
- }
-#endif
- unlink("sock");
+ {
+ int s;
+ const char *pathname = "sock";
+ struct sockaddr_un addr;
- strcpy (newfilename, filename);
- strcat(newfilename, "_new");
- ret = rename (filename, newfilename);
+ s = socket(PF_LOCAL, SOCK_STREAM, 0);
+ memset(&addr, 0, sizeof(addr));
+ strncpy(addr.sun_path, pathname, sizeof(addr.sun_path));
+ ret = bind(s, (const struct sockaddr *)&addr, SUN_LEN(&addr));
if (ret < 0) {
- fprintf (stderr, "rename failed: %s\n", strerror (errno));
- result |= ret;
+ fprintf(stderr, "fifo mknod failed: %s\n", strerror(errno));
+ result |= ret;
}
- unlink (newfilename);
-
- if (fd)
- close (fd);
-
- unlink (filename);
- return result;
+ close(s);
+ }
+#endif
+ unlink("sock");
+
+ strcpy(newfilename, filename);
+ strcat(newfilename, "_new");
+ ret = rename(filename, newfilename);
+ if (ret < 0) {
+ fprintf(stderr, "rename failed: %s\n", strerror(errno));
+ result |= ret;
+ }
+ unlink(newfilename);
+
+ if (fd)
+ close(fd);
+
+ unlink(filename);
+ return result;
}
int
-dup_fd_based_fops (char *filename)
+dup_fd_based_fops(char *filename)
{
- int fd = 0;
- int result = 0;
- int newfd = 0;
- int ret = -1;
- struct stat stbuf = {0,};
- char wstr[50] = {0,};
- char rstr[50] = {0,};
-
- fd = open (filename, O_RDWR|O_CREAT, OPEN_MODE);
- if (fd < 0) {
- fprintf (stderr, "open failed : %s\n", strerror (errno));
- return ret;
- }
-
- newfd = dup (fd);
- if (newfd < 0) {
- fprintf (stderr, "dup failed: %s\n", strerror (errno));
- result |= ret;
- }
-
- close (fd);
-
- strcpy (wstr, "This is my string\n");
- ret = write (newfd, wstr, strlen(wstr));
- if (ret <= 0) {
- fprintf (stderr, "write failed: %s\n", strerror (errno));
- result |= ret;
- }
-
- ret = lseek (newfd, 0, SEEK_SET);
- if (ret < 0) {
- fprintf (stderr, "lseek failed: %s\n", strerror (errno));
- result |= ret;
- }
-
- ret = read (newfd, rstr, strlen(wstr));
- if (ret <= 0) {
- fprintf (stderr, "read failed: %s\n", strerror (errno));
- result |= ret;
- }
-
- ret = memcmp (rstr, wstr, strlen (wstr));
- if (ret != 0) {
- fprintf (stderr, "read returning junk\n");
- result |= ret;
- }
-
- ret = ftruncate (newfd, 0);
- if (ret < 0) {
- fprintf (stderr, "ftruncate failed : %s\n", strerror (errno));
- result |= ret;
- }
-
- ret = fstat (newfd, &stbuf);
- if (ret < 0) {
- fprintf (stderr, "fstat failed : %s\n", strerror (errno));
- result |= ret;
- }
-
- ret = fchmod (newfd, 0640);
- if (ret < 0) {
- fprintf (stderr, "fchmod failed : %s\n", strerror (errno));
- result |= ret;
- }
-
- ret = fchown (newfd, 10001, 10001);
- if (ret < 0) {
- fprintf (stderr, "fchown failed : %s\n", strerror (errno));
- result |= ret;
- }
-
- ret = fsync (newfd);
- if (ret < 0) {
- fprintf (stderr, "fsync failed : %s\n", strerror (errno));
- result |= ret;
- }
-
- ret = fsetxattr (newfd, "trusted.xattr-test", "working", 8, 0);
- if (ret < 0) {
- fprintf (stderr, "fsetxattr failed : %s\n", strerror (errno));
- result |= ret;
- }
-
- ret = fdatasync (newfd);
- if (ret < 0) {
- fprintf (stderr, "fdatasync failed : %s\n", strerror (errno));
- result |= ret;
- }
-
- ret = flistxattr (newfd, NULL, 0);
- if (ret <= 0) {
- fprintf (stderr, "flistxattr failed : %s\n", strerror (errno));
- result |= ret;
- }
-
- ret = fgetxattr (newfd, "trusted.xattr-test", NULL, 0);
- if (ret <= 0) {
- fprintf (stderr, "fgetxattr failed : %s\n", strerror (errno));
- result |= ret;
- }
-
- ret = fremovexattr (newfd, "trusted.xattr-test");
- if (ret < 0) {
- fprintf (stderr, "fremovexattr failed : %s\n", strerror (errno));
- result |= ret;
- }
-
- if (newfd)
- close (newfd);
- ret = unlink (filename);
- if (ret < 0) {
- fprintf (stderr, "unlink failed : %s\n", strerror (errno));
- result |= ret;
- }
- return result;
+ int fd = 0;
+ int result = 0;
+ int newfd = 0;
+ int ret = -1;
+ struct stat stbuf = {
+ 0,
+ };
+ char wstr[50] = {
+ 0,
+ };
+ char rstr[50] = {
+ 0,
+ };
+
+ fd = open(filename, O_RDWR | O_CREAT, OPEN_MODE);
+ if (fd < 0) {
+ fprintf(stderr, "open failed : %s\n", strerror(errno));
+ return ret;
+ }
+
+ newfd = dup(fd);
+ if (newfd < 0) {
+ fprintf(stderr, "dup failed: %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ close(fd);
+
+ strcpy(wstr, "This is my string\n");
+ ret = write(newfd, wstr, strlen(wstr));
+ if (ret <= 0) {
+ fprintf(stderr, "write failed: %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = lseek(newfd, 0, SEEK_SET);
+ if (ret < 0) {
+ fprintf(stderr, "lseek failed: %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = read(newfd, rstr, strlen(wstr));
+ if (ret <= 0) {
+ fprintf(stderr, "read failed: %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = memcmp(rstr, wstr, strlen(wstr));
+ if (ret != 0) {
+ fprintf(stderr, "read returning junk\n");
+ result |= ret;
+ }
+
+ ret = ftruncate(newfd, 0);
+ if (ret < 0) {
+ fprintf(stderr, "ftruncate failed : %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = fstat(newfd, &stbuf);
+ if (ret < 0) {
+ fprintf(stderr, "fstat failed : %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = fchmod(newfd, 0640);
+ if (ret < 0) {
+ fprintf(stderr, "fchmod failed : %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = fchown(newfd, 10001, 10001);
+ if (ret < 0) {
+ fprintf(stderr, "fchown failed : %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = fsync(newfd);
+ if (ret < 0) {
+ fprintf(stderr, "fsync failed : %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = fsetxattr(newfd, "trusted.xattr-test", "working", 8, 0);
+ if (ret < 0) {
+ fprintf(stderr, "fsetxattr failed : %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = fdatasync(newfd);
+ if (ret < 0) {
+ fprintf(stderr, "fdatasync failed : %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = flistxattr(newfd, NULL, 0);
+ if (ret <= 0) {
+ fprintf(stderr, "flistxattr failed : %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = fgetxattr(newfd, "trusted.xattr-test", NULL, 0);
+ if (ret <= 0) {
+ fprintf(stderr, "fgetxattr failed : %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = fremovexattr(newfd, "trusted.xattr-test");
+ if (ret < 0) {
+ fprintf(stderr, "fremovexattr failed : %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ if (newfd)
+ close(newfd);
+ ret = unlink(filename);
+ if (ret < 0) {
+ fprintf(stderr, "unlink failed : %s\n", strerror(errno));
+ result |= ret;
+ }
+ return result;
}
int
-dir_based_fops (char *dirname)
+dir_based_fops(char *dirname)
{
- int ret = -1;
- int result = 0;
- DIR *dp = NULL;
- char buff[255] = {0,};
- struct dirent *dbuff = {0,};
- struct stat stbuff = {0,};
- char newdname[255] = {0,};
- char *cwd = NULL;
-
- ret = mkdir (dirname, 0755);
- if (ret < 0) {
- fprintf (stderr, "mkdir failed: %s\n", strerror (errno));
- return ret;
- }
-
- dp = opendir (dirname);
- if (dp == NULL) {
- fprintf (stderr, "opendir failed: %s\n", strerror (errno));
- result |= ret;
- }
-
- dbuff = readdir (dp);
- if (NULL == dbuff) {
- fprintf (stderr, "readdir failed: %s\n", strerror (errno));
- result |= ret;
- }
-
- ret = closedir (dp);
- if (ret < 0) {
- fprintf (stderr, "closedir failed: %s\n", strerror (errno));
- result |= ret;
- }
-
- ret = stat (dirname, &stbuff);
- if (ret < 0) {
- fprintf (stderr, "stat failed: %s\n", strerror (errno));
- result |= ret;
- }
-
- ret = chmod (dirname, 0744);
- if (ret < 0) {
- fprintf (stderr, "chmod failed: %s\n", strerror (errno));
- result |= ret;
- }
-
- ret = chown (dirname, 10001, 10001);
- if (ret < 0) {
- fprintf (stderr, "chmod failed: %s\n", strerror (errno));
- result |= ret;
- }
-
- ret = setxattr (dirname, "trusted.xattr-test", "working", 8, 0);
- if (ret < 0) {
- fprintf (stderr, "setxattr failed: %s\n", strerror (errno));
- result |= ret;
- }
-
- ret = listxattr (dirname, NULL, 0);
- if (ret <= 0) {
- ret = -1;
- fprintf (stderr, "listxattr failed: %s\n", strerror (errno));
- result |= ret;
- }
-
- ret = getxattr (dirname, "trusted.xattr-test", NULL, 0);
- if (ret <= 0) {
- ret = -1;
- fprintf (stderr, "getxattr failed: %s\n", strerror (errno));
- result |= ret;
- }
-
- ret = removexattr (dirname, "trusted.xattr-test");
- if (ret < 0) {
- fprintf (stderr, "removexattr failed: %s\n", strerror (errno));
- result |= ret;
- }
-
- strcpy (newdname, dirname);
- strcat (newdname, "/../");
- ret = chdir (newdname);
- if (ret < 0) {
- fprintf (stderr, "chdir failed: %s\n", strerror (errno));
- result |= ret;
- }
-
- cwd = getcwd (buff, 255);
- if (NULL == cwd) {
- fprintf (stderr, "getcwd failed: %s\n", strerror (errno));
- result |= ret;
- }
-
- strcpy (newdname, dirname);
- strcat (newdname, "new");
- ret = rename (dirname, newdname);
- if (ret < 0) {
- fprintf (stderr, "rename failed: %s\n", strerror (errno));
- result |= ret;
- }
-
- ret = rmdir (newdname);
- if (ret < 0) {
- fprintf (stderr, "rmdir failed: %s\n", strerror (errno));
- result |= ret;
- }
-
- rmdir (dirname);
- return result;
+ int ret = -1;
+ int result = 0;
+ DIR *dp = NULL;
+ char buff[255] = {
+ 0,
+ };
+ struct dirent *dbuff = {
+ 0,
+ };
+ struct stat stbuff = {
+ 0,
+ };
+ char newdname[255] = {
+ 0,
+ };
+ char *cwd = NULL;
+
+ ret = mkdir(dirname, 0755);
+ if (ret < 0) {
+ fprintf(stderr, "mkdir failed: %s\n", strerror(errno));
+ return ret;
+ }
+
+ dp = opendir(dirname);
+ if (dp == NULL) {
+ fprintf(stderr, "opendir failed: %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ dbuff = readdir(dp);
+ if (NULL == dbuff) {
+ fprintf(stderr, "readdir failed: %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = closedir(dp);
+ if (ret < 0) {
+ fprintf(stderr, "closedir failed: %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = stat(dirname, &stbuff);
+ if (ret < 0) {
+ fprintf(stderr, "stat failed: %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = chmod(dirname, 0744);
+ if (ret < 0) {
+ fprintf(stderr, "chmod failed: %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = chown(dirname, 10001, 10001);
+ if (ret < 0) {
+ fprintf(stderr, "chmod failed: %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = setxattr(dirname, "trusted.xattr-test", "working", 8, 0);
+ if (ret < 0) {
+ fprintf(stderr, "setxattr failed: %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = listxattr(dirname, NULL, 0);
+ if (ret <= 0) {
+ ret = -1;
+ fprintf(stderr, "listxattr failed: %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = getxattr(dirname, "trusted.xattr-test", NULL, 0);
+ if (ret <= 0) {
+ ret = -1;
+ fprintf(stderr, "getxattr failed: %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = removexattr(dirname, "trusted.xattr-test");
+ if (ret < 0) {
+ fprintf(stderr, "removexattr failed: %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ strcpy(newdname, dirname);
+ strcat(newdname, "/../");
+ ret = chdir(newdname);
+ if (ret < 0) {
+ fprintf(stderr, "chdir failed: %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ cwd = getcwd(buff, 255);
+ if (NULL == cwd) {
+ fprintf(stderr, "getcwd failed: %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ strcpy(newdname, dirname);
+ strcat(newdname, "new");
+ ret = rename(dirname, newdname);
+ if (ret < 0) {
+ fprintf(stderr, "rename failed: %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = rmdir(newdname);
+ if (ret < 0) {
+ fprintf(stderr, "rmdir failed: %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ rmdir(dirname);
+ return result;
}
int
-link_based_fops (char *filename)
+link_based_fops(char *filename)
{
- int ret = -1;
- int result = 0;
- int fd = 0;
- char newname[255] = {0,};
- char linkname[255] = {0,};
- struct stat lstbuf = {0,};
-
- fd = creat (filename, 0644);
- if (fd < 0) {
- fd = 0;
- fprintf (stderr, "creat failed: %s\n", strerror (errno));
- return ret;
- }
-
- strcpy (newname, filename);
- strcat (newname, "_hlink");
- ret = link (filename, newname);
- if (ret < 0) {
- fprintf (stderr, "link failed: %s\n", strerror (errno));
- result |= ret;
- }
-
- ret = unlink (filename);
- if (ret < 0) {
- fprintf (stderr, "unlink failed: %s\n", strerror (errno));
- result |= ret;
- }
-
- strcpy (linkname, filename);
- strcat (linkname, "_slink");
- ret = symlink (newname, linkname);
- if (ret < 0) {
- fprintf (stderr, "symlink failed: %s\n", strerror (errno));
- result |= ret;
- }
-
- ret = lstat (linkname, &lstbuf);
- if (ret < 0) {
- fprintf (stderr, "lstbuf failed: %s\n", strerror (errno));
- result |= ret;
- }
-
- ret = lchown (linkname, 10001, 10001);
- if (ret < 0) {
- fprintf (stderr, "lchown failed: %s\n", strerror (errno));
- result |= ret;
- }
-
- ret = lsetxattr (linkname, "trusted.lxattr-test", "working", 8, 0);
- if (ret < 0) {
- fprintf (stderr, "lsetxattr failed: %s\n", strerror (errno));
- result |= ret;
- }
-
- ret = llistxattr (linkname, NULL, 0);
- if (ret < 0) {
- ret = -1;
- fprintf (stderr, "llistxattr failed: %s\n", strerror (errno));
- result |= ret;
- }
-
- ret = lgetxattr (linkname, "trusted.lxattr-test", NULL, 0);
- if (ret < 0) {
- ret = -1;
- fprintf (stderr, "lgetxattr failed: %s\n", strerror (errno));
- result |= ret;
- }
-
- ret = lremovexattr (linkname, "trusted.lxattr-test");
- if (ret < 0) {
- fprintf (stderr, "lremovexattr failed: %s\n", strerror (errno));
- result |= ret;
- }
-
- if (fd)
- close(fd);
- unlink (linkname);
- unlink (newname);
- return result;
+ int ret = -1;
+ int result = 0;
+ int fd = 0;
+ char newname[255] = {
+ 0,
+ };
+ char linkname[255] = {
+ 0,
+ };
+ struct stat lstbuf = {
+ 0,
+ };
+
+ fd = creat(filename, 0644);
+ if (fd < 0) {
+ fd = 0;
+ fprintf(stderr, "creat failed: %s\n", strerror(errno));
+ return ret;
+ }
+
+ strcpy(newname, filename);
+ strcat(newname, "_hlink");
+ ret = link(filename, newname);
+ if (ret < 0) {
+ fprintf(stderr, "link failed: %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = unlink(filename);
+ if (ret < 0) {
+ fprintf(stderr, "unlink failed: %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ strcpy(linkname, filename);
+ strcat(linkname, "_slink");
+ ret = symlink(newname, linkname);
+ if (ret < 0) {
+ fprintf(stderr, "symlink failed: %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = lstat(linkname, &lstbuf);
+ if (ret < 0) {
+ fprintf(stderr, "lstbuf failed: %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = lchown(linkname, 10001, 10001);
+ if (ret < 0) {
+ fprintf(stderr, "lchown failed: %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = lsetxattr(linkname, "trusted.lxattr-test", "working", 8, 0);
+ if (ret < 0) {
+ fprintf(stderr, "lsetxattr failed: %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = llistxattr(linkname, NULL, 0);
+ if (ret < 0) {
+ ret = -1;
+ fprintf(stderr, "llistxattr failed: %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = lgetxattr(linkname, "trusted.lxattr-test", NULL, 0);
+ if (ret < 0) {
+ ret = -1;
+ fprintf(stderr, "lgetxattr failed: %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ ret = lremovexattr(linkname, "trusted.lxattr-test");
+ if (ret < 0) {
+ fprintf(stderr, "lremovexattr failed: %s\n", strerror(errno));
+ result |= ret;
+ }
+
+ if (fd)
+ close(fd);
+ unlink(linkname);
+ unlink(newname);
+ return result;
}
int
-test_open_modes (char *filename)
+test_open_modes(char *filename)
{
- int ret = -1;
- int result = 0;
-
- ret = generic_open_read_write (filename, O_CREAT|O_WRONLY, OPEN_MODE);
- if (ret != 0) {
- fprintf (stderr, "flag O_CREAT|O_WRONLY failed: \n");
- result |= ret;
- }
-
- ret = generic_open_read_write (filename, O_CREAT|O_RDWR, OPEN_MODE);
- if (ret != 0) {
- fprintf (stderr, "flag O_CREAT|O_RDWR failed\n");
- result |= ret;
- }
-
- ret = generic_open_read_write (filename, O_CREAT|O_RDONLY, OPEN_MODE);
- if (ret != 0) {
- fprintf (stderr, "flag O_CREAT|O_RDONLY failed\n");
- result |= ret;
- }
-
- ret = creat (filename, 0644);
- close (ret);
- ret = generic_open_read_write (filename, O_WRONLY, 0);
- if (ret != 0) {
- fprintf (stderr, "flag O_WRONLY failed\n");
- result |= ret;
- }
-
- ret = creat (filename, 0644);
- close (ret);
- ret = generic_open_read_write (filename, O_RDWR, 0);
- if (0 != ret) {
- fprintf (stderr, "flag O_RDWR failed\n");
- result |= ret;
- }
-
- ret = creat (filename, 0644);
- close (ret);
- ret = generic_open_read_write (filename, O_RDONLY, 0);
- if (0 != ret) {
- fprintf (stderr, "flag O_RDONLY failed\n");
- result |= ret;
- }
-
- ret = creat (filename, 0644);
- close (ret);
- ret = generic_open_read_write (filename, O_TRUNC|O_WRONLY, 0);
- if (0 != ret) {
- fprintf (stderr, "flag O_TRUNC|O_WRONLY failed\n");
- result |= ret;
- }
+ int ret = -1;
+ int result = 0;
+
+ ret = generic_open_read_write(filename, O_CREAT | O_WRONLY, OPEN_MODE);
+ if (ret != 0) {
+ fprintf(stderr, "flag O_CREAT|O_WRONLY failed: \n");
+ result |= ret;
+ }
+
+ ret = generic_open_read_write(filename, O_CREAT | O_RDWR, OPEN_MODE);
+ if (ret != 0) {
+ fprintf(stderr, "flag O_CREAT|O_RDWR failed\n");
+ result |= ret;
+ }
+
+ ret = generic_open_read_write(filename, O_CREAT | O_RDONLY, OPEN_MODE);
+ if (ret != 0) {
+ fprintf(stderr, "flag O_CREAT|O_RDONLY failed\n");
+ result |= ret;
+ }
+
+ ret = creat(filename, 0644);
+ close(ret);
+ ret = generic_open_read_write(filename, O_WRONLY, 0);
+ if (ret != 0) {
+ fprintf(stderr, "flag O_WRONLY failed\n");
+ result |= ret;
+ }
+
+ ret = creat(filename, 0644);
+ close(ret);
+ ret = generic_open_read_write(filename, O_RDWR, 0);
+ if (0 != ret) {
+ fprintf(stderr, "flag O_RDWR failed\n");
+ result |= ret;
+ }
+
+ ret = creat(filename, 0644);
+ close(ret);
+ ret = generic_open_read_write(filename, O_RDONLY, 0);
+ if (0 != ret) {
+ fprintf(stderr, "flag O_RDONLY failed\n");
+ result |= ret;
+ }
+
+ ret = creat(filename, 0644);
+ close(ret);
+ ret = generic_open_read_write(filename, O_TRUNC | O_WRONLY, 0);
+ if (0 != ret) {
+ fprintf(stderr, "flag O_TRUNC|O_WRONLY failed\n");
+ result |= ret;
+ }
#if 0 /* undefined behaviour, unable to reliably test */
ret = creat (filename, 0644);
@@ -897,87 +943,90 @@ test_open_modes (char *filename)
}
#endif
- ret = generic_open_read_write (filename, O_CREAT|O_RDWR|O_SYNC,
- OPEN_MODE);
- if (0 != ret) {
- fprintf (stderr, "flag O_CREAT|O_RDWR|O_SYNC failed\n");
- result |= ret;
- }
-
- ret = creat (filename, 0644);
- close (ret);
- ret = generic_open_read_write (filename, O_CREAT|O_EXCL, OPEN_MODE);
- if (0 != ret) {
- fprintf (stderr, "flag O_CREAT|O_EXCL failed\n");
- result |= ret;
- }
-
- return result;
+ ret = generic_open_read_write(filename, O_CREAT | O_RDWR | O_SYNC,
+ OPEN_MODE);
+ if (0 != ret) {
+ fprintf(stderr, "flag O_CREAT|O_RDWR|O_SYNC failed\n");
+ result |= ret;
+ }
+
+ ret = creat(filename, 0644);
+ close(ret);
+ ret = generic_open_read_write(filename, O_CREAT | O_EXCL, OPEN_MODE);
+ if (0 != ret) {
+ fprintf(stderr, "flag O_CREAT|O_EXCL failed\n");
+ result |= ret;
+ }
+
+ return result;
}
int
-generic_open_read_write (char *filename, int flag, mode_t mode)
+generic_open_read_write(char *filename, int flag, mode_t mode)
{
- int fd = 0;
- int ret = -1;
- char wstring[50] = {0,};
- char rstring[50] = {0,};
-
- fd = open (filename, flag, mode);
- if (fd < 0) {
- if (flag == (O_CREAT|O_EXCL) && errno == EEXIST) {
- unlink (filename);
- return 0;
- }
- else {
- fprintf (stderr, "open failed: %s\n", strerror (errno));
- return -1;
- }
- }
-
- strcpy (wstring, "My string to write\n");
- ret = write (fd, wstring, strlen(wstring));
- if (ret <= 0) {
- if (errno != EBADF) {
- fprintf (stderr, "write failed: %s\n", strerror (errno));
- close (fd);
- unlink(filename);
- return ret;
- }
- }
-
- ret = lseek (fd, 0, SEEK_SET);
- if (ret < 0) {
- close (fd);
- unlink(filename);
- return ret;
- }
-
- ret = read (fd, rstring, strlen(wstring));
- if (ret < 0 && flag != (O_CREAT|O_WRONLY) && flag != O_WRONLY && \
- flag != (O_TRUNC|O_WRONLY)) {
- close (fd);
- unlink (filename);
- return ret;
- }
-
- /* Compare the rstring with wstring. But we do not want to return
- * error when the flag is either O_RDONLY, O_CREAT|O_RDONLY or
- * O_TRUNC|O_RDONLY. Because in that case we are not writing
- * anything to the file.*/
-
- ret = memcmp (wstring, rstring, strlen (wstring));
- if (0 != ret && flag != (O_TRUNC|O_WRONLY) && flag != O_WRONLY && \
- flag != (O_CREAT|O_WRONLY) && !(flag == \
- (O_CREAT|O_RDONLY) || flag == O_RDONLY \
- || flag == (O_TRUNC|O_RDONLY))) {
- fprintf (stderr, "read is returning junk\n");
- close (fd);
- unlink (filename);
- return ret;
- }
-
- close (fd);
- unlink (filename);
- return 0;
+ int fd = 0;
+ int ret = -1;
+ char wstring[50] = {
+ 0,
+ };
+ char rstring[50] = {
+ 0,
+ };
+
+ fd = open(filename, flag, mode);
+ if (fd < 0) {
+ if (flag == (O_CREAT | O_EXCL) && errno == EEXIST) {
+ unlink(filename);
+ return 0;
+ } else {
+ fprintf(stderr, "open failed: %s\n", strerror(errno));
+ return -1;
+ }
+ }
+
+ strcpy(wstring, "My string to write\n");
+ ret = write(fd, wstring, strlen(wstring));
+ if (ret <= 0) {
+ if (errno != EBADF) {
+ fprintf(stderr, "write failed: %s\n", strerror(errno));
+ close(fd);
+ unlink(filename);
+ return ret;
+ }
+ }
+
+ ret = lseek(fd, 0, SEEK_SET);
+ if (ret < 0) {
+ close(fd);
+ unlink(filename);
+ return ret;
+ }
+
+ ret = read(fd, rstring, strlen(wstring));
+ if (ret < 0 && flag != (O_CREAT | O_WRONLY) && flag != O_WRONLY &&
+ flag != (O_TRUNC | O_WRONLY)) {
+ close(fd);
+ unlink(filename);
+ return ret;
+ }
+
+ /* Compare the rstring with wstring. But we do not want to return
+ * error when the flag is either O_RDONLY, O_CREAT|O_RDONLY or
+ * O_TRUNC|O_RDONLY. Because in that case we are not writing
+ * anything to the file.*/
+
+ ret = memcmp(wstring, rstring, strlen(wstring));
+ if (0 != ret && flag != (O_TRUNC | O_WRONLY) && flag != O_WRONLY &&
+ flag != (O_CREAT | O_WRONLY) &&
+ !(flag == (O_CREAT | O_RDONLY) || flag == O_RDONLY ||
+ flag == (O_TRUNC | O_RDONLY))) {
+ fprintf(stderr, "read is returning junk\n");
+ close(fd);
+ unlink(filename);
+ return ret;
+ }
+
+ close(fd);
+ unlink(filename);
+ return 0;
}
diff --git a/tests/basic/fuse/seek.c b/tests/basic/fuse/seek.c
index e4db41c03d7..30943ad0f33 100644
--- a/tests/basic/fuse/seek.c
+++ b/tests/basic/fuse/seek.c
@@ -17,64 +17,66 @@
#include <unistd.h>
int
-main (int argc, char **argv)
+main(int argc, char **argv)
{
- int ret = EXIT_SUCCESS;
- int fd = -1;
- char *filename = NULL;
- struct stat st = { 0, };
- off_t hole_start = 0;
- off_t hole_end = 0;
+ int ret = EXIT_SUCCESS;
+ int fd = -1;
+ char *filename = NULL;
+ struct stat st = {
+ 0,
+ };
+ off_t hole_start = 0;
+ off_t hole_end = 0;
- if (argc != 2) {
- fprintf (stderr, "Invalid argument, use %s <file>\n", argv[0]);
- return EXIT_FAILURE;
- }
-
- filename = argv[1];
+ if (argc != 2) {
+ fprintf(stderr, "Invalid argument, use %s <file>\n", argv[0]);
+ return EXIT_FAILURE;
+ }
- fd = open (filename, O_RDONLY);
- if (fd <= 0) {
- perror ("open");
- return EXIT_FAILURE;
- }
+ filename = argv[1];
- if (fstat (fd, &st)) {
- perror ("fstat");
- return EXIT_FAILURE;
- }
+ fd = open(filename, O_RDONLY);
+ if (fd <= 0) {
+ perror("open");
+ return EXIT_FAILURE;
+ }
- while (hole_end < st.st_size) {
- hole_start = lseek (fd, hole_end, SEEK_HOLE);
- if (hole_start == -1 && errno == ENXIO) {
- /* no more holes */
- break;
- } else if (hole_start == -1 && errno == ENOTSUP) {
- /* SEEK_HOLE is not supported */
- perror ("lseek(SEEK_HOLE)");
- ret = EXIT_FAILURE;
- break;
- } else if (hole_start == -1) {
- perror ("no more holes");
- break;
- }
+ if (fstat(fd, &st)) {
+ perror("fstat");
+ return EXIT_FAILURE;
+ }
- hole_end = lseek (fd, hole_start, SEEK_DATA);
- if (hole_end == -1 && errno == ENXIO) {
- /* no more data */
- break;
- } else if (hole_end == -1 && errno == ENOTSUP) {
- /* SEEK_DATA is not supported */
- perror ("lseek(SEEK_DATA)");
- ret = EXIT_FAILURE;
- break;
- }
+ while (hole_end < st.st_size) {
+ hole_start = lseek(fd, hole_end, SEEK_HOLE);
+ if (hole_start == -1 && errno == ENXIO) {
+ /* no more holes */
+ break;
+ } else if (hole_start == -1 && errno == ENOTSUP) {
+ /* SEEK_HOLE is not supported */
+ perror("lseek(SEEK_HOLE)");
+ ret = EXIT_FAILURE;
+ break;
+ } else if (hole_start == -1) {
+ perror("no more holes");
+ break;
+ }
- printf ("HOLE found: %ld - %ld%s\n", hole_start, hole_end,
- (hole_end == st.st_size) ? " (EOF)" : "");
+ hole_end = lseek(fd, hole_start, SEEK_DATA);
+ if (hole_end == -1 && errno == ENXIO) {
+ /* no more data */
+ break;
+ } else if (hole_end == -1 && errno == ENOTSUP) {
+ /* SEEK_DATA is not supported */
+ perror("lseek(SEEK_DATA)");
+ ret = EXIT_FAILURE;
+ break;
}
- close (fd);
+ printf("HOLE found: %ld - %ld%s\n", hole_start, hole_end,
+ (hole_end == st.st_size) ? " (EOF)" : "");
+ }
+
+ close(fd);
- return ret;
+ return ret;
}
diff --git a/tests/basic/gfapi/anonymous_fd_read_write.c b/tests/basic/gfapi/anonymous_fd_read_write.c
index 6945dd634f0..fc276ca4310 100644
--- a/tests/basic/gfapi/anonymous_fd_read_write.c
+++ b/tests/basic/gfapi/anonymous_fd_read_write.c
@@ -9,95 +9,98 @@
#include <glusterfs/api/glfs.h>
#include <glusterfs/api/glfs-handles.h>
-#define LOG_ERR(func, ret) do { \
- if (ret != 0) { \
- fprintf (stderr, "%s : returned error %d (%s)\n", \
- func, ret, strerror (errno)); \
- goto out; \
- } else { \
- fprintf (stderr, "%s : returned %d\n", func, ret); \
- } \
- } while (0)
+#define LOG_ERR(func, ret) \
+ do { \
+ if (ret != 0) { \
+ fprintf(stderr, "%s : returned error %d (%s)\n", func, ret, \
+ strerror(errno)); \
+ goto out; \
+ } else { \
+ fprintf(stderr, "%s : returned %d\n", func, ret); \
+ } \
+ } while (0)
int
-main (int argc, char *argv[])
+main(int argc, char *argv[])
{
- int ret = 0;
- glfs_t *fs = NULL;
- struct glfs_object *root = NULL, *file_obj = NULL;
- struct stat sb = {0, };
- char readbuf[32], writebuf[32];
- char *filename = "file.txt";
- char *logfile = NULL;
- char *volname = NULL;
- char *hostname = NULL;
-
- if (argc != 4) {
- fprintf (stderr, "Invalid argument\n");
- exit(1);
- }
-
- hostname = argv[1];
- volname = argv[2];
- logfile = argv[3];
-
- fs = glfs_new (volname);
- if (!fs) {
- fprintf (stderr, "glfs_new: returned NULL\n");
- ret = -1;
- }
-
- ret = glfs_set_volfile_server (fs, "tcp", hostname, 24007);
- LOG_ERR("glfs_set_volfile_server", ret);
-
- ret = glfs_set_logging (fs, logfile, 7);
- LOG_ERR("glfs_set_logging", ret);
-
- ret = glfs_init (fs);
- LOG_ERR("glfs_init", ret);
-
- root = glfs_h_lookupat (fs, NULL, "/", &sb, 0);
- if (root == NULL) {
- fprintf (stderr, "glfs_h_lookupat: error on lookup of / ,%s\n",
- strerror (errno));
- goto out;
- }
-
- file_obj = glfs_h_creat (fs, root, filename, O_CREAT, 0644, &sb);
- if (file_obj == NULL) {
- fprintf (stderr, "glfs_h_creat: error on create of %s: from (%p),%s\n",
- filename, root, strerror (errno));
- goto out;
- }
-
- /* test read/write based on anonymous fd */
- memcpy (writebuf, "abcdefghijklmnopqrstuvwxyz012345", 32);
-
- ret = glfs_h_anonymous_write (fs, file_obj, writebuf, 32, 0);
- if (ret < 0)
- LOG_ERR ("glfs_h_anonymous_write", ret);
-
- ret = glfs_h_anonymous_read (fs, file_obj, readbuf, 32, 0);
- if (ret < 0)
- LOG_ERR ("glfs_h_anonymous_read", ret);
-
- if (memcmp (readbuf, writebuf, 32)) {
- fprintf (stderr, "Failed to read what I wrote: %s %s\n", readbuf,
- writebuf);
- ret = -1;
- goto out;
- }
-
- ret = 0;
+ int ret = 0;
+ glfs_t *fs = NULL;
+ struct glfs_object *root = NULL, *file_obj = NULL;
+ struct stat sb = {
+ 0,
+ };
+ char readbuf[32], writebuf[32];
+ char *filename = "file.txt";
+ char *logfile = NULL;
+ char *volname = NULL;
+ char *hostname = NULL;
+
+ if (argc != 4) {
+ fprintf(stderr, "Invalid argument\n");
+ exit(1);
+ }
+
+ hostname = argv[1];
+ volname = argv[2];
+ logfile = argv[3];
+
+ fs = glfs_new(volname);
+ if (!fs) {
+ fprintf(stderr, "glfs_new: returned NULL\n");
+ ret = -1;
+ }
+
+ ret = glfs_set_volfile_server(fs, "tcp", hostname, 24007);
+ LOG_ERR("glfs_set_volfile_server", ret);
+
+ ret = glfs_set_logging(fs, logfile, 7);
+ LOG_ERR("glfs_set_logging", ret);
+
+ ret = glfs_init(fs);
+ LOG_ERR("glfs_init", ret);
+
+ root = glfs_h_lookupat(fs, NULL, "/", &sb, 0);
+ if (root == NULL) {
+ fprintf(stderr, "glfs_h_lookupat: error on lookup of / ,%s\n",
+ strerror(errno));
+ goto out;
+ }
+
+ file_obj = glfs_h_creat(fs, root, filename, O_CREAT, 0644, &sb);
+ if (file_obj == NULL) {
+ fprintf(stderr, "glfs_h_creat: error on create of %s: from (%p),%s\n",
+ filename, root, strerror(errno));
+ goto out;
+ }
+
+ /* test read/write based on anonymous fd */
+ memcpy(writebuf, "abcdefghijklmnopqrstuvwxyz012345", 32);
+
+ ret = glfs_h_anonymous_write(fs, file_obj, writebuf, 32, 0);
+ if (ret < 0)
+ LOG_ERR("glfs_h_anonymous_write", ret);
+
+ ret = glfs_h_anonymous_read(fs, file_obj, readbuf, 32, 0);
+ if (ret < 0)
+ LOG_ERR("glfs_h_anonymous_read", ret);
+
+ if (memcmp(readbuf, writebuf, 32)) {
+ fprintf(stderr, "Failed to read what I wrote: %s %s\n", readbuf,
+ writebuf);
+ ret = -1;
+ goto out;
+ }
+
+ ret = 0;
out:
- if (file_obj)
- glfs_h_close (file_obj);
-
- if (fs) {
- ret = glfs_fini(fs);
- fprintf (stderr, "glfs_fini(fs) returned %d \n", ret);
- }
- if (ret)
- exit(1);
- exit(0);
+ if (file_obj)
+ glfs_h_close(file_obj);
+
+ if (fs) {
+ ret = glfs_fini(fs);
+ fprintf(stderr, "glfs_fini(fs) returned %d \n", ret);
+ }
+ if (ret)
+ exit(1);
+ exit(0);
}
diff --git a/tests/basic/gfapi/bug-1241104.c b/tests/basic/gfapi/bug-1241104.c
index 311323f672a..78c87595a71 100644
--- a/tests/basic/gfapi/bug-1241104.c
+++ b/tests/basic/gfapi/bug-1241104.c
@@ -12,81 +12,82 @@
int gfapi = 1;
-#define LOG_ERR(func, ret) do { \
- if (ret != 0) { \
- fprintf (stderr, "%s : returned error %d (%s)\n", \
- func, ret, strerror (errno)); \
- goto out; \
- } else { \
- fprintf (stderr, "%s : returned %d\n", func, ret); \
- } \
- } while (0)
+#define LOG_ERR(func, ret) \
+ do { \
+ if (ret != 0) { \
+ fprintf(stderr, "%s : returned error %d (%s)\n", func, ret, \
+ strerror(errno)); \
+ goto out; \
+ } else { \
+ fprintf(stderr, "%s : returned %d\n", func, ret); \
+ } \
+ } while (0)
int
-main (int argc, char *argv[])
+main(int argc, char *argv[])
{
- glfs_t *fs = NULL;
- int ret = 0, i, status = 0;
- glfs_fd_t *fd = NULL;
- char *filename = "file_tmp";
- char *volname = NULL;
- char *logfile = NULL;
- char *hostname = NULL;
- struct flock lock = {0, };
-
- if (argc != 4) {
- fprintf (stderr, "Invalid argument\n");
- exit(1);
- }
-
- hostname = argv[1];
- volname = argv[2];
- logfile = argv[3];
-
- fs = glfs_new (volname);
- if (!fs) {
- fprintf (stderr, "glfs_new: returned NULL\n");
- return -1;
- }
-
- ret = glfs_set_volfile_server (fs, "tcp", hostname, 24007);
- LOG_ERR("glfs_set_volfile_server", ret);
-
- ret = glfs_set_logging (fs, logfile, 7);
- LOG_ERR("glfs_set_logging", ret);
-
- ret = glfs_init (fs);
- LOG_ERR("glfs_init", ret);
-
- fd = glfs_creat(fs, filename, O_RDWR|O_SYNC, 0644);
- if (fd <= 0) {
- ret = -1;
- LOG_ERR ("glfs_creat", ret);
- }
- fprintf (stderr, "glfs-create fd - %d\n", fd);
-
- /* validate locks for negative range */
- lock.l_type = F_WRLCK;
- lock.l_whence = SEEK_SET;
- lock.l_start = 10;
- lock.l_len = -9;
-
- ret = glfs_posix_lock (fd, F_SETLK, &lock);
- LOG_ERR ("glfs_posix_lock", ret);
+ glfs_t *fs = NULL;
+ int ret = 0, i, status = 0;
+ glfs_fd_t *fd = NULL;
+ char *filename = "file_tmp";
+ char *volname = NULL;
+ char *logfile = NULL;
+ char *hostname = NULL;
+ struct flock lock = {
+ 0,
+ };
+
+ if (argc != 4) {
+ fprintf(stderr, "Invalid argument\n");
+ exit(1);
+ }
+
+ hostname = argv[1];
+ volname = argv[2];
+ logfile = argv[3];
+
+ fs = glfs_new(volname);
+ if (!fs) {
+ fprintf(stderr, "glfs_new: returned NULL\n");
+ return -1;
+ }
+
+ ret = glfs_set_volfile_server(fs, "tcp", hostname, 24007);
+ LOG_ERR("glfs_set_volfile_server", ret);
+
+ ret = glfs_set_logging(fs, logfile, 7);
+ LOG_ERR("glfs_set_logging", ret);
+
+ ret = glfs_init(fs);
+ LOG_ERR("glfs_init", ret);
+
+ fd = glfs_creat(fs, filename, O_RDWR | O_SYNC, 0644);
+ if (fd <= 0) {
+ ret = -1;
+ LOG_ERR("glfs_creat", ret);
+ }
+ fprintf(stderr, "glfs-create fd - %d\n", fd);
+
+ /* validate locks for negative range */
+ lock.l_type = F_WRLCK;
+ lock.l_whence = SEEK_SET;
+ lock.l_start = 10;
+ lock.l_len = -9;
+
+ ret = glfs_posix_lock(fd, F_SETLK, &lock);
+ LOG_ERR("glfs_posix_lock", ret);
err:
- glfs_close(fd);
- LOG_ERR ("glfs_close", ret);
+ glfs_close(fd);
+ LOG_ERR("glfs_close", ret);
out:
- if (fs) {
- ret = glfs_fini(fs);
- fprintf (stderr, "glfs_fini(fs) returned %d \n", ret);
- }
-
- if (ret)
- exit(1);
- exit(0);
+ if (fs) {
+ ret = glfs_fini(fs);
+ fprintf(stderr, "glfs_fini(fs) returned %d \n", ret);
+ }
+
+ if (ret)
+ exit(1);
+ exit(0);
}
-
-
diff --git a/tests/basic/gfapi/bug1283983.c b/tests/basic/gfapi/bug1283983.c
index 3334b290d9e..b920013d0e0 100644
--- a/tests/basic/gfapi/bug1283983.c
+++ b/tests/basic/gfapi/bug1283983.c
@@ -10,114 +10,113 @@
#include <glusterfs/api/glfs-handles.h>
int gfapi = 1;
-#define LOG_ERR(func, ret) do { \
- if (ret != 0) { \
- fprintf (stderr, "%s : returned error ret(%d), errno(%d)\n", \
- func, ret, errno); \
- exit(1); \
- } else { \
- fprintf (stderr, "%s : returned %d\n", func, ret); \
- } \
- } while (0)
-#define LOG_IF_NO_ERR(func, ret) do { \
- if (ret == 0) { \
- fprintf (stderr, "%s : hasn't returned error %d\n", \
- func, ret); \
- exit(1); \
- } else { \
- fprintf (stderr, "%s : returned %d\n", func, ret); \
- } \
- } while (0)
+#define LOG_ERR(func, ret) \
+ do { \
+ if (ret != 0) { \
+ fprintf(stderr, "%s : returned error ret(%d), errno(%d)\n", func, \
+ ret, errno); \
+ exit(1); \
+ } else { \
+ fprintf(stderr, "%s : returned %d\n", func, ret); \
+ } \
+ } while (0)
+#define LOG_IF_NO_ERR(func, ret) \
+ do { \
+ if (ret == 0) { \
+ fprintf(stderr, "%s : hasn't returned error %d\n", func, ret); \
+ exit(1); \
+ } else { \
+ fprintf(stderr, "%s : returned %d\n", func, ret); \
+ } \
+ } while (0)
int
-main (int argc, char *argv[])
+main(int argc, char *argv[])
{
- glfs_t *fs = NULL;
- int ret = 0, i;
- glfs_fd_t *fd = NULL;
- char *filename = "/a1";
- char *filename2 = "/a2";
- struct stat sb = {0, };
- struct glfs_upcall *cbk = NULL;
- char *logfile = NULL;
- char *volname = NULL;
- int cnt = 1;
- struct glfs_upcall_inode *in_arg = NULL;
- struct glfs_object *root = NULL, *leaf = NULL;
-
- fprintf (stderr, "Starting libgfapi_fini\n");
- if (argc != 4) {
- fprintf (stderr, "Invalid argument\n");
- exit(1);
+ glfs_t *fs = NULL;
+ int ret = 0, i;
+ glfs_fd_t *fd = NULL;
+ char *filename = "/a1";
+ char *filename2 = "/a2";
+ struct stat sb = {
+ 0,
+ };
+ struct glfs_upcall *cbk = NULL;
+ char *logfile = NULL;
+ char *volname = NULL;
+ int cnt = 1;
+ struct glfs_upcall_inode *in_arg = NULL;
+ struct glfs_object *root = NULL, *leaf = NULL;
+
+ fprintf(stderr, "Starting libgfapi_fini\n");
+ if (argc != 4) {
+ fprintf(stderr, "Invalid argument\n");
+ exit(1);
+ }
+
+ hostname = argv[1] volname = argv[2];
+ logfile = argv[3];
+
+ fs = glfs_new(volname);
+ if (!fs) {
+ fprintf(stderr, "glfs_new: returned NULL\n");
+ return 1;
+ }
+
+ ret = glfs_set_volfile_server(fs, "tcp", hostname, 24007);
+ LOG_ERR("glfs_set_volfile_server", ret);
+
+ ret = glfs_set_logging(fs, logfile, 7);
+ LOG_ERR("glfs_set_logging", ret);
+
+ ret = glfs_init(fs);
+ LOG_ERR("glfs_init", ret);
+
+ sleep(2);
+ root = glfs_h_lookupat(fs, NULL, "/", &sb, 0);
+ if (!root) {
+ ret = -1;
+ LOG_ERR("glfs_h_lookupat root", ret);
+ }
+ leaf = glfs_h_lookupat(fs, root, filename, &sb, 0);
+ if (!leaf) {
+ ret = -1;
+ LOG_IF_NO_ERR("glfs_h_lookupat leaf", ret);
+ }
+
+ leaf = glfs_h_creat(fs, root, filename, O_RDWR, 0644, &sb);
+ if (!leaf) {
+ ret = -1;
+ LOG_ERR("glfs_h_lookupat leaf", ret);
+ }
+ fprintf(stderr, "glfs_h_create leaf - %p\n", leaf);
+
+ leaf = glfs_h_lookupat(fs, root, filename2, &sb, 0);
+ if (!leaf) {
+ ret = -1;
+ LOG_IF_NO_ERR("glfs_h_lookupat leaf", ret);
+ }
+
+ ret = glfs_h_rename(fs, root, filename, root, filename2);
+ LOG_ERR("glfs_rename", ret);
+
+ while (cnt++ < 5) {
+ ret = glfs_h_poll_upcall(fs, &cbk);
+ LOG_ERR("glfs_h_poll_upcall", ret);
+
+ /* There should not be any upcalls sent */
+ if (glfs_upcall_get_reason(cbk) != GLFS_UPCALL_EVENT_NULL) {
+ fprintf(stderr, "Error: Upcall received(%d)\n",
+ glfs_upcall_get_reason(cbk));
+ exit(1);
}
- hostname = argv[1]
- volname = argv[2];
- logfile = argv[3];
+ glfs_free(cbk);
+ }
+ ret = glfs_fini(fs);
+ LOG_ERR("glfs_fini", ret);
- fs = glfs_new (volname);
- if (!fs) {
- fprintf (stderr, "glfs_new: returned NULL\n");
- return 1;
- }
-
- ret = glfs_set_volfile_server (fs, "tcp", hostname, 24007);
- LOG_ERR("glfs_set_volfile_server", ret);
-
- ret = glfs_set_logging (fs, logfile, 7);
- LOG_ERR("glfs_set_logging", ret);
-
- ret = glfs_init (fs);
- LOG_ERR("glfs_init", ret);
-
- sleep (2);
- root = glfs_h_lookupat (fs, NULL, "/", &sb, 0);
- if (!root) {
- ret = -1;
- LOG_ERR ("glfs_h_lookupat root", ret);
- }
- leaf = glfs_h_lookupat (fs, root, filename, &sb, 0);
- if (!leaf) {
- ret = -1;
- LOG_IF_NO_ERR ("glfs_h_lookupat leaf", ret);
- }
-
- leaf = glfs_h_creat (fs, root, filename, O_RDWR, 0644, &sb);
- if (!leaf) {
- ret = -1;
- LOG_ERR ("glfs_h_lookupat leaf", ret);
- }
- fprintf (stderr, "glfs_h_create leaf - %p\n", leaf);
-
- leaf = glfs_h_lookupat (fs, root, filename2, &sb, 0);
- if (!leaf) {
- ret = -1;
- LOG_IF_NO_ERR ("glfs_h_lookupat leaf", ret);
- }
-
- ret = glfs_h_rename (fs, root, filename, root, filename2);
- LOG_ERR("glfs_rename", ret);
-
- while (cnt++ < 5) {
- ret = glfs_h_poll_upcall(fs, &cbk);
- LOG_ERR ("glfs_h_poll_upcall", ret);
-
- /* There should not be any upcalls sent */
- if (glfs_upcall_get_reason(cbk) != GLFS_UPCALL_EVENT_NULL) {
- fprintf (stderr, "Error: Upcall received(%d)\n",
- glfs_upcall_get_reason(cbk));
- exit (1);
- }
-
- glfs_free (cbk);
- }
-
- ret = glfs_fini(fs);
- LOG_ERR("glfs_fini", ret);
-
- fprintf (stderr, "End of libgfapi_fini\n");
+ fprintf(stderr, "End of libgfapi_fini\n");
- exit(0);
+ exit(0);
}
-
-
diff --git a/tests/basic/gfapi/bug1291259.c b/tests/basic/gfapi/bug1291259.c
index 26fc1e01449..cd7bc65268b 100644
--- a/tests/basic/gfapi/bug1291259.c
+++ b/tests/basic/gfapi/bug1291259.c
@@ -10,174 +10,172 @@
#include <glusterfs/api/glfs-handles.h>
int gfapi = 1;
-#define LOG_ERR(func, ret) do { \
- if (ret != 0) { \
- fprintf (stderr, "%s : returned error ret(%d), errno(%d)\n", \
- func, ret, errno); \
- exit(1); \
- } else { \
- fprintf (stderr, "%s : returned %d\n", func, ret); \
- } \
- } while (0)
-#define LOG_IF_NO_ERR(func, ret) do { \
- if (ret == 0) { \
- fprintf (stderr, "%s : hasn't returned error %d\n", \
- func, ret); \
- exit(1); \
- } else { \
- fprintf (stderr, "%s : returned %d\n", func, ret); \
- } \
- } while (0)
+#define LOG_ERR(func, ret) \
+ do { \
+ if (ret != 0) { \
+ fprintf(stderr, "%s : returned error ret(%d), errno(%d)\n", func, \
+ ret, errno); \
+ exit(1); \
+ } else { \
+ fprintf(stderr, "%s : returned %d\n", func, ret); \
+ } \
+ } while (0)
+#define LOG_IF_NO_ERR(func, ret) \
+ do { \
+ if (ret == 0) { \
+ fprintf(stderr, "%s : hasn't returned error %d\n", func, ret); \
+ exit(1); \
+ } else { \
+ fprintf(stderr, "%s : returned %d\n", func, ret); \
+ } \
+ } while (0)
#define GLAPI_UUID_LENGTH 16
int
-main (int argc, char *argv[])
+main(int argc, char *argv[])
{
- glfs_t *fs = NULL;
- glfs_t *fs2 = NULL;
- int ret = 0, i;
- glfs_fd_t *fd = NULL;
- char *filename = "/a1";
- char *filename2 = "/a2";
- struct stat sb = {0, };
- char *logfile = NULL;
- char *volname = NULL;
- char *hostname = NULL;
- int cnt = 1;
- int upcall_received = 0;
- struct glfs_upcall *cbk = NULL;
- struct glfs_object *root = NULL, *leaf = NULL;
- unsigned char globjhdl[GFAPI_HANDLE_LENGTH];
- unsigned char globjhdl2[GFAPI_HANDLE_LENGTH];
-
- fprintf (stderr, "Starting libgfapi_fini\n");
- if (argc != 4) {
- fprintf (stderr, "Invalid argument\n");
- exit(1);
- }
+ glfs_t *fs = NULL;
+ glfs_t *fs2 = NULL;
+ int ret = 0, i;
+ glfs_fd_t *fd = NULL;
+ char *filename = "/a1";
+ char *filename2 = "/a2";
+ struct stat sb = {
+ 0,
+ };
+ char *logfile = NULL;
+ char *volname = NULL;
+ char *hostname = NULL;
+ int cnt = 1;
+ int upcall_received = 0;
+ struct glfs_upcall *cbk = NULL;
+ struct glfs_object *root = NULL, *leaf = NULL;
+ unsigned char globjhdl[GFAPI_HANDLE_LENGTH];
+ unsigned char globjhdl2[GFAPI_HANDLE_LENGTH];
+
+ fprintf(stderr, "Starting libgfapi_fini\n");
+ if (argc != 4) {
+ fprintf(stderr, "Invalid argument\n");
+ exit(1);
+ }
+
+ hostname = argv[1];
+ volname = argv[2];
+ logfile = argv[3];
+
+ fs = glfs_new(volname);
+ if (!fs) {
+ fprintf(stderr, "glfs_new: returned NULL\n");
+ return 1;
+ }
+
+ ret = glfs_set_volfile_server(fs, "tcp", hostname, 24007);
+ LOG_ERR("glfs_set_volfile_server", ret);
+
+ ret = glfs_set_logging(fs, logfile, 7);
+ LOG_ERR("glfs_set_logging", ret);
+
+ ret = glfs_init(fs);
+ LOG_ERR("glfs_init", ret);
+
+ /* This does not block, but enables caching of events. Real
+ * applications like NFS-Ganesha run this in a thread before activity
+ * on the fs (through this instance) happens. */
+ ret = glfs_h_poll_upcall(fs, &cbk);
+ LOG_ERR("glfs_h_poll_upcall", ret);
+
+ fs2 = glfs_new(volname);
+ if (!fs) {
+ fprintf(stderr, "glfs_new: returned NULL\n");
+ return 1;
+ }
+
+ ret = glfs_set_volfile_server(fs2, "tcp", hostname, 24007);
+ LOG_ERR("glfs_set_volfile_server", ret);
+
+ ret = glfs_set_logging(fs2, logfile, 7);
+ LOG_ERR("glfs_set_logging", ret);
+
+ ret = glfs_init(fs2);
+ LOG_ERR("glfs_init", ret);
+
+ sleep(2);
+ root = glfs_h_lookupat(fs, NULL, "/", &sb, 0);
+ if (!root) {
+ ret = -1;
+ LOG_ERR("glfs_h_lookupat root", ret);
+ }
+ leaf = glfs_h_lookupat(fs, root, filename, &sb, 0);
+ if (!leaf) {
+ ret = -1;
+ LOG_IF_NO_ERR("glfs_h_lookupat leaf", ret);
+ }
+
+ root = glfs_h_lookupat(fs2, NULL, "/", &sb, 0);
+ if (!root) {
+ ret = -1;
+ LOG_ERR("glfs_h_lookupat root", ret);
+ }
+ leaf = glfs_h_creat(fs2, root, filename, O_RDWR, 0644, &sb);
+ if (!leaf) {
+ ret = -1;
+ LOG_ERR("glfs_h_lookupat leaf", ret);
+ }
+ fprintf(stderr, "glfs_h_create leaf - %p\n", leaf);
+
+ while (cnt++ < 5 && !upcall_received) {
+ enum glfs_upcall_reason reason = 0;
+ struct glfs_upcall_inode *in_arg = NULL;
- hostname = argv[1];
- volname = argv[2];
- logfile = argv[3];
+ ret = glfs_h_poll_upcall(fs, &cbk);
+ LOG_ERR("glfs_h_poll_upcall", ret);
+ if (ret)
+ goto retry;
+ reason = glfs_upcall_get_reason(cbk);
+ fprintf(stderr, "Upcall received(%d)\n", reason);
- fs = glfs_new (volname);
- if (!fs) {
- fprintf (stderr, "glfs_new: returned NULL\n");
- return 1;
- }
+ if (reason == GLFS_UPCALL_INODE_INVALIDATE) {
+ struct glfs_object *object = NULL;
- ret = glfs_set_volfile_server (fs, "tcp", hostname, 24007);
- LOG_ERR("glfs_set_volfile_server", ret);
+ in_arg = glfs_upcall_get_event(cbk);
+ object = glfs_upcall_inode_get_object(in_arg);
- ret = glfs_set_logging (fs, logfile, 7);
- LOG_ERR("glfs_set_logging", ret);
+ ret = glfs_h_extract_handle(root, globjhdl + GLAPI_UUID_LENGTH,
+ GFAPI_HANDLE_LENGTH);
+ LOG_ERR("glfs_h_extract_handle", (ret != 16));
- ret = glfs_init (fs);
- LOG_ERR("glfs_init", ret);
+ ret = glfs_h_extract_handle(object, globjhdl2 + GLAPI_UUID_LENGTH,
+ GFAPI_HANDLE_LENGTH);
+ LOG_ERR("glfs_h_extract_handle", (ret != 16));
- /* This does not block, but enables caching of events. Real
- * applications like NFS-Ganesha run this in a thread before activity
- * on the fs (through this instance) happens. */
- ret = glfs_h_poll_upcall(fs, &cbk);
- LOG_ERR ("glfs_h_poll_upcall", ret);
-
- fs2 = glfs_new (volname);
- if (!fs) {
- fprintf (stderr, "glfs_new: returned NULL\n");
- return 1;
+ if (memcmp(globjhdl + GLAPI_UUID_LENGTH,
+ globjhdl2 + GLAPI_UUID_LENGTH, 16)) {
+ fprintf(stderr, "Error: gfid mismatch\n");
+ exit(1);
+ }
+ upcall_received = 1;
}
- ret = glfs_set_volfile_server (fs2, "tcp", hostname, 24007);
- LOG_ERR("glfs_set_volfile_server", ret);
-
- ret = glfs_set_logging (fs2, logfile, 7);
- LOG_ERR("glfs_set_logging", ret);
-
- ret = glfs_init (fs2);
- LOG_ERR("glfs_init", ret);
+ retry:
+ if (!upcall_received)
+ sleep(1); /* glfs_h_poll_upcall() does not block */
- sleep (2);
- root = glfs_h_lookupat (fs, NULL, "/", &sb, 0);
- if (!root) {
- ret = -1;
- LOG_ERR ("glfs_h_lookupat root", ret);
- }
- leaf = glfs_h_lookupat (fs, root, filename, &sb, 0);
- if (!leaf) {
- ret = -1;
- LOG_IF_NO_ERR ("glfs_h_lookupat leaf", ret);
- }
-
- root = glfs_h_lookupat (fs2, NULL, "/", &sb, 0);
- if (!root) {
- ret = -1;
- LOG_ERR ("glfs_h_lookupat root", ret);
- }
- leaf = glfs_h_creat (fs2, root, filename, O_RDWR, 0644, &sb);
- if (!leaf) {
- ret = -1;
- LOG_ERR ("glfs_h_lookupat leaf", ret);
- }
- fprintf (stderr, "glfs_h_create leaf - %p\n", leaf);
-
- while (cnt++ < 5 && !upcall_received) {
- enum glfs_upcall_reason reason = 0;
- struct glfs_upcall_inode *in_arg = NULL;
-
- ret = glfs_h_poll_upcall(fs, &cbk);
- LOG_ERR ("glfs_h_poll_upcall", ret);
- if (ret)
- goto retry;
-
- reason = glfs_upcall_get_reason (cbk);
- fprintf (stderr, "Upcall received(%d)\n", reason);
-
- if (reason == GLFS_UPCALL_INODE_INVALIDATE) {
- struct glfs_object *object = NULL;
-
- in_arg = glfs_upcall_get_event (cbk);
- object = glfs_upcall_inode_get_object (in_arg);
-
- ret = glfs_h_extract_handle (root,
- globjhdl+GLAPI_UUID_LENGTH,
- GFAPI_HANDLE_LENGTH);
- LOG_ERR("glfs_h_extract_handle", (ret != 16));
-
- ret = glfs_h_extract_handle (object,
- globjhdl2+GLAPI_UUID_LENGTH,
- GFAPI_HANDLE_LENGTH);
- LOG_ERR("glfs_h_extract_handle", (ret != 16));
-
- if (memcmp (globjhdl+GLAPI_UUID_LENGTH,
- globjhdl2+GLAPI_UUID_LENGTH, 16)) {
- fprintf (stderr, "Error: gfid mismatch\n");
- exit (1);
- }
- upcall_received = 1;
- }
-
-retry:
- if (!upcall_received)
- sleep (1); /* glfs_h_poll_upcall() does not block */
-
- if (!ret) {
- glfs_free (cbk);
- cbk = NULL;
- }
+ if (!ret) {
+ glfs_free(cbk);
+ cbk = NULL;
}
+ }
- if (!upcall_received) {
- fprintf (stderr, "Error: Upcall not received\n");
- exit (1);
- }
+ if (!upcall_received) {
+ fprintf(stderr, "Error: Upcall not received\n");
+ exit(1);
+ }
- ret = glfs_fini(fs);
- LOG_ERR("glfs_fini", ret);
+ ret = glfs_fini(fs);
+ LOG_ERR("glfs_fini", ret);
- fprintf (stderr, "End of libgfapi_fini\n");
+ fprintf(stderr, "End of libgfapi_fini\n");
- exit(0);
+ exit(0);
}
-
-
diff --git a/tests/basic/gfapi/bug1613098.c b/tests/basic/gfapi/bug1613098.c
index cdb69fdedfa..ee67e97a034 100644
--- a/tests/basic/gfapi/bug1613098.c
+++ b/tests/basic/gfapi/bug1613098.c
@@ -6,90 +6,91 @@
#include <glusterfs/api/glfs.h>
#include <glusterfs/api/glfs-handles.h>
-#define ACL_TYPE_ACCESS (0x8000)
+#define ACL_TYPE_ACCESS (0x8000)
-#define VALIDATE_AND_GOTO_LABEL_ON_ERROR(func, ret, label) do { \
- if (ret < 0) { \
- fprintf (stderr, "%s : returned error %d (%s)\n", \
- func, ret, strerror (errno)); \
- goto label; \
- } \
- } while (0)
+#define VALIDATE_AND_GOTO_LABEL_ON_ERROR(func, ret, label) \
+ do { \
+ if (ret < 0) { \
+ fprintf(stderr, "%s : returned error %d (%s)\n", func, ret, \
+ strerror(errno)); \
+ goto label; \
+ } \
+ } while (0)
int
-main (int argc, char *argv[])
+main(int argc, char *argv[])
{
- int ret = -1;
- int flags = O_RDWR|O_SYNC;
- glfs_t *fs = NULL;
- glfs_fd_t *fd = NULL;
- char *volname = NULL;
- char *logfile = NULL;
- const char *filename = "file_tmp";
- struct glfs_object *object = NULL;
- acl_t acl = NULL;
- struct stat sb;
-
- if (argc != 3) {
- fprintf (stderr, "Invalid argument\n");
- return 1;
- }
-
- volname = argv[1];
- logfile = argv[2];
-
- fs = glfs_new (volname);
- if (!fs)
- VALIDATE_AND_GOTO_LABEL_ON_ERROR ("glfs_new", ret, out);
-
- ret = glfs_set_volfile_server (fs, "tcp", "localhost", 24007);
- VALIDATE_AND_GOTO_LABEL_ON_ERROR ("glfs_set_volfile_server", ret, out);
-
- ret = glfs_set_logging (fs, logfile, 7);
- VALIDATE_AND_GOTO_LABEL_ON_ERROR ("glfs_set_logging", ret, out);
-
- ret = glfs_init (fs);
- VALIDATE_AND_GOTO_LABEL_ON_ERROR ("glfs_init", ret, out);
-
- fd = glfs_creat(fs, filename, flags, 0044);
- if (fd == NULL) {
- ret = -1;
- VALIDATE_AND_GOTO_LABEL_ON_ERROR ("glfs_creat", ret, out);
- }
- glfs_close(fd);
-
- object = glfs_h_lookupat(fs, NULL, filename, NULL, 0);
- if (object == NULL) {
- ret = -1;
- VALIDATE_AND_GOTO_LABEL_ON_ERROR ("glfs_h_lookupat", ret, out);
- }
-
- ret = glfs_chown(fs, filename, 99, 99);
- VALIDATE_AND_GOTO_LABEL_ON_ERROR ("glfs_chown", ret, out);
-
- ret = glfs_setfsuid(99);
- VALIDATE_AND_GOTO_LABEL_ON_ERROR ("glfs_setfsuid", ret, out);
-
- ret = glfs_setfsgid(99);
- VALIDATE_AND_GOTO_LABEL_ON_ERROR ("glfs_setfsgid", ret, out);
-
- acl = glfs_h_acl_get(fs, object, ACL_TYPE_ACCESS);
- if (acl == NULL) {
- ret = -1;
- VALIDATE_AND_GOTO_LABEL_ON_ERROR ("glfs_h_acl_get", ret, out);
- }
-
- ret = glfs_h_acl_set(fs, object, ACL_TYPE_ACCESS, acl);
- VALIDATE_AND_GOTO_LABEL_ON_ERROR ("glfs_h_acl_get", ret, out);
+ int ret = -1;
+ int flags = O_RDWR | O_SYNC;
+ glfs_t *fs = NULL;
+ glfs_fd_t *fd = NULL;
+ char *volname = NULL;
+ char *logfile = NULL;
+ const char *filename = "file_tmp";
+ struct glfs_object *object = NULL;
+ acl_t acl = NULL;
+ struct stat sb;
+
+ if (argc != 3) {
+ fprintf(stderr, "Invalid argument\n");
+ return 1;
+ }
+
+ volname = argv[1];
+ logfile = argv[2];
+
+ fs = glfs_new(volname);
+ if (!fs)
+ VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_new", ret, out);
+
+ ret = glfs_set_volfile_server(fs, "tcp", "localhost", 24007);
+ VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_set_volfile_server", ret, out);
+
+ ret = glfs_set_logging(fs, logfile, 7);
+ VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_set_logging", ret, out);
+
+ ret = glfs_init(fs);
+ VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_init", ret, out);
+
+ fd = glfs_creat(fs, filename, flags, 0044);
+ if (fd == NULL) {
+ ret = -1;
+ VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_creat", ret, out);
+ }
+ glfs_close(fd);
+
+ object = glfs_h_lookupat(fs, NULL, filename, NULL, 0);
+ if (object == NULL) {
+ ret = -1;
+ VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_h_lookupat", ret, out);
+ }
+
+ ret = glfs_chown(fs, filename, 99, 99);
+ VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_chown", ret, out);
+
+ ret = glfs_setfsuid(99);
+ VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_setfsuid", ret, out);
+
+ ret = glfs_setfsgid(99);
+ VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_setfsgid", ret, out);
+
+ acl = glfs_h_acl_get(fs, object, ACL_TYPE_ACCESS);
+ if (acl == NULL) {
+ ret = -1;
+ VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_h_acl_get", ret, out);
+ }
+
+ ret = glfs_h_acl_set(fs, object, ACL_TYPE_ACCESS, acl);
+ VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_h_acl_get", ret, out);
out:
- glfs_setfsuid(0);
- glfs_setfsgid(0);
+ glfs_setfsuid(0);
+ glfs_setfsgid(0);
- if (object)
- glfs_h_close(object);
+ if (object)
+ glfs_h_close(object);
- if (fs)
- glfs_fini(fs);
+ if (fs)
+ glfs_fini(fs);
- return ret;
+ return ret;
}
diff --git a/tests/basic/gfapi/gfapi-async-calls-test.c b/tests/basic/gfapi/gfapi-async-calls-test.c
index b9f29a44ac0..5a291c3c76b 100644
--- a/tests/basic/gfapi/gfapi-async-calls-test.c
+++ b/tests/basic/gfapi/gfapi-async-calls-test.c
@@ -9,170 +9,164 @@
#include <glusterfs/api/glfs.h>
#include <glusterfs/api/glfs-handles.h>
-#define LOG_ERR(msg) do { \
- fprintf (stderr, "%s : Error (%s)\n", msg, strerror (errno)); \
- } while (0)
+#define LOG_ERR(msg) \
+ do { \
+ fprintf(stderr, "%s : Error (%s)\n", msg, strerror(errno)); \
+ } while (0)
int cbk_complete = 0;
int cbk_ret_val = -1;
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;
}
glfs_t *
-init_glfs (const char *hostname, const char *volname,
- const char *logfile)
+init_glfs(const char *hostname, const char *volname, const char *logfile)
{
- int ret = -1;
- glfs_t *fs = NULL;
-
- fs = glfs_new (volname);
- if (!fs) {
- LOG_ERR ("glfs_new failed");
- return NULL;
- }
-
- ret = glfs_set_volfile_server (fs, "tcp", hostname, 24007);
- if (ret < 0) {
- LOG_ERR ("glfs_set_volfile_server failed");
- goto out;
- }
-
- ret = glfs_set_logging (fs, logfile, 7);
- if (ret < 0) {
- LOG_ERR ("glfs_set_logging failed");
- goto out;
- }
-
- ret = glfs_init (fs);
- if (ret < 0) {
- LOG_ERR ("glfs_init failed");
- goto out;
- }
-
- ret = 0;
+ int ret = -1;
+ glfs_t *fs = NULL;
+
+ fs = glfs_new(volname);
+ if (!fs) {
+ LOG_ERR("glfs_new failed");
+ return NULL;
+ }
+
+ ret = glfs_set_volfile_server(fs, "tcp", hostname, 24007);
+ if (ret < 0) {
+ LOG_ERR("glfs_set_volfile_server failed");
+ goto out;
+ }
+
+ ret = glfs_set_logging(fs, logfile, 7);
+ if (ret < 0) {
+ LOG_ERR("glfs_set_logging failed");
+ goto out;
+ }
+
+ ret = glfs_init(fs);
+ if (ret < 0) {
+ LOG_ERR("glfs_init failed");
+ goto out;
+ }
+
+ ret = 0;
out:
- if (ret) {
- glfs_fini (fs);
- fs = NULL;
- }
+ if (ret) {
+ glfs_fini(fs);
+ fs = NULL;
+ }
- return fs;
+ return fs;
}
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) {
- LOG_ERR ("glfs_write failed");
- }
- cbk_ret_val = ret;
- cbk_complete = 1;
+ if (ret < 0) {
+ LOG_ERR("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;
- const char *buff = "This is from my prog\n";
- struct iovec iov = {0};
- void *write_cookie = NULL;
- void *read_cookie = NULL;
-
-
-
- ret = fill_iov (&iov, 'a', char_count);
- if (ret) {
- LOG_ERR ("failed to create iov");
- goto out;
- }
-
- write_cookie = strdup ("write_cookie");
- ret = glfs_pwritev_async (glfd, &iov, 1, 0, flags, write_async_cbk,
- &write_cookie);
+ ssize_t ret = -1;
+ int flags = O_RDWR;
+ const char *buff = "This is from my prog\n";
+ struct iovec iov = {0};
+ void *write_cookie = NULL;
+ void *read_cookie = NULL;
+
+ ret = fill_iov(&iov, 'a', char_count);
+ if (ret) {
+ LOG_ERR("failed to create iov");
+ goto out;
+ }
+
+ write_cookie = strdup("write_cookie");
+ ret = glfs_pwritev_async(glfd, &iov, 1, 0, flags, write_async_cbk,
+ &write_cookie);
out:
- if (ret < 0) {
- LOG_ERR ("glfs_pwritev async failed");
- }
- return ret;
-
+ if (ret < 0) {
+ LOG_ERR("glfs_pwritev async failed");
+ }
+ return ret;
}
int
-main (int argc, char *argv[])
+main(int argc, char *argv[])
{
- int ret = 0;
- char *hostname = NULL;
- char *volname = NULL;
- char *logfile = NULL;
- glfs_t *fs = NULL;
- const char *filename = "glfs_test.txt";
- int flags = (O_RDWR|O_CREAT);
- glfs_fd_t *glfd = NULL;
- int count = 200;
-
- if (argc != 4) {
- fprintf (stderr, "Invalid argument\n");
- exit(1);
- }
-
- hostname = argv[1];
- volname = argv[2];
- logfile = argv[3];
-
- fs = init_glfs (hostname, volname, logfile);
- if (fs == NULL) {
- LOG_ERR ("init_glfs failed");
- return -1;
- }
-
- glfd = glfs_creat (fs, filename, flags, 0644);
- if (glfd == NULL) {
- LOG_ERR ("glfs_creat failed");
- exit(1);
- }
-
- ret = write_async (fs, glfd, count);
- if (ret) {
- LOG_ERR ("glfs_test_function failed");
- exit(1);
- }
-
- while (cbk_complete != 1) {
- sleep(1);
- }
-
- ret = glfs_close (glfd);
- if (ret < 0) {
- LOG_ERR ("glfs close failed");
- }
-
- /*
- * skipping fini
- */
-
- if (cbk_ret_val == count)
- return 0;
- else
- return -1;
+ int ret = 0;
+ char *hostname = NULL;
+ char *volname = NULL;
+ char *logfile = NULL;
+ glfs_t *fs = NULL;
+ const char *filename = "glfs_test.txt";
+ int flags = (O_RDWR | O_CREAT);
+ glfs_fd_t *glfd = NULL;
+ int count = 200;
+
+ if (argc != 4) {
+ fprintf(stderr, "Invalid argument\n");
+ exit(1);
+ }
+
+ hostname = argv[1];
+ volname = argv[2];
+ logfile = argv[3];
+
+ fs = init_glfs(hostname, volname, logfile);
+ if (fs == NULL) {
+ LOG_ERR("init_glfs failed");
+ return -1;
+ }
+
+ glfd = glfs_creat(fs, filename, flags, 0644);
+ if (glfd == NULL) {
+ LOG_ERR("glfs_creat failed");
+ exit(1);
+ }
+
+ ret = write_async(fs, glfd, count);
+ if (ret) {
+ LOG_ERR("glfs_test_function failed");
+ exit(1);
+ }
+
+ while (cbk_complete != 1) {
+ sleep(1);
+ }
+
+ ret = glfs_close(glfd);
+ if (ret < 0) {
+ LOG_ERR("glfs close failed");
+ }
+
+ /*
+ * skipping fini
+ */
+
+ if (cbk_ret_val == count)
+ return 0;
+ else
+ return -1;
}
-
-
diff --git a/tests/basic/gfapi/gfapi-dup.c b/tests/basic/gfapi/gfapi-dup.c
index 96f133eae33..028108e4590 100644
--- a/tests/basic/gfapi/gfapi-dup.c
+++ b/tests/basic/gfapi/gfapi-dup.c
@@ -4,81 +4,81 @@
#include <glusterfs/api/glfs.h>
#include <glusterfs/api/glfs-handles.h>
-#define VALIDATE_AND_GOTO_LABEL_ON_ERROR(func, ret, label) do { \
- if (ret < 0) { \
- fprintf (stderr, "%s : returned error %d (%s)\n", \
- func, ret, strerror (errno)); \
- goto label; \
- } \
- } while (0)
+#define VALIDATE_AND_GOTO_LABEL_ON_ERROR(func, ret, label) \
+ do { \
+ if (ret < 0) { \
+ fprintf(stderr, "%s : returned error %d (%s)\n", func, ret, \
+ strerror(errno)); \
+ goto label; \
+ } \
+ } while (0)
int
-main (int argc, char *argv[])
+main(int argc, char *argv[])
{
- int ret = -1;
- int flags = O_RDWR|O_SYNC;
- glfs_t *fs = NULL;
- glfs_fd_t *fd1 = NULL;
- glfs_fd_t *fd2 = NULL;
- char *volname = NULL;
- char *logfile = NULL;
- char *hostname = NULL;
- const char *filename = "file_tmp";
- const char *buff = "An opinion should be the result of thought, "
- "not a substitute for it.";
-
- if (argc != 4) {
- fprintf (stderr, "Invalid argument\n");
- return 1;
- }
-
- hostname = argv[1];
- volname = argv[2];
- logfile = argv[3];
-
- fs = glfs_new (volname);
- if (!fs)
- VALIDATE_AND_GOTO_LABEL_ON_ERROR ("glfs_new", ret, out);
-
- ret = glfs_set_volfile_server (fs, "tcp", hostname, 24007);
- VALIDATE_AND_GOTO_LABEL_ON_ERROR ("glfs_set_volfile_server", ret, out);
-
- ret = glfs_set_logging (fs, logfile, 7);
- VALIDATE_AND_GOTO_LABEL_ON_ERROR ("glfs_set_logging", ret, out);
-
- ret = glfs_init (fs);
- VALIDATE_AND_GOTO_LABEL_ON_ERROR ("glfs_init", ret, out);
-
- fd1 = glfs_creat(fs, filename, flags, 0644);
- if (fd1 == NULL) {
- ret = -1;
- VALIDATE_AND_GOTO_LABEL_ON_ERROR ("glfs_creat", ret, out);
- }
-
- ret = glfs_write (fd1, buff, strlen (buff), flags);
- VALIDATE_AND_GOTO_LABEL_ON_ERROR ("glfs_write", ret, out);
-
- fd2 = glfs_dup(fd1);
- if (fd2 == NULL) {
- ret = -1;
- VALIDATE_AND_GOTO_LABEL_ON_ERROR ("glfs_dup", ret, out);
- }
-
- ret = glfs_lseek (fd2, 0, SEEK_SET);
- VALIDATE_AND_GOTO_LABEL_ON_ERROR ("glfs_lseek", ret, out);
+ int ret = -1;
+ int flags = O_RDWR | O_SYNC;
+ glfs_t *fs = NULL;
+ glfs_fd_t *fd1 = NULL;
+ glfs_fd_t *fd2 = NULL;
+ char *volname = NULL;
+ char *logfile = NULL;
+ char *hostname = NULL;
+ const char *filename = "file_tmp";
+ const char *buff =
+ "An opinion should be the result of thought, "
+ "not a substitute for it.";
+
+ if (argc != 4) {
+ fprintf(stderr, "Invalid argument\n");
+ return 1;
+ }
+
+ hostname = argv[1];
+ volname = argv[2];
+ logfile = argv[3];
+
+ fs = glfs_new(volname);
+ if (!fs)
+ VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_new", ret, out);
+
+ ret = glfs_set_volfile_server(fs, "tcp", hostname, 24007);
+ VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_set_volfile_server", ret, out);
+
+ ret = glfs_set_logging(fs, logfile, 7);
+ VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_set_logging", ret, out);
+
+ ret = glfs_init(fs);
+ VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_init", ret, out);
+
+ fd1 = glfs_creat(fs, filename, flags, 0644);
+ if (fd1 == NULL) {
+ ret = -1;
+ VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_creat", ret, out);
+ }
+
+ ret = glfs_write(fd1, buff, strlen(buff), flags);
+ VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_write", ret, out);
+
+ fd2 = glfs_dup(fd1);
+ if (fd2 == NULL) {
+ ret = -1;
+ VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_dup", ret, out);
+ }
+
+ ret = glfs_lseek(fd2, 0, SEEK_SET);
+ VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_lseek", ret, out);
out:
- if (fd1 != NULL)
- glfs_close(fd1);
- if (fd2 != NULL)
- glfs_close(fd2);
- if (fs) {
- ret = glfs_fini(fs);
- if (ret)
- fprintf (stderr, "glfs_fini(fs) returned %d\n", ret);
- }
-
- return ret;
+ if (fd1 != NULL)
+ glfs_close(fd1);
+ if (fd2 != NULL)
+ glfs_close(fd2);
+ if (fs) {
+ ret = glfs_fini(fs);
+ if (ret)
+ fprintf(stderr, "glfs_fini(fs) returned %d\n", ret);
+ }
+
+ return ret;
}
-
-
diff --git a/tests/basic/gfapi/gfapi-load-volfile.c b/tests/basic/gfapi/gfapi-load-volfile.c
index 79502f7a44f..fbfc6045cd7 100644
--- a/tests/basic/gfapi/gfapi-load-volfile.c
+++ b/tests/basic/gfapi/gfapi-load-volfile.c
@@ -16,50 +16,50 @@
void
usage(FILE *output)
{
- fprintf(output, "Usage: " PROGNAME " <volfile>\n");
+ fprintf(output, "Usage: " PROGNAME " <volfile>\n");
}
void
main(int argc, char **argv)
{
- int ret = 0;
- glfs_t *fs = NULL;
+ int ret = 0;
+ glfs_t *fs = NULL;
- if (argc != 2) {
- usage(stderr);
- exit(EXIT_FAILURE);
- }
+ if (argc != 2) {
+ usage(stderr);
+ exit(EXIT_FAILURE);
+ }
- if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "-h")) {
- usage(stdout);
- exit(EXIT_SUCCESS);
- }
+ if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "-h")) {
+ usage(stdout);
+ exit(EXIT_SUCCESS);
+ }
- fs = glfs_new(PROGNAME);
- if (!fs) {
- perror("glfs_new failed");
- exit(EXIT_FAILURE);
- }
+ fs = glfs_new(PROGNAME);
+ if (!fs) {
+ perror("glfs_new failed");
+ exit(EXIT_FAILURE);
+ }
- glfs_set_logging(fs, PROGNAME ".log", 9);
+ glfs_set_logging(fs, PROGNAME ".log", 9);
- ret = glfs_set_volfile(fs, argv[1]);
- if (ret) {
- perror("glfs_set_volfile failed");
- ret = EXIT_FAILURE;
- goto out;
- }
+ ret = glfs_set_volfile(fs, argv[1]);
+ if (ret) {
+ perror("glfs_set_volfile failed");
+ ret = EXIT_FAILURE;
+ goto out;
+ }
- ret = glfs_init(fs);
- if (ret) {
- perror("glfs_init failed");
- ret = EXIT_FAILURE;
- goto out;
- }
+ ret = glfs_init(fs);
+ if (ret) {
+ perror("glfs_init failed");
+ ret = EXIT_FAILURE;
+ goto out;
+ }
- ret = EXIT_SUCCESS;
+ ret = EXIT_SUCCESS;
out:
- glfs_fini(fs);
+ glfs_fini(fs);
- exit(ret);
+ exit(ret);
}
diff --git a/tests/basic/gfapi/gfapi-ssl-test.c b/tests/basic/gfapi/gfapi-ssl-test.c
index 41126bdc6db..a27b5233702 100644
--- a/tests/basic/gfapi/gfapi-ssl-test.c
+++ b/tests/basic/gfapi/gfapi-ssl-test.c
@@ -9,118 +9,116 @@
#include <glusterfs/api/glfs.h>
#include <glusterfs/api/glfs-handles.h>
-#define LOG_ERR(msg) do { \
- fprintf (stderr, "%s : Error (%s)\n", msg, strerror (errno)); \
- } while (0)
+#define LOG_ERR(msg) \
+ do { \
+ fprintf(stderr, "%s : Error (%s)\n", msg, strerror(errno)); \
+ } while (0)
glfs_t *
-init_glfs (const char *hostname, const char *volname,
- const char *logfile)
+init_glfs(const char *hostname, const char *volname, const char *logfile)
{
- int ret = -1;
- glfs_t *fs = NULL;
-
- fs = glfs_new (volname);
- if (!fs) {
- LOG_ERR ("glfs_new failed");
- return NULL;
- }
-
- ret = glfs_set_volfile_server (fs, "tcp", hostname, 24007);
- if (ret < 0) {
- LOG_ERR ("glfs_set_volfile_server failed");
- goto out;
- }
-
- ret = glfs_set_logging (fs, logfile, 7);
- if (ret < 0) {
- LOG_ERR ("glfs_set_logging failed");
- goto out;
- }
-
- ret = glfs_init (fs);
- if (ret < 0) {
- LOG_ERR ("glfs_init failed");
- goto out;
- }
-
- ret = 0;
+ int ret = -1;
+ glfs_t *fs = NULL;
+
+ fs = glfs_new(volname);
+ if (!fs) {
+ LOG_ERR("glfs_new failed");
+ return NULL;
+ }
+
+ ret = glfs_set_volfile_server(fs, "tcp", hostname, 24007);
+ if (ret < 0) {
+ LOG_ERR("glfs_set_volfile_server failed");
+ goto out;
+ }
+
+ ret = glfs_set_logging(fs, logfile, 7);
+ if (ret < 0) {
+ LOG_ERR("glfs_set_logging failed");
+ goto out;
+ }
+
+ ret = glfs_init(fs);
+ if (ret < 0) {
+ LOG_ERR("glfs_init failed");
+ goto out;
+ }
+
+ ret = 0;
out:
- if (ret) {
- glfs_fini (fs);
- fs = NULL;
- }
+ if (ret) {
+ glfs_fini(fs);
+ fs = NULL;
+ }
- return fs;
+ return fs;
}
int
-glfs_test_function (const char *hostname, const char *volname,
- const char *logfile)
+glfs_test_function(const char *hostname, const char *volname,
+ const char *logfile)
{
- int ret = -1;
- int flags = O_CREAT | O_RDWR;
- glfs_t *fs = NULL;
- glfs_fd_t *glfd = NULL;
- const char *buff = "This is from my prog\n";
- const char *filename = "glfs_test.txt";
-
- fs = init_glfs (hostname, volname, logfile);
- if (fs == NULL) {
- LOG_ERR ("init_glfs failed");
- return -1;
- }
-
- glfd = glfs_creat (fs, filename, flags, 0644);
- if (glfd == NULL) {
- LOG_ERR ("glfs_creat failed");
- goto out;
- }
-
- ret = glfs_write (glfd, buff, strlen (buff), flags);
- if (ret < 0) {
- LOG_ERR ("glfs_write failed");
- goto out;
- }
-
- ret = glfs_close (glfd);
- if (ret < 0) {
- LOG_ERR ("glfs_write failed");
- goto out;
- }
+ int ret = -1;
+ int flags = O_CREAT | O_RDWR;
+ glfs_t *fs = NULL;
+ glfs_fd_t *glfd = NULL;
+ const char *buff = "This is from my prog\n";
+ const char *filename = "glfs_test.txt";
+
+ fs = init_glfs(hostname, volname, logfile);
+ if (fs == NULL) {
+ LOG_ERR("init_glfs failed");
+ return -1;
+ }
+
+ glfd = glfs_creat(fs, filename, flags, 0644);
+ if (glfd == NULL) {
+ LOG_ERR("glfs_creat failed");
+ goto out;
+ }
+
+ ret = glfs_write(glfd, buff, strlen(buff), flags);
+ if (ret < 0) {
+ LOG_ERR("glfs_write failed");
+ goto out;
+ }
+
+ ret = glfs_close(glfd);
+ if (ret < 0) {
+ LOG_ERR("glfs_write failed");
+ goto out;
+ }
out:
- ret = glfs_fini (fs);
- if (ret) {
- LOG_ERR ("glfs_fini failed");
- }
+ ret = glfs_fini(fs);
+ if (ret) {
+ LOG_ERR("glfs_fini failed");
+ }
- return ret;
+ return ret;
}
int
-main (int argc, char *argv[])
+main(int argc, char *argv[])
{
- int ret = 0;
- char *hostname = NULL;
- char *volname = NULL;
- char *logfile = NULL;
-
- if (argc != 4) {
- fprintf (stderr, "Invalid argument\n");
- exit(1);
- }
-
- hostname = argv[1];
- volname = argv[2];
- logfile = argv[3];
-
- ret = glfs_test_function (hostname, volname, logfile);
- if (ret) {
- LOG_ERR ("glfs_test_function failed");
- }
-
- return ret;
+ int ret = 0;
+ char *hostname = NULL;
+ char *volname = NULL;
+ char *logfile = NULL;
+
+ if (argc != 4) {
+ fprintf(stderr, "Invalid argument\n");
+ exit(1);
+ }
+
+ hostname = argv[1];
+ volname = argv[2];
+ logfile = argv[3];
+
+ ret = glfs_test_function(hostname, volname, logfile);
+ if (ret) {
+ LOG_ERR("glfs_test_function failed");
+ }
+
+ return ret;
}
-
-
diff --git a/tests/basic/gfapi/gfapi-trunc.c b/tests/basic/gfapi/gfapi-trunc.c
index af187e50c78..769f6cfa1d9 100644
--- a/tests/basic/gfapi/gfapi-trunc.c
+++ b/tests/basic/gfapi/gfapi-trunc.c
@@ -5,86 +5,85 @@
#include <glusterfs/api/glfs.h>
#include <glusterfs/api/glfs-handles.h>
-#define VALIDATE_AND_GOTO_LABEL_ON_ERROR(func, ret, label) do { \
- if (ret < 0) { \
- fprintf (stderr, "%s : returned error %d (%s)\n", \
- func, ret, strerror (errno)); \
- goto label; \
- } \
- } while (0)
-
-#define WRITE_SIZE 4096
-#define TRUNC_SIZE 1234
+#define VALIDATE_AND_GOTO_LABEL_ON_ERROR(func, ret, label) \
+ do { \
+ if (ret < 0) { \
+ fprintf(stderr, "%s : returned error %d (%s)\n", func, ret, \
+ strerror(errno)); \
+ goto label; \
+ } \
+ } while (0)
+
+#define WRITE_SIZE 4096
+#define TRUNC_SIZE 1234
/* Make sure TRUNC_SIZE is smaller than WRITE_SIZE at compile time. */
-typedef char _size_check[WRITE_SIZE-TRUNC_SIZE];
+typedef char _size_check[WRITE_SIZE - TRUNC_SIZE];
int
-main (int argc, char *argv[])
+main(int argc, char *argv[])
{
- int ret = -1;
- int flags = O_RDWR|O_SYNC;
- glfs_t *fs = NULL;
- glfs_fd_t *fd1 = NULL;
- char *volname = NULL;
- char *logfile = NULL;
- const char *filename = "file_tmp";
- const char buff[WRITE_SIZE];
- struct stat sb;
-
- if (argc != 3) {
- fprintf (stderr, "Invalid argument\n");
- return 1;
- }
-
- volname = argv[1];
- logfile = argv[2];
-
- fs = glfs_new (volname);
- if (!fs)
- VALIDATE_AND_GOTO_LABEL_ON_ERROR ("glfs_new", ret, out);
-
- ret = glfs_set_volfile_server (fs, "tcp", "localhost", 24007);
- VALIDATE_AND_GOTO_LABEL_ON_ERROR ("glfs_set_volfile_server", ret, out);
-
- ret = glfs_set_logging (fs, logfile, 7);
- VALIDATE_AND_GOTO_LABEL_ON_ERROR ("glfs_set_logging", ret, out);
-
- ret = glfs_init (fs);
- VALIDATE_AND_GOTO_LABEL_ON_ERROR ("glfs_init", ret, out);
-
- fd1 = glfs_creat(fs, filename, flags, 0644);
- if (fd1 == NULL) {
- ret = -1;
- VALIDATE_AND_GOTO_LABEL_ON_ERROR ("glfs_creat", ret, out);
- }
-
- ret = glfs_write (fd1, buff, WRITE_SIZE, flags);
- VALIDATE_AND_GOTO_LABEL_ON_ERROR ("glfs_write", ret, out);
-
- ret = glfs_truncate (fs, filename, TRUNC_SIZE);
- VALIDATE_AND_GOTO_LABEL_ON_ERROR ("glfs_truncate", ret, out);
-
- ret = glfs_fstat (fd1, &sb);
- VALIDATE_AND_GOTO_LABEL_ON_ERROR ("glfs_fstat", ret, out);
-
- if (sb.st_size != TRUNC_SIZE) {
- fprintf (stderr, "wrong size %jd should be %jd\n",
- (intmax_t)sb.st_size, (intmax_t)2048);
- ret = -1;
- }
+ int ret = -1;
+ int flags = O_RDWR | O_SYNC;
+ glfs_t *fs = NULL;
+ glfs_fd_t *fd1 = NULL;
+ char *volname = NULL;
+ char *logfile = NULL;
+ const char *filename = "file_tmp";
+ const char buff[WRITE_SIZE];
+ struct stat sb;
+
+ if (argc != 3) {
+ fprintf(stderr, "Invalid argument\n");
+ return 1;
+ }
+
+ volname = argv[1];
+ logfile = argv[2];
+
+ fs = glfs_new(volname);
+ if (!fs)
+ VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_new", ret, out);
+
+ ret = glfs_set_volfile_server(fs, "tcp", "localhost", 24007);
+ VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_set_volfile_server", ret, out);
+
+ ret = glfs_set_logging(fs, logfile, 7);
+ VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_set_logging", ret, out);
+
+ ret = glfs_init(fs);
+ VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_init", ret, out);
+
+ fd1 = glfs_creat(fs, filename, flags, 0644);
+ if (fd1 == NULL) {
+ ret = -1;
+ VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_creat", ret, out);
+ }
+
+ ret = glfs_write(fd1, buff, WRITE_SIZE, flags);
+ VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_write", ret, out);
+
+ ret = glfs_truncate(fs, filename, TRUNC_SIZE);
+ VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_truncate", ret, out);
+
+ ret = glfs_fstat(fd1, &sb);
+ VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_fstat", ret, out);
+
+ if (sb.st_size != TRUNC_SIZE) {
+ fprintf(stderr, "wrong size %jd should be %jd\n", (intmax_t)sb.st_size,
+ (intmax_t)2048);
+ ret = -1;
+ }
out:
- if (fd1 != NULL)
- glfs_close(fd1);
- if (fs) {
- /*
- * If this fails (as it does on Special Snowflake NetBSD for no
- * good reason), it shouldn't affect the result of the test.
- */
- (void) glfs_fini(fs);
- }
-
- return ret;
+ if (fd1 != NULL)
+ glfs_close(fd1);
+ if (fs) {
+ /*
+ * If this fails (as it does on Special Snowflake NetBSD for no
+ * good reason), it shouldn't affect the result of the test.
+ */
+ (void)glfs_fini(fs);
+ }
+
+ return ret;
}
-
-
diff --git a/tests/basic/gfapi/glfd-lkowner.c b/tests/basic/gfapi/glfd-lkowner.c
index 031a076683c..ec0429dc3c4 100644
--- a/tests/basic/gfapi/glfd-lkowner.c
+++ b/tests/basic/gfapi/glfd-lkowner.c
@@ -13,200 +13,202 @@
int gfapi = 1;
-#define LOG_ERR(func, ret) do { \
- if (ret != 0) { \
- fprintf (stderr, "%s : returned error %d (%s)\n", \
- func, ret, strerror (errno)); \
- goto out; \
- } else { \
- fprintf (stderr, "%s : returned %d\n", func, ret); \
- } \
- } while (0)
+#define LOG_ERR(func, ret) \
+ do { \
+ if (ret != 0) { \
+ fprintf(stderr, "%s : returned error %d (%s)\n", func, ret, \
+ strerror(errno)); \
+ goto out; \
+ } else { \
+ fprintf(stderr, "%s : returned %d\n", func, ret); \
+ } \
+ } while (0)
char lownera[8] = "lownera", lownerb[8] = "lownerb";
char lownerc[8] = "lownerc";
-int lock_test (glfs_fd_t *glfd1, glfs_fd_t *glfd2, bool should_fail,
- int l1_start, int l1_len, char *l1_owner, int lo1_len,
- int l2_start, int l2_len, char *l2_owner, int lo2_len)
+int
+lock_test(glfs_fd_t *glfd1, glfs_fd_t *glfd2, bool should_fail, int l1_start,
+ int l1_len, char *l1_owner, int lo1_len, int l2_start, int l2_len,
+ char *l2_owner, int lo2_len)
{
- int ret = -1, f_ret = -1;
- struct flock lock1 = {0, }, lock2 = {0, };
+ int ret = -1, f_ret = -1;
+ struct flock lock1 =
+ {
+ 0,
+ },
+ lock2 = {
+ 0,
+ };
lock1:
- if (!glfd1)
- goto lock2;
+ if (!glfd1)
+ goto lock2;
- /* lock on glfd1 */
- lock1.l_type = F_WRLCK;
- lock1.l_whence = SEEK_SET;
- lock1.l_start = l1_start;
- lock1.l_len = l1_len;
+ /* lock on glfd1 */
+ lock1.l_type = F_WRLCK;
+ lock1.l_whence = SEEK_SET;
+ lock1.l_start = l1_start;
+ lock1.l_len = l1_len;
- ret = glfs_fd_set_lkowner (glfd1, l1_owner, lo1_len);
- LOG_ERR ("glfs_fd_set_lkowner on glfd1", ret);
+ ret = glfs_fd_set_lkowner(glfd1, l1_owner, lo1_len);
+ LOG_ERR("glfs_fd_set_lkowner on glfd1", ret);
- ret = glfs_posix_lock (glfd1, F_SETLK, &lock1);
- LOG_ERR ("glfs_posix_lock on glfd1", ret);
+ ret = glfs_posix_lock(glfd1, F_SETLK, &lock1);
+ LOG_ERR("glfs_posix_lock on glfd1", ret);
lock2:
- if (!glfd2)
- goto out;
-
- /* lock on glfd2 */
- lock2.l_type = F_WRLCK;
- lock2.l_whence = SEEK_SET;
- lock2.l_start = l2_start;
- lock2.l_len = l2_len;
-
- ret = glfs_fd_set_lkowner (glfd2, l2_owner, lo2_len);
- LOG_ERR ("glfs_fd_set_lkowner on glfd2", ret);
-
- ret = glfs_posix_lock (glfd2, F_SETLK, &lock2);
-
- if (should_fail && ret) {
- f_ret = 0;
- } else if (!ret && !should_fail) {
- f_ret = 0;
- } else {
- f_ret = -1;
- }
+ if (!glfd2)
+ goto out;
+
+ /* lock on glfd2 */
+ lock2.l_type = F_WRLCK;
+ lock2.l_whence = SEEK_SET;
+ lock2.l_start = l2_start;
+ lock2.l_len = l2_len;
+
+ ret = glfs_fd_set_lkowner(glfd2, l2_owner, lo2_len);
+ LOG_ERR("glfs_fd_set_lkowner on glfd2", ret);
+
+ ret = glfs_posix_lock(glfd2, F_SETLK, &lock2);
+
+ if (should_fail && ret) {
+ f_ret = 0;
+ } else if (!ret && !should_fail) {
+ f_ret = 0;
+ } else {
+ f_ret = -1;
+ }
out:
- fprintf (stderr, "Lock test on glfd1 (start(%d), len(%d),"
- " lk_owner(%s)) and glfd2 (start(%d), len(%d), "
- "lk_owner(%s)) - expected(%s) - result(%s)\n",
- l1_start, l1_len, l1_owner, l2_start, l2_len, l2_owner,
- (should_fail ? "FAIL" : "SUCCESS"),
- (ret ? "FAIL" : "SUCCESS"));
- return f_ret;
+ fprintf(stderr,
+ "Lock test on glfd1 (start(%d), len(%d),"
+ " lk_owner(%s)) and glfd2 (start(%d), len(%d), "
+ "lk_owner(%s)) - expected(%s) - result(%s)\n",
+ l1_start, l1_len, l1_owner, l2_start, l2_len, l2_owner,
+ (should_fail ? "FAIL" : "SUCCESS"), (ret ? "FAIL" : "SUCCESS"));
+ return f_ret;
}
int
-main (int argc, char *argv[])
+main(int argc, char *argv[])
{
- glfs_t *fs = NULL;
- int ret = 0, i, status = 0;
- glfs_fd_t *fd1 = NULL;
- glfs_fd_t *fd2 = NULL;
- glfs_fd_t *fd3 = NULL;
- char *filename = "file_tmp";
- char *volname = NULL;
- char *logfile = NULL;
- char *hostname = NULL;
-
- if (argc != 4) {
- fprintf (stderr, "Invalid argument\n");
- exit(1);
- }
-
- hostname = argv[1];
- volname = argv[2];
- logfile = argv[3];
-
- fs = glfs_new (volname);
- if (!fs) {
- fprintf (stderr, "glfs_new: returned NULL\n");
- return -1;
- }
-
- ret = glfs_set_volfile_server (fs, "tcp", hostname, 24007);
- LOG_ERR("glfs_set_volfile_server", ret);
-
- ret = glfs_set_logging (fs, logfile, 7);
- LOG_ERR("glfs_set_logging", ret);
-
- ret = glfs_init (fs);
- LOG_ERR("glfs_init", ret);
-
- fd1 = glfs_creat(fs, filename, O_RDWR|O_SYNC, 0644);
- if (fd1 <= 0) {
- ret = -1;
- LOG_ERR ("glfs_creat", ret);
- }
- fprintf (stderr, "glfs-create fd1 - %d\n", fd1);
-
- fd2 = glfs_dup(fd1);
- fprintf (stderr, "glfs-dup fd2 - %d\n", fd2);
-
- fd3 = glfs_open(fs, filename, O_RDWR|O_SYNC);
- if (fd2 <= 0) {
- ret = -1;
- LOG_ERR ("glfs_open", ret);
- }
- fprintf (stderr, "glfs-open fd3 - %d\n", fd3);
-
- /* TEST 1: Conflicting ranges, same lk_owner
- * lock1 (0, 10, lownera)
- * lock2 (5, 10, lownera)
- * Expected: should not fail but get merged
- */
- ret = lock_test (fd1, fd2, false, 0, 10, lownera, 8,
- 5, 10, lownera, 8);
- LOG_ERR ("==== glfs_lock_test_1", ret);
-
- /* TEST 2: Conflicting ranges, different lk_owner
- * lock1 (0, 10, lownera) - already taken
- * lock2 (5, 10, lownerb)
- * Expected: should fail and not get merged
- */
- ret = lock_test (NULL, fd2, true, 0, 10, lownera, 8,
- 5, 10, lownerb, 8);
- LOG_ERR ("==== glfs_lock_test_2", ret);
-
- /* TEST 3: Different ranges, same lk_owner
- * lock1 (0, 10, lownera) - already taken
- * lock2 (30, 10, lownera)
- * Expected: should not fail
- */
- ret = lock_test (NULL, fd2, false, 0, 10, lownera, 8,
- 30, 10, lownera, 8);
- LOG_ERR ("==== glfs_lock_test_3", ret);
-
- /* TEST 4: Conflicting ranges, different lk_owner
- * lock1 (0, 10, lownera) - already taken
- * lock2 (50, 10, lownerb)
- * Expected: should not fail
- */
- ret = lock_test (NULL, fd2, false, 0, 10, lownera, 8,
- 50, 10, lownerb, 8);
- LOG_ERR ("==== glfs_lock_test_4", ret);
-
- /* TEST 5: Close fd1 & retry TEST2
- * lock1 (not applicable)
- * lock2 (5, 10, lownerb)
- * Expected: should succeed now
- */
- ret = glfs_close(fd1);
- LOG_ERR ("glfs_close", ret);
-
- ret = lock_test (NULL, fd2, false, 0, 10, lownera, 8,
- 5, 10, lownerb, 8);
- LOG_ERR ("==== glfs_lock_test_5", ret);
-
- /* TEST 6: Check closing fd1 doesn't flush fd2 locks
- * retry TEST 4 but with fd2 and fd3.
- * lock1 (50, 10, lownerb) - already taken
- * lock2 (55, 10, lownerc)
- * Expected: should fail
- */
- ret = lock_test (NULL, fd3, true, 50, 10, lownerb, 8,
- 55, 10, lownerc, 8);
- LOG_ERR ("==== glfs_lock_test_6", ret);
+ glfs_t *fs = NULL;
+ int ret = 0, i, status = 0;
+ glfs_fd_t *fd1 = NULL;
+ glfs_fd_t *fd2 = NULL;
+ glfs_fd_t *fd3 = NULL;
+ char *filename = "file_tmp";
+ char *volname = NULL;
+ char *logfile = NULL;
+ char *hostname = NULL;
+
+ if (argc != 4) {
+ fprintf(stderr, "Invalid argument\n");
+ exit(1);
+ }
+
+ hostname = argv[1];
+ volname = argv[2];
+ logfile = argv[3];
+
+ fs = glfs_new(volname);
+ if (!fs) {
+ fprintf(stderr, "glfs_new: returned NULL\n");
+ return -1;
+ }
+
+ ret = glfs_set_volfile_server(fs, "tcp", hostname, 24007);
+ LOG_ERR("glfs_set_volfile_server", ret);
+
+ ret = glfs_set_logging(fs, logfile, 7);
+ LOG_ERR("glfs_set_logging", ret);
+
+ ret = glfs_init(fs);
+ LOG_ERR("glfs_init", ret);
+
+ fd1 = glfs_creat(fs, filename, O_RDWR | O_SYNC, 0644);
+ if (fd1 <= 0) {
+ ret = -1;
+ LOG_ERR("glfs_creat", ret);
+ }
+ fprintf(stderr, "glfs-create fd1 - %d\n", fd1);
+
+ fd2 = glfs_dup(fd1);
+ fprintf(stderr, "glfs-dup fd2 - %d\n", fd2);
+
+ fd3 = glfs_open(fs, filename, O_RDWR | O_SYNC);
+ if (fd2 <= 0) {
+ ret = -1;
+ LOG_ERR("glfs_open", ret);
+ }
+ fprintf(stderr, "glfs-open fd3 - %d\n", fd3);
+
+ /* TEST 1: Conflicting ranges, same lk_owner
+ * lock1 (0, 10, lownera)
+ * lock2 (5, 10, lownera)
+ * Expected: should not fail but get merged
+ */
+ ret = lock_test(fd1, fd2, false, 0, 10, lownera, 8, 5, 10, lownera, 8);
+ LOG_ERR("==== glfs_lock_test_1", ret);
+
+ /* TEST 2: Conflicting ranges, different lk_owner
+ * lock1 (0, 10, lownera) - already taken
+ * lock2 (5, 10, lownerb)
+ * Expected: should fail and not get merged
+ */
+ ret = lock_test(NULL, fd2, true, 0, 10, lownera, 8, 5, 10, lownerb, 8);
+ LOG_ERR("==== glfs_lock_test_2", ret);
+
+ /* TEST 3: Different ranges, same lk_owner
+ * lock1 (0, 10, lownera) - already taken
+ * lock2 (30, 10, lownera)
+ * Expected: should not fail
+ */
+ ret = lock_test(NULL, fd2, false, 0, 10, lownera, 8, 30, 10, lownera, 8);
+ LOG_ERR("==== glfs_lock_test_3", ret);
+
+ /* TEST 4: Conflicting ranges, different lk_owner
+ * lock1 (0, 10, lownera) - already taken
+ * lock2 (50, 10, lownerb)
+ * Expected: should not fail
+ */
+ ret = lock_test(NULL, fd2, false, 0, 10, lownera, 8, 50, 10, lownerb, 8);
+ LOG_ERR("==== glfs_lock_test_4", ret);
+
+ /* TEST 5: Close fd1 & retry TEST2
+ * lock1 (not applicable)
+ * lock2 (5, 10, lownerb)
+ * Expected: should succeed now
+ */
+ ret = glfs_close(fd1);
+ LOG_ERR("glfs_close", ret);
+
+ ret = lock_test(NULL, fd2, false, 0, 10, lownera, 8, 5, 10, lownerb, 8);
+ LOG_ERR("==== glfs_lock_test_5", ret);
+
+ /* TEST 6: Check closing fd1 doesn't flush fd2 locks
+ * retry TEST 4 but with fd2 and fd3.
+ * lock1 (50, 10, lownerb) - already taken
+ * lock2 (55, 10, lownerc)
+ * Expected: should fail
+ */
+ ret = lock_test(NULL, fd3, true, 50, 10, lownerb, 8, 55, 10, lownerc, 8);
+ LOG_ERR("==== glfs_lock_test_6", ret);
err:
- ret = glfs_close(fd2);
- LOG_ERR ("glfs_close", ret);
+ ret = glfs_close(fd2);
+ LOG_ERR("glfs_close", ret);
- ret = glfs_close(fd3);
- LOG_ERR ("glfs_close", ret);
+ ret = glfs_close(fd3);
+ LOG_ERR("glfs_close", ret);
out:
- if (fs) {
- ret = glfs_fini(fs);
- fprintf (stderr, "glfs_fini(fs) returned %d\n", ret);
- }
-
- if (ret)
- exit(1);
- exit(0);
+ if (fs) {
+ ret = glfs_fini(fs);
+ fprintf(stderr, "glfs_fini(fs) returned %d\n", ret);
+ }
+
+ if (ret)
+ exit(1);
+ exit(0);
}
diff --git a/tests/basic/gfapi/glfs_sysrq.c b/tests/basic/gfapi/glfs_sysrq.c
index c843c2a3559..13e06be6df2 100644
--- a/tests/basic/gfapi/glfs_sysrq.c
+++ b/tests/basic/gfapi/glfs_sysrq.c
@@ -10,52 +10,51 @@
#include <glusterfs/api/glfs.h>
int
-main (int argc, char *argv[])
+main(int argc, char *argv[])
{
- /* cmdline arguments */
- char *host = NULL;
- char *volume = NULL;
- char *logfile = NULL;
-
- /* other variables */
- glfs_t *fs = NULL;
- int ret = 0;
-
- if (argc != 4) {
- fprintf (stderr, "Usage: %s <host> <volume> <logfile>\n",
- argv[0]);
- return -1;
- }
-
- host = argv[1];
- volume = argv[2];
- logfile = argv[3];
-
- fs = glfs_new (volume);
- if (!fs) {
- return -1;
- }
-
- ret = glfs_set_logging (fs, logfile, 7);
- if (ret < 0) {
- return -1;
- }
-
- ret = glfs_set_volfile_server (fs, "tcp", host, 24007);
- if (ret < 0) {
- return -1;
- }
-
- ret = glfs_init (fs);
- if (ret < 0) {
- return -1;
- }
-
- /* checking of the results is easier in the script running this test */
- glfs_sysrq (fs, GLFS_SYSRQ_HELP);
- glfs_sysrq (fs, GLFS_SYSRQ_STATEDUMP);
-
- glfs_fini (fs);
-
- return 0;
+ /* cmdline arguments */
+ char *host = NULL;
+ char *volume = NULL;
+ char *logfile = NULL;
+
+ /* other variables */
+ glfs_t *fs = NULL;
+ int ret = 0;
+
+ if (argc != 4) {
+ fprintf(stderr, "Usage: %s <host> <volume> <logfile>\n", argv[0]);
+ return -1;
+ }
+
+ host = argv[1];
+ volume = argv[2];
+ logfile = argv[3];
+
+ fs = glfs_new(volume);
+ if (!fs) {
+ return -1;
+ }
+
+ ret = glfs_set_logging(fs, logfile, 7);
+ if (ret < 0) {
+ return -1;
+ }
+
+ ret = glfs_set_volfile_server(fs, "tcp", host, 24007);
+ if (ret < 0) {
+ return -1;
+ }
+
+ ret = glfs_init(fs);
+ if (ret < 0) {
+ return -1;
+ }
+
+ /* checking of the results is easier in the script running this test */
+ glfs_sysrq(fs, GLFS_SYSRQ_HELP);
+ glfs_sysrq(fs, GLFS_SYSRQ_STATEDUMP);
+
+ glfs_fini(fs);
+
+ return 0;
}
diff --git a/tests/basic/gfapi/glfs_xreaddirplus_r.c b/tests/basic/gfapi/glfs_xreaddirplus_r.c
index 17f4d1b1d57..0c4c79123eb 100644
--- a/tests/basic/gfapi/glfs_xreaddirplus_r.c
+++ b/tests/basic/gfapi/glfs_xreaddirplus_r.c
@@ -6,237 +6,237 @@
#include <glusterfs/api/glfs-handles.h>
#include <time.h>
-#define VALIDATE_AND_GOTO_LABEL_ON_ERROR(func, ret, label) do { \
- if (ret < 0) { \
- fprintf (stderr, "%s : returned error %d (%s)\n", \
- func, ret, strerror (errno)); \
- goto label; \
- } \
- } while (0)
-
-#define VALIDATE_BOOL_AND_GOTO_LABEL_ON_ERROR(func, bool_var, ret, label) do { \
- if (!bool_var) { \
- fprintf (stderr, "%s : returned error (%s)\n", \
- func, strerror (errno)); \
- ret = -1; \
- goto label; \
- } \
- } while (0)
+#define VALIDATE_AND_GOTO_LABEL_ON_ERROR(func, ret, label) \
+ do { \
+ if (ret < 0) { \
+ fprintf(stderr, "%s : returned error %d (%s)\n", func, ret, \
+ strerror(errno)); \
+ goto label; \
+ } \
+ } while (0)
+
+#define VALIDATE_BOOL_AND_GOTO_LABEL_ON_ERROR(func, bool_var, ret, label) \
+ do { \
+ if (!bool_var) { \
+ fprintf(stderr, "%s : returned error (%s)\n", func, \
+ strerror(errno)); \
+ ret = -1; \
+ goto label; \
+ } \
+ } while (0)
#define MAX_FILES_CREATE 10
-#define MAXPATHNAME 512
+#define MAXPATHNAME 512
void
-assimilatetime (struct timespec *ts, struct timespec ts_st,
- struct timespec ts_ed)
+assimilatetime(struct timespec *ts, struct timespec ts_st,
+ struct timespec ts_ed)
{
- if ((ts_ed.tv_nsec - ts_st.tv_nsec) < 0) {
- ts->tv_sec += ts_ed.tv_sec - ts_st.tv_sec - 1;
- ts->tv_nsec += 1000000000 + ts_ed.tv_nsec - ts_st.tv_nsec;
- } else {
- ts->tv_sec += ts_ed.tv_sec - ts_st.tv_sec;
- ts->tv_nsec += ts_ed.tv_nsec - ts_st.tv_nsec;
- }
-
- if (ts->tv_nsec > 1000000000) {
- ts->tv_nsec = ts->tv_nsec - 1000000000;
- ts->tv_sec += 1;
- }
-
- return;
+ if ((ts_ed.tv_nsec - ts_st.tv_nsec) < 0) {
+ ts->tv_sec += ts_ed.tv_sec - ts_st.tv_sec - 1;
+ ts->tv_nsec += 1000000000 + ts_ed.tv_nsec - ts_st.tv_nsec;
+ } else {
+ ts->tv_sec += ts_ed.tv_sec - ts_st.tv_sec;
+ ts->tv_nsec += ts_ed.tv_nsec - ts_st.tv_nsec;
+ }
+
+ if (ts->tv_nsec > 1000000000) {
+ ts->tv_nsec = ts->tv_nsec - 1000000000;
+ ts->tv_sec += 1;
+ }
+
+ return;
}
/*
* Returns '%' difference between ts1 & ts2
*/
int
-comparetime (struct timespec ts1, struct timespec ts2)
+comparetime(struct timespec ts1, struct timespec ts2)
{
- uint64_t ts1_n, ts2_n;
- int pct = 0;
+ uint64_t ts1_n, ts2_n;
+ int pct = 0;
- ts1_n = (ts1.tv_sec * 1000000000) + ts1.tv_nsec;
- ts2_n = (ts2.tv_sec * 1000000000) + ts2.tv_nsec;
+ ts1_n = (ts1.tv_sec * 1000000000) + ts1.tv_nsec;
+ ts2_n = (ts2.tv_sec * 1000000000) + ts2.tv_nsec;
- pct = ((ts1_n - ts2_n)*100)/ts1_n;
+ pct = ((ts1_n - ts2_n) * 100) / ts1_n;
- return pct;
+ return pct;
}
int
-old_readdir (glfs_t *fs)
+old_readdir(glfs_t *fs)
{
- struct glfs_object *root = NULL;
- struct glfs_fd *fd = NULL;
- struct stat *sb = NULL;
- char buf[512];
- struct dirent *entry = NULL;
- int ret = -1;
- struct glfs_object *glhandle = NULL;
-
- if (!fs)
- return -1;
-
- root = glfs_h_lookupat (fs, NULL, "/", sb, 0);
- VALIDATE_BOOL_AND_GOTO_LABEL_ON_ERROR ("glfs_h_lookupat", !!root, ret, out);
-
- fd = glfs_opendir (fs, "/");
- VALIDATE_BOOL_AND_GOTO_LABEL_ON_ERROR ("glfs_opendir", !!fd, ret, out);
-
- while (glfs_readdir_r (fd, (struct dirent *)buf, &entry), entry) {
- if (strcmp(entry->d_name, ".") && strcmp(entry->d_name, "..")) {
- glhandle = glfs_h_lookupat (fs, root, "/", sb, 0);
- VALIDATE_BOOL_AND_GOTO_LABEL_ON_ERROR ("glfs_h_lookupat", !!glhandle, ret, out);
- }
+ struct glfs_object *root = NULL;
+ struct glfs_fd *fd = NULL;
+ struct stat *sb = NULL;
+ char buf[512];
+ struct dirent *entry = NULL;
+ int ret = -1;
+ struct glfs_object *glhandle = NULL;
+
+ if (!fs)
+ return -1;
+
+ root = glfs_h_lookupat(fs, NULL, "/", sb, 0);
+ VALIDATE_BOOL_AND_GOTO_LABEL_ON_ERROR("glfs_h_lookupat", !!root, ret, out);
+
+ fd = glfs_opendir(fs, "/");
+ VALIDATE_BOOL_AND_GOTO_LABEL_ON_ERROR("glfs_opendir", !!fd, ret, out);
+
+ while (glfs_readdir_r(fd, (struct dirent *)buf, &entry), entry) {
+ if (strcmp(entry->d_name, ".") && strcmp(entry->d_name, "..")) {
+ glhandle = glfs_h_lookupat(fs, root, "/", sb, 0);
+ VALIDATE_BOOL_AND_GOTO_LABEL_ON_ERROR("glfs_h_lookupat", !!glhandle,
+ ret, out);
}
+ }
- glfs_closedir (fd);
+ glfs_closedir(fd);
- ret = 0;
+ ret = 0;
out:
- return ret;
+ return ret;
}
int
-new_xreaddirplus (glfs_t *fs)
+new_xreaddirplus(glfs_t *fs)
{
- struct glfs_fd *fd = NULL;
- struct stat *sb = NULL;
- int ret = -1;
- uint32_t rflags = (GFAPI_XREADDIRP_STAT |
- GFAPI_XREADDIRP_HANDLE);
- struct glfs_xreaddirp_stat *xstat = NULL;
- struct dirent de;
- struct dirent *pde = NULL;
- struct glfs_object *glhandle = NULL;
-
- if (!fs)
- return -1;
-
- fd = glfs_opendir (fs, "/");
- VALIDATE_BOOL_AND_GOTO_LABEL_ON_ERROR ("glfs_opendir", !!fd, ret, out);
-
- ret = glfs_xreaddirplus_r(fd, rflags, &xstat, &de, &pde);
- while (ret > 0 && pde != NULL) {
- if (xstat) {
- sb = glfs_xreaddirplus_get_stat (xstat);
- VALIDATE_BOOL_AND_GOTO_LABEL_ON_ERROR ("glfs_xreaddirplus_get_stat", !!sb, ret, out);
-
- if (strcmp(de.d_name, ".") && strcmp(de.d_name, "..")) {
- glhandle = glfs_xreaddirplus_get_object (xstat);
- VALIDATE_BOOL_AND_GOTO_LABEL_ON_ERROR ("glfs_xreaddirplus_get_object", !!glhandle, ret, out);
- }
- }
-
- if (xstat) {
- glfs_free(xstat);
- xstat = NULL;
- }
+ struct glfs_fd *fd = NULL;
+ struct stat *sb = NULL;
+ int ret = -1;
+ uint32_t rflags = (GFAPI_XREADDIRP_STAT | GFAPI_XREADDIRP_HANDLE);
+ struct glfs_xreaddirp_stat *xstat = NULL;
+ struct dirent de;
+ struct dirent *pde = NULL;
+ struct glfs_object *glhandle = NULL;
+
+ if (!fs)
+ return -1;
+
+ fd = glfs_opendir(fs, "/");
+ VALIDATE_BOOL_AND_GOTO_LABEL_ON_ERROR("glfs_opendir", !!fd, ret, out);
+
+ ret = glfs_xreaddirplus_r(fd, rflags, &xstat, &de, &pde);
+ while (ret > 0 && pde != NULL) {
+ if (xstat) {
+ sb = glfs_xreaddirplus_get_stat(xstat);
+ VALIDATE_BOOL_AND_GOTO_LABEL_ON_ERROR("glfs_xreaddirplus_get_stat",
+ !!sb, ret, out);
+
+ if (strcmp(de.d_name, ".") && strcmp(de.d_name, "..")) {
+ glhandle = glfs_xreaddirplus_get_object(xstat);
+ VALIDATE_BOOL_AND_GOTO_LABEL_ON_ERROR(
+ "glfs_xreaddirplus_get_object", !!glhandle, ret, out);
+ }
+ }
- ret = glfs_xreaddirplus_r(fd, rflags, &xstat, &de, &pde);
+ if (xstat) {
+ glfs_free(xstat);
+ xstat = NULL;
+ }
- VALIDATE_AND_GOTO_LABEL_ON_ERROR ("glfs_xreaddirp_r", ret, out);
+ ret = glfs_xreaddirplus_r(fd, rflags, &xstat, &de, &pde);
- }
+ VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_xreaddirp_r", ret, out);
+ }
- if (xstat)
- glfs_free(xstat);
+ if (xstat)
+ glfs_free(xstat);
- ret = 0;
+ ret = 0;
out:
- return ret;
+ return ret;
}
int
-main (int argc, char *argv[])
+main(int argc, char *argv[])
{
- int ret = -1;
- glfs_t *fs = NULL;
- char *volname = NULL;
- char *logfile = NULL;
- char *hostname = NULL;
- char *my_file = "file_";
- char my_file_name[MAXPATHNAME];
- uint32_t flags = O_RDWR|O_SYNC;
- struct glfs_fd *fd = NULL;
- int i = 0;
- int pct = 0;
- struct timespec timestamp = {0, 0}, st_timestamp, ed_timestamp;
- struct timespec otimestamp = {0, 0}, ost_timestamp, oed_timestamp;
-
- if (argc != 4) {
- fprintf (stderr, "Invalid argument\n");
- return 1;
- }
+ int ret = -1;
+ glfs_t *fs = NULL;
+ char *volname = NULL;
+ char *logfile = NULL;
+ char *hostname = NULL;
+ char *my_file = "file_";
+ char my_file_name[MAXPATHNAME];
+ uint32_t flags = O_RDWR | O_SYNC;
+ struct glfs_fd *fd = NULL;
+ int i = 0;
+ int pct = 0;
+ struct timespec timestamp = {0, 0}, st_timestamp, ed_timestamp;
+ struct timespec otimestamp = {0, 0}, ost_timestamp, oed_timestamp;
- hostname = argv[1];
- volname = argv[2];
- logfile = argv[3];
+ if (argc != 4) {
+ fprintf(stderr, "Invalid argument\n");
+ return 1;
+ }
- fs = glfs_new (volname);
- VALIDATE_BOOL_AND_GOTO_LABEL_ON_ERROR ("glfs_new", !!fs, ret, out);
+ hostname = argv[1];
+ volname = argv[2];
+ logfile = argv[3];
- ret = glfs_set_volfile_server (fs, "tcp", hostname, 24007);
- VALIDATE_AND_GOTO_LABEL_ON_ERROR ("glfs_set_volfile_server", ret, out);
+ fs = glfs_new(volname);
+ VALIDATE_BOOL_AND_GOTO_LABEL_ON_ERROR("glfs_new", !!fs, ret, out);
- ret = glfs_set_logging (fs, logfile, 7);
- VALIDATE_AND_GOTO_LABEL_ON_ERROR ("glfs_set_logging", ret, out);
+ ret = glfs_set_volfile_server(fs, "tcp", hostname, 24007);
+ VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_set_volfile_server", ret, out);
- ret = glfs_init (fs);
- VALIDATE_AND_GOTO_LABEL_ON_ERROR ("glfs_init", ret, out);
+ ret = glfs_set_logging(fs, logfile, 7);
+ VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_set_logging", ret, out);
- for (i = 0; i < MAX_FILES_CREATE; i++) {
- sprintf (my_file_name, "%s%d", my_file, i);
+ ret = glfs_init(fs);
+ VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_init", ret, out);
- fd = glfs_creat(fs, my_file_name, flags, 0644);
- VALIDATE_BOOL_AND_GOTO_LABEL_ON_ERROR ("glfs_creat", !!fd, ret, out);
+ for (i = 0; i < MAX_FILES_CREATE; i++) {
+ sprintf(my_file_name, "%s%d", my_file, i);
- glfs_close (fd);
- }
+ fd = glfs_creat(fs, my_file_name, flags, 0644);
+ VALIDATE_BOOL_AND_GOTO_LABEL_ON_ERROR("glfs_creat", !!fd, ret, out);
- /* measure performance using old readdir call and new xreaddirplus call and compare */
- ret = clock_gettime (CLOCK_REALTIME, &ost_timestamp);
- VALIDATE_AND_GOTO_LABEL_ON_ERROR ("clock_gettime", ret, out);
+ glfs_close(fd);
+ }
- ret = old_readdir (fs);
- VALIDATE_AND_GOTO_LABEL_ON_ERROR ("old_readdir", ret, out);
+ /* measure performance using old readdir call and new xreaddirplus call and
+ * compare */
+ ret = clock_gettime(CLOCK_REALTIME, &ost_timestamp);
+ VALIDATE_AND_GOTO_LABEL_ON_ERROR("clock_gettime", ret, out);
- ret = clock_gettime (CLOCK_REALTIME, &oed_timestamp);
- VALIDATE_AND_GOTO_LABEL_ON_ERROR ("clock_gettime", ret, out);
+ ret = old_readdir(fs);
+ VALIDATE_AND_GOTO_LABEL_ON_ERROR("old_readdir", ret, out);
- assimilatetime (&otimestamp, ost_timestamp, oed_timestamp);
+ ret = clock_gettime(CLOCK_REALTIME, &oed_timestamp);
+ VALIDATE_AND_GOTO_LABEL_ON_ERROR("clock_gettime", ret, out);
- printf ("\tOverall time using readdir:\n\t\tSecs:%ld\n\t\tnSecs:%ld\n",
- otimestamp.tv_sec, otimestamp.tv_nsec);
+ assimilatetime(&otimestamp, ost_timestamp, oed_timestamp);
+ printf("\tOverall time using readdir:\n\t\tSecs:%ld\n\t\tnSecs:%ld\n",
+ otimestamp.tv_sec, otimestamp.tv_nsec);
- ret = clock_gettime (CLOCK_REALTIME, &st_timestamp);
- VALIDATE_AND_GOTO_LABEL_ON_ERROR ("clock_gettime", ret, out);
+ ret = clock_gettime(CLOCK_REALTIME, &st_timestamp);
+ VALIDATE_AND_GOTO_LABEL_ON_ERROR("clock_gettime", ret, out);
- ret = new_xreaddirplus (fs);
- VALIDATE_AND_GOTO_LABEL_ON_ERROR ("new_xreaddirplus", ret, out);
+ ret = new_xreaddirplus(fs);
+ VALIDATE_AND_GOTO_LABEL_ON_ERROR("new_xreaddirplus", ret, out);
- ret = clock_gettime (CLOCK_REALTIME, &ed_timestamp);
- VALIDATE_AND_GOTO_LABEL_ON_ERROR ("clock_gettime", ret, out);
+ ret = clock_gettime(CLOCK_REALTIME, &ed_timestamp);
+ VALIDATE_AND_GOTO_LABEL_ON_ERROR("clock_gettime", ret, out);
- assimilatetime (&timestamp, st_timestamp, ed_timestamp);
+ assimilatetime(&timestamp, st_timestamp, ed_timestamp);
- printf ("\tOverall time using xreaddirplus:\n\t\tSecs:%ld\n\t\tnSecs:%ld\n",
- timestamp.tv_sec, timestamp.tv_nsec);
+ printf("\tOverall time using xreaddirplus:\n\t\tSecs:%ld\n\t\tnSecs:%ld\n",
+ timestamp.tv_sec, timestamp.tv_nsec);
+ pct = comparetime(otimestamp, timestamp);
+ printf("There is improvement by %d%%\n", pct);
- pct = comparetime (otimestamp, timestamp);
- printf ("There is improvement by %d%%\n", pct);
-
- ret = 0;
+ ret = 0;
out:
- if (fs) {
- ret = glfs_fini(fs);
- if (ret)
- fprintf (stderr, "glfs_fini(fs) returned %d\n", ret);
- }
+ if (fs) {
+ ret = glfs_fini(fs);
+ if (ret)
+ fprintf(stderr, "glfs_fini(fs) returned %d\n", ret);
+ }
- return ret;
+ return ret;
}
-
-
diff --git a/tests/basic/gfapi/libgfapi-fini-hang.c b/tests/basic/gfapi/libgfapi-fini-hang.c
index e192751f295..37800e3188b 100644
--- a/tests/basic/gfapi/libgfapi-fini-hang.c
+++ b/tests/basic/gfapi/libgfapi-fini-hang.c
@@ -8,56 +8,55 @@
#include <glusterfs/api/glfs.h>
#include <glusterfs/api/glfs-handles.h>
-#define LOG_ERR(func, ret) do { \
- if (ret != 0) { \
- fprintf (stderr, "%s : returned error %d\n", func, ret); \
- exit(1); \
- } else { \
- fprintf (stderr, "%s : returned %d\n", func, ret); \
- } \
-} while (0)
+#define LOG_ERR(func, ret) \
+ do { \
+ if (ret != 0) { \
+ fprintf(stderr, "%s : returned error %d\n", func, ret); \
+ exit(1); \
+ } else { \
+ fprintf(stderr, "%s : returned %d\n", func, ret); \
+ } \
+ } while (0)
int
-main (int argc, char *argv[])
+main(int argc, char *argv[])
{
- glfs_t *fs = NULL;
- int ret = 0, i;
- glfs_fd_t *fd = NULL;
- char readbuf[32];
- char *logname = NULL;
- char *hostname = NULL;
- char *volname = NULL;
-
- fprintf (stderr, "Starting libgfapi_fini\n");
-
- if (argc < 4) {
- fprintf (stderr, "Invalid argument\n");
- exit(1);
- }
-
- hostname = argv[1];
- volname = argv[2];
- logname = argv[3];
-
- fs = glfs_new (volname);
- if (!fs) {
- fprintf (stderr, "glfs_new: returned NULL\n");
- exit(1);
- }
-
- ret = glfs_set_volfile_server (fs, "tcp", hostname, 0);
- LOG_ERR("glfs_set_volfile_server", ret);
-
- ret = glfs_set_logging (fs, logname, 7);
- LOG_ERR("glfs_set_logging", ret);
-
- /* Do not call glfs_init.
- * glfs_fini() shouldn't hang in that case*/
- ret = glfs_fini(fs);
- LOG_ERR("glfs_fini", ret);
- fprintf (stderr, "End of libgfapi_fini\n");
-
- exit(0);
+ glfs_t *fs = NULL;
+ int ret = 0, i;
+ glfs_fd_t *fd = NULL;
+ char readbuf[32];
+ char *logname = NULL;
+ char *hostname = NULL;
+ char *volname = NULL;
+
+ fprintf(stderr, "Starting libgfapi_fini\n");
+
+ if (argc < 4) {
+ fprintf(stderr, "Invalid argument\n");
+ exit(1);
+ }
+
+ hostname = argv[1];
+ volname = argv[2];
+ logname = argv[3];
+
+ fs = glfs_new(volname);
+ if (!fs) {
+ fprintf(stderr, "glfs_new: returned NULL\n");
+ exit(1);
+ }
+
+ ret = glfs_set_volfile_server(fs, "tcp", hostname, 0);
+ LOG_ERR("glfs_set_volfile_server", ret);
+
+ ret = glfs_set_logging(fs, logname, 7);
+ LOG_ERR("glfs_set_logging", ret);
+
+ /* Do not call glfs_init.
+ * glfs_fini() shouldn't hang in that case*/
+ ret = glfs_fini(fs);
+ LOG_ERR("glfs_fini", ret);
+ fprintf(stderr, "End of libgfapi_fini\n");
+
+ exit(0);
}
-
-
diff --git a/tests/basic/gfapi/mandatory-lock-optimal.c b/tests/basic/gfapi/mandatory-lock-optimal.c
index 4142258c06d..34fef8d0b80 100644
--- a/tests/basic/gfapi/mandatory-lock-optimal.c
+++ b/tests/basic/gfapi/mandatory-lock-optimal.c
@@ -1,11 +1,13 @@
/* Pre-requisites:-
*
- * 1. Make sure that performance translators are switched off while running this test.
+ * 1. Make sure that performance translators are switched off while running this
+ * test.
* 2. Perform the following volume set operation:
* # gluster volume set <VOLNAME> locks.mandatory-locking optimal
* 3. For installation under non-standard paths, export LD_LIBRARY_PATH to
* automatically load exact libgfapi.so and compile this C file as follows:
- * $ gcc mandatory-lock-optimal.c -lgfapi -I <include path for api/glfs.h> -L <include path for libgfapi shared library>
+ * $ gcc mandatory-lock-optimal.c -lgfapi -I <include path for api/glfs.h> -L
+ * <include path for libgfapi shared library>
*/
#include <errno.h>
@@ -70,434 +72,461 @@ off_t offset;
Expected result : First write should fail with EAGAIN.
Second write should pass. */
-#define LOG_ERR(func, err) do { \
- if (!fp) \
- fprintf (stderr, "\n%s : returned error (%s)\n", func, strerror (err)); \
- else \
- fprintf (fp, "\n%s : returned error (%s)\n", func, strerror (err)); \
- cleanup_and_exit (err); \
-} while (0)
-
-void cleanup_and_exit (int exit_status) {
- if (exit_status || test_count != TOTAL_TEST_COUNT) {
- fprintf (fp, "\nAborting due to some test failures.\n");
- exit_status = 1;
- } else
- fprintf (fp, "\nAll tests ran successfully.\n");
- if (fp)
- fclose (fp);
- if (fd)
- glfs_close (fd);
- if (fd1)
- glfs_close (fd1);
- if (fd2)
- glfs_close (fd2);
-
- glfs_unlink (fs1, fname);
-
- if (fs1)
- glfs_fini (fs1);
- if (fs2)
- glfs_fini (fs2);
-
- exit (exit_status);
+#define LOG_ERR(func, err) \
+ do { \
+ if (!fp) \
+ fprintf(stderr, "\n%s : returned error (%s)\n", func, \
+ strerror(err)); \
+ else \
+ fprintf(fp, "\n%s : returned error (%s)\n", func, strerror(err)); \
+ cleanup_and_exit(err); \
+ } while (0)
+
+void
+cleanup_and_exit(int exit_status)
+{
+ if (exit_status || test_count != TOTAL_TEST_COUNT) {
+ fprintf(fp, "\nAborting due to some test failures.\n");
+ exit_status = 1;
+ } else
+ fprintf(fp, "\nAll tests ran successfully.\n");
+ if (fp)
+ fclose(fp);
+ if (fd)
+ glfs_close(fd);
+ if (fd1)
+ glfs_close(fd1);
+ if (fd2)
+ glfs_close(fd2);
+
+ glfs_unlink(fs1, fname);
+
+ if (fs1)
+ glfs_fini(fs1);
+ if (fs2)
+ glfs_fini(fs2);
+
+ exit(exit_status);
}
-glfs_t *new_client_create (char *hostname, char *volname, char *logfile_name) {
- glfs_t *fs = NULL;
+glfs_t *
+new_client_create(char *hostname, char *volname, char *logfile_name)
+{
+ glfs_t *fs = NULL;
- fs = glfs_new (volname);
- if (!fs)
- LOG_ERR ("glfs_new", errno);
+ fs = glfs_new(volname);
+ if (!fs)
+ LOG_ERR("glfs_new", errno);
- ret = glfs_set_volfile_server (fs, "tcp", hostname, 24007);
- if (ret)
- LOG_ERR ("glfs_set_volfile_server", errno);
+ ret = glfs_set_volfile_server(fs, "tcp", hostname, 24007);
+ if (ret)
+ LOG_ERR("glfs_set_volfile_server", errno);
- ret = glfs_set_logging (fs, logfile_name, 7);
- if (ret)
- LOG_ERR ("glfs_set_logging", errno);
+ ret = glfs_set_logging(fs, logfile_name, 7);
+ if (ret)
+ LOG_ERR("glfs_set_logging", errno);
- ret = glfs_init (fs);
- if (ret)
- LOG_ERR ("glfs_init", errno);
+ ret = glfs_init(fs);
+ if (ret)
+ LOG_ERR("glfs_init", errno);
- return fs;
+ return fs;
}
-void run_test_1 (int i) {
- fprintf (fp, "\nRunning Test-%d . . . ", i);
-
- fd1 = glfs_open (fs1, fname, O_RDONLY | O_NONBLOCK);
- if (!fd1)
- LOG_ERR ("glfs_open", errno);
-
- lock.l_type = F_RDLCK;
- lock.l_whence = SEEK_SET;
- lock.l_start = 0L;
- lock.l_len = 5L;
-
- ret = glfs_file_lock (fd1, F_SETLK, &lock, GLFS_LK_MANDATORY);
- if (ret)
- LOG_ERR ("glfs_file_lock", errno);
-
- fd2 = glfs_open (fs2, fname, O_RDONLY | O_NONBLOCK);
- if (!fd2)
- LOG_ERR ("glfs_open", errno);
-
- /* On successful read, 0 is returned as there is no content inside the
- * file
- */
- ret = glfs_read (fd2, buf1, 10, 0);
- if (ret)
- LOG_ERR ("glfs_read", errno);
-
- ret = glfs_close (fd1);
- if (ret)
- LOG_ERR ("glfs_close", errno);
- fd1 = NULL;
-
- ret = glfs_close (fd2);
- if (ret)
- LOG_ERR ("glfs_close", errno);
- fd2 = NULL;
-
- test_count++;
- fprintf (fp, "OK\n", i);
+void
+run_test_1(int i)
+{
+ fprintf(fp, "\nRunning Test-%d . . . ", i);
+
+ fd1 = glfs_open(fs1, fname, O_RDONLY | O_NONBLOCK);
+ if (!fd1)
+ LOG_ERR("glfs_open", errno);
+
+ lock.l_type = F_RDLCK;
+ lock.l_whence = SEEK_SET;
+ lock.l_start = 0L;
+ lock.l_len = 5L;
+
+ ret = glfs_file_lock(fd1, F_SETLK, &lock, GLFS_LK_MANDATORY);
+ if (ret)
+ LOG_ERR("glfs_file_lock", errno);
+
+ fd2 = glfs_open(fs2, fname, O_RDONLY | O_NONBLOCK);
+ if (!fd2)
+ LOG_ERR("glfs_open", errno);
+
+ /* On successful read, 0 is returned as there is no content inside the
+ * file
+ */
+ ret = glfs_read(fd2, buf1, 10, 0);
+ if (ret)
+ LOG_ERR("glfs_read", errno);
+
+ ret = glfs_close(fd1);
+ if (ret)
+ LOG_ERR("glfs_close", errno);
+ fd1 = NULL;
+
+ ret = glfs_close(fd2);
+ if (ret)
+ LOG_ERR("glfs_close", errno);
+ fd2 = NULL;
+
+ test_count++;
+ fprintf(fp, "OK\n", i);
}
-void run_test_2 (int i) {
- fprintf (fp, "\nRunning Test-%d . . . ", i);
+void
+run_test_2(int i)
+{
+ fprintf(fp, "\nRunning Test-%d . . . ", i);
- fd1 = glfs_open (fs1, fname, O_RDONLY | O_NONBLOCK);
- if (!fd1)
- LOG_ERR ("glfs_open", errno);
+ fd1 = glfs_open(fs1, fname, O_RDONLY | O_NONBLOCK);
+ if (!fd1)
+ LOG_ERR("glfs_open", errno);
- lock.l_type = F_RDLCK;
- lock.l_whence = SEEK_SET;
- lock.l_start = 0L;
- lock.l_len = 5L;
+ lock.l_type = F_RDLCK;
+ lock.l_whence = SEEK_SET;
+ lock.l_start = 0L;
+ lock.l_len = 5L;
- ret = glfs_file_lock (fd1, F_SETLK, &lock, GLFS_LK_MANDATORY);
- if (ret)
- LOG_ERR ("glfs_file_lock", errno);
+ ret = glfs_file_lock(fd1, F_SETLK, &lock, GLFS_LK_MANDATORY);
+ if (ret)
+ LOG_ERR("glfs_file_lock", errno);
- fd2 = glfs_open (fs2, fname, O_WRONLY | O_NONBLOCK);
- if (!fd2)
- LOG_ERR ("glfs_open", errno);
+ fd2 = glfs_open(fs2, fname, O_WRONLY | O_NONBLOCK);
+ if (!fd2)
+ LOG_ERR("glfs_open", errno);
- ret = glfs_write (fd2, buf2, 10, 0);
- if (ret == 10 || errno != EAGAIN)
- LOG_ERR ("glfs_write", errno);
+ ret = glfs_write(fd2, buf2, 10, 0);
+ if (ret == 10 || errno != EAGAIN)
+ LOG_ERR("glfs_write", errno);
- ret = glfs_close (fd1);
- if (ret)
- LOG_ERR ("glfs_close", errno);
- fd1 = NULL;
+ ret = glfs_close(fd1);
+ if (ret)
+ LOG_ERR("glfs_close", errno);
+ fd1 = NULL;
- ret = glfs_close (fd2);
- if (ret)
- LOG_ERR ("glfs_close", errno);
- fd2 = NULL;
+ ret = glfs_close(fd2);
+ if (ret)
+ LOG_ERR("glfs_close", errno);
+ fd2 = NULL;
- test_count++;
- fprintf (fp, "OK\n", i);
+ test_count++;
+ fprintf(fp, "OK\n", i);
}
-void run_test_3 (int i) {
- fprintf (fp, "\nRunning Test-%d . . . ", i);
-
- fd1 = glfs_open (fs1, fname, O_WRONLY | O_NONBLOCK);
- if (!fd1)
- LOG_ERR ("glfs_open", errno);
-
- lock.l_type = F_WRLCK;
- lock.l_whence = SEEK_SET;
- lock.l_start = 0L;
- lock.l_len = 5L;
-
- ret = glfs_file_lock (fd1, F_SETLK, &lock, GLFS_LK_ADVISORY);
- if (ret)
- LOG_ERR ("glfs_file_lock", errno);
-
- fd2 = glfs_open (fs2, fname, O_RDONLY | O_NONBLOCK);
- if (!fd2)
- LOG_ERR ("glfs_open", errno);
-
- /* Still there is no content inside file. So following read should
- * return 0
- */
- ret = glfs_read (fd2, buf1, 10, 0);
- if (ret)
- LOG_ERR ("glfs_read", errno);
-
- ret = glfs_close (fd1);
- if (ret)
- LOG_ERR ("glfs_close", errno);
- fd1 = NULL;
-
- ret = glfs_close (fd2);
- if (ret)
- LOG_ERR ("glfs_close", errno);
- fd2 = NULL;
-
- test_count++;
- fprintf (fp, "OK\n", i);
+void
+run_test_3(int i)
+{
+ fprintf(fp, "\nRunning Test-%d . . . ", i);
+
+ fd1 = glfs_open(fs1, fname, O_WRONLY | O_NONBLOCK);
+ if (!fd1)
+ LOG_ERR("glfs_open", errno);
+
+ lock.l_type = F_WRLCK;
+ lock.l_whence = SEEK_SET;
+ lock.l_start = 0L;
+ lock.l_len = 5L;
+
+ ret = glfs_file_lock(fd1, F_SETLK, &lock, GLFS_LK_ADVISORY);
+ if (ret)
+ LOG_ERR("glfs_file_lock", errno);
+
+ fd2 = glfs_open(fs2, fname, O_RDONLY | O_NONBLOCK);
+ if (!fd2)
+ LOG_ERR("glfs_open", errno);
+
+ /* Still there is no content inside file. So following read should
+ * return 0
+ */
+ ret = glfs_read(fd2, buf1, 10, 0);
+ if (ret)
+ LOG_ERR("glfs_read", errno);
+
+ ret = glfs_close(fd1);
+ if (ret)
+ LOG_ERR("glfs_close", errno);
+ fd1 = NULL;
+
+ ret = glfs_close(fd2);
+ if (ret)
+ LOG_ERR("glfs_close", errno);
+ fd2 = NULL;
+
+ test_count++;
+ fprintf(fp, "OK\n", i);
}
-void run_test_4 (int i) {
- fprintf (fp, "\nRunning Test-%d . . . ", i);
+void
+run_test_4(int i)
+{
+ fprintf(fp, "\nRunning Test-%d . . . ", i);
- fd1 = glfs_open (fs1, fname, O_WRONLY | O_NONBLOCK);
- if (!fd1)
- LOG_ERR ("glfs_open", errno);
+ fd1 = glfs_open(fs1, fname, O_WRONLY | O_NONBLOCK);
+ if (!fd1)
+ LOG_ERR("glfs_open", errno);
- lock.l_type = F_WRLCK;
- lock.l_whence = SEEK_SET;
- lock.l_start = 0L;
- lock.l_len = 5L;
+ lock.l_type = F_WRLCK;
+ lock.l_whence = SEEK_SET;
+ lock.l_start = 0L;
+ lock.l_len = 5L;
- ret = glfs_file_lock (fd1, F_SETLK, &lock, GLFS_LK_ADVISORY);
- if (ret)
- LOG_ERR ("glfs_file_lock", errno);
+ ret = glfs_file_lock(fd1, F_SETLK, &lock, GLFS_LK_ADVISORY);
+ if (ret)
+ LOG_ERR("glfs_file_lock", errno);
- fd2 = glfs_open (fs2, fname, O_WRONLY | O_NONBLOCK);
- if (!fd2)
- LOG_ERR ("glfs_open", errno);
+ fd2 = glfs_open(fs2, fname, O_WRONLY | O_NONBLOCK);
+ if (!fd2)
+ LOG_ERR("glfs_open", errno);
- ret = glfs_write (fd2, buf2, 10, 0);
- if (ret != 10)
- LOG_ERR ("glfs_write", errno);
+ ret = glfs_write(fd2, buf2, 10, 0);
+ if (ret != 10)
+ LOG_ERR("glfs_write", errno);
- ret = glfs_close (fd1);
- if (ret)
- LOG_ERR ("glfs_close", errno);
- fd1 = NULL;
+ ret = glfs_close(fd1);
+ if (ret)
+ LOG_ERR("glfs_close", errno);
+ fd1 = NULL;
- ret = glfs_close (fd2);
- if (ret)
- LOG_ERR ("glfs_close", errno);
- fd2 = NULL;
+ ret = glfs_close(fd2);
+ if (ret)
+ LOG_ERR("glfs_close", errno);
+ fd2 = NULL;
- test_count++;
- fprintf (fp, "OK\n", i);
+ test_count++;
+ fprintf(fp, "OK\n", i);
}
-void run_test_5 (int i) {
- fprintf (fp, "\nRunning Test-%d . . . ", i);
+void
+run_test_5(int i)
+{
+ fprintf(fp, "\nRunning Test-%d . . . ", i);
- fd1 = glfs_open (fs1, fname, O_RDONLY | O_NONBLOCK);
- if (!fd1)
- LOG_ERR ("glfs_open", errno);
+ fd1 = glfs_open(fs1, fname, O_RDONLY | O_NONBLOCK);
+ if (!fd1)
+ LOG_ERR("glfs_open", errno);
- lock.l_type = F_RDLCK;
- lock.l_whence = SEEK_SET;
- lock.l_start = 0L;
- lock.l_len = 5L;
+ lock.l_type = F_RDLCK;
+ lock.l_whence = SEEK_SET;
+ lock.l_start = 0L;
+ lock.l_len = 5L;
- ret = glfs_file_lock (fd1, F_SETLK, &lock, GLFS_LK_ADVISORY);
- if (ret)
- LOG_ERR ("glfs_file_lock", errno);
+ ret = glfs_file_lock(fd1, F_SETLK, &lock, GLFS_LK_ADVISORY);
+ if (ret)
+ LOG_ERR("glfs_file_lock", errno);
- fd2 = glfs_open (fs2, fname, O_RDONLY | O_NONBLOCK | O_TRUNC);
- if (!fd2)
- LOG_ERR ("glfs_open", errno);
+ fd2 = glfs_open(fs2, fname, O_RDONLY | O_NONBLOCK | O_TRUNC);
+ if (!fd2)
+ LOG_ERR("glfs_open", errno);
- ret = glfs_close (fd1);
- if (ret)
- LOG_ERR ("glfs_close", errno);
- fd1 = NULL;
+ ret = glfs_close(fd1);
+ if (ret)
+ LOG_ERR("glfs_close", errno);
+ fd1 = NULL;
- ret = glfs_close (fd2);
- if (ret)
- LOG_ERR ("glfs_close", errno);
- fd2 = NULL;
+ ret = glfs_close(fd2);
+ if (ret)
+ LOG_ERR("glfs_close", errno);
+ fd2 = NULL;
- test_count++;
- fprintf (fp, "OK\n", i);
+ test_count++;
+ fprintf(fp, "OK\n", i);
}
-void run_test_6 (int i) {
- fprintf (fp, "\nRunning Test-%d . . . ", i);
+void
+run_test_6(int i)
+{
+ fprintf(fp, "\nRunning Test-%d . . . ", i);
- fd1 = glfs_open (fs1, fname, O_RDONLY | O_NONBLOCK);
- if (!fd1)
- LOG_ERR ("glfs_open", errno);
+ fd1 = glfs_open(fs1, fname, O_RDONLY | O_NONBLOCK);
+ if (!fd1)
+ LOG_ERR("glfs_open", errno);
- lock.l_type = F_RDLCK;
- lock.l_whence = SEEK_SET;
- lock.l_start = 0L;
- lock.l_len = 5L;
+ lock.l_type = F_RDLCK;
+ lock.l_whence = SEEK_SET;
+ lock.l_start = 0L;
+ lock.l_len = 5L;
- ret = glfs_file_lock (fd1, F_SETLK, &lock, GLFS_LK_MANDATORY);
- if (ret)
- LOG_ERR ("glfs_file_lock", errno);
+ ret = glfs_file_lock(fd1, F_SETLK, &lock, GLFS_LK_MANDATORY);
+ if (ret)
+ LOG_ERR("glfs_file_lock", errno);
- fd2 = glfs_open (fs2, fname, O_RDONLY | O_NONBLOCK | O_TRUNC);
- if (fd2)
- LOG_ERR ("glfs_open", errno);
+ fd2 = glfs_open(fs2, fname, O_RDONLY | O_NONBLOCK | O_TRUNC);
+ if (fd2)
+ LOG_ERR("glfs_open", errno);
- ret = glfs_close (fd1);
- if (ret)
- LOG_ERR ("glfs_close", errno);
- fd1 = NULL;
+ ret = glfs_close(fd1);
+ if (ret)
+ LOG_ERR("glfs_close", errno);
+ fd1 = NULL;
- test_count++;
- fprintf (fp, "OK\n", i);
+ test_count++;
+ fprintf(fp, "OK\n", i);
}
-void run_test_7 (int i) {
- fprintf (fp, "\nRunning Test-%d . . . ", i);
+void
+run_test_7(int i)
+{
+ fprintf(fp, "\nRunning Test-%d . . . ", i);
- fd1 = glfs_open (fs1, fname, O_RDONLY | O_NONBLOCK);
- if (!fd1)
- LOG_ERR ("glfs_open", errno);
+ fd1 = glfs_open(fs1, fname, O_RDONLY | O_NONBLOCK);
+ if (!fd1)
+ LOG_ERR("glfs_open", errno);
- lock.l_type = F_RDLCK;
- lock.l_whence = SEEK_SET;
- lock.l_start = 0L;
- lock.l_len = 5L;
+ lock.l_type = F_RDLCK;
+ lock.l_whence = SEEK_SET;
+ lock.l_start = 0L;
+ lock.l_len = 5L;
- ret = glfs_file_lock (fd1, F_SETLK, &lock, GLFS_LK_MANDATORY);
- if (ret)
- LOG_ERR ("glfs_file_lock", errno);
+ ret = glfs_file_lock(fd1, F_SETLK, &lock, GLFS_LK_MANDATORY);
+ if (ret)
+ LOG_ERR("glfs_file_lock", errno);
- fd2 = glfs_open (fs2, fname, O_RDWR | O_NONBLOCK);
- if (!fd2)
- LOG_ERR ("glfs_open", errno);
+ fd2 = glfs_open(fs2, fname, O_RDWR | O_NONBLOCK);
+ if (!fd2)
+ LOG_ERR("glfs_open", errno);
- ret = glfs_ftruncate (fd2, 4, NULL, NULL);
- if (ret == 0 || errno != EAGAIN)
- LOG_ERR ("glfs_ftruncate", errno);
+ ret = glfs_ftruncate(fd2, 4, NULL, NULL);
+ if (ret == 0 || errno != EAGAIN)
+ LOG_ERR("glfs_ftruncate", errno);
- ret = glfs_close (fd1);
- if (ret)
- LOG_ERR ("glfs_close", errno);
- fd1 = NULL;
+ ret = glfs_close(fd1);
+ if (ret)
+ LOG_ERR("glfs_close", errno);
+ fd1 = NULL;
- ret = glfs_close (fd2);
- if (ret)
- LOG_ERR ("glfs_close", errno);
- fd2 = NULL;
+ ret = glfs_close(fd2);
+ if (ret)
+ LOG_ERR("glfs_close", errno);
+ fd2 = NULL;
- test_count++;
- fprintf (fp, "OK\n", i);
+ test_count++;
+ fprintf(fp, "OK\n", i);
}
-void run_test_8 (int i) {
- fprintf (fp, "\nRunning Test-%d . . . ", i);
-
- fd1 = glfs_open (fs1, fname, O_RDONLY | O_NONBLOCK);
- if (!fd1)
- LOG_ERR ("glfs_open", errno);
-
- lock.l_type = F_RDLCK;
- lock.l_whence = SEEK_SET;
- lock.l_start = 0L;
- lock.l_len = 10L;
-
- ret = glfs_file_lock (fd1, F_SETLK, &lock, GLFS_LK_ADVISORY);
- if (ret)
- LOG_ERR ("glfs_file_lock", errno);
-
- fd2 = glfs_open (fs2, fname, O_RDONLY | O_NONBLOCK);
- if (!fd2)
- LOG_ERR ("glfs_open", errno);
-
- lock.l_type = F_RDLCK;
- lock.l_whence = SEEK_SET;
- lock.l_start = 5L;
- lock.l_len = 2L;
-
- ret = glfs_file_lock (fd2, F_SETLK, &lock, GLFS_LK_MANDATORY);
- if (ret)
- LOG_ERR ("glfs_file_lock", errno);
-
- fd3 = glfs_open (fs3, fname, O_RDWR | O_NONBLOCK);
- if (!fd3)
- LOG_ERR ("glfs_open", errno);
-
- offset = glfs_lseek (fd3, 5L, SEEK_SET);
- if (offset != 5)
- LOG_ERR ("glfs_lseek", errno);
-
- ret = glfs_write (fd3, buf2, 10, 0);
- if (ret == 10 || errno != EAGAIN)
- LOG_ERR ("glfs_write", errno);
-
- offset = glfs_lseek (fd3, 8L, SEEK_SET);
- if (offset != 8)
- LOG_ERR ("glfs_lseek", errno);
-
- ret = glfs_write (fd3, buf2, 10, 0);
- if (ret != 10)
- LOG_ERR ("glfs_write", errno);
-
- ret = glfs_close (fd1);
- if (ret)
- LOG_ERR ("glfs_close", errno);
- fd1 = NULL;
-
- ret = glfs_close (fd2);
- if (ret)
- LOG_ERR ("glfs_close", errno);
- fd2 = NULL;
-
- ret = glfs_close (fd3);
- if (ret)
- LOG_ERR ("glfs_close", errno);
- fd3 = NULL;
-
- test_count++;
- fprintf (fp, "OK\n", i);
+void
+run_test_8(int i)
+{
+ fprintf(fp, "\nRunning Test-%d . . . ", i);
+
+ fd1 = glfs_open(fs1, fname, O_RDONLY | O_NONBLOCK);
+ if (!fd1)
+ LOG_ERR("glfs_open", errno);
+
+ lock.l_type = F_RDLCK;
+ lock.l_whence = SEEK_SET;
+ lock.l_start = 0L;
+ lock.l_len = 10L;
+
+ ret = glfs_file_lock(fd1, F_SETLK, &lock, GLFS_LK_ADVISORY);
+ if (ret)
+ LOG_ERR("glfs_file_lock", errno);
+
+ fd2 = glfs_open(fs2, fname, O_RDONLY | O_NONBLOCK);
+ if (!fd2)
+ LOG_ERR("glfs_open", errno);
+
+ lock.l_type = F_RDLCK;
+ lock.l_whence = SEEK_SET;
+ lock.l_start = 5L;
+ lock.l_len = 2L;
+
+ ret = glfs_file_lock(fd2, F_SETLK, &lock, GLFS_LK_MANDATORY);
+ if (ret)
+ LOG_ERR("glfs_file_lock", errno);
+
+ fd3 = glfs_open(fs3, fname, O_RDWR | O_NONBLOCK);
+ if (!fd3)
+ LOG_ERR("glfs_open", errno);
+
+ offset = glfs_lseek(fd3, 5L, SEEK_SET);
+ if (offset != 5)
+ LOG_ERR("glfs_lseek", errno);
+
+ ret = glfs_write(fd3, buf2, 10, 0);
+ if (ret == 10 || errno != EAGAIN)
+ LOG_ERR("glfs_write", errno);
+
+ offset = glfs_lseek(fd3, 8L, SEEK_SET);
+ if (offset != 8)
+ LOG_ERR("glfs_lseek", errno);
+
+ ret = glfs_write(fd3, buf2, 10, 0);
+ if (ret != 10)
+ LOG_ERR("glfs_write", errno);
+
+ ret = glfs_close(fd1);
+ if (ret)
+ LOG_ERR("glfs_close", errno);
+ fd1 = NULL;
+
+ ret = glfs_close(fd2);
+ if (ret)
+ LOG_ERR("glfs_close", errno);
+ fd2 = NULL;
+
+ ret = glfs_close(fd3);
+ if (ret)
+ LOG_ERR("glfs_close", errno);
+ fd3 = NULL;
+
+ test_count++;
+ fprintf(fp, "OK\n", i);
}
-int main (int argc, char *argv[]) {
- char logfile[50];
-
- if (argc != 4) {
- fprintf (stderr, "Usage: %s <server ip/hostname> <volume name> <test log directory>\n", argv[0]);
- return 0;
- }
-
- sprintf (logfile, "%s/%s", argv[3], "mandatory-lock-optimal-test.log");
- fp = fopen (logfile, "w");
- if (!fp) {
- fprintf (stderr, "\n%s\n", logfile);
- LOG_ERR ("Log file creation", errno);
- }
-
- sprintf (logfile, "%s/%s", argv[3], "glfs-client-1.log");
- fs1 = new_client_create (argv[1], argv[2], logfile);
- if (!fs1)
- LOG_ERR ("client-1 creation", EINVAL);
-
- sprintf (logfile, "%s/%s", argv[3], "glfs-client-2.log");
- fs2 = new_client_create (argv[1], argv[2], logfile);
- if (!fs2)
- LOG_ERR ("client-2 creation", EINVAL);
-
- sprintf (logfile, "%s/%s", argv[3], "glfs-client-3.log");
- fs3 = new_client_create (argv[1], argv[2], logfile);
- if (!fs3)
- LOG_ERR ("client-3 creation", EINVAL);
-
- fd = glfs_creat (fs1, fname, O_RDWR, 0644);
- if (!fd)
- LOG_ERR ("glfs_creat", errno);
-
- test_count = 0;
-
- run_test_1 (1);
- run_test_2 (2);
- run_test_3 (3);
- run_test_4 (4);
- run_test_5 (5);
- run_test_6 (6);
- run_test_7 (7);
- run_test_8 (8);
-
- cleanup_and_exit (0);
+int
+main(int argc, char *argv[])
+{
+ char logfile[50];
+ if (argc != 4) {
+ fprintf(stderr,
+ "Usage: %s <server ip/hostname> <volume name> <test log "
+ "directory>\n",
+ argv[0]);
return 0;
+ }
+
+ sprintf(logfile, "%s/%s", argv[3], "mandatory-lock-optimal-test.log");
+ fp = fopen(logfile, "w");
+ if (!fp) {
+ fprintf(stderr, "\n%s\n", logfile);
+ LOG_ERR("Log file creation", errno);
+ }
+
+ sprintf(logfile, "%s/%s", argv[3], "glfs-client-1.log");
+ fs1 = new_client_create(argv[1], argv[2], logfile);
+ if (!fs1)
+ LOG_ERR("client-1 creation", EINVAL);
+
+ sprintf(logfile, "%s/%s", argv[3], "glfs-client-2.log");
+ fs2 = new_client_create(argv[1], argv[2], logfile);
+ if (!fs2)
+ LOG_ERR("client-2 creation", EINVAL);
+
+ sprintf(logfile, "%s/%s", argv[3], "glfs-client-3.log");
+ fs3 = new_client_create(argv[1], argv[2], logfile);
+ if (!fs3)
+ LOG_ERR("client-3 creation", EINVAL);
+
+ fd = glfs_creat(fs1, fname, O_RDWR, 0644);
+ if (!fd)
+ LOG_ERR("glfs_creat", errno);
+
+ test_count = 0;
+
+ run_test_1(1);
+ run_test_2(2);
+ run_test_3(3);
+ run_test_4(4);
+ run_test_5(5);
+ run_test_6(6);
+ run_test_7(7);
+ run_test_8(8);
+
+ cleanup_and_exit(0);
+
+ return 0;
}
diff --git a/tests/basic/gfapi/seek.c b/tests/basic/gfapi/seek.c
index fb2f6361bf3..85ea9b88141 100644
--- a/tests/basic/gfapi/seek.c
+++ b/tests/basic/gfapi/seek.c
@@ -18,80 +18,82 @@
#include <glusterfs/api/glfs-handles.h>
int
-main (int argc, char **argv)
+main(int argc, char **argv)
{
- glfs_t *fs = NULL;
- int ret = 0;
- glfs_fd_t *fd = NULL;
- char *filename = NULL;
- char *volname = NULL;
- char *hostname = NULL;
- struct stat st = { 0, };
- off_t hole_start = 0;
- off_t hole_end = 0;
-
- if (argc != 4) {
- fprintf (stderr, "Invalid argument, use %s <hostname> <vol> <file>\n",
- argv[0]);
- exit (1);
+ glfs_t *fs = NULL;
+ int ret = 0;
+ glfs_fd_t *fd = NULL;
+ char *filename = NULL;
+ char *volname = NULL;
+ char *hostname = NULL;
+ struct stat st = {
+ 0,
+ };
+ off_t hole_start = 0;
+ off_t hole_end = 0;
+
+ if (argc != 4) {
+ fprintf(stderr, "Invalid argument, use %s <hostname> <vol> <file>\n",
+ argv[0]);
+ exit(1);
+ }
+
+ hostname = argv[1];
+ volname = argv[2];
+ filename = argv[3];
+
+ fs = glfs_new(volname);
+ if (!fs) {
+ perror("glfs_new() returned NULL");
+ return 1;
+ }
+
+ if (glfs_set_volfile_server(fs, "tcp", hostname, 24007)) {
+ perror("glfs_set_volfile_server");
+ return 1;
+ }
+
+ if (glfs_init(fs)) {
+ perror("glfs_init");
+ return 1;
+ }
+
+ fd = glfs_open(fs, filename, O_RDONLY);
+ if (fd <= 0) {
+ perror("glfs_open");
+ return 1;
+ }
+
+ if (glfs_fstat(fd, &st)) {
+ perror("glfs_fstat");
+ return 1;
+ }
+
+ while (hole_end < st.st_size) {
+ hole_start = glfs_lseek(fd, hole_end, SEEK_HOLE);
+ if (hole_start == -1 && errno == ENXIO)
+ /* no more holes */
+ break;
+ if (hole_start == -1) {
+ perror("no more holes");
+ break;
}
- hostname = argv[1];
- volname = argv[2];
- filename = argv[3];
-
- fs = glfs_new (volname);
- if (!fs) {
- perror ("glfs_new() returned NULL");
- return 1;
- }
-
- if (glfs_set_volfile_server (fs, "tcp", hostname, 24007)) {
- perror ("glfs_set_volfile_server");
- return 1;
+ hole_end = glfs_lseek(fd, hole_start, SEEK_DATA);
+ if (hole_end == -1 && errno == ENXIO) {
+ /* no more data */
+ break;
}
- if (glfs_init (fs)) {
- perror ("glfs_init");
- return 1;
- }
+ printf("HOLE found: %ld - %ld%s\n", hole_start, hole_end,
+ (hole_end == st.st_size) ? " (EOF)" : "");
+ }
- fd = glfs_open (fs, filename, O_RDONLY);
- if (fd <= 0) {
- perror ("glfs_open");
- return 1;
- }
+ glfs_close(fd);
- if (glfs_fstat (fd, &st)) {
- perror ("glfs_fstat");
- return 1;
- }
-
- while (hole_end < st.st_size) {
- hole_start = glfs_lseek (fd, hole_end, SEEK_HOLE);
- if (hole_start == -1 && errno == ENXIO)
- /* no more holes */
- break;
- if (hole_start == -1) {
- perror ("no more holes");
- break;
- }
-
- hole_end = glfs_lseek (fd, hole_start, SEEK_DATA);
- if (hole_end == -1 && errno == ENXIO) {
- /* no more data */
- break;
- }
-
- printf ("HOLE found: %ld - %ld%s\n", hole_start, hole_end,
- (hole_end == st.st_size) ? " (EOF)" : "");
- }
-
- glfs_close (fd);
-
- if (fs) {
- glfs_fini (fs);
- }
+ if (fs) {
+ glfs_fini(fs);
+ }
- return ret;
+ return ret;
}
diff --git a/tests/basic/gfapi/upcall-cache-invalidate.c b/tests/basic/gfapi/upcall-cache-invalidate.c
index 2014bb9dccf..078286a8956 100644
--- a/tests/basic/gfapi/upcall-cache-invalidate.c
+++ b/tests/basic/gfapi/upcall-cache-invalidate.c
@@ -9,204 +9,201 @@
#include <glusterfs/api/glfs.h>
#include <glusterfs/api/glfs-handles.h>
-#define LOG_ERR(func, ret) do { \
- if (ret != 0) { \
- fprintf (stderr, "%s : returned error %d (%s)\n", \
- func, ret, strerror (errno)); \
- goto out; \
- } else { \
- fprintf (stderr, "%s : returned %d\n", func, ret); \
- } \
- } while (0)
+#define LOG_ERR(func, ret) \
+ do { \
+ if (ret != 0) { \
+ fprintf(stderr, "%s : returned error %d (%s)\n", func, ret, \
+ strerror(errno)); \
+ goto out; \
+ } else { \
+ fprintf(stderr, "%s : returned %d\n", func, ret); \
+ } \
+ } while (0)
int
-main (int argc, char *argv[])
+main(int argc, char *argv[])
{
- glfs_t *fs = NULL;
- glfs_t *fs2 = NULL;
- glfs_t *fs_tmp = NULL;
- glfs_t *fs_tmp2 = NULL;
- int ret = 0, i;
- glfs_fd_t *fd = NULL;
- glfs_fd_t *fd2 = NULL;
- glfs_fd_t *fd_tmp = NULL;
- glfs_fd_t *fd_tmp2 = NULL;
- char readbuf[32];
- char *filename = "file_tmp";
- char *writebuf = NULL;
- char *vol_id = NULL;
- unsigned int cnt = 1;
- struct glfs_upcall *cbk = NULL;
- char *logfile = NULL;
- char *volname = NULL;
- char *hostname = NULL;
-
- if (argc != 4) {
- fprintf (stderr, "Invalid argument\n");
- exit(1);
+ glfs_t *fs = NULL;
+ glfs_t *fs2 = NULL;
+ glfs_t *fs_tmp = NULL;
+ glfs_t *fs_tmp2 = NULL;
+ int ret = 0, i;
+ glfs_fd_t *fd = NULL;
+ glfs_fd_t *fd2 = NULL;
+ glfs_fd_t *fd_tmp = NULL;
+ glfs_fd_t *fd_tmp2 = NULL;
+ char readbuf[32];
+ char *filename = "file_tmp";
+ char *writebuf = NULL;
+ char *vol_id = NULL;
+ unsigned int cnt = 1;
+ struct glfs_upcall *cbk = NULL;
+ char *logfile = NULL;
+ char *volname = NULL;
+ char *hostname = NULL;
+
+ if (argc != 4) {
+ fprintf(stderr, "Invalid argument\n");
+ exit(1);
+ }
+
+ hostname = argv[1];
+ volname = argv[2];
+ logfile = argv[3];
+
+ fs = glfs_new(volname);
+ if (!fs) {
+ fprintf(stderr, "glfs_new: returned NULL\n");
+ return -1;
+ }
+
+ ret = glfs_set_volfile_server(fs, "tcp", hostname, 24007);
+ LOG_ERR("glfs_set_volfile_server", ret);
+
+ ret = glfs_set_logging(fs, logfile, 7);
+ LOG_ERR("glfs_set_logging", ret);
+
+ ret = glfs_init(fs);
+ LOG_ERR("glfs_init", ret);
+
+ /* This does not block, but enables caching of events. Real
+ * applications like NFS-Ganesha run this in a thread before activity
+ * on the fs (through this instance) happens. */
+ ret = glfs_h_poll_upcall(fs_tmp, &cbk);
+ LOG_ERR("glfs_h_poll_upcall", ret);
+
+ fs2 = glfs_new(volname);
+ if (!fs2) {
+ fprintf(stderr, "glfs_new fs2: returned NULL\n");
+ return 1;
+ }
+
+ ret = glfs_set_volfile_server(fs2, "tcp", hostname, 24007);
+ LOG_ERR("glfs_set_volfile_server-fs2", ret);
+
+ ret = glfs_set_logging(fs2, logfile, 7);
+ LOG_ERR("glfs_set_logging-fs2", ret);
+
+ ret = glfs_init(fs2);
+ LOG_ERR("glfs_init-fs2", ret);
+
+ fd = glfs_creat(fs, filename, O_RDWR | O_SYNC, 0644);
+ if (fd <= 0) {
+ ret = -1;
+ LOG_ERR("glfs_creat", ret);
+ }
+ fprintf(stderr, "glfs-create fd - %d\n", fd);
+
+ fd2 = glfs_open(fs2, filename, O_SYNC | O_RDWR | O_CREAT);
+ if (fd2 <= 0) {
+ ret = -1;
+ LOG_ERR("glfs_open-fs2", ret);
+ }
+ fprintf(stderr, "glfs-open fd2 - %d\n", fd2);
+
+ do {
+ if (cnt % 2) {
+ fd_tmp = fd;
+ fs_tmp = fs;
+ fd_tmp2 = fd2;
+ fs_tmp2 = fs2;
+ } else {
+ fd_tmp = fd2;
+ fs_tmp = fs2;
+ fd_tmp2 = fd;
+ fs_tmp2 = fs;
}
- hostname = argv[1];
- volname = argv[2];
- logfile = argv[3];
-
- fs = glfs_new (volname);
- if (!fs) {
- fprintf (stderr, "glfs_new: returned NULL\n");
- return -1;
+ /* WRITE on fd_tmp */
+ writebuf = malloc(10);
+ if (writebuf) {
+ memcpy(writebuf, "abcd", 4);
+ ret = glfs_write(fd_tmp, writebuf, 4, 0);
+ if (ret <= 0) {
+ ret = -1;
+ LOG_ERR("glfs_write", ret);
+ } else {
+ fprintf(stderr, "glfs_write succeeded\n");
+ }
+ free(writebuf);
+ } else {
+ fprintf(stderr, "Could not allocate writebuf\n");
+ return -1;
}
- ret = glfs_set_volfile_server (fs, "tcp", hostname, 24007);
- LOG_ERR("glfs_set_volfile_server", ret);
-
- ret = glfs_set_logging (fs, logfile, 7);
- LOG_ERR("glfs_set_logging", ret);
-
- ret = glfs_init (fs);
- LOG_ERR("glfs_init", ret);
+ /* READ on fd_tmp2 */
+ ret = glfs_lseek(fd_tmp2, 0, SEEK_SET);
+ LOG_ERR("glfs_lseek", ret);
- /* This does not block, but enables caching of events. Real
- * applications like NFS-Ganesha run this in a thread before activity
- * on the fs (through this instance) happens. */
- ret = glfs_h_poll_upcall(fs_tmp, &cbk);
- LOG_ERR ("glfs_h_poll_upcall", ret);
+ memset(readbuf, 0, sizeof(readbuf));
+ ret = glfs_pread(fd_tmp2, readbuf, 4, 0, 0, NULL);
- fs2 = glfs_new (volname);
- if (!fs2) {
- fprintf (stderr, "glfs_new fs2: returned NULL\n");
- return 1;
+ if (ret <= 0) {
+ ret = -1;
+ LOG_ERR("glfs_pread", ret);
+ } else {
+ fprintf(stderr, "glfs_read: %s\n", readbuf);
}
- ret = glfs_set_volfile_server (fs2, "tcp", hostname, 24007);
- LOG_ERR("glfs_set_volfile_server-fs2", ret);
-
- ret = glfs_set_logging (fs2, logfile, 7);
- LOG_ERR("glfs_set_logging-fs2", ret);
-
- ret = glfs_init (fs2);
- LOG_ERR("glfs_init-fs2", ret);
-
- fd = glfs_creat(fs, filename, O_RDWR|O_SYNC, 0644);
- if (fd <= 0) {
+ /* Open() fops seem to be not performed on server side until
+ * there are I/Os on that fd
+ */
+ if (cnt > 2) {
+ struct glfs_upcall_inode *in_arg = NULL;
+ enum glfs_upcall_reason reason = 0;
+ struct glfs_object *object = NULL;
+ uint64_t flags = 0;
+ uint64_t expire = 0;
+
+ ret = glfs_h_poll_upcall(fs_tmp, &cbk);
+ LOG_ERR("glfs_h_poll_upcall", ret);
+
+ reason = glfs_upcall_get_reason(cbk);
+
+ /* Expect 'GLFS_INODE_INVALIDATE' upcall event. */
+ if (reason == GLFS_UPCALL_INODE_INVALIDATE) {
+ in_arg = glfs_upcall_get_event(cbk);
+
+ object = glfs_upcall_inode_get_object(in_arg);
+ flags = glfs_upcall_inode_get_flags(in_arg);
+ expire = glfs_upcall_inode_get_expire(in_arg);
+
+ fprintf(stderr,
+ " upcall event type - %d,"
+ " object(%p), flags(%d), "
+ " expire_time_attr(%d)\n",
+ reason, object, flags, expire);
+ } else {
+ fprintf(stderr, "Didn't receive upcall notify event");
ret = -1;
- LOG_ERR ("glfs_creat", ret);
- }
- fprintf (stderr, "glfs-create fd - %d\n", fd);
+ goto err;
+ }
- fd2 = glfs_open(fs2, filename, O_SYNC|O_RDWR|O_CREAT);
- if (fd2 <= 0) {
- ret = -1;
- LOG_ERR ("glfs_open-fs2", ret);
+ glfs_free(cbk);
}
- fprintf (stderr, "glfs-open fd2 - %d\n", fd2);
-
- do {
- if (cnt%2) {
- fd_tmp = fd;
- fs_tmp = fs;
- fd_tmp2 = fd2;
- fs_tmp2 = fs2;
- } else {
- fd_tmp = fd2;
- fs_tmp = fs2;
- fd_tmp2 = fd;
- fs_tmp2 = fs;
- }
-
- /* WRITE on fd_tmp */
- writebuf = malloc(10);
- if (writebuf) {
- memcpy (writebuf, "abcd", 4);
- ret = glfs_write (fd_tmp, writebuf, 4, 0);
- if (ret <= 0) {
- ret = -1;
- LOG_ERR ("glfs_write", ret);
- } else {
- fprintf (stderr,
- "glfs_write succeeded\n");
- }
- free(writebuf);
- } else {
- fprintf (stderr,
- "Could not allocate writebuf\n");
- return -1;
- }
-
- /* READ on fd_tmp2 */
- ret = glfs_lseek (fd_tmp2, 0, SEEK_SET);
- LOG_ERR ("glfs_lseek", ret);
-
- memset (readbuf, 0, sizeof(readbuf));
- ret = glfs_pread (fd_tmp2, readbuf, 4, 0, 0, NULL);
-
- if (ret <= 0) {
- ret = -1;
- LOG_ERR ("glfs_pread", ret);
- } else {
- fprintf (stderr, "glfs_read: %s\n", readbuf);
- }
-
- /* Open() fops seem to be not performed on server side until
- * there are I/Os on that fd
- */
- if (cnt > 2) {
- struct glfs_upcall_inode *in_arg = NULL;
- enum glfs_upcall_reason reason = 0;
- struct glfs_object *object = NULL;
- uint64_t flags = 0;
- uint64_t expire = 0;
-
- ret = glfs_h_poll_upcall(fs_tmp, &cbk);
- LOG_ERR ("glfs_h_poll_upcall", ret);
-
- reason = glfs_upcall_get_reason (cbk);
-
- /* Expect 'GLFS_INODE_INVALIDATE' upcall event. */
- if (reason == GLFS_UPCALL_INODE_INVALIDATE) {
- in_arg = glfs_upcall_get_event (cbk);
-
- object = glfs_upcall_inode_get_object (in_arg);
- flags = glfs_upcall_inode_get_flags (in_arg);
- expire = glfs_upcall_inode_get_expire (in_arg);
-
- fprintf (stderr, " upcall event type - %d,"
- " object(%p), flags(%d), "
- " expire_time_attr(%d)\n" ,
- reason, object, flags, expire);
- } else {
- fprintf (stderr,
- "Didn't receive upcall notify event");
- ret = -1;
- goto err;
- }
-
- glfs_free (cbk);
- }
-
- sleep(5);
- } while (++cnt < 5);
+
+ sleep(5);
+ } while (++cnt < 5);
err:
- glfs_close(fd);
- LOG_ERR ("glfs_close", ret);
+ glfs_close(fd);
+ LOG_ERR("glfs_close", ret);
- glfs_close(fd2);
- LOG_ERR ("glfs_close-fd2", ret);
+ glfs_close(fd2);
+ LOG_ERR("glfs_close-fd2", ret);
out:
- if (fs) {
- ret = glfs_fini(fs);
- fprintf (stderr, "glfs_fini(fs) returned %d \n", ret);
- }
-
- if (fs2) {
- ret = glfs_fini(fs2);
- fprintf (stderr, "glfs_fini(fs2) returned %d \n", ret);
- }
-
- if (ret)
- exit(1);
- exit(0);
+ if (fs) {
+ ret = glfs_fini(fs);
+ fprintf(stderr, "glfs_fini(fs) returned %d \n", ret);
+ }
+
+ if (fs2) {
+ ret = glfs_fini(fs2);
+ fprintf(stderr, "glfs_fini(fs2) returned %d \n", ret);
+ }
+
+ if (ret)
+ exit(1);
+ exit(0);
}
-
-
diff --git a/tests/basic/gfapi/upcall-register-api.c b/tests/basic/gfapi/upcall-register-api.c
index 994069c0446..78594dbb108 100644
--- a/tests/basic/gfapi/upcall-register-api.c
+++ b/tests/basic/gfapi/upcall-register-api.c
@@ -9,273 +9,278 @@
#include <glusterfs/api/glfs.h>
#include <glusterfs/api/glfs-handles.h>
-#define LOG_ERR(func, ret) do { \
- if (ret != 0) { \
- fprintf (stderr, "%s : returned error %d (%s)\n", \
- func, ret, strerror (errno)); \
- goto out; \
- } else { \
- fprintf (stderr, "%s : returned %d\n", func, ret); \
- } \
- } while (0)
+#define LOG_ERR(func, ret) \
+ do { \
+ if (ret != 0) { \
+ fprintf(stderr, "%s : returned error %d (%s)\n", func, ret, \
+ strerror(errno)); \
+ goto out; \
+ } else { \
+ fprintf(stderr, "%s : returned %d\n", func, ret); \
+ } \
+ } while (0)
int upcall_recv = 0;
-void up_async_invalidate (struct glfs_upcall *up_arg, void *data)
+void
+up_async_invalidate(struct glfs_upcall *up_arg, void *data)
{
- struct glfs_upcall_inode *in_arg = NULL;
- enum glfs_upcall_reason reason = 0;
- struct glfs_object *object = NULL;
- uint64_t flags = 0;
- uint64_t expire = 0;
+ struct glfs_upcall_inode *in_arg = NULL;
+ enum glfs_upcall_reason reason = 0;
+ struct glfs_object *object = NULL;
+ uint64_t flags = 0;
+ uint64_t expire = 0;
- if (!up_arg)
- return;
-
- reason = glfs_upcall_get_reason (up_arg);
-
- /* Expect 'GLFS_INODE_INVALIDATE' upcall event. */
-
- if (reason == GLFS_UPCALL_INODE_INVALIDATE) {
- in_arg = glfs_upcall_get_event (up_arg);
-
- object = glfs_upcall_inode_get_object (in_arg);
- flags = glfs_upcall_inode_get_flags (in_arg);
- expire = glfs_upcall_inode_get_expire (in_arg);
-
- fprintf (stderr, " upcall event type - %d,"
- " object(%p), flags(%d), "
- " expire_time_attr(%d)\n" ,
- reason, object, flags, expire);
- upcall_recv++;
- }
-
- glfs_free (up_arg);
+ if (!up_arg)
return;
-}
-int perform_io (glfs_t *fs, glfs_t *fs2, int cnt)
-{
- glfs_t *fs_tmp = NULL;
- glfs_t *fs_tmp2 = NULL;
- glfs_fd_t *fd_tmp = NULL;
- glfs_fd_t *fd_tmp2 = NULL;
- char readbuf[32];
- char *writebuf = NULL;
- glfs_fd_t *fd = NULL;
- glfs_fd_t *fd2 = NULL;
- char *filename = "file_tmp";
- int ret = -1;
-
- if (!fs || !fs2)
- return -1;
-
- /* Create file from fs and open it from fs2 */
- fd = glfs_creat(fs, filename, O_RDWR|O_SYNC, 0644);
- if (fd <= 0) {
- ret = -1;
- LOG_ERR ("glfs_creat", ret);
- }
+ reason = glfs_upcall_get_reason(up_arg);
- fd2 = glfs_open(fs2, filename, O_SYNC|O_RDWR|O_CREAT);
- if (fd2 <= 0) {
- ret = -1;
- LOG_ERR ("glfs_open-fs2", ret);
- }
+ /* Expect 'GLFS_INODE_INVALIDATE' upcall event. */
- do {
- if (cnt%2) {
- fd_tmp = fd;
- fs_tmp = fs;
- fd_tmp2 = fd2;
- fs_tmp2 = fs2;
- } else {
- fd_tmp = fd2;
- fs_tmp = fs2;
- fd_tmp2 = fd;
- fs_tmp2 = fs;
- }
-
- /* WRITE on fd_tmp */
- writebuf = malloc(10);
- if (writebuf) {
- memcpy (writebuf, "abcd", 4);
- ret = glfs_write (fd_tmp, writebuf, 4, 0);
- if (ret <= 0) {
- ret = -1;
- LOG_ERR ("glfs_write", ret);
- }
- free(writebuf);
- } else {
- fprintf (stderr,
- "Could not allocate writebuf\n");
- return -1;
- }
-
- /* READ on fd_tmp2 */
- ret = glfs_lseek (fd_tmp2, 0, SEEK_SET);
- LOG_ERR ("glfs_lseek", ret);
-
- memset (readbuf, 0, sizeof(readbuf));
- ret = glfs_pread (fd_tmp2, readbuf, 4, 0, 0, NULL);
-
- if (ret <= 0) {
- ret = -1;
- LOG_ERR ("glfs_pread", ret);
- }
-
- sleep(2);
- } while (--cnt > 0);
+ if (reason == GLFS_UPCALL_INODE_INVALIDATE) {
+ in_arg = glfs_upcall_get_event(up_arg);
- sleep(2);
+ object = glfs_upcall_inode_get_object(in_arg);
+ flags = glfs_upcall_inode_get_flags(in_arg);
+ expire = glfs_upcall_inode_get_expire(in_arg);
- ret = 0;
-err:
- glfs_close(fd);
+ fprintf(stderr,
+ " upcall event type - %d,"
+ " object(%p), flags(%d), "
+ " expire_time_attr(%d)\n",
+ reason, object, flags, expire);
+ upcall_recv++;
+ }
- glfs_close(fd2);
-
-out:
- return ret;
+ glfs_free(up_arg);
+ return;
}
int
-main (int argc, char *argv[])
+perform_io(glfs_t *fs, glfs_t *fs2, int cnt)
{
- glfs_t *fs = NULL;
- glfs_t *fs2 = NULL;
- int ret = 0, i;
- char *vol_id = NULL;
- unsigned int cnt = 5;
- struct glfs_upcall *cbk = NULL;
- char *logfile = NULL;
- char *volname = NULL;
- char *hostname = NULL;
- int up_events = GLFS_EVENT_ANY;
-
- if (argc != 4) {
- fprintf (stderr, "Invalid argument\n");
- exit(1);
- }
-
- hostname = argv[1];
- volname = argv[2];
- logfile = argv[3];
-
- /* Initialize fs */
- fs = glfs_new (volname);
- if (!fs) {
- fprintf (stderr, "glfs_new: returned NULL\n");
- return -1;
- }
-
- ret = glfs_set_volfile_server (fs, "tcp", hostname, 24007);
- LOG_ERR("glfs_set_volfile_server", ret);
-
- ret = glfs_set_logging (fs, logfile, 7);
- LOG_ERR("glfs_set_logging", ret);
-
- ret = glfs_init (fs);
- LOG_ERR("glfs_init", ret);
-
- /* Initialize fs2 */
- fs2 = glfs_new (volname);
- if (!fs2) {
- fprintf (stderr, "glfs_new fs2: returned NULL\n");
- return 1;
- }
-
- ret = glfs_set_volfile_server (fs2, "tcp", hostname, 24007);
- LOG_ERR("glfs_set_volfile_server-fs2", ret);
-
- ret = glfs_set_logging (fs2, logfile, 7);
- LOG_ERR("glfs_set_logging-fs2", ret);
-
- ret = glfs_init (fs2);
- LOG_ERR("glfs_init-fs2", ret);
-
- /* Register Upcalls */
- ret = glfs_upcall_register (fs, up_events, up_async_invalidate, NULL);
-
- /* Check if the return mask contains the event */
- if (!(ret & GLFS_EVENT_INODE_INVALIDATE)) {
- fprintf (stderr, "glfs_upcall_register return doesn't contain"
- " upcall event\n");
- return -1;
- }
-
- ret = glfs_upcall_register (fs2, up_events, up_async_invalidate, NULL);
-
- /* Check if the return mask contains the event */
- if ((ret < 0) || !(ret & GLFS_EVENT_INODE_INVALIDATE)) {
- fprintf (stderr, "glfs_upcall_register return doesn't contain"
- " upcall event\n");
- return -1;
+ glfs_t *fs_tmp = NULL;
+ glfs_t *fs_tmp2 = NULL;
+ glfs_fd_t *fd_tmp = NULL;
+ glfs_fd_t *fd_tmp2 = NULL;
+ char readbuf[32];
+ char *writebuf = NULL;
+ glfs_fd_t *fd = NULL;
+ glfs_fd_t *fd2 = NULL;
+ char *filename = "file_tmp";
+ int ret = -1;
+
+ if (!fs || !fs2)
+ return -1;
+
+ /* Create file from fs and open it from fs2 */
+ fd = glfs_creat(fs, filename, O_RDWR | O_SYNC, 0644);
+ if (fd <= 0) {
+ ret = -1;
+ LOG_ERR("glfs_creat", ret);
+ }
+
+ fd2 = glfs_open(fs2, filename, O_SYNC | O_RDWR | O_CREAT);
+ if (fd2 <= 0) {
+ ret = -1;
+ LOG_ERR("glfs_open-fs2", ret);
+ }
+
+ do {
+ if (cnt % 2) {
+ fd_tmp = fd;
+ fs_tmp = fs;
+ fd_tmp2 = fd2;
+ fs_tmp2 = fs2;
+ } else {
+ fd_tmp = fd2;
+ fs_tmp = fs2;
+ fd_tmp2 = fd;
+ fs_tmp2 = fs;
}
- /* Perform I/O */
- ret = perform_io (fs, fs2, cnt);
- LOG_ERR("perform_io", ret);
-
- if (upcall_recv == 0) {
- fprintf (stderr, "Upcalls are not received.\n");
+ /* WRITE on fd_tmp */
+ writebuf = malloc(10);
+ if (writebuf) {
+ memcpy(writebuf, "abcd", 4);
+ ret = glfs_write(fd_tmp, writebuf, 4, 0);
+ if (ret <= 0) {
ret = -1;
+ LOG_ERR("glfs_write", ret);
+ }
+ free(writebuf);
} else {
- fprintf (stderr, "Received %d upcalls as expected\n",
- upcall_recv);
- ret = 0;
+ fprintf(stderr, "Could not allocate writebuf\n");
+ return -1;
}
- sleep(5); /* to flush out previous upcalls if any */
+ /* READ on fd_tmp2 */
+ ret = glfs_lseek(fd_tmp2, 0, SEEK_SET);
+ LOG_ERR("glfs_lseek", ret);
- /* Now unregister and check there are no upcall events received */
- ret = glfs_upcall_unregister (fs, up_events);
+ memset(readbuf, 0, sizeof(readbuf));
+ ret = glfs_pread(fd_tmp2, readbuf, 4, 0, 0, NULL);
- /* Check if the return mask contains the event */
- if ((ret < 0) || !(ret & GLFS_EVENT_INODE_INVALIDATE)) {
- fprintf (stderr, "glfs_upcall_register return doesn't contain"
- " upcall event\n");
- return -1;
+ if (ret <= 0) {
+ ret = -1;
+ LOG_ERR("glfs_pread", ret);
}
- ret = glfs_upcall_unregister (fs2, up_events);
+ sleep(2);
+ } while (--cnt > 0);
- /* Check if the return mask contains the event */
- if ((ret < 0) || !(ret & GLFS_EVENT_INODE_INVALIDATE)) {
- fprintf (stderr, "glfs_upcall_register return doesn't contain"
- " upcall event\n");
- return -1;
- }
+ sleep(2);
- upcall_recv = 0;
+ ret = 0;
+err:
+ glfs_close(fd);
- ret = perform_io (fs, fs2, cnt);
- LOG_ERR("perform_io", ret);
-
- if (upcall_recv != 0) {
- fprintf (stderr, "%d upcalls received even after unregister.\n",
- upcall_recv);
- ret = -1;
- } else {
- fprintf (stderr, "Post unregister, no upcalls received as"
- " expected\n");
- ret = 0;
- }
+ glfs_close(fd2);
out:
- if (fs) {
- ret = glfs_fini(fs);
- fprintf (stderr, "glfs_fini(fs) returned %d\n", ret);
- }
-
- if (fs2) {
- ret = glfs_fini(fs2);
- fprintf (stderr, "glfs_fini(fs2) returned %d\n", ret);
- }
-
- if (ret)
- exit(1);
- exit(0);
+ return ret;
}
+int
+main(int argc, char *argv[])
+{
+ glfs_t *fs = NULL;
+ glfs_t *fs2 = NULL;
+ int ret = 0, i;
+ char *vol_id = NULL;
+ unsigned int cnt = 5;
+ struct glfs_upcall *cbk = NULL;
+ char *logfile = NULL;
+ char *volname = NULL;
+ char *hostname = NULL;
+ int up_events = GLFS_EVENT_ANY;
+
+ if (argc != 4) {
+ fprintf(stderr, "Invalid argument\n");
+ exit(1);
+ }
+
+ hostname = argv[1];
+ volname = argv[2];
+ logfile = argv[3];
+
+ /* Initialize fs */
+ fs = glfs_new(volname);
+ if (!fs) {
+ fprintf(stderr, "glfs_new: returned NULL\n");
+ return -1;
+ }
+
+ ret = glfs_set_volfile_server(fs, "tcp", hostname, 24007);
+ LOG_ERR("glfs_set_volfile_server", ret);
+
+ ret = glfs_set_logging(fs, logfile, 7);
+ LOG_ERR("glfs_set_logging", ret);
+
+ ret = glfs_init(fs);
+ LOG_ERR("glfs_init", ret);
+
+ /* Initialize fs2 */
+ fs2 = glfs_new(volname);
+ if (!fs2) {
+ fprintf(stderr, "glfs_new fs2: returned NULL\n");
+ return 1;
+ }
+
+ ret = glfs_set_volfile_server(fs2, "tcp", hostname, 24007);
+ LOG_ERR("glfs_set_volfile_server-fs2", ret);
+
+ ret = glfs_set_logging(fs2, logfile, 7);
+ LOG_ERR("glfs_set_logging-fs2", ret);
+
+ ret = glfs_init(fs2);
+ LOG_ERR("glfs_init-fs2", ret);
+
+ /* Register Upcalls */
+ ret = glfs_upcall_register(fs, up_events, up_async_invalidate, NULL);
+
+ /* Check if the return mask contains the event */
+ if (!(ret & GLFS_EVENT_INODE_INVALIDATE)) {
+ fprintf(stderr,
+ "glfs_upcall_register return doesn't contain"
+ " upcall event\n");
+ return -1;
+ }
+
+ ret = glfs_upcall_register(fs2, up_events, up_async_invalidate, NULL);
+
+ /* Check if the return mask contains the event */
+ if ((ret < 0) || !(ret & GLFS_EVENT_INODE_INVALIDATE)) {
+ fprintf(stderr,
+ "glfs_upcall_register return doesn't contain"
+ " upcall event\n");
+ return -1;
+ }
+
+ /* Perform I/O */
+ ret = perform_io(fs, fs2, cnt);
+ LOG_ERR("perform_io", ret);
+
+ if (upcall_recv == 0) {
+ fprintf(stderr, "Upcalls are not received.\n");
+ ret = -1;
+ } else {
+ fprintf(stderr, "Received %d upcalls as expected\n", upcall_recv);
+ ret = 0;
+ }
+
+ sleep(5); /* to flush out previous upcalls if any */
+
+ /* Now unregister and check there are no upcall events received */
+ ret = glfs_upcall_unregister(fs, up_events);
+
+ /* Check if the return mask contains the event */
+ if ((ret < 0) || !(ret & GLFS_EVENT_INODE_INVALIDATE)) {
+ fprintf(stderr,
+ "glfs_upcall_register return doesn't contain"
+ " upcall event\n");
+ return -1;
+ }
+
+ ret = glfs_upcall_unregister(fs2, up_events);
+
+ /* Check if the return mask contains the event */
+ if ((ret < 0) || !(ret & GLFS_EVENT_INODE_INVALIDATE)) {
+ fprintf(stderr,
+ "glfs_upcall_register return doesn't contain"
+ " upcall event\n");
+ return -1;
+ }
+
+ upcall_recv = 0;
+
+ ret = perform_io(fs, fs2, cnt);
+ LOG_ERR("perform_io", ret);
+
+ if (upcall_recv != 0) {
+ fprintf(stderr, "%d upcalls received even after unregister.\n",
+ upcall_recv);
+ ret = -1;
+ } else {
+ fprintf(stderr,
+ "Post unregister, no upcalls received as"
+ " expected\n");
+ ret = 0;
+ }
+out:
+ if (fs) {
+ ret = glfs_fini(fs);
+ fprintf(stderr, "glfs_fini(fs) returned %d\n", ret);
+ }
+
+ if (fs2) {
+ ret = glfs_fini(fs2);
+ fprintf(stderr, "glfs_fini(fs2) returned %d\n", ret);
+ }
+
+ if (ret)
+ exit(1);
+ exit(0);
+}
diff --git a/tests/basic/logchecks.c b/tests/basic/logchecks.c
index a40278b0d77..86891057230 100644
--- a/tests/basic/logchecks.c
+++ b/tests/basic/logchecks.c
@@ -18,191 +18,197 @@
#include "logchecks-messages.h"
#include "../../libglusterfs/src/logging.h"
-glusterfs_ctx_t *ctx = NULL;
+glusterfs_ctx_t *ctx = NULL;
-#define TEST_FILENAME "/tmp/logchecks.log"
-#define GF_LOG_CONTROL_FILE "/etc/glusterfs/logger.conf"
+#define TEST_FILENAME "/tmp/logchecks.log"
+#define GF_LOG_CONTROL_FILE "/etc/glusterfs/logger.conf"
int
go_log_vargs(gf_loglevel_t level, const char *fmt, ...)
{
- va_list ap;
+ va_list ap;
- va_start (ap, fmt);
- gf_msg_vplain (level, fmt, ap);
- va_end (ap);
+ va_start(ap, fmt);
+ gf_msg_vplain(level, fmt, ap);
+ va_end(ap);
- return 0;
+ return 0;
}
int
-go_log (void)
+go_log(void)
{
- /*** gf_msg ***/
- gf_msg ("logchecks", GF_LOG_INFO, 0, logchecks_msg_1);
- gf_msg ("logchecks", GF_LOG_INFO, 22, logchecks_msg_2, 42, "Forty-Two",
- 42);
- /* change criticality */
- gf_msg ("logchecks", GF_LOG_CRITICAL, 0, logchecks_msg_3);
- gf_msg ("logchecks", GF_LOG_CRITICAL, 22, logchecks_msg_4, 42,
- "Forty-Two", 42);
-
- /*** msg_nomem ***/
- gf_msg_nomem ("logchecks", GF_LOG_ALERT, 555);
- gf_msg_nomem ("logchecks", GF_LOG_INFO, 555);
-
- /*** msg_plain ***/
- gf_msg_plain (GF_LOG_INFO, "Informational: gf_msg_plain with"
- " args %d:%s:%x", 42, "Forty-Two", 42);
- gf_msg_plain (GF_LOG_ALERT, "Alert: gf_msg_plain with"
- " args %d:%s:%x", 42, "Forty-Two", 42);
-
- /*** msg_vplain ***/
- go_log_vargs (GF_LOG_INFO, "Informational: gf_msg_vplain: No args!!!");
- go_log_vargs (GF_LOG_INFO, "Informational: gf_msg_vplain: Some"
- " args %d:%s:%x", 42, "Forty-Two", 42);
- go_log_vargs (GF_LOG_INFO, "Critical: gf_msg_vplain: No args!!!");
- go_log_vargs (GF_LOG_INFO, "Critical: gf_msg_vplain: Some"
- " args %d:%s:%x", 42, "Forty-Two", 42);
-
- /*** msg_plain_nomem ***/
- gf_msg_plain_nomem (GF_LOG_INFO, "Informational: gf_msg_plain_nomem");
- gf_msg_plain_nomem (GF_LOG_ALERT, "Alert: gf_msg_plain_nomem");
-
- /*** msg_backtrace_nomem ***/
- // TODO: Need to create a stack depth and then call
- gf_msg_backtrace_nomem (GF_LOG_INFO, 5);
- gf_msg_backtrace_nomem (GF_LOG_ALERT, 5);
-
- /*** gf_msg_callingfn ***/
- // TODO: Need to create a stack depth and then call
- gf_msg_callingfn ("logchecks", GF_LOG_INFO, 0, logchecks_msg_7);
- gf_msg_callingfn ("logchecks", GF_LOG_INFO, 0, logchecks_msg_8, 42,
- "Forty-Two", 42);
- gf_msg_callingfn ("logchecks", GF_LOG_CRITICAL, 0, logchecks_msg_9);
- gf_msg_callingfn ("logchecks", GF_LOG_CRITICAL, 0, logchecks_msg_10, 42,
- "Forty-Two", 42);
-
- /*** gf_msg_debug ***/
- gf_msg_debug ("logchecks", 0, "Debug: Hello World!!!");
- gf_msg_debug ("logchecks", 22, "Debug: With args %d:%s:%x", 42,
- "Forty-Two", 42);
-
- /*** gf_msg_trace ***/
- gf_msg_trace ("logchecks", 0, "Trace: Hello World!!!");
- gf_msg_trace ("logchecks", 22, "Trace: With args %d:%s:%x", 42,
- "Forty-Two", 42);
-
- /*** gf_msg_backtrace ***/
- // TODO: Test with lower callstr values to check truncation
-
- return 0;
+ /*** gf_msg ***/
+ gf_msg("logchecks", GF_LOG_INFO, 0, logchecks_msg_1);
+ gf_msg("logchecks", GF_LOG_INFO, 22, logchecks_msg_2, 42, "Forty-Two", 42);
+ /* change criticality */
+ gf_msg("logchecks", GF_LOG_CRITICAL, 0, logchecks_msg_3);
+ gf_msg("logchecks", GF_LOG_CRITICAL, 22, logchecks_msg_4, 42, "Forty-Two",
+ 42);
+
+ /*** msg_nomem ***/
+ gf_msg_nomem("logchecks", GF_LOG_ALERT, 555);
+ gf_msg_nomem("logchecks", GF_LOG_INFO, 555);
+
+ /*** msg_plain ***/
+ gf_msg_plain(GF_LOG_INFO,
+ "Informational: gf_msg_plain with"
+ " args %d:%s:%x",
+ 42, "Forty-Two", 42);
+ gf_msg_plain(GF_LOG_ALERT,
+ "Alert: gf_msg_plain with"
+ " args %d:%s:%x",
+ 42, "Forty-Two", 42);
+
+ /*** msg_vplain ***/
+ go_log_vargs(GF_LOG_INFO, "Informational: gf_msg_vplain: No args!!!");
+ go_log_vargs(GF_LOG_INFO,
+ "Informational: gf_msg_vplain: Some"
+ " args %d:%s:%x",
+ 42, "Forty-Two", 42);
+ go_log_vargs(GF_LOG_INFO, "Critical: gf_msg_vplain: No args!!!");
+ go_log_vargs(GF_LOG_INFO,
+ "Critical: gf_msg_vplain: Some"
+ " args %d:%s:%x",
+ 42, "Forty-Two", 42);
+
+ /*** msg_plain_nomem ***/
+ gf_msg_plain_nomem(GF_LOG_INFO, "Informational: gf_msg_plain_nomem");
+ gf_msg_plain_nomem(GF_LOG_ALERT, "Alert: gf_msg_plain_nomem");
+
+ /*** msg_backtrace_nomem ***/
+ // TODO: Need to create a stack depth and then call
+ gf_msg_backtrace_nomem(GF_LOG_INFO, 5);
+ gf_msg_backtrace_nomem(GF_LOG_ALERT, 5);
+
+ /*** gf_msg_callingfn ***/
+ // TODO: Need to create a stack depth and then call
+ gf_msg_callingfn("logchecks", GF_LOG_INFO, 0, logchecks_msg_7);
+ gf_msg_callingfn("logchecks", GF_LOG_INFO, 0, logchecks_msg_8, 42,
+ "Forty-Two", 42);
+ gf_msg_callingfn("logchecks", GF_LOG_CRITICAL, 0, logchecks_msg_9);
+ gf_msg_callingfn("logchecks", GF_LOG_CRITICAL, 0, logchecks_msg_10, 42,
+ "Forty-Two", 42);
+
+ /*** gf_msg_debug ***/
+ gf_msg_debug("logchecks", 0, "Debug: Hello World!!!");
+ gf_msg_debug("logchecks", 22, "Debug: With args %d:%s:%x", 42, "Forty-Two",
+ 42);
+
+ /*** gf_msg_trace ***/
+ gf_msg_trace("logchecks", 0, "Trace: Hello World!!!");
+ gf_msg_trace("logchecks", 22, "Trace: With args %d:%s:%x", 42, "Forty-Two",
+ 42);
+
+ /*** gf_msg_backtrace ***/
+ // TODO: Test with lower callstr values to check truncation
+
+ return 0;
}
int
-main (int argc, char *argv[])
+main(int argc, char *argv[])
{
- int ret = -1;
-
- unlink (GF_LOG_CONTROL_FILE);
- creat (GF_LOG_CONTROL_FILE, O_RDONLY);
- ctx = glusterfs_ctx_new ();
- if (!ctx)
- return -1;
-
- ret = glusterfs_globals_init (ctx);
- if (ret) {
- printf ("Error from glusterfs_globals_init [%s]\n",
- strerror (errno));
- return ret;
- }
-
- /* Pre init test, message should not be printed */
- gf_msg ("logchecks", GF_LOG_ALERT, 0, logchecks_msg_19);
-
- THIS->ctx = ctx;
-
- /* TEST 1: messages before initializing the log, goes to stderr
- * and syslog based on criticality */
- gf_msg ("logchecks", GF_LOG_ALERT, 0, logchecks_msg_11);
- gf_msg ("logchecks", GF_LOG_ALERT, 0, logchecks_msg_12);
- go_log ();
- gf_msg ("logchecks", GF_LOG_ALERT, 0, logchecks_msg_11);
-
- /* TEST 2: messages post initialization, goes to glusterlog and
- * syslog based on severity */
- ret = gf_log_init(ctx, TEST_FILENAME, "logchecks");
- if (ret != 0) {
- printf ("Error from gf_log_init [%s]\n", strerror (errno));
- return -1;
- }
- gf_msg ("logchecks", GF_LOG_ALERT, 0, logchecks_msg_11);
- gf_msg ("logchecks", GF_LOG_ALERT, 0, logchecks_msg_13);
- go_log ();
- gf_msg ("logchecks", GF_LOG_ALERT, 0, logchecks_msg_11);
-
- /* TEST 3: Test rotation */
- gf_msg ("logchecks", GF_LOG_ALERT, 0, logchecks_msg_11);
- gf_log_logrotate (0);
- gf_msg ("logchecks", GF_LOG_CRITICAL, 0, logchecks_msg_5);
- gf_msg ("logchecks", GF_LOG_ALERT, 0, logchecks_msg_11);
-
- /* TEST 4: Check flush, nothing noticeable should occur :) */
- gf_msg ("logchecks", GF_LOG_ALERT, 0, logchecks_msg_11);
- gf_log_flush ();
- gf_msg ("logchecks", GF_LOG_CRITICAL, 0, logchecks_msg_6);
- gf_msg ("logchecks", GF_LOG_ALERT, 0, logchecks_msg_11);
-
- /* TEST 5: Change format */
- gf_msg ("logchecks", GF_LOG_ALERT, 0, logchecks_msg_11);
- gf_log_set_logformat (gf_logformat_traditional);
- gf_msg ("logchecks", GF_LOG_ALERT, 0, logchecks_msg_14);
- go_log ();
- gf_msg ("logchecks", GF_LOG_ALERT, 0, logchecks_msg_11);
-
- /* TEST 6: Change level */
- gf_msg ("logchecks", GF_LOG_ALERT, 0, logchecks_msg_11);
- gf_log_set_loglevel (ctx, GF_LOG_CRITICAL);
- gf_msg ("logchecks", GF_LOG_ALERT, 0, logchecks_msg_15);
- go_log ();
- gf_msg ("logchecks", GF_LOG_ALERT, 0, logchecks_msg_11);
-
- /* Reset to run with syslog */
- gf_log_set_logformat (gf_logformat_withmsgid);
- gf_log_set_loglevel (ctx, GF_LOG_INFO);
-
- /* Run tests with logger changed to syslog */
- /* TEST 7: No more gluster logs */
- gf_msg ("logchecks", GF_LOG_ALERT, 0, logchecks_msg_11);
- gf_log_set_logger (gf_logger_syslog);
- gf_msg ("logchecks", GF_LOG_ALERT, 0, logchecks_msg_16);
- go_log ();
- gf_msg ("logchecks", GF_LOG_ALERT, 0, logchecks_msg_11);
-
- /* TEST 8: Change format */
- gf_msg ("logchecks", GF_LOG_ALERT, 0, logchecks_msg_11);
- gf_log_set_logformat (gf_logformat_traditional);
- gf_msg ("logchecks", GF_LOG_ALERT, 0, logchecks_msg_14);
- go_log ();
- gf_msg ("logchecks", GF_LOG_ALERT, 0, logchecks_msg_11);
-
- /* TEST 9: Change level */
- gf_msg ("logchecks", GF_LOG_ALERT, 0, logchecks_msg_11);
- gf_log_set_loglevel (ctx, GF_LOG_CRITICAL);
- gf_msg ("logchecks", GF_LOG_ALERT, 0, logchecks_msg_15);
- go_log ();
- gf_msg ("logchecks", GF_LOG_ALERT, 0, logchecks_msg_11);
-
- // TODO: signal crash prints, but not yet feasible here
- // TODO: Graph printing
- // TODO: Multi threaded logging
-
- /* Close out the logging */
- gf_log_fini (ctx);
- gf_log_globals_fini ();
-
- unlink (GF_LOG_CONTROL_FILE);
- unlink (TEST_FILENAME);
-
- return 0;
+ int ret = -1;
+
+ unlink(GF_LOG_CONTROL_FILE);
+ creat(GF_LOG_CONTROL_FILE, O_RDONLY);
+ ctx = glusterfs_ctx_new();
+ if (!ctx)
+ return -1;
+
+ ret = glusterfs_globals_init(ctx);
+ if (ret) {
+ printf("Error from glusterfs_globals_init [%s]\n", strerror(errno));
+ return ret;
+ }
+
+ /* Pre init test, message should not be printed */
+ gf_msg("logchecks", GF_LOG_ALERT, 0, logchecks_msg_19);
+
+ THIS->ctx = ctx;
+
+ /* TEST 1: messages before initializing the log, goes to stderr
+ * and syslog based on criticality */
+ gf_msg("logchecks", GF_LOG_ALERT, 0, logchecks_msg_11);
+ gf_msg("logchecks", GF_LOG_ALERT, 0, logchecks_msg_12);
+ go_log();
+ gf_msg("logchecks", GF_LOG_ALERT, 0, logchecks_msg_11);
+
+ /* TEST 2: messages post initialization, goes to glusterlog and
+ * syslog based on severity */
+ ret = gf_log_init(ctx, TEST_FILENAME, "logchecks");
+ if (ret != 0) {
+ printf("Error from gf_log_init [%s]\n", strerror(errno));
+ return -1;
+ }
+ gf_msg("logchecks", GF_LOG_ALERT, 0, logchecks_msg_11);
+ gf_msg("logchecks", GF_LOG_ALERT, 0, logchecks_msg_13);
+ go_log();
+ gf_msg("logchecks", GF_LOG_ALERT, 0, logchecks_msg_11);
+
+ /* TEST 3: Test rotation */
+ gf_msg("logchecks", GF_LOG_ALERT, 0, logchecks_msg_11);
+ gf_log_logrotate(0);
+ gf_msg("logchecks", GF_LOG_CRITICAL, 0, logchecks_msg_5);
+ gf_msg("logchecks", GF_LOG_ALERT, 0, logchecks_msg_11);
+
+ /* TEST 4: Check flush, nothing noticeable should occur :) */
+ gf_msg("logchecks", GF_LOG_ALERT, 0, logchecks_msg_11);
+ gf_log_flush();
+ gf_msg("logchecks", GF_LOG_CRITICAL, 0, logchecks_msg_6);
+ gf_msg("logchecks", GF_LOG_ALERT, 0, logchecks_msg_11);
+
+ /* TEST 5: Change format */
+ gf_msg("logchecks", GF_LOG_ALERT, 0, logchecks_msg_11);
+ gf_log_set_logformat(gf_logformat_traditional);
+ gf_msg("logchecks", GF_LOG_ALERT, 0, logchecks_msg_14);
+ go_log();
+ gf_msg("logchecks", GF_LOG_ALERT, 0, logchecks_msg_11);
+
+ /* TEST 6: Change level */
+ gf_msg("logchecks", GF_LOG_ALERT, 0, logchecks_msg_11);
+ gf_log_set_loglevel(ctx, GF_LOG_CRITICAL);
+ gf_msg("logchecks", GF_LOG_ALERT, 0, logchecks_msg_15);
+ go_log();
+ gf_msg("logchecks", GF_LOG_ALERT, 0, logchecks_msg_11);
+
+ /* Reset to run with syslog */
+ gf_log_set_logformat(gf_logformat_withmsgid);
+ gf_log_set_loglevel(ctx, GF_LOG_INFO);
+
+ /* Run tests with logger changed to syslog */
+ /* TEST 7: No more gluster logs */
+ gf_msg("logchecks", GF_LOG_ALERT, 0, logchecks_msg_11);
+ gf_log_set_logger(gf_logger_syslog);
+ gf_msg("logchecks", GF_LOG_ALERT, 0, logchecks_msg_16);
+ go_log();
+ gf_msg("logchecks", GF_LOG_ALERT, 0, logchecks_msg_11);
+
+ /* TEST 8: Change format */
+ gf_msg("logchecks", GF_LOG_ALERT, 0, logchecks_msg_11);
+ gf_log_set_logformat(gf_logformat_traditional);
+ gf_msg("logchecks", GF_LOG_ALERT, 0, logchecks_msg_14);
+ go_log();
+ gf_msg("logchecks", GF_LOG_ALERT, 0, logchecks_msg_11);
+
+ /* TEST 9: Change level */
+ gf_msg("logchecks", GF_LOG_ALERT, 0, logchecks_msg_11);
+ gf_log_set_loglevel(ctx, GF_LOG_CRITICAL);
+ gf_msg("logchecks", GF_LOG_ALERT, 0, logchecks_msg_15);
+ go_log();
+ gf_msg("logchecks", GF_LOG_ALERT, 0, logchecks_msg_11);
+
+ // TODO: signal crash prints, but not yet feasible here
+ // TODO: Graph printing
+ // TODO: Multi threaded logging
+
+ /* Close out the logging */
+ gf_log_fini(ctx);
+ gf_log_globals_fini();
+
+ unlink(GF_LOG_CONTROL_FILE);
+ unlink(TEST_FILENAME);
+
+ return 0;
}
diff --git a/tests/basic/posix/zero-fill-enospace.c b/tests/basic/posix/zero-fill-enospace.c
index 7c0d31128b3..1371ff59a5f 100644
--- a/tests/basic/posix/zero-fill-enospace.c
+++ b/tests/basic/posix/zero-fill-enospace.c
@@ -3,62 +3,64 @@
#include <glusterfs/api/glfs-handles.h>
int
-main (int argc, char *argv[])
+main(int argc, char *argv[])
{
- glfs_t *fs = NULL;
- glfs_fd_t *fd = NULL;
- int ret = 1;
- int size = 0;
+ glfs_t *fs = NULL;
+ glfs_fd_t *fd = NULL;
+ int ret = 1;
+ int size = 0;
- if (argc != 6) {
- fprintf (stderr, "Syntax: %s <host> <volname> <file-path> <log-file> <size>\n", argv[0]);
- return 1;
- }
+ if (argc != 6) {
+ fprintf(stderr,
+ "Syntax: %s <host> <volname> <file-path> <log-file> <size>\n",
+ argv[0]);
+ return 1;
+ }
- fs = glfs_new (argv[2]);
- if (!fs) {
- fprintf (stderr, "glfs_new: returned NULL\n");
- 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, argv[4], 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;
- }
+ 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, argv[4], 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);
- if (fd == NULL) {
- fprintf (stderr, "glfs_open: returned NULL\n");
- goto out;
- }
+ fd = glfs_open(fs, argv[3], O_RDWR);
+ if (fd == NULL) {
+ fprintf(stderr, "glfs_open: returned NULL\n");
+ goto out;
+ }
- size = atoi(argv[5]);
- if (size < 0) {
- fprintf (stderr, "Wrong size %s", argv[5]);
- goto out;
- }
- ret = glfs_zerofill (fd, 0, atoi(argv[5]));
- if (ret <= 0) {
- fprintf (stderr, "glfs_zerofill: returned %d\n", ret);
- goto out;
- }
+ size = atoi(argv[5]);
+ if (size < 0) {
+ fprintf(stderr, "Wrong size %s", argv[5]);
+ goto out;
+ }
+ ret = glfs_zerofill(fd, 0, atoi(argv[5]));
+ if (ret <= 0) {
+ fprintf(stderr, "glfs_zerofill: returned %d\n", ret);
+ goto out;
+ }
- ret = 0;
+ ret = 0;
out:
- if (fd)
- glfs_close(fd);
- glfs_fini (fs);
- return ret;
+ if (fd)
+ glfs_close(fd);
+ glfs_fini(fs);
+ return ret;
}
diff --git a/tests/basic/quota.c b/tests/basic/quota.c
index f69b0ea9bc5..809ceb8e54c 100644
--- a/tests/basic/quota.c
+++ b/tests/basic/quota.c
@@ -8,83 +8,82 @@
#include <unistd.h>
ssize_t
-nwrite (int fd, const void *buf, size_t count)
+nwrite(int fd, const void *buf, size_t count)
{
- ssize_t ret = 0;
- ssize_t written = 0;
+ ssize_t ret = 0;
+ ssize_t written = 0;
- for (written = 0; written != count; written += ret) {
- ret = write (fd, buf + written, count - written);
- if (ret < 0) {
- if (errno == EINTR)
- ret = 0;
- else
- goto out;
- }
+ for (written = 0; written != count; written += ret) {
+ ret = write(fd, buf + written, count - written);
+ if (ret < 0) {
+ if (errno == EINTR)
+ ret = 0;
+ else
+ goto out;
}
+ }
- ret = written;
+ ret = written;
out:
- return ret;
+ return ret;
}
int
-file_write (char *filename, int bs, int count)
+file_write(char *filename, int bs, int count)
{
- int fd = 0;
- int ret = -1;
- int i = 0;
- char *buf = NULL;
+ int fd = 0;
+ int ret = -1;
+ int i = 0;
+ char *buf = NULL;
- bs = bs * 1024;
+ bs = bs * 1024;
- buf = (char *) malloc (bs);
- if (buf == NULL)
- goto out;
+ buf = (char *)malloc(bs);
+ if (buf == NULL)
+ goto out;
- memset (buf, 0, bs);
+ memset(buf, 0, bs);
- fd = open (filename, O_RDWR|O_CREAT|O_SYNC, 0600);
- while (i < count) {
- ret = nwrite(fd, buf, bs);
- if (ret == -1) {
- close (fd);
- goto out;
- }
- i++;
+ fd = open(filename, O_RDWR | O_CREAT | O_SYNC, 0600);
+ while (i < count) {
+ ret = nwrite(fd, buf, bs);
+ if (ret == -1) {
+ close(fd);
+ goto out;
}
+ i++;
+ }
- ret = fdatasync(fd);
- if (ret) {
- close (fd);
- goto out;
- }
+ ret = fdatasync(fd);
+ if (ret) {
+ close(fd);
+ goto out;
+ }
- ret = close(fd);
- if (ret)
- goto out;
+ ret = close(fd);
+ if (ret)
+ goto out;
- ret = 0;
+ ret = 0;
out:
- if (buf)
- free (buf);
- return ret;
+ if (buf)
+ free(buf);
+ return ret;
}
int
-main (int argc, char **argv)
+main(int argc, char **argv)
{
- if (argc != 4) {
- printf("Usage: %s <filename> <block size in k> <count>\n",
- argv[0]);
- return EXIT_FAILURE;
- }
+ if (argc != 4) {
+ printf("Usage: %s <filename> <block size in k> <count>\n", argv[0]);
+ return EXIT_FAILURE;
+ }
- if (file_write (argv[1], atoi(argv[2]), atoi(argv[3])) < 0) {
- perror ("write failed");
- return EXIT_FAILURE;
- }
+ if (file_write(argv[1], atoi(argv[2]), atoi(argv[3])) < 0) {
+ perror("write failed");
+ return EXIT_FAILURE;
+ }
- return EXIT_SUCCESS;
+ return EXIT_SUCCESS;
}
diff --git a/tests/basic/tier/file_lock.c b/tests/basic/tier/file_lock.c
index 730cca92e42..20fdbc0f668 100644
--- a/tests/basic/tier/file_lock.c
+++ b/tests/basic/tier/file_lock.c
@@ -3,73 +3,70 @@
#include <unistd.h>
#include <fcntl.h>
-
-void usage (void)
+void
+usage(void)
{
-
- printf ("Usage: testlock <filepath> [R|W]\n");
- return;
+ printf("Usage: testlock <filepath> [R|W]\n");
+ return;
}
-
-int main (int argc, char *argv[])
+int
+main(int argc, char *argv[])
{
- char *file_path = NULL;
- int fd = -1;
- struct flock lock = {0};
- int ret = -1;
- int c = 0;
-
- if (argc != 3) {
- usage ();
- exit (1);
- }
-
- file_path = argv[1];
- fd = open (file_path, O_RDWR);
-
- if (-1 == fd) {
- printf ("Failed to open file %s. %m\n", file_path);
- exit (1);
- }
-
- /* TODO: Check for invalid input*/
-
- if (!strcmp (argv[2], "W")) {
- lock.l_type = F_WRLCK;
- printf("Taking write lock\n");
-
- } else {
- lock.l_type = F_RDLCK;
- printf("Taking read lock\n");
- }
-
- lock.l_whence = SEEK_SET;
- lock.l_start = 0;
- lock.l_len = 0;
- lock.l_pid = getpid ();
-
-
- printf ("Acquiring lock on %s\n", file_path);
- ret = fcntl (fd, F_SETLK, &lock);
- if (ret) {
- printf ("Failed to acquire lock on %s (%m)\n", file_path);
- close (fd);
- exit (1);
- }
-
- sleep(10);
-
- /*Unlock*/
-
- printf ("Releasing lock on %s\n", file_path);
- lock.l_type = F_UNLCK;
- ret = fcntl (fd, F_SETLK, &lock);
- if (ret) {
- printf ("Failed to release lock on %s (%m)\n", file_path);
- }
-
- close (fd);
- return ret;
-
+ char *file_path = NULL;
+ int fd = -1;
+ struct flock lock = {0};
+ int ret = -1;
+ int c = 0;
+
+ if (argc != 3) {
+ usage();
+ exit(1);
+ }
+
+ file_path = argv[1];
+ fd = open(file_path, O_RDWR);
+
+ if (-1 == fd) {
+ printf("Failed to open file %s. %m\n", file_path);
+ exit(1);
+ }
+
+ /* TODO: Check for invalid input*/
+
+ if (!strcmp(argv[2], "W")) {
+ lock.l_type = F_WRLCK;
+ printf("Taking write lock\n");
+
+ } else {
+ lock.l_type = F_RDLCK;
+ printf("Taking read lock\n");
+ }
+
+ lock.l_whence = SEEK_SET;
+ lock.l_start = 0;
+ lock.l_len = 0;
+ lock.l_pid = getpid();
+
+ printf("Acquiring lock on %s\n", file_path);
+ ret = fcntl(fd, F_SETLK, &lock);
+ if (ret) {
+ printf("Failed to acquire lock on %s (%m)\n", file_path);
+ close(fd);
+ exit(1);
+ }
+
+ sleep(10);
+
+ /*Unlock*/
+
+ printf("Releasing lock on %s\n", file_path);
+ lock.l_type = F_UNLCK;
+ ret = fcntl(fd, F_SETLK, &lock);
+ if (ret) {
+ printf("Failed to release lock on %s (%m)\n", file_path);
+ }
+
+ close(fd);
+ return ret;
}