summaryrefslogtreecommitdiffstats
path: root/tests/bugs
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/bugs
parent45a71c0548b6fd2c757aa2e7b7671a1411948894 (diff)
Land part 2 of clang-format changes
Change-Id: Ia84cc24c8924e6d22d02ac15f611c10e26db99b4 Signed-off-by: Nigel Babu <nigelb@redhat.com>
Diffstat (limited to 'tests/bugs')
-rw-r--r--tests/bugs/access-control/bug-1051896.c147
-rw-r--r--tests/bugs/access-control/bug-1387241.c17
-rw-r--r--tests/bugs/cli/bug-1169302.c127
-rw-r--r--tests/bugs/core/bug-834465.c85
-rw-r--r--tests/bugs/distribute/bug-1193636.c100
-rw-r--r--tests/bugs/distribute/bug-860663.c48
-rw-r--r--tests/bugs/ec/bug-1161886.c84
-rw-r--r--tests/bugs/fuse/bug-1126048.c48
-rw-r--r--tests/bugs/gfapi/bug-1093594.c508
-rw-r--r--tests/bugs/gfapi/bug-1319374.c220
-rw-r--r--tests/bugs/gfapi/bug-1447266/1460514.c259
-rw-r--r--tests/bugs/gfapi/bug-1447266/bug-1447266.c194
-rw-r--r--tests/bugs/gfapi/glfs_vol_set_IO_ERR.c260
-rw-r--r--tests/bugs/glusterd/bug-824753-file-locker.c14
-rw-r--r--tests/bugs/glusterfs-server/bug-905864.c99
-rw-r--r--tests/bugs/glusterfs/getlk_owner.c96
-rw-r--r--tests/bugs/io-cache/bug-858242.c113
-rw-r--r--tests/bugs/io-cache/bug-read-hang.c200
-rw-r--r--tests/bugs/nfs/bug-1210338.c27
-rw-r--r--tests/bugs/posix/bug-1175711.c40
-rw-r--r--tests/bugs/posix/disallow-gfid-volumeid-fremovexattr.c160
-rw-r--r--tests/bugs/protocol/bug-808400-fcntl.c191
-rw-r--r--tests/bugs/protocol/bug-808400-flock.c124
-rw-r--r--tests/bugs/quick-read/bz1523599/test_bz1523599.c322
-rw-r--r--tests/bugs/readdir-ahead/bug-1390050.c98
-rw-r--r--tests/bugs/replicate/bug-1250170-fsync.c78
-rw-r--r--tests/bugs/shard/bug-shard-discard.c97
-rw-r--r--tests/bugs/shard/bug-shard-zerofill.c101
-rw-r--r--tests/bugs/shard/shard-append-test.c276
-rw-r--r--tests/bugs/shard/shard-fallocate.c151
-rw-r--r--tests/bugs/write-behind/bug-1058663.c158
-rw-r--r--tests/bugs/write-behind/bug-1279730.c232
32 files changed, 2366 insertions, 2308 deletions
diff --git a/tests/bugs/access-control/bug-1051896.c b/tests/bugs/access-control/bug-1051896.c
index 27aa1559453..31799d97a71 100644
--- a/tests/bugs/access-control/bug-1051896.c
+++ b/tests/bugs/access-control/bug-1051896.c
@@ -13,85 +13,82 @@
#include <utime.h>
#include <sys/acl.h>
-int do_setfacl(const char *path, const char *options, const char *textacl)
+int
+do_setfacl(const char *path, const char *options, const char *textacl)
{
- int r;
- int type;
- acl_t acl;
- int dob;
- int dok;
- int dom;
- struct stat st;
- char textmode[30];
+ int r;
+ int type;
+ acl_t acl;
+ int dob;
+ int dok;
+ int dom;
+ struct stat st;
+ char textmode[30];
- r = 0;
- dob = strchr(options, 'b') != (char *)NULL;
- dok = strchr(options, 'k') != (char *)NULL;
- dom = strchr(options, 'm') != (char *)NULL;
- if ((dom && !textacl)
- || (!dom && (textacl || (!dok && !dob) ||
- strchr(options, 'd')))) {
- errno = EBADRQC; /* "bad request" */
- r = -1;
- } else {
- if (dob || dok) {
- r = acl_delete_def_file(path);
- }
- if (dob && !r) {
- if (!stat(path, &st)) {
- sprintf(textmode,
- "u::%c%c%c,g::%c%c%c,o::%c%c%c",
- (st.st_mode & 0400 ? 'r' : '-'),
- (st.st_mode & 0200 ? 'w' : '-'),
- (st.st_mode & 0100 ? 'x' : '-'),
- (st.st_mode & 0040 ? 'r' : '-'),
- (st.st_mode & 0020 ? 'w' : '-'),
- (st.st_mode & 0010 ? 'x' : '-'),
- (st.st_mode & 004 ? 'r' : '-'),
- (st.st_mode & 002 ? 'w' : '-'),
- (st.st_mode & 001 ? 'x' : '-'));
- acl = acl_from_text(textmode);
- if (acl) {
- r = acl_set_file(path,
- ACL_TYPE_ACCESS, acl);
- acl_free(acl);
- } else
- r = -1;
- } else
- r = -1;
- }
- if (!r && dom) {
- if (strchr(options, 'd'))
- type = ACL_TYPE_DEFAULT;
- else
- type = ACL_TYPE_ACCESS;
- acl = acl_from_text(textacl);
- if (acl) {
- r = acl_set_file(path, type, acl);
- acl_free(acl);
- } else
- r = -1;
- }
- }
- if (r)
- r = -errno;
- return r;
+ r = 0;
+ dob = strchr(options, 'b') != (char *)NULL;
+ dok = strchr(options, 'k') != (char *)NULL;
+ dom = strchr(options, 'm') != (char *)NULL;
+ if ((dom && !textacl) ||
+ (!dom && (textacl || (!dok && !dob) || strchr(options, 'd')))) {
+ errno = EBADRQC; /* "bad request" */
+ r = -1;
+ } else {
+ if (dob || dok) {
+ r = acl_delete_def_file(path);
+ }
+ if (dob && !r) {
+ if (!stat(path, &st)) {
+ sprintf(textmode, "u::%c%c%c,g::%c%c%c,o::%c%c%c",
+ (st.st_mode & 0400 ? 'r' : '-'),
+ (st.st_mode & 0200 ? 'w' : '-'),
+ (st.st_mode & 0100 ? 'x' : '-'),
+ (st.st_mode & 0040 ? 'r' : '-'),
+ (st.st_mode & 0020 ? 'w' : '-'),
+ (st.st_mode & 0010 ? 'x' : '-'),
+ (st.st_mode & 004 ? 'r' : '-'),
+ (st.st_mode & 002 ? 'w' : '-'),
+ (st.st_mode & 001 ? 'x' : '-'));
+ acl = acl_from_text(textmode);
+ if (acl) {
+ r = acl_set_file(path, ACL_TYPE_ACCESS, acl);
+ acl_free(acl);
+ } else
+ r = -1;
+ } else
+ r = -1;
+ }
+ if (!r && dom) {
+ if (strchr(options, 'd'))
+ type = ACL_TYPE_DEFAULT;
+ else
+ type = ACL_TYPE_ACCESS;
+ acl = acl_from_text(textacl);
+ if (acl) {
+ r = acl_set_file(path, type, acl);
+ acl_free(acl);
+ } else
+ r = -1;
+ }
+ }
+ if (r)
+ r = -errno;
+ return r;
}
-
-int main(int argc, char *argv[])
+int
+main(int argc, char *argv[])
{
- int rc = 0;
+ int rc = 0;
- if (argc != 4) {
- fprintf(stderr,
- "usage: ./setfacl_test <path> <options> <textacl>\n");
- return 0;
- }
- rc = do_setfacl(argv[1], argv[2], argv[3]);
- if (rc != 0) {
- fprintf(stderr, "do_setfacl failed: %s\n", strerror(errno));
- return rc;
- }
- return 0;
+ if (argc != 4) {
+ fprintf(stderr, "usage: ./setfacl_test <path> <options> <textacl>\n");
+ return 0;
+ }
+ rc = do_setfacl(argv[1], argv[2], argv[3]);
+ if (rc != 0) {
+ fprintf(stderr, "do_setfacl failed: %s\n", strerror(errno));
+ return rc;
+ }
+ return 0;
}
diff --git a/tests/bugs/access-control/bug-1387241.c b/tests/bugs/access-control/bug-1387241.c
index 04e0d6ea11f..e2e843a2fda 100644
--- a/tests/bugs/access-control/bug-1387241.c
+++ b/tests/bugs/access-control/bug-1387241.c
@@ -3,15 +3,16 @@
#include <unistd.h>
#include <fcntl.h>
-int main(int argc, char *argv[])
+int
+main(int argc, char *argv[])
{
- int ret = EXIT_FAILURE;
- int fd = open(argv[1], O_RDONLY|O_TRUNC);
+ int ret = EXIT_FAILURE;
+ int fd = open(argv[1], O_RDONLY | O_TRUNC);
- if (fd) {
- ret = EXIT_SUCCESS;
- close(fd);
- }
+ if (fd) {
+ ret = EXIT_SUCCESS;
+ close(fd);
+ }
- return ret;
+ return ret;
}
diff --git a/tests/bugs/cli/bug-1169302.c b/tests/bugs/cli/bug-1169302.c
index aa9f950abf2..7c6b5fbf856 100644
--- a/tests/bugs/cli/bug-1169302.c
+++ b/tests/bugs/cli/bug-1169302.c
@@ -7,72 +7,73 @@
int keep_running = 1;
-void stop_running(int sig)
+void
+stop_running(int sig)
{
- if (sig == SIGTERM)
- keep_running = 0;
+ if (sig == SIGTERM)
+ keep_running = 0;
}
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 *logfile = NULL;
- char *host = NULL;
-
- if (argc != 5) {
- return -1;
- }
-
- host = argv[2];
- logfile = argv[3];
- filename = argv[4];
-
- /* setup signal handler for exiting */
- signal (SIGTERM, stop_running);
-
- fs = glfs_new (argv[1]);
- if (!fs) {
- return -1;
- }
-
- ret = glfs_set_volfile_server (fs, "tcp", host, 24007);
- if (ret < 0) {
- return -1;
- }
-
- ret = glfs_set_logging (fs, logfile, 7);
- if (ret < 0) {
- return -1;
- }
-
- ret = glfs_init (fs);
- if (ret < 0) {
- return -1;
- }
-
- fd = glfs_creat (fs, filename, O_RDWR, 0644);
- if (!fd) {
- return -1;
- }
-
- /* sleep until SIGTERM has been received */
- while (keep_running) {
- sleep (1);
- }
-
- ret = glfs_close (fd);
- if (ret < 0) {
- return -1;
- }
-
- ret = glfs_fini (fs);
- if (ret < 0) {
- return -1;
- }
-
- return 0;
+ glfs_t *fs = NULL;
+ int ret = 0;
+ glfs_fd_t *fd = NULL;
+ char *filename = NULL;
+ char *logfile = NULL;
+ char *host = NULL;
+
+ if (argc != 5) {
+ return -1;
+ }
+
+ host = argv[2];
+ logfile = argv[3];
+ filename = argv[4];
+
+ /* setup signal handler for exiting */
+ signal(SIGTERM, stop_running);
+
+ fs = glfs_new(argv[1]);
+ if (!fs) {
+ return -1;
+ }
+
+ ret = glfs_set_volfile_server(fs, "tcp", host, 24007);
+ if (ret < 0) {
+ return -1;
+ }
+
+ ret = glfs_set_logging(fs, logfile, 7);
+ if (ret < 0) {
+ return -1;
+ }
+
+ ret = glfs_init(fs);
+ if (ret < 0) {
+ return -1;
+ }
+
+ fd = glfs_creat(fs, filename, O_RDWR, 0644);
+ if (!fd) {
+ return -1;
+ }
+
+ /* sleep until SIGTERM has been received */
+ while (keep_running) {
+ sleep(1);
+ }
+
+ ret = glfs_close(fd);
+ if (ret < 0) {
+ return -1;
+ }
+
+ ret = glfs_fini(fs);
+ if (ret < 0) {
+ return -1;
+ }
+
+ return 0;
}
diff --git a/tests/bugs/core/bug-834465.c b/tests/bugs/core/bug-834465.c
index 61d3deac077..33dd270b112 100644
--- a/tests/bugs/core/bug-834465.c
+++ b/tests/bugs/core/bug-834465.c
@@ -7,55 +7,54 @@
#include <fcntl.h>
int
-main (int argc, char *argv[])
+main(int argc, char *argv[])
{
- int fd = -1;
- char *filename = NULL;
- struct flock lock = {0, };
- int i = 0;
- int ret = -1;
-
- if (argc != 2) {
- fprintf (stderr, "Usage: %s <filename> ", argv[0]);
- goto out;
+ int fd = -1;
+ char *filename = NULL;
+ struct flock lock = {
+ 0,
+ };
+ int i = 0;
+ int ret = -1;
+
+ if (argc != 2) {
+ fprintf(stderr, "Usage: %s <filename> ", argv[0]);
+ goto out;
+ }
+
+ filename = argv[1];
+
+ fd = open(filename, O_RDWR | O_CREAT, 0);
+ if (fd < 0) {
+ fprintf(stderr, "open (%s) failed (%s)\n", filename, strerror(errno));
+ goto out;
+ }
+
+ lock.l_type = F_WRLCK;
+ lock.l_whence = SEEK_SET;
+ lock.l_start = 1;
+ lock.l_len = 1;
+
+ while (i < 100) {
+ lock.l_type = F_WRLCK;
+ ret = fcntl(fd, F_SETLK, &lock);
+ if (ret < 0) {
+ fprintf(stderr, "fcntl setlk failed (%s)\n", strerror(errno));
+ goto out;
}
- filename = argv[1];
-
- fd = open (filename, O_RDWR | O_CREAT, 0);
- if (fd < 0) {
- fprintf (stderr, "open (%s) failed (%s)\n", filename,
- strerror (errno));
- goto out;
+ lock.l_type = F_UNLCK;
+ ret = fcntl(fd, F_SETLK, &lock);
+ if (ret < 0) {
+ fprintf(stderr, "fcntl setlk failed (%s)\n", strerror(errno));
+ goto out;
}
- lock.l_type = F_WRLCK;
- lock.l_whence = SEEK_SET;
- lock.l_start = 1;
- lock.l_len = 1;
-
- while (i < 100) {
- lock.l_type = F_WRLCK;
- ret = fcntl (fd, F_SETLK, &lock);
- if (ret < 0) {
- fprintf (stderr, "fcntl setlk failed (%s)\n",
- strerror (errno));
- goto out;
- }
-
- lock.l_type = F_UNLCK;
- ret = fcntl (fd, F_SETLK, &lock);
- if (ret < 0) {
- fprintf (stderr, "fcntl setlk failed (%s)\n",
- strerror (errno));
- goto out;
- }
-
- i++;
- }
+ i++;
+ }
- ret = 0;
+ ret = 0;
out:
- return ret;
+ return ret;
}
diff --git a/tests/bugs/distribute/bug-1193636.c b/tests/bugs/distribute/bug-1193636.c
index 438efa8e686..ea3f79a4e06 100644
--- a/tests/bugs/distribute/bug-1193636.c
+++ b/tests/bugs/distribute/bug-1193636.c
@@ -5,66 +5,64 @@
#include <fcntl.h>
#include <string.h>
+#define MY_XATTR_NAME "user.ftest"
+#define MY_XATTR_VAL "ftestval"
-#define MY_XATTR_NAME "user.ftest"
-#define MY_XATTR_VAL "ftestval"
-
-
-void usage (void)
+void
+usage(void)
{
- printf ("Usage : bug-1193636 <filename> <xattr_name> <op>\n");
- printf (" op : 0 - set, 1 - remove\n");
+ printf("Usage : bug-1193636 <filename> <xattr_name> <op>\n");
+ printf(" op : 0 - set, 1 - remove\n");
}
-
-int main (int argc, char **argv)
+int
+main(int argc, char **argv)
{
- int fd;
- int err = 0;
- char *xattr_name = NULL;
- int op = 0;
-
- if (argc != 4) {
- usage ();
- exit (1);
- }
-
- op = atoi (argv[3]);
-
- if ((op != 0) && (op != 1)) {
- printf ("Invalid operation specified.\n");
- usage ();
- exit (1);
+ int fd;
+ int err = 0;
+ char *xattr_name = NULL;
+ int op = 0;
+
+ if (argc != 4) {
+ usage();
+ exit(1);
+ }
+
+ op = atoi(argv[3]);
+
+ if ((op != 0) && (op != 1)) {
+ printf("Invalid operation specified.\n");
+ usage();
+ exit(1);
+ }
+
+ xattr_name = argv[2];
+
+ fd = open(argv[1], O_RDWR);
+ if (fd == -1) {
+ printf("Failed to open file %s\n", argv[1]);
+ exit(1);
+ }
+
+ if (!op) {
+ err = fsetxattr(fd, xattr_name, MY_XATTR_VAL, strlen(MY_XATTR_VAL) + 1,
+ XATTR_CREATE);
+
+ if (err) {
+ printf("Failed to set xattr %s: %m\n", xattr_name);
+ exit(1);
}
- xattr_name = argv[2];
+ } else {
+ err = fremovexattr(fd, xattr_name);
- fd = open(argv[1], O_RDWR);
- if (fd == -1) {
- printf ("Failed to open file %s\n", argv[1]);
- exit (1);
+ if (err) {
+ printf("Failed to remove xattr %s: %m\n", xattr_name);
+ exit(1);
}
+ }
- if (!op) {
- err = fsetxattr (fd, xattr_name, MY_XATTR_VAL,
- strlen (MY_XATTR_VAL) + 1, XATTR_CREATE);
+ close(fd);
- if (err) {
- printf ("Failed to set xattr %s: %m\n", xattr_name);
- exit (1);
- }
-
- } else {
- err = fremovexattr (fd, xattr_name);
-
- if (err) {
- printf ("Failed to remove xattr %s: %m\n", xattr_name);
- exit (1);
- }
- }
-
- close (fd);
-
- return 0;
+ return 0;
}
-
diff --git a/tests/bugs/distribute/bug-860663.c b/tests/bugs/distribute/bug-860663.c
index bee4e7d40b1..ca0c31ffe8f 100644
--- a/tests/bugs/distribute/bug-860663.c
+++ b/tests/bugs/distribute/bug-860663.c
@@ -6,38 +6,36 @@
#include <err.h>
#include <sys/param.h>
-int
-main(argc, argv)
- int argc;
- char **argv;
+int main(argc, argv) int argc;
+char **argv;
{
- char *basepath;
- char path[MAXPATHLEN + 1];
- unsigned int count;
- int i, fd;
+ char *basepath;
+ char path[MAXPATHLEN + 1];
+ unsigned int count;
+ int i, fd;
- if (argc != 3)
- errx(1, "usage: %s path count", argv[0]);
+ if (argc != 3)
+ errx(1, "usage: %s path count", argv[0]);
- basepath = argv[1];
- count = atoi(argv[2]);
+ basepath = argv[1];
+ count = atoi(argv[2]);
- if (count > 999999)
- errx(1, "count too big");
+ if (count > 999999)
+ errx(1, "count too big");
- if (strlen(basepath) > MAXPATHLEN - 6)
- errx(1, "path too long");
+ if (strlen(basepath) > MAXPATHLEN - 6)
+ errx(1, "path too long");
- for (i = 0; i < count; i++) {
- (void)sprintf(path, "%s%06d", basepath, i);
+ for (i = 0; i < count; i++) {
+ (void)sprintf(path, "%s%06d", basepath, i);
- fd = open(path, O_CREAT|O_RDWR, 0644);
- if (fd == -1)
- err(1, "create %s failed", path);
+ fd = open(path, O_CREAT | O_RDWR, 0644);
+ if (fd == -1)
+ err(1, "create %s failed", path);
- if (close(fd) != 0)
- warn("close %s failed", path);
- }
+ if (close(fd) != 0)
+ warn("close %s failed", path);
+ }
- return 0;
+ return 0;
}
diff --git a/tests/bugs/ec/bug-1161886.c b/tests/bugs/ec/bug-1161886.c
index 1faae831898..1f12650ea6d 100644
--- a/tests/bugs/ec/bug-1161886.c
+++ b/tests/bugs/ec/bug-1161886.c
@@ -4,50 +4,50 @@
#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;
-
- 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, "/dev/null", 7);
- if (ret != 0) {
- fprintf (stderr, "glfs_set_logging: returned %d\n", ret);
- goto out;
- }
- ret = glfs_init (fs);
- if (ret != 0) {
- fprintf (stderr, "glfs_init: returned %d\n", ret);
- goto out;
- }
-
- fd = glfs_open (fs, argv[3], O_RDWR | O_TRUNC);
- if (fd == NULL) {
- fprintf (stderr, "glfs_open: returned NULL\n");
- goto out;
- }
- glfs_close(fd);
-
- ret = 0;
+ glfs_t *fs = NULL;
+ glfs_fd_t *fd = NULL;
+ int ret = 1;
+
+ 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, "/dev/null", 7);
+ if (ret != 0) {
+ fprintf(stderr, "glfs_set_logging: returned %d\n", ret);
+ goto out;
+ }
+ ret = glfs_init(fs);
+ if (ret != 0) {
+ fprintf(stderr, "glfs_init: returned %d\n", ret);
+ goto out;
+ }
+
+ fd = glfs_open(fs, argv[3], O_RDWR | O_TRUNC);
+ if (fd == NULL) {
+ fprintf(stderr, "glfs_open: returned NULL\n");
+ goto out;
+ }
+ glfs_close(fd);
+
+ ret = 0;
out:
- glfs_fini (fs);
+ glfs_fini(fs);
- return ret;
+ return ret;
}
diff --git a/tests/bugs/fuse/bug-1126048.c b/tests/bugs/fuse/bug-1126048.c
index 01c3484172d..19165ecf6f7 100644
--- a/tests/bugs/fuse/bug-1126048.c
+++ b/tests/bugs/fuse/bug-1126048.c
@@ -12,30 +12,32 @@
* fsync should fail without crashing the mount process.
*/
int
-main (int argc, char **argv)
+main(int argc, char **argv)
{
- int ret = 0;
- int fd = 0;
- char *cmd = argv[1];
- struct stat stbuf = {0, };
+ int ret = 0;
+ int fd = 0;
+ char *cmd = argv[1];
+ struct stat stbuf = {
+ 0,
+ };
- printf ("cmd is: %s\n", cmd);
- fd = open("a.txt", O_CREAT|O_RDWR, 0644);
- if (fd < 0)
- printf ("open failed: %s\n", strerror(errno));
+ printf("cmd is: %s\n", cmd);
+ fd = open("a.txt", O_CREAT | O_RDWR, 0644);
+ if (fd < 0)
+ printf("open failed: %s\n", strerror(errno));
- ret = unlink("a.txt");
- if (ret < 0)
- printf ("unlink failed: %s\n", strerror(errno));
- if (write (fd, "abc", 3) < 0)
- printf ("Not able to print %s\n", strerror (errno));
- system(cmd);
- sleep(1); /* No way to confirm graph switch so sleep 1 */
- ret = fstat (fd, &stbuf);
- if (ret < 0)
- printf ("fstat failed %\n", strerror (errno));
- ret = fsync(fd);
- if (ret < 0)
- printf ("Not able to fsync %s\n", strerror (errno));
- return 0;
+ ret = unlink("a.txt");
+ if (ret < 0)
+ printf("unlink failed: %s\n", strerror(errno));
+ if (write(fd, "abc", 3) < 0)
+ printf("Not able to print %s\n", strerror(errno));
+ system(cmd);
+ sleep(1); /* No way to confirm graph switch so sleep 1 */
+ ret = fstat(fd, &stbuf);
+ if (ret < 0)
+ printf("fstat failed %\n", strerror(errno));
+ ret = fsync(fd);
+ if (ret < 0)
+ printf("Not able to fsync %s\n", strerror(errno));
+ return 0;
}
diff --git a/tests/bugs/gfapi/bug-1093594.c b/tests/bugs/gfapi/bug-1093594.c
index aff271e4caf..f7a06dd5ba8 100644
--- a/tests/bugs/gfapi/bug-1093594.c
+++ b/tests/bugs/gfapi/bug-1093594.c
@@ -5,7 +5,7 @@
#include <stdlib.h>
#include <string.h>
-#define WRITE_SIZE (128*1024)
+#define WRITE_SIZE (128 * 1024)
#define READ_WRITE_LOOP 100
#define FOP_LOOP_COUNT 20
#define TEST_CASE_LOOP 20
@@ -14,304 +14,298 @@ int gfapi = 1;
static int extension = 1;
static int
-large_number_of_fops (glfs_t *fs) {
- int ret = 0;
- int i = 0;
- glfs_fd_t *fd = NULL;
- glfs_fd_t *fd1 = NULL;
- char *dir1 = NULL, *dir2 = NULL, *filename1 = NULL, *filename2 = NULL;
- char *buf = NULL;
- struct stat sb = {0, };
-
- for (i = 0 ; i < FOP_LOOP_COUNT ; i++) {
- ret = asprintf (&dir1, "dir%d", extension);
- if (ret < 0) {
- fprintf (stderr, "cannot construct filename (%s)",
- strerror (errno));
- return ret;
- }
-
- extension++;
-
- ret = glfs_mkdir (fs, dir1, 0755);
- if (ret < 0) {
- fprintf (stderr, "mkdir(%s): %s\n", dir1, strerror (errno));
- return -1;
- }
-
- fd = glfs_opendir (fs, dir1);
- if (!fd) {
- fprintf (stderr, "/: %s\n", strerror (errno));
- return -1;
- }
-
- ret = glfs_fsetxattr (fd, "user.dirfattr", "fsetxattr", 8, 0);
- if (ret < 0) {
- fprintf (stderr, "fsetxattr(%s): %d (%s)\n", dir1, ret,
- strerror (errno));
- return -1;
- }
-
- ret = glfs_closedir (fd);
- if (ret < 0) {
- fprintf (stderr, "glfs_closedir failed with ret: %d (%s)\n",
- ret, strerror (errno));
- return -1;
- }
-
- ret = glfs_rmdir (fs, dir1);
- if (ret < 0) {
- fprintf (stderr, "glfs_unlink failed with ret: %d (%s)\n",
- ret, strerror (errno));
- return -1;
- }
-
- ret = asprintf (&filename1, "file%d", extension);
- if (ret < 0) {
- fprintf (stderr, "cannot construct filename (%s)",
- strerror (errno));
- return ret;
- }
-
- ret = asprintf (&filename2, "file-%d", extension);
- if (ret < 0) {
- fprintf (stderr, "cannot construct filename (%s)",
- strerror (errno));
- return ret;
- }
-
- extension++;
-
- fd = glfs_creat (fs, filename1, O_RDWR, 0644);
- if (!fd) {
- fprintf (stderr, "%s: (%p) %s\n", filename1, fd,
- strerror (errno));
- return -1;
- }
-
- ret = glfs_rename (fs, filename1, filename2);
- if (ret < 0) {
- fprintf (stderr, "glfs_rename failed with ret: %d (%s)\n",
- ret, strerror (errno));
- return -1;
- }
-
- ret = glfs_lstat (fs, filename2, &sb);
- if (ret < 0) {
- fprintf (stderr, "glfs_lstat failed with ret: %d (%s)\n",
- ret, strerror (errno));
- return -1;
- }
-
- ret = glfs_close (fd);
- if (ret < 0) {
- fprintf (stderr, "glfs_close failed with ret: %d (%s)\n",
- ret, strerror (errno));
- return -1;
- }
-
- ret = glfs_unlink (fs, filename2);
- if (ret < 0) {
- fprintf (stderr, "glfs_unlink failed with ret: %d (%s)\n",
- ret, strerror (errno));
- return -1;
- }
+large_number_of_fops(glfs_t *fs)
+{
+ int ret = 0;
+ int i = 0;
+ glfs_fd_t *fd = NULL;
+ glfs_fd_t *fd1 = NULL;
+ char *dir1 = NULL, *dir2 = NULL, *filename1 = NULL, *filename2 = NULL;
+ char *buf = NULL;
+ struct stat sb = {
+ 0,
+ };
+
+ for (i = 0; i < FOP_LOOP_COUNT; i++) {
+ ret = asprintf(&dir1, "dir%d", extension);
+ if (ret < 0) {
+ fprintf(stderr, "cannot construct filename (%s)", strerror(errno));
+ return ret;
}
-}
-static int
-large_read_write (glfs_t *fs) {
+ extension++;
- int ret = 0;
- int j = 0;
- glfs_fd_t *fd = NULL;
- glfs_fd_t *fd1 = NULL;
- char *filename = NULL;
- char *buf = NULL;
+ ret = glfs_mkdir(fs, dir1, 0755);
+ if (ret < 0) {
+ fprintf(stderr, "mkdir(%s): %s\n", dir1, strerror(errno));
+ return -1;
+ }
- ret = asprintf (&filename, "filerw%d", extension);
+ fd = glfs_opendir(fs, dir1);
+ if (!fd) {
+ fprintf(stderr, "/: %s\n", strerror(errno));
+ return -1;
+ }
+
+ ret = glfs_fsetxattr(fd, "user.dirfattr", "fsetxattr", 8, 0);
if (ret < 0) {
- fprintf (stderr, "cannot construct filename (%s)",
- strerror (errno));
- return ret;
+ fprintf(stderr, "fsetxattr(%s): %d (%s)\n", dir1, ret,
+ strerror(errno));
+ return -1;
}
- extension++;
+ ret = glfs_closedir(fd);
+ if (ret < 0) {
+ fprintf(stderr, "glfs_closedir failed with ret: %d (%s)\n", ret,
+ strerror(errno));
+ return -1;
+ }
- fd = glfs_creat (fs, filename, O_RDWR, 0644);
- if (!fd) {
- fprintf (stderr, "%s: (%p) %s\n", filename, fd,
- strerror (errno));
- return -1;
+ ret = glfs_rmdir(fs, dir1);
+ if (ret < 0) {
+ fprintf(stderr, "glfs_unlink failed with ret: %d (%s)\n", ret,
+ strerror(errno));
+ return -1;
}
- buf = (char *) malloc (WRITE_SIZE);
- memset (buf, '-', WRITE_SIZE);
+ ret = asprintf(&filename1, "file%d", extension);
+ if (ret < 0) {
+ fprintf(stderr, "cannot construct filename (%s)", strerror(errno));
+ return ret;
+ }
- for (j = 0; j < READ_WRITE_LOOP; j++) {
- ret = glfs_write (fd, buf, WRITE_SIZE, 0);
- if (ret < 0) {
- fprintf (stderr, "Write(%s): %d (%s)\n", filename, ret,
- strerror (errno));
- return ret;
- }
+ ret = asprintf(&filename2, "file-%d", extension);
+ if (ret < 0) {
+ fprintf(stderr, "cannot construct filename (%s)", strerror(errno));
+ return ret;
}
- fd1 = glfs_open (fs, filename, O_RDWR);
- if (fd1 < 0) {
- fprintf (stderr, "Open(%s): %d (%s)\n", filename, ret,
- strerror (errno));
- return -1;
+ extension++;
+
+ fd = glfs_creat(fs, filename1, O_RDWR, 0644);
+ if (!fd) {
+ fprintf(stderr, "%s: (%p) %s\n", filename1, fd, strerror(errno));
+ return -1;
}
- glfs_lseek (fd1, 0, SEEK_SET);
- for (j = 0; j < READ_WRITE_LOOP; j++) {
- ret = glfs_read (fd1, buf, WRITE_SIZE, 0);
- if (ret < 0) {
- fprintf (stderr, "Read(%s): %d (%s)\n", filename, ret,
- strerror (errno));
- return ret;
- }
+ ret = glfs_rename(fs, filename1, filename2);
+ if (ret < 0) {
+ fprintf(stderr, "glfs_rename failed with ret: %d (%s)\n", ret,
+ strerror(errno));
+ return -1;
}
- for (j = 0; j < READ_WRITE_LOOP; j++) {
- ret = glfs_write (fd1, buf, WRITE_SIZE, 0);
- if (ret < 0) {
- fprintf (stderr, "Write(%s): %d (%s)\n", filename, ret,
- strerror (errno));
- return ret;
- }
+ ret = glfs_lstat(fs, filename2, &sb);
+ if (ret < 0) {
+ fprintf(stderr, "glfs_lstat failed with ret: %d (%s)\n", ret,
+ strerror(errno));
+ return -1;
}
- glfs_close (fd);
- glfs_close (fd1);
- ret = glfs_unlink (fs, filename);
+ ret = glfs_close(fd);
if (ret < 0) {
- fprintf (stderr, "glfs_unlink failed with ret: %d (%s)\n",
- ret, strerror (errno));
- return -1;
+ fprintf(stderr, "glfs_close failed with ret: %d (%s)\n", ret,
+ strerror(errno));
+ return -1;
}
- free (buf);
- free (filename);
+ ret = glfs_unlink(fs, filename2);
+ if (ret < 0) {
+ fprintf(stderr, "glfs_unlink failed with ret: %d (%s)\n", ret,
+ strerror(errno));
+ return -1;
+ }
+ }
}
static int
-volfile_change (const char *volname) {
- int ret = 0;
- char *cmd = NULL, *cmd1 = NULL;
+large_read_write(glfs_t *fs)
+{
+ int ret = 0;
+ int j = 0;
+ glfs_fd_t *fd = NULL;
+ glfs_fd_t *fd1 = NULL;
+ char *filename = NULL;
+ char *buf = NULL;
+
+ ret = asprintf(&filename, "filerw%d", extension);
+ if (ret < 0) {
+ fprintf(stderr, "cannot construct filename (%s)", strerror(errno));
+ return ret;
+ }
- ret = asprintf (&cmd, "gluster volume set %s stat-prefetch off",
- volname);
- if (ret < 0) {
- fprintf (stderr, "cannot construct cli command string (%s)",
- strerror (errno));
- return ret;
- }
+ extension++;
- ret = asprintf (&cmd1, "gluster volume set %s stat-prefetch on",
- volname);
+ fd = glfs_creat(fs, filename, O_RDWR, 0644);
+ if (!fd) {
+ fprintf(stderr, "%s: (%p) %s\n", filename, fd, strerror(errno));
+ return -1;
+ }
+
+ buf = (char *)malloc(WRITE_SIZE);
+ memset(buf, '-', WRITE_SIZE);
+
+ for (j = 0; j < READ_WRITE_LOOP; j++) {
+ ret = glfs_write(fd, buf, WRITE_SIZE, 0);
if (ret < 0) {
- fprintf (stderr, "cannot construct cli command string (%s)",
- strerror (errno));
- return ret;
+ fprintf(stderr, "Write(%s): %d (%s)\n", filename, ret,
+ strerror(errno));
+ return ret;
}
+ }
- ret = system (cmd);
+ fd1 = glfs_open(fs, filename, O_RDWR);
+ if (fd1 < 0) {
+ fprintf(stderr, "Open(%s): %d (%s)\n", filename, ret, strerror(errno));
+ return -1;
+ }
+
+ glfs_lseek(fd1, 0, SEEK_SET);
+ for (j = 0; j < READ_WRITE_LOOP; j++) {
+ ret = glfs_read(fd1, buf, WRITE_SIZE, 0);
if (ret < 0) {
- fprintf (stderr, "stat-prefetch off on (%s) failed", volname);
- return ret;
+ fprintf(stderr, "Read(%s): %d (%s)\n", filename, ret,
+ strerror(errno));
+ return ret;
}
+ }
- ret = system (cmd1);
+ for (j = 0; j < READ_WRITE_LOOP; j++) {
+ ret = glfs_write(fd1, buf, WRITE_SIZE, 0);
if (ret < 0) {
- fprintf (stderr, "stat-prefetch on on (%s) failed", volname);
- return ret;
+ fprintf(stderr, "Write(%s): %d (%s)\n", filename, ret,
+ strerror(errno));
+ return ret;
}
+ }
+
+ glfs_close(fd);
+ glfs_close(fd1);
+ ret = glfs_unlink(fs, filename);
+ if (ret < 0) {
+ fprintf(stderr, "glfs_unlink failed with ret: %d (%s)\n", ret,
+ strerror(errno));
+ return -1;
+ }
+
+ free(buf);
+ free(filename);
+}
- free (cmd);
- free (cmd1);
+static int
+volfile_change(const char *volname)
+{
+ int ret = 0;
+ char *cmd = NULL, *cmd1 = NULL;
+
+ ret = asprintf(&cmd, "gluster volume set %s stat-prefetch off", volname);
+ if (ret < 0) {
+ fprintf(stderr, "cannot construct cli command string (%s)",
+ strerror(errno));
return ret;
+ }
+
+ ret = asprintf(&cmd1, "gluster volume set %s stat-prefetch on", volname);
+ if (ret < 0) {
+ fprintf(stderr, "cannot construct cli command string (%s)",
+ strerror(errno));
+ return ret;
+ }
+
+ ret = system(cmd);
+ if (ret < 0) {
+ fprintf(stderr, "stat-prefetch off on (%s) failed", volname);
+ return ret;
+ }
+
+ ret = system(cmd1);
+ if (ret < 0) {
+ fprintf(stderr, "stat-prefetch on on (%s) failed", volname);
+ return ret;
+ }
+
+ free(cmd);
+ free(cmd1);
+ return ret;
}
int
-main (int argc, char *argv[])
+main(int argc, char *argv[])
{
- glfs_t *fs = NULL;
- int ret = 0;
- int i = 0;
- glfs_fd_t *fd = NULL;
- glfs_fd_t *fd1 = NULL;
- char *topdir = "topdir", *filename = "file1";
- char *buf = NULL;
- char *logfile = NULL;
- char *hostname = NULL;
-
- if (argc != 4) {
- fprintf (stderr,
- "Expect following args %s <hostname> <Vol> <log file>\n"
- , argv[0]);
- return -1;
+ glfs_t *fs = NULL;
+ int ret = 0;
+ int i = 0;
+ glfs_fd_t *fd = NULL;
+ glfs_fd_t *fd1 = NULL;
+ char *topdir = "topdir", *filename = "file1";
+ char *buf = NULL;
+ char *logfile = NULL;
+ char *hostname = NULL;
+
+ if (argc != 4) {
+ fprintf(stderr,
+ "Expect following args %s <hostname> <Vol> <log file>\n",
+ argv[0]);
+ return -1;
+ }
+
+ hostname = argv[1];
+ logfile = argv[3];
+
+ for (i = 0; i < TEST_CASE_LOOP; i++) {
+ fs = glfs_new(argv[2]);
+ if (!fs) {
+ fprintf(stderr, "glfs_new: returned NULL (%s)\n", strerror(errno));
+ return -1;
}
- hostname = argv[1];
- logfile = argv[3];
-
- for (i = 0; i < TEST_CASE_LOOP; i++) {
- fs = glfs_new (argv[2]);
- if (!fs) {
- fprintf (stderr, "glfs_new: returned NULL (%s)\n",
- strerror (errno));
- return -1;
- }
-
- ret = glfs_set_volfile_server (fs, "tcp", hostname, 24007);
- if (ret < 0) {
- fprintf (stderr, "glfs_set_volfile_server failed ret:%d (%s)\n",
- ret, strerror (errno));
- return -1;
- }
-
- ret = glfs_set_logging (fs, logfile, 7);
- if (ret < 0) {
- fprintf (stderr, "glfs_set_logging failed with ret: %d (%s)\n",
- ret, strerror (errno));
- return -1;
- }
-
- ret = glfs_init (fs);
- if (ret < 0) {
- fprintf (stderr, "glfs_init failed with ret: %d (%s)\n",
- ret, strerror (errno));
- return -1;
- }
-
- ret = large_number_of_fops (fs);
- if (ret < 0)
- return -1;
-
- ret = large_read_write (fs);
- if (ret < 0)
- return -1;
-
- ret = volfile_change (argv[2]);
- if (ret < 0)
- return -1;
-
- ret = large_number_of_fops (fs);
- if (ret < 0)
- return -1;
-
- ret = large_read_write (fs);
- if (ret < 0)
- return -1;
-
- ret = glfs_fini (fs);
- if (ret < 0) {
- fprintf (stderr, "glfs_fini failed with ret: %d (%s)\n",
- ret, strerror (errno));
- return -1;
- }
+ ret = glfs_set_volfile_server(fs, "tcp", hostname, 24007);
+ if (ret < 0) {
+ fprintf(stderr, "glfs_set_volfile_server failed ret:%d (%s)\n", ret,
+ strerror(errno));
+ return -1;
+ }
+
+ ret = glfs_set_logging(fs, logfile, 7);
+ if (ret < 0) {
+ fprintf(stderr, "glfs_set_logging failed with ret: %d (%s)\n", ret,
+ strerror(errno));
+ return -1;
+ }
+
+ ret = glfs_init(fs);
+ if (ret < 0) {
+ fprintf(stderr, "glfs_init failed with ret: %d (%s)\n", ret,
+ strerror(errno));
+ return -1;
+ }
+
+ ret = large_number_of_fops(fs);
+ if (ret < 0)
+ return -1;
+
+ ret = large_read_write(fs);
+ if (ret < 0)
+ return -1;
+
+ ret = volfile_change(argv[2]);
+ if (ret < 0)
+ return -1;
+
+ ret = large_number_of_fops(fs);
+ if (ret < 0)
+ return -1;
+
+ ret = large_read_write(fs);
+ if (ret < 0)
+ return -1;
+
+ ret = glfs_fini(fs);
+ if (ret < 0) {
+ fprintf(stderr, "glfs_fini failed with ret: %d (%s)\n", ret,
+ strerror(errno));
+ return -1;
}
- return 0;
+ }
+ return 0;
}
diff --git a/tests/bugs/gfapi/bug-1319374.c b/tests/bugs/gfapi/bug-1319374.c
index bf2da998d6e..bd80462e3ba 100644
--- a/tests/bugs/gfapi/bug-1319374.c
+++ b/tests/bugs/gfapi/bug-1319374.c
@@ -9,122 +9,122 @@
glfs_t *
setup_new_client(char *hostname, char *volname, char *log_file, int flag)
{
- int ret = 0;
- glfs_t *fs = NULL;
-
- fs = glfs_new (volname);
- if (!fs) {
- fprintf (stderr, "\nglfs_new: returned NULL (%s)\n",
- strerror (errno));
- goto error;
- }
-
- ret = glfs_set_volfile_server (fs, "tcp", hostname, 24007);
- if (ret < 0) {
- fprintf (stderr, "\nglfs_set_volfile_server failed ret:%d (%s)\n",
- ret, strerror (errno));
- goto error;
- }
-
- ret = glfs_set_logging (fs, log_file, 7);
- if (ret < 0) {
- fprintf (stderr, "\nglfs_set_logging failed with ret: %d (%s)\n",
- ret, strerror (errno));
- goto error;
- }
-
- if (flag == NO_INIT)
- goto out;
-
- ret = glfs_init (fs);
- if (ret < 0) {
- fprintf (stderr, "\nglfs_init failed with ret: %d (%s)\n",
- ret, strerror (errno));
- goto error;
- }
+ int ret = 0;
+ glfs_t *fs = NULL;
+
+ fs = glfs_new(volname);
+ if (!fs) {
+ fprintf(stderr, "\nglfs_new: returned NULL (%s)\n", strerror(errno));
+ goto error;
+ }
+
+ ret = glfs_set_volfile_server(fs, "tcp", hostname, 24007);
+ if (ret < 0) {
+ fprintf(stderr, "\nglfs_set_volfile_server failed ret:%d (%s)\n", ret,
+ strerror(errno));
+ goto error;
+ }
+
+ ret = glfs_set_logging(fs, log_file, 7);
+ if (ret < 0) {
+ fprintf(stderr, "\nglfs_set_logging failed with ret: %d (%s)\n", ret,
+ strerror(errno));
+ goto error;
+ }
+
+ if (flag == NO_INIT)
+ goto out;
+
+ ret = glfs_init(fs);
+ if (ret < 0) {
+ fprintf(stderr, "\nglfs_init failed with ret: %d (%s)\n", ret,
+ strerror(errno));
+ goto error;
+ }
out:
- return fs;
+ return fs;
error:
- return NULL;
+ return NULL;
}
int
-main (int argc, char *argv[])
+main(int argc, char *argv[])
{
- int ret = 0;
- glfs_t *fs1 = NULL;
- glfs_t *fs2 = NULL;
- glfs_t *fs3 = NULL;
- char *volname = NULL;
- char *log_file = NULL;
- char *hostname = NULL;
-
- if (argc != 4) {
- fprintf (stderr,
- "Expect following args %s <hostname> <Vol> <log file location>\n"
- , argv[0]);
- return -1;
- }
-
- hostname = argv[1];
- volname = argv[2];
- log_file = argv[3];
-
- fs1 = setup_new_client (hostname, volname, log_file, NO_INIT);
- if (!fs1) {
- fprintf (stderr, "\nsetup_new_client: returned NULL (%s)\n",
- strerror (errno));
- goto error;
- }
-
- fs2 = setup_new_client (hostname, volname, log_file, 0);
- if (!fs2) {
- fprintf (stderr, "\nsetup_new_client: returned NULL (%s)\n",
- strerror (errno));
- goto error;
- }
-
- fs3 = setup_new_client (hostname, volname, log_file, 0);
- if (!fs3) {
- fprintf (stderr, "\nsetup_new_client: returned NULL (%s)\n",
- strerror (errno));
- goto error;
- }
-
- ret = glfs_fini (fs3);
- if (ret < 0) {
- fprintf (stderr, "glfs_fini failed with ret: %d (%s)\n",
- ret, strerror (errno));
- goto error;
- }
-
- /* The crash is seen in gf_log_flush_timeout_cbk(), and this gets
- * triggered when 30s timer expires, hence the sleep of 31s
- */
- sleep (31);
- ret = glfs_fini (fs2);
- if (ret < 0) {
- fprintf (stderr, "glfs_fini failed with ret: %d (%s)\n",
- ret, strerror (errno));
- goto error;
- }
-
- ret = glfs_init (fs1);
- if (ret < 0) {
- fprintf (stderr, "\nglfs_init failed with ret: %d (%s)\n",
- ret, strerror (errno));
- goto error;
- }
-
- ret = glfs_fini (fs1);
- if (ret < 0) {
- fprintf (stderr, "glfs_fini failed with ret: %d (%s)\n",
- ret, strerror (errno));
- goto error;
- }
-
- return 0;
-error:
+ int ret = 0;
+ glfs_t *fs1 = NULL;
+ glfs_t *fs2 = NULL;
+ glfs_t *fs3 = NULL;
+ char *volname = NULL;
+ char *log_file = NULL;
+ char *hostname = NULL;
+
+ if (argc != 4) {
+ fprintf(
+ stderr,
+ "Expect following args %s <hostname> <Vol> <log file location>\n",
+ argv[0]);
return -1;
+ }
+
+ hostname = argv[1];
+ volname = argv[2];
+ log_file = argv[3];
+
+ fs1 = setup_new_client(hostname, volname, log_file, NO_INIT);
+ if (!fs1) {
+ fprintf(stderr, "\nsetup_new_client: returned NULL (%s)\n",
+ strerror(errno));
+ goto error;
+ }
+
+ fs2 = setup_new_client(hostname, volname, log_file, 0);
+ if (!fs2) {
+ fprintf(stderr, "\nsetup_new_client: returned NULL (%s)\n",
+ strerror(errno));
+ goto error;
+ }
+
+ fs3 = setup_new_client(hostname, volname, log_file, 0);
+ if (!fs3) {
+ fprintf(stderr, "\nsetup_new_client: returned NULL (%s)\n",
+ strerror(errno));
+ goto error;
+ }
+
+ ret = glfs_fini(fs3);
+ if (ret < 0) {
+ fprintf(stderr, "glfs_fini failed with ret: %d (%s)\n", ret,
+ strerror(errno));
+ goto error;
+ }
+
+ /* The crash is seen in gf_log_flush_timeout_cbk(), and this gets
+ * triggered when 30s timer expires, hence the sleep of 31s
+ */
+ sleep(31);
+ ret = glfs_fini(fs2);
+ if (ret < 0) {
+ fprintf(stderr, "glfs_fini failed with ret: %d (%s)\n", ret,
+ strerror(errno));
+ goto error;
+ }
+
+ ret = glfs_init(fs1);
+ if (ret < 0) {
+ fprintf(stderr, "\nglfs_init failed with ret: %d (%s)\n", ret,
+ strerror(errno));
+ goto error;
+ }
+
+ ret = glfs_fini(fs1);
+ if (ret < 0) {
+ fprintf(stderr, "glfs_fini failed with ret: %d (%s)\n", ret,
+ strerror(errno));
+ goto error;
+ }
+
+ return 0;
+error:
+ return -1;
}
diff --git a/tests/bugs/gfapi/bug-1447266/1460514.c b/tests/bugs/gfapi/bug-1447266/1460514.c
index f04d2d1463f..c721559a668 100644
--- a/tests/bugs/gfapi/bug-1447266/1460514.c
+++ b/tests/bugs/gfapi/bug-1447266/1460514.c
@@ -9,135 +9,142 @@
#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, *dir = NULL, *subdir = NULL;
- struct stat sb = {0, };
- char *dirname = "dir";
- char *subdirname = "subdir";
- char *logfile = NULL;
- char *volname = NULL;
- char *hostname = NULL;
- unsigned char subdir_handle[GFAPI_HANDLE_LENGTH] = {'\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");
- ret = -1;
- goto out;
- }
-
- 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("first attempt 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;
- }
- dir = glfs_h_mkdir (fs, root, dirname, 0644, &sb);
- if (dir == NULL) {
- fprintf (stderr, "glfs_h_mkdir: error on directory creation dir ,%s\n",
- strerror (errno));
- goto out;
- }
- subdir = glfs_h_mkdir (fs, root, subdirname, 0644, &sb);
- if (subdir == NULL) {
- fprintf (stderr, "glfs_h_mkdir: error on directory creation subdir ,%s\n",
- strerror (errno));
- goto out;
- }
- ret = glfs_h_extract_handle (subdir, subdir_handle,
- GFAPI_HANDLE_LENGTH);
- if (ret < 0) {
- fprintf (stderr, "glfs_h_extract_handle: error extracting handle of %s: %s\n",
- subdirname, strerror (errno));
- goto out;
- }
-
- glfs_h_close (subdir);
- subdir = NULL;
- glfs_h_close (dir);
- dir = NULL;
-
- if (fs) {
- ret = glfs_fini(fs);
- fprintf (stderr, "glfs_fini(fs) returned %d \n", ret);
- }
-
- fs = NULL;
-
- fs = glfs_new (volname);
- if (!fs) {
- fprintf (stderr, "glfs_new: returned NULL\n");
- ret = -1;
- goto out;
- }
-
- 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("second attempt glfs_init", ret);
-
- subdir = glfs_h_create_from_handle (fs, subdir_handle, GFAPI_HANDLE_LENGTH,
- &sb);
- if (subdir == NULL) {
- fprintf (stderr, "glfs_h_create_from_handle: error on create of %s: from (%p),%s\n",
- subdirname, subdir_handle, strerror (errno));
- goto out;
- }
- dir = glfs_h_lookupat (fs, subdir, "..", &sb, 0);
- if (dir == NULL) {
- fprintf (stderr, "glfs_h_lookupat: error on directory lookup dir using .. ,%s\n",
- strerror (errno));
- goto out;
- }
+ int ret = 0;
+ glfs_t *fs = NULL;
+ struct glfs_object *root = NULL, *dir = NULL, *subdir = NULL;
+ struct stat sb = {
+ 0,
+ };
+ char *dirname = "dir";
+ char *subdirname = "subdir";
+ char *logfile = NULL;
+ char *volname = NULL;
+ char *hostname = NULL;
+ unsigned char subdir_handle[GFAPI_HANDLE_LENGTH] = {'\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");
+ ret = -1;
+ goto out;
+ }
+
+ 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("first attempt 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;
+ }
+ dir = glfs_h_mkdir(fs, root, dirname, 0644, &sb);
+ if (dir == NULL) {
+ fprintf(stderr, "glfs_h_mkdir: error on directory creation dir ,%s\n",
+ strerror(errno));
+ goto out;
+ }
+ subdir = glfs_h_mkdir(fs, root, subdirname, 0644, &sb);
+ if (subdir == NULL) {
+ fprintf(stderr,
+ "glfs_h_mkdir: error on directory creation subdir ,%s\n",
+ strerror(errno));
+ goto out;
+ }
+ ret = glfs_h_extract_handle(subdir, subdir_handle, GFAPI_HANDLE_LENGTH);
+ if (ret < 0) {
+ fprintf(stderr,
+ "glfs_h_extract_handle: error extracting handle of %s: %s\n",
+ subdirname, strerror(errno));
+ goto out;
+ }
+
+ glfs_h_close(subdir);
+ subdir = NULL;
+ glfs_h_close(dir);
+ dir = NULL;
+
+ if (fs) {
+ ret = glfs_fini(fs);
+ fprintf(stderr, "glfs_fini(fs) returned %d \n", ret);
+ }
+
+ fs = NULL;
+
+ fs = glfs_new(volname);
+ if (!fs) {
+ fprintf(stderr, "glfs_new: returned NULL\n");
+ ret = -1;
+ goto out;
+ }
+
+ 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("second attempt glfs_init", ret);
+
+ subdir = glfs_h_create_from_handle(fs, subdir_handle, GFAPI_HANDLE_LENGTH,
+ &sb);
+ if (subdir == NULL) {
+ fprintf(
+ stderr,
+ "glfs_h_create_from_handle: error on create of %s: from (%p),%s\n",
+ subdirname, subdir_handle, strerror(errno));
+ goto out;
+ }
+ dir = glfs_h_lookupat(fs, subdir, "..", &sb, 0);
+ if (dir == NULL) {
+ fprintf(stderr,
+ "glfs_h_lookupat: error on directory lookup dir using .. ,%s\n",
+ strerror(errno));
+ goto out;
+ }
out:
- if (subdir)
- glfs_h_close (subdir);
- if (dir)
- glfs_h_close (dir);
-
- if (fs) {
- ret = glfs_fini(fs);
- fprintf (stderr, "glfs_fini(fs) returned %d \n", ret);
- }
-
- if (ret)
- exit(1);
- exit(0);
+ if (subdir)
+ glfs_h_close(subdir);
+ if (dir)
+ glfs_h_close(dir);
+
+ 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/bugs/gfapi/bug-1447266/bug-1447266.c b/tests/bugs/gfapi/bug-1447266/bug-1447266.c
index e4b3c888a57..2b7e2d627fe 100644
--- a/tests/bugs/gfapi/bug-1447266/bug-1447266.c
+++ b/tests/bugs/gfapi/bug-1447266/bug-1447266.c
@@ -4,102 +4,104 @@
#include <string.h>
#include <stdlib.h>
#define TOTAL_ARGS 4
-int main(int argc, char *argv[])
+int
+main(int argc, char *argv[])
{
- char *cwd = (char *)malloc(PATH_MAX*sizeof(char *));
- char *resolved = NULL;
- char *result = NULL;
- char *buf = NULL;
- struct stat st;
- char *path = NULL;
- int ret;
-
- if (argc != TOTAL_ARGS) {
- printf ("Please give all required command line args.\n"
- "Format : <volname> <server_ip> <path_name>\n");
- goto out;
- }
-
- glfs_t *fs = glfs_new (argv[1]);
-
- if (fs == NULL) {
- printf ("glfs_new: %s\n", strerror(errno));
- /* No need to fail the test for this error */
- ret = 0;
- goto out;
- }
-
- ret = glfs_set_volfile_server(fs, "tcp", argv[2], 24007);
- if (ret) {
- printf ("glfs_set_volfile_server: %s\n", strerror(errno));
- /* No need to fail the test for this error */
- ret = 0;
- goto out;
- }
-
- path = argv[3];
-
- ret = glfs_set_logging(fs, "/tmp/gfapi.log", 7);
- if (ret) {
- printf ("glfs_set_logging: %s\n", strerror(errno));
- /* No need to fail the test for this error */
- ret = 0;
- goto out;
- }
-
- ret = glfs_init(fs);
- if (ret) {
- printf ("glfs_init: %s\n", strerror(errno));
- /* No need to fail the test for this error */
- ret = 0;
- goto out;
- }
-
- sleep(1);
-
- ret = glfs_chdir(fs, path);
- if (ret) {
- printf ("glfs_chdir: %s\n", strerror(errno));
- goto out;
- }
-
- buf = glfs_getcwd(fs, cwd, PATH_MAX);
- if (cwd == NULL) {
- printf ("glfs_getcwd: %s\n", strerror(errno));
- goto out;
- }
-
- printf ("\ncwd = %s\n\n", cwd);
-
- result = glfs_realpath(fs, path, resolved);
- if (result == NULL) {
- printf ("glfs_realpath: %s\n", strerror(errno));
- goto out;
- }
-
- ret = glfs_stat(fs, path, &st);
- if (ret) {
- printf ("glfs_stat: %s\n", strerror(errno));
- goto out;
- }
- if (cwd)
- free(cwd);
-
- result = glfs_realpath(fs, path, resolved);
- if (result == NULL) {
- printf ("glfs_realpath: %s\n", strerror(errno));
- goto out;
- }
-
- ret = glfs_fini(fs);
- if (ret) {
- printf ("glfs_fini: %s\n", strerror(errno));
- /* No need to fail the test for this error */
- ret = 0;
- goto out;
- }
-
- printf ("\n");
+ char *cwd = (char *)malloc(PATH_MAX * sizeof(char *));
+ char *resolved = NULL;
+ char *result = NULL;
+ char *buf = NULL;
+ struct stat st;
+ char *path = NULL;
+ int ret;
+
+ if (argc != TOTAL_ARGS) {
+ printf(
+ "Please give all required command line args.\n"
+ "Format : <volname> <server_ip> <path_name>\n");
+ goto out;
+ }
+
+ glfs_t *fs = glfs_new(argv[1]);
+
+ if (fs == NULL) {
+ printf("glfs_new: %s\n", strerror(errno));
+ /* No need to fail the test for this error */
+ ret = 0;
+ goto out;
+ }
+
+ ret = glfs_set_volfile_server(fs, "tcp", argv[2], 24007);
+ if (ret) {
+ printf("glfs_set_volfile_server: %s\n", strerror(errno));
+ /* No need to fail the test for this error */
+ ret = 0;
+ goto out;
+ }
+
+ path = argv[3];
+
+ ret = glfs_set_logging(fs, "/tmp/gfapi.log", 7);
+ if (ret) {
+ printf("glfs_set_logging: %s\n", strerror(errno));
+ /* No need to fail the test for this error */
+ ret = 0;
+ goto out;
+ }
+
+ ret = glfs_init(fs);
+ if (ret) {
+ printf("glfs_init: %s\n", strerror(errno));
+ /* No need to fail the test for this error */
+ ret = 0;
+ goto out;
+ }
+
+ sleep(1);
+
+ ret = glfs_chdir(fs, path);
+ if (ret) {
+ printf("glfs_chdir: %s\n", strerror(errno));
+ goto out;
+ }
+
+ buf = glfs_getcwd(fs, cwd, PATH_MAX);
+ if (cwd == NULL) {
+ printf("glfs_getcwd: %s\n", strerror(errno));
+ goto out;
+ }
+
+ printf("\ncwd = %s\n\n", cwd);
+
+ result = glfs_realpath(fs, path, resolved);
+ if (result == NULL) {
+ printf("glfs_realpath: %s\n", strerror(errno));
+ goto out;
+ }
+
+ ret = glfs_stat(fs, path, &st);
+ if (ret) {
+ printf("glfs_stat: %s\n", strerror(errno));
+ goto out;
+ }
+ if (cwd)
+ free(cwd);
+
+ result = glfs_realpath(fs, path, resolved);
+ if (result == NULL) {
+ printf("glfs_realpath: %s\n", strerror(errno));
+ goto out;
+ }
+
+ ret = glfs_fini(fs);
+ if (ret) {
+ printf("glfs_fini: %s\n", strerror(errno));
+ /* No need to fail the test for this error */
+ ret = 0;
+ goto out;
+ }
+
+ printf("\n");
out:
- return ret;
+ return ret;
}
diff --git a/tests/bugs/gfapi/glfs_vol_set_IO_ERR.c b/tests/bugs/gfapi/glfs_vol_set_IO_ERR.c
index 68011171744..f38f01144d3 100644
--- a/tests/bugs/gfapi/glfs_vol_set_IO_ERR.c
+++ b/tests/bugs/gfapi/glfs_vol_set_IO_ERR.c
@@ -10,156 +10,154 @@
glfs_t *
setup_new_client(char *hostname, char *volname, char *log_fileile)
{
- int ret = 0;
- glfs_t *fs = NULL;
-
- fs = glfs_new (volname);
- if (!fs) {
- fprintf (stderr, "\nglfs_new: returned NULL (%s)\n",
- strerror (errno));
- goto error;
- }
-
- ret = glfs_set_volfile_server (fs, "tcp", hostname, 24007);
- if (ret < 0) {
- fprintf (stderr, "\nglfs_set_volfile_server failed ret:%d (%s)\n",
- ret, strerror (errno));
- goto error;
- }
-
- ret = glfs_set_logging (fs, log_fileile, 7);
- if (ret < 0) {
- fprintf (stderr, "\nglfs_set_logging failed with ret: %d (%s)\n",
- ret, strerror (errno));
- goto error;
- }
-
- ret = glfs_init (fs);
- if (ret < 0) {
- fprintf (stderr, "\nglfs_init failed with ret: %d (%s)\n",
- ret, strerror (errno));
- goto error;
- }
- return fs;
+ int ret = 0;
+ glfs_t *fs = NULL;
+
+ fs = glfs_new(volname);
+ if (!fs) {
+ fprintf(stderr, "\nglfs_new: returned NULL (%s)\n", strerror(errno));
+ goto error;
+ }
+
+ ret = glfs_set_volfile_server(fs, "tcp", hostname, 24007);
+ if (ret < 0) {
+ fprintf(stderr, "\nglfs_set_volfile_server failed ret:%d (%s)\n", ret,
+ strerror(errno));
+ goto error;
+ }
+
+ ret = glfs_set_logging(fs, log_fileile, 7);
+ if (ret < 0) {
+ fprintf(stderr, "\nglfs_set_logging failed with ret: %d (%s)\n", ret,
+ strerror(errno));
+ goto error;
+ }
+
+ ret = glfs_init(fs);
+ if (ret < 0) {
+ fprintf(stderr, "\nglfs_init failed with ret: %d (%s)\n", ret,
+ strerror(errno));
+ goto error;
+ }
+ return fs;
error:
- return NULL;
+ return NULL;
}
int
-write_something (glfs_t *fs)
+write_something(glfs_t *fs)
{
- glfs_fd_t *fd = NULL;
- char *buf = NULL;
- int ret = 0;
- int j = 0;
-
- fd = glfs_creat (fs, "filename", O_RDWR, 0644);
- if (!fd) {
- fprintf (stderr, "%s: (%p) %s\n", "filename", fd,
- strerror (errno));
- return -1;
- }
+ glfs_fd_t *fd = NULL;
+ char *buf = NULL;
+ int ret = 0;
+ int j = 0;
+
+ fd = glfs_creat(fs, "filename", O_RDWR, 0644);
+ if (!fd) {
+ fprintf(stderr, "%s: (%p) %s\n", "filename", fd, strerror(errno));
+ return -1;
+ }
+
+ buf = (char *)malloc(WRITE_SIZE);
+ memset(buf, '-', WRITE_SIZE);
- buf = (char *) malloc (WRITE_SIZE);
- memset (buf, '-', WRITE_SIZE);
-
- for (j = 0; j < 4; j++) {
- ret = glfs_write (fd, buf, WRITE_SIZE, 0);
- if (ret < 0) {
- fprintf (stderr, "Write(%s): %d (%s)\n", "filename", ret,
- strerror (errno));
- return ret;
- }
- glfs_lseek (fd, 0, SEEK_SET);
+ for (j = 0; j < 4; j++) {
+ ret = glfs_write(fd, buf, WRITE_SIZE, 0);
+ if (ret < 0) {
+ fprintf(stderr, "Write(%s): %d (%s)\n", "filename", ret,
+ strerror(errno));
+ return ret;
}
- return 0;
+ glfs_lseek(fd, 0, SEEK_SET);
+ }
+ return 0;
}
static int
-volfile_change (const char *volname) {
- int ret = 0;
- char *cmd = NULL, *cmd1 = NULL;
-
- ret = asprintf (&cmd, "gluster volume set %s quick-read on",
- volname);
- if (ret < 0) {
- fprintf (stderr, "cannot construct cli command string (%s)",
- strerror (errno));
- return ret;
- }
+volfile_change(const char *volname)
+{
+ int ret = 0;
+ char *cmd = NULL, *cmd1 = NULL;
- ret = asprintf (&cmd1, "gluster volume set %s quick-read off",
- volname);
- if (ret < 0) {
- fprintf (stderr, "cannot construct cli command string (%s)",
- strerror (errno));
- return ret;
- }
+ ret = asprintf(&cmd, "gluster volume set %s quick-read on", volname);
+ if (ret < 0) {
+ fprintf(stderr, "cannot construct cli command string (%s)",
+ strerror(errno));
+ return ret;
+ }
- ret = system (cmd);
- if (ret < 0) {
- fprintf (stderr, "quick-read off on (%s) failed", volname);
- return ret;
- }
+ ret = asprintf(&cmd1, "gluster volume set %s quick-read off", volname);
+ if (ret < 0) {
+ fprintf(stderr, "cannot construct cli command string (%s)",
+ strerror(errno));
+ return ret;
+ }
- ret = system (cmd1);
- if (ret < 0) {
- fprintf (stderr, "quick-read on on (%s) failed", volname);
- return ret;
- }
+ ret = system(cmd);
+ if (ret < 0) {
+ fprintf(stderr, "quick-read off on (%s) failed", volname);
+ return ret;
+ }
- ret = system (cmd);
- if (ret < 0) {
- fprintf (stderr, "quick-read off on (%s) failed", volname);
- return ret;
- }
+ ret = system(cmd1);
+ if (ret < 0) {
+ fprintf(stderr, "quick-read on on (%s) failed", volname);
+ return ret;
+ }
- free (cmd);
- free (cmd1);
+ ret = system(cmd);
+ if (ret < 0) {
+ fprintf(stderr, "quick-read off on (%s) failed", volname);
return ret;
+ }
+
+ free(cmd);
+ free(cmd1);
+ return ret;
}
int
-main (int argc, char *argv[])
+main(int argc, char *argv[])
{
- int ret = 0;
- glfs_t *fs = NULL;
- char buf[100];
- glfs_fd_t *fd = NULL;
-
- if (argc != 4) {
- fprintf (stderr,
- "Expect following args %s <hostname> <Vol> <log file location>\n"
- , argv[0]);
- return -1;
- }
-
- fs = setup_new_client (argv[1], argv[2], argv[3]);
- if (!fs)
- goto error;
-
- ret = volfile_change (argv[2]);
- if (ret < 0)
- goto error;
-
- /* This is required as volfile change takes a while to reach this
- * gfapi client and precess the graph change. Without this the issue
- * cannot be reproduced as in cannot be tested.
- */
- sleep (10);
-
- ret = write_something (fs);
- if (ret < 0)
- goto error;
-
- ret = glfs_fini (fs);
- if (ret < 0) {
- fprintf (stderr, "glfs_fini failed with ret: %d (%s)\n",
- ret, strerror (errno));
- goto error;
- }
-
- return 0;
-error:
+ int ret = 0;
+ glfs_t *fs = NULL;
+ char buf[100];
+ glfs_fd_t *fd = NULL;
+
+ if (argc != 4) {
+ fprintf(
+ stderr,
+ "Expect following args %s <hostname> <Vol> <log file location>\n",
+ argv[0]);
return -1;
+ }
+
+ fs = setup_new_client(argv[1], argv[2], argv[3]);
+ if (!fs)
+ goto error;
+
+ ret = volfile_change(argv[2]);
+ if (ret < 0)
+ goto error;
+
+ /* This is required as volfile change takes a while to reach this
+ * gfapi client and precess the graph change. Without this the issue
+ * cannot be reproduced as in cannot be tested.
+ */
+ sleep(10);
+
+ ret = write_something(fs);
+ if (ret < 0)
+ goto error;
+
+ ret = glfs_fini(fs);
+ if (ret < 0) {
+ fprintf(stderr, "glfs_fini failed with ret: %d (%s)\n", ret,
+ strerror(errno));
+ goto error;
+ }
+
+ return 0;
+error:
+ return -1;
}
diff --git a/tests/bugs/glusterd/bug-824753-file-locker.c b/tests/bugs/glusterd/bug-824753-file-locker.c
index 915161b626b..f5dababad30 100644
--- a/tests/bugs/glusterd/bug-824753-file-locker.c
+++ b/tests/bugs/glusterd/bug-824753-file-locker.c
@@ -5,13 +5,13 @@
#include <unistd.h>
#include <stdlib.h>
-
-int main (int argc, char *argv[])
+int
+main(int argc, char *argv[])
{
- int fd = -1;
- int ret = -1;
- char command[2048] = "";
- char filepath[255] = "";
+ int fd = -1;
+ int ret = -1;
+ char command[2048] = "";
+ char filepath[255] = "";
struct flock fl;
fl.l_type = F_WRLCK;
@@ -36,7 +36,7 @@ int main (int argc, char *argv[])
" grep %s | awk -F'..: ' '{print $1}' | grep %s:%s/%s",
argv[1], argv[5], argv[2], argv[2], argv[3], argv[1]);
- ret = system (command);
+ ret = system(command);
close(fd);
if (ret)
diff --git a/tests/bugs/glusterfs-server/bug-905864.c b/tests/bugs/glusterfs-server/bug-905864.c
index 3cc4cc5d232..f70003736e7 100644
--- a/tests/bugs/glusterfs-server/bug-905864.c
+++ b/tests/bugs/glusterfs-server/bug-905864.c
@@ -4,10 +4,9 @@
#include <fcntl.h>
#include <pthread.h>
-
-pthread_t th[5] = {0};
+pthread_t th[5] = {0};
void
-flock_init (struct flock *f, short int type, off_t start, off_t len)
+flock_init(struct flock *f, short int type, off_t start, off_t len)
{
f->l_type = type;
f->l_start = start;
@@ -15,68 +14,70 @@ flock_init (struct flock *f, short int type, off_t start, off_t len)
}
int
-flock_range_in_steps (int fd, int is_set, short l_type,
- int start, int end, int step)
+flock_range_in_steps(int fd, int is_set, short l_type, int start, int end,
+ int step)
{
- int ret = 0;
- int i = 0;
- struct flock f = {0,};
+ int ret = 0;
+ int i = 0;
+ struct flock f = {
+ 0,
+ };
- for (i = start; i+step < end; i += step) {
- flock_init (&f, l_type, i, step);
- ret = fcntl (fd, (is_set) ? F_SETLKW : F_GETLK, &f);
- if (ret) {
- perror ("fcntl");
- goto out;
- }
+ for (i = start; i + step < end; i += step) {
+ flock_init(&f, l_type, i, step);
+ ret = fcntl(fd, (is_set) ? F_SETLKW : F_GETLK, &f);
+ if (ret) {
+ perror("fcntl");
+ goto out;
}
+ }
out:
- return ret;
+ return ret;
}
void *
-random_locker (void *arg)
+random_locker(void *arg)
{
- int fd = *(int *)arg;
- int i = 0;
- int is_set = 0;
+ int fd = *(int *)arg;
+ int i = 0;
+ int is_set = 0;
- /* use thread id to choose GETLK or SETLK operation*/
- is_set = pthread_self () % 2;
- (void)flock_range_in_steps (fd, is_set, F_WRLCK, 0, 400, 1);
+ /* use thread id to choose GETLK or SETLK operation*/
+ is_set = pthread_self() % 2;
+ (void)flock_range_in_steps(fd, is_set, F_WRLCK, 0, 400, 1);
- return NULL;
+ return NULL;
}
-
-int main (int argc, char **argv)
+int
+main(int argc, char **argv)
{
- int fd = -1;
- int ret = 1;
- int i = 0;
- char *fname = NULL;
+ int fd = -1;
+ int ret = 1;
+ int i = 0;
+ char *fname = NULL;
- if (argc < 2)
- goto out;
+ if (argc < 2)
+ goto out;
- fname = argv[1];
- fd = open (fname, O_RDWR);
- if (fd == -1) {
- perror ("open");
- goto out;
- }
+ fname = argv[1];
+ fd = open(fname, O_RDWR);
+ if (fd == -1) {
+ perror("open");
+ goto out;
+ }
- ret = flock_range_in_steps (fd, 1, F_WRLCK, 0, 2000, 2);
- for (i = 0; i < 5; i++) {
- pthread_create (&th[i], NULL, random_locker, (void *) &fd);
- }
- ret = flock_range_in_steps (fd, 1, F_WRLCK, 0, 2000, 2);
- for (i = 0; i < 5; i++) {
- pthread_join (th[i], NULL);
- }
+ ret = flock_range_in_steps(fd, 1, F_WRLCK, 0, 2000, 2);
+ for (i = 0; i < 5; i++) {
+ pthread_create(&th[i], NULL, random_locker, (void *)&fd);
+ }
+ ret = flock_range_in_steps(fd, 1, F_WRLCK, 0, 2000, 2);
+ for (i = 0; i < 5; i++) {
+ pthread_join(th[i], NULL);
+ }
out:
- if (fd != -1)
- close (fd);
+ if (fd != -1)
+ close(fd);
- return ret;
+ return ret;
}
diff --git a/tests/bugs/glusterfs/getlk_owner.c b/tests/bugs/glusterfs/getlk_owner.c
index 85fd1042496..cbe277318c1 100644
--- a/tests/bugs/glusterfs/getlk_owner.c
+++ b/tests/bugs/glusterfs/getlk_owner.c
@@ -3,24 +3,24 @@
#include <fcntl.h>
#include <string.h>
-#define GETLK_OWNER_CHECK(f, cp, label) \
- do { \
- switch (f.l_type) { \
- case F_RDLCK: \
- case F_WRLCK: \
- ret = 1; \
- goto label; \
- case F_UNLCK: \
- if (!are_flocks_sane (&f, &cp)) { \
- ret = 1; \
- goto label; \
- } \
- break; \
- } \
+#define GETLK_OWNER_CHECK(f, cp, label) \
+ do { \
+ switch (f.l_type) { \
+ case F_RDLCK: \
+ case F_WRLCK: \
+ ret = 1; \
+ goto label; \
+ case F_UNLCK: \
+ if (!are_flocks_sane(&f, &cp)) { \
+ ret = 1; \
+ goto label; \
+ } \
+ break; \
+ } \
} while (0)
void
-flock_init (struct flock *f, short int type, off_t start, off_t len)
+flock_init(struct flock *f, short int type, off_t start, off_t len)
{
f->l_type = type;
f->l_start = start;
@@ -28,17 +28,16 @@ flock_init (struct flock *f, short int type, off_t start, off_t len)
}
int
-flock_cp (struct flock *dst, struct flock *src)
+flock_cp(struct flock *dst, struct flock *src)
{
- memcpy ((void *) dst, (void *) src, sizeof (struct flock));
+ memcpy((void *)dst, (void *)src, sizeof(struct flock));
}
int
-are_flocks_sane (struct flock *src, struct flock *cpy)
+are_flocks_sane(struct flock *src, struct flock *cpy)
{
return ((src->l_whence == cpy->l_whence) &&
- (src->l_start == cpy->l_start) &&
- (src->l_len == cpy->l_len));
+ (src->l_start == cpy->l_start) && (src->l_len == cpy->l_len));
}
/*
@@ -53,68 +52,73 @@ are_flocks_sane (struct flock *src, struct flock *cpy)
*
* */
-int main (int argc, char **argv)
+int
+main(int argc, char **argv)
{
int fd = -1;
int ret = 1;
char *fname = NULL;
- struct flock f = {0,};
- struct flock cp = {0,};
+ struct flock f = {
+ 0,
+ };
+ struct flock cp = {
+ 0,
+ };
if (argc < 2)
goto out;
fname = argv[1];
- fd = open (fname, O_RDWR);
+ fd = open(fname, O_RDWR);
if (fd == -1) {
- perror ("open");
+ perror("open");
goto out;
}
- flock_init (&f, F_WRLCK, 0, 3);
- flock_cp (&cp, &f);
- ret = fcntl (fd, F_SETLK, &f);
+ flock_init(&f, F_WRLCK, 0, 3);
+ flock_cp(&cp, &f);
+ ret = fcntl(fd, F_SETLK, &f);
if (ret) {
- perror ("fcntl");
+ perror("fcntl");
goto out;
}
- if (!are_flocks_sane (&f, &cp)) {
+ if (!are_flocks_sane(&f, &cp)) {
ret = 1;
goto out;
}
- flock_init (&f, F_WRLCK, 3, 3);
- flock_cp (&cp, &f);
- ret = fcntl (fd, F_SETLK, &f);
+ flock_init(&f, F_WRLCK, 3, 3);
+ flock_cp(&cp, &f);
+ ret = fcntl(fd, F_SETLK, &f);
if (ret) {
- perror ("fcntl");
+ perror("fcntl");
goto out;
}
- if (!are_flocks_sane (&f, &cp)) {
+ if (!are_flocks_sane(&f, &cp)) {
ret = 1;
goto out;
}
- flock_init (&f, F_WRLCK, 3, 3);
- flock_cp (&cp, &f);
- ret = fcntl (fd, F_GETLK, &f);
+ flock_init(&f, F_WRLCK, 3, 3);
+ flock_cp(&cp, &f);
+ ret = fcntl(fd, F_GETLK, &f);
if (ret) {
- perror ("fcntl");
+ perror("fcntl");
return 1;
}
- GETLK_OWNER_CHECK (f, cp, out);
+ GETLK_OWNER_CHECK(f, cp, out);
- flock_init (&f, F_RDLCK, 3, 3);
- flock_cp (&cp, &f);
- ret = fcntl (fd, F_GETLK, &f);
+ flock_init(&f, F_RDLCK, 3, 3);
+ flock_cp(&cp, &f);
+ ret = fcntl(fd, F_GETLK, &f);
if (ret) {
- perror ("fcntl");
+ perror("fcntl");
return 1;
}
- GETLK_OWNER_CHECK (f, cp, out);
+ GETLK_OWNER_CHECK(f, cp, out);
out:
if (fd != -1)
- close (fd);
+ close(fd);
return ret;
}
diff --git a/tests/bugs/io-cache/bug-858242.c b/tests/bugs/io-cache/bug-858242.c
index b6a412d578c..ac87a15533e 100644
--- a/tests/bugs/io-cache/bug-858242.c
+++ b/tests/bugs/io-cache/bug-858242.c
@@ -10,72 +10,75 @@
#include <unistd.h>
int
-main (int argc, char *argv[])
+main(int argc, char *argv[])
{
- char *filename = NULL, *volname = NULL, *cmd = NULL;
- char buffer[1024] = {0, };
- int fd = -1;
- int ret = -1;
- struct stat statbuf = {0, };
+ char *filename = NULL, *volname = NULL, *cmd = NULL;
+ char buffer[1024] = {
+ 0,
+ };
+ int fd = -1;
+ int ret = -1;
+ struct stat statbuf = {
+ 0,
+ };
- if (argc != 3) {
- fprintf (stderr, "usage: %s <file-name> <volname>\n", argv[0]);
- goto out;
- }
+ if (argc != 3) {
+ fprintf(stderr, "usage: %s <file-name> <volname>\n", argv[0]);
+ goto out;
+ }
- filename = argv[1];
- volname = argv[2];
+ filename = argv[1];
+ volname = argv[2];
- fd = open (filename, O_RDWR | O_CREAT, 0);
- if (fd < 0) {
- fprintf (stderr, "open (%s) failed (%s)\n", filename,
- strerror (errno));
- goto out;
- }
+ fd = open(filename, O_RDWR | O_CREAT, 0);
+ if (fd < 0) {
+ fprintf(stderr, "open (%s) failed (%s)\n", filename, strerror(errno));
+ goto out;
+ }
- ret = write (fd, "test-content", 12);
- if (ret < 0) {
- fprintf (stderr, "write failed (%s)", strerror (errno));
- goto out;
- }
+ ret = write(fd, "test-content", 12);
+ if (ret < 0) {
+ fprintf(stderr, "write failed (%s)", strerror(errno));
+ goto out;
+ }
- ret = fsync (fd);
- if (ret < 0) {
- fprintf (stderr, "fsync failed (%s)", strerror (errno));
- goto out;
- }
+ ret = fsync(fd);
+ if (ret < 0) {
+ fprintf(stderr, "fsync failed (%s)", strerror(errno));
+ goto out;
+ }
- ret = fstat (fd, &statbuf);
- if (ret < 0) {
- fprintf (stderr, "fstat failed (%s)", strerror (errno));
- goto out;
- }
+ ret = fstat(fd, &statbuf);
+ if (ret < 0) {
+ fprintf(stderr, "fstat failed (%s)", strerror(errno));
+ goto out;
+ }
- ret = asprintf (&cmd, "gluster --mode=script volume stop %s force",
- volname);
- if (ret < 0) {
- fprintf (stderr, "cannot construct cli command string (%s)",
- strerror (errno));
- goto out;
- }
+ ret = asprintf(&cmd, "gluster --mode=script volume stop %s force", volname);
+ if (ret < 0) {
+ fprintf(stderr, "cannot construct cli command string (%s)",
+ strerror(errno));
+ goto out;
+ }
- ret = system (cmd);
- if (ret < 0) {
- fprintf (stderr, "stopping volume (%s) failed", volname);
- goto out;
- }
+ ret = system(cmd);
+ if (ret < 0) {
+ fprintf(stderr, "stopping volume (%s) failed", volname);
+ goto out;
+ }
- sleep (3);
+ sleep(3);
- ret = read (fd, buffer, 1024);
- if (ret >= 0) {
- fprintf (stderr, "read should've returned error, "
- "but is successful\n");
- ret = -1;
- goto out;
- }
+ ret = read(fd, buffer, 1024);
+ if (ret >= 0) {
+ fprintf(stderr,
+ "read should've returned error, "
+ "but is successful\n");
+ ret = -1;
+ goto out;
+ }
- ret = 0;
+ ret = 0;
out:
- return ret;
+ return ret;
}
diff --git a/tests/bugs/io-cache/bug-read-hang.c b/tests/bugs/io-cache/bug-read-hang.c
index 7709a41719d..e1fae97e7e8 100644
--- a/tests/bugs/io-cache/bug-read-hang.c
+++ b/tests/bugs/io-cache/bug-read-hang.c
@@ -9,117 +9,117 @@
int count = 0;
void
-read_cbk (glfs_fd_t *fd, ssize_t ret, void *data) {
-count++;
+read_cbk(glfs_fd_t *fd, ssize_t ret, void *data)
+{
+ count++;
}
glfs_t *
setup_new_client(char *hostname, char *volname, char *log_file, int flag)
{
- int ret = 0;
- glfs_t *fs = NULL;
-
- fs = glfs_new (volname);
- if (!fs) {
- fprintf (stderr, "\nglfs_new: returned NULL (%s)\n",
- strerror (errno));
- goto error;
- }
-
- ret = glfs_set_volfile_server (fs, "tcp", hostname, 24007);
- if (ret < 0) {
- fprintf (stderr, "\nglfs_set_volfile_server failed ret:%d (%s)\n",
- ret, strerror (errno));
- goto error;
- }
-
- ret = glfs_set_logging (fs, log_file, 7);
- if (ret < 0) {
- fprintf (stderr, "\nglfs_set_logging failed with ret: %d (%s)\n",
- ret, strerror (errno));
- goto error;
- }
-
- if (flag == NO_INIT)
- goto out;
-
- ret = glfs_init (fs);
- if (ret < 0) {
- fprintf (stderr, "\nglfs_init failed with ret: %d (%s)\n",
- ret, strerror (errno));
- goto error;
- }
+ int ret = 0;
+ glfs_t *fs = NULL;
+
+ fs = glfs_new(volname);
+ if (!fs) {
+ fprintf(stderr, "\nglfs_new: returned NULL (%s)\n", strerror(errno));
+ goto error;
+ }
+
+ ret = glfs_set_volfile_server(fs, "tcp", hostname, 24007);
+ if (ret < 0) {
+ fprintf(stderr, "\nglfs_set_volfile_server failed ret:%d (%s)\n", ret,
+ strerror(errno));
+ goto error;
+ }
+
+ ret = glfs_set_logging(fs, log_file, 7);
+ if (ret < 0) {
+ fprintf(stderr, "\nglfs_set_logging failed with ret: %d (%s)\n", ret,
+ strerror(errno));
+ goto error;
+ }
+
+ if (flag == NO_INIT)
+ goto out;
+
+ ret = glfs_init(fs);
+ if (ret < 0) {
+ fprintf(stderr, "\nglfs_init failed with ret: %d (%s)\n", ret,
+ strerror(errno));
+ goto error;
+ }
out:
- return fs;
+ return fs;
error:
- return NULL;
+ return NULL;
}
int
-main (int argc, char *argv[])
+main(int argc, char *argv[])
{
- int ret = 0;
- glfs_t *fs = NULL;
- struct glfs_fd *fd = NULL;
- char *volname = NULL;
- char *log_file = NULL;
- char *hostname = NULL;
- char *buf = NULL;
- struct stat stat;
-
- if (argc != 4) {
- fprintf (stderr,
- "Expect following args %s <hostname> <Vol> <log file location>\n"
- , argv[0]);
- return -1;
- }
-
- hostname = argv[1];
- volname = argv[2];
- log_file = argv[3];
-
- fs = setup_new_client (hostname, volname, log_file, 0);
- if (!fs) {
- fprintf (stderr, "\nsetup_new_client: returned NULL (%s)\n",
- strerror (errno));
- goto error;
- }
-
- fd = glfs_opendir (fs, "/");
- if (!fd) {
- fprintf (stderr, "/: %s\n", strerror (errno));
- return -1;
- }
-
- glfs_readdirplus (fd, &stat);
-
- fd = glfs_open (fs, "/test", O_RDWR);
- if (fd == NULL) {
- fprintf (stderr, "glfs_open: returned NULL\n");
- goto error;
- }
-
- buf = (char *) malloc (5);
-
- ret = glfs_pread (fd, buf, 5, 0, 0, NULL);
- if (ret < 0) {
- fprintf (stderr, "Read(%s): %d (%s)\n", "test", ret,
- strerror (errno));
- return ret;
- }
-
- free (buf);
- glfs_close (fd);
-
- ret = glfs_fini (fs);
- if (ret < 0) {
- fprintf (stderr, "glfs_fini failed with ret: %d (%s)\n",
- ret, strerror (errno));
- return -1;
- }
-
- return 0;
-error:
+ int ret = 0;
+ glfs_t *fs = NULL;
+ struct glfs_fd *fd = NULL;
+ char *volname = NULL;
+ char *log_file = NULL;
+ char *hostname = NULL;
+ char *buf = NULL;
+ struct stat stat;
+
+ if (argc != 4) {
+ fprintf(
+ stderr,
+ "Expect following args %s <hostname> <Vol> <log file location>\n",
+ argv[0]);
+ return -1;
+ }
+
+ hostname = argv[1];
+ volname = argv[2];
+ log_file = argv[3];
+
+ fs = setup_new_client(hostname, volname, log_file, 0);
+ if (!fs) {
+ fprintf(stderr, "\nsetup_new_client: returned NULL (%s)\n",
+ strerror(errno));
+ goto error;
+ }
+
+ fd = glfs_opendir(fs, "/");
+ if (!fd) {
+ fprintf(stderr, "/: %s\n", strerror(errno));
+ return -1;
+ }
+
+ glfs_readdirplus(fd, &stat);
+
+ fd = glfs_open(fs, "/test", O_RDWR);
+ if (fd == NULL) {
+ fprintf(stderr, "glfs_open: returned NULL\n");
+ goto error;
+ }
+
+ buf = (char *)malloc(5);
+
+ ret = glfs_pread(fd, buf, 5, 0, 0, NULL);
+ if (ret < 0) {
+ fprintf(stderr, "Read(%s): %d (%s)\n", "test", ret, strerror(errno));
+ return ret;
+ }
+
+ free(buf);
+ glfs_close(fd);
+
+ ret = glfs_fini(fs);
+ if (ret < 0) {
+ fprintf(stderr, "glfs_fini failed with ret: %d (%s)\n", ret,
+ strerror(errno));
return -1;
+ }
+
+ return 0;
+error:
+ return -1;
}
diff --git a/tests/bugs/nfs/bug-1210338.c b/tests/bugs/nfs/bug-1210338.c
index 7a17b9d68ce..d4099244176 100644
--- a/tests/bugs/nfs/bug-1210338.c
+++ b/tests/bugs/nfs/bug-1210338.c
@@ -7,26 +7,25 @@
#include <fcntl.h>
#include <sys/stat.h>
-
int
-main (int argc, char *argv[])
+main(int argc, char *argv[])
{
- int ret = -1;
- int fd = -1;
+ int ret = -1;
+ int fd = -1;
- fd = open (argv[1], O_CREAT|O_EXCL, 0644);
+ fd = open(argv[1], O_CREAT | O_EXCL, 0644);
- if (fd == -1) {
- fprintf (stderr, "creation of the file %s failed (%s)\n", argv[1],
- strerror (errno));
- goto out;
- }
+ if (fd == -1) {
+ fprintf(stderr, "creation of the file %s failed (%s)\n", argv[1],
+ strerror(errno));
+ goto out;
+ }
- ret = 0;
+ ret = 0;
out:
- if (fd > 0)
- close (fd);
+ if (fd > 0)
+ close(fd);
- return ret;
+ return ret;
}
diff --git a/tests/bugs/posix/bug-1175711.c b/tests/bugs/posix/bug-1175711.c
index fbbea3f636b..8ab193c4014 100644
--- a/tests/bugs/posix/bug-1175711.c
+++ b/tests/bugs/posix/bug-1175711.c
@@ -6,32 +6,32 @@
int
main(int argc, char **argv)
{
- DIR *dir = NULL;
- struct dirent *entry = NULL;
- int ret = 0;
- char *path = NULL;
+ DIR *dir = NULL;
+ struct dirent *entry = NULL;
+ int ret = 0;
+ char *path = NULL;
- assert (argc == 2);
- path = argv[1];
+ assert(argc == 2);
+ path = argv[1];
- dir = opendir(path);
- if (!dir) {
- printf("opendir(%s) failed.\n", path);
- return -1;
- }
+ dir = opendir(path);
+ if (!dir) {
+ printf("opendir(%s) failed.\n", path);
+ return -1;
+ }
#ifdef _DIRENT_HAVE_D_TYPE
- while ((entry = readdir(dir)) != NULL) {
- if (entry->d_type == DT_UNKNOWN) {
- printf("d_type found to be DT_UNKNOWN\n");
- ret = -1;
- break;
- }
+ while ((entry = readdir(dir)) != NULL) {
+ if (entry->d_type == DT_UNKNOWN) {
+ printf("d_type found to be DT_UNKNOWN\n");
+ ret = -1;
+ break;
}
+ }
#endif
- if (dir)
- closedir(dir);
+ if (dir)
+ closedir(dir);
- return ret;
+ return ret;
}
diff --git a/tests/bugs/posix/disallow-gfid-volumeid-fremovexattr.c b/tests/bugs/posix/disallow-gfid-volumeid-fremovexattr.c
index 325edbbed97..4ed3181d48f 100644
--- a/tests/bugs/posix/disallow-gfid-volumeid-fremovexattr.c
+++ b/tests/bugs/posix/disallow-gfid-volumeid-fremovexattr.c
@@ -5,94 +5,100 @@
#include <string.h>
int
-main (int argc, char *argv[])
+main(int argc, char *argv[])
{
- glfs_t *fs = NULL;
- int ret = 0;
- int i = 0;
- glfs_fd_t *fd = NULL;
- char *logfile = NULL;
- char *hostname = NULL;
+ glfs_t *fs = NULL;
+ int ret = 0;
+ int i = 0;
+ glfs_fd_t *fd = NULL;
+ char *logfile = NULL;
+ char *hostname = NULL;
- if (argc != 4) {
- fprintf (stderr,
- "Expect following args %s <hostname> <Vol> <log file>\n"
- , argv[0]);
- return -1;
- }
+ if (argc != 4) {
+ fprintf(stderr,
+ "Expect following args %s <hostname> <Vol> <log file>\n",
+ argv[0]);
+ return -1;
+ }
- hostname = argv[1];
- logfile = argv[3];
+ hostname = argv[1];
+ logfile = argv[3];
- fs = glfs_new (argv[2]);
- if (!fs) {
- fprintf (stderr, "glfs_new: returned NULL (%s)\n",
- strerror (errno));
- return -1;
- }
+ fs = glfs_new(argv[2]);
+ if (!fs) {
+ fprintf(stderr, "glfs_new: returned NULL (%s)\n", strerror(errno));
+ return -1;
+ }
- ret = glfs_set_volfile_server (fs, "tcp", hostname, 24007);
- if (ret < 0) {
- fprintf (stderr, "glfs_set_volfile_server failed ret:%d (%s)\n",
- ret, strerror (errno));
- return -1;
- }
+ ret = glfs_set_volfile_server(fs, "tcp", hostname, 24007);
+ if (ret < 0) {
+ fprintf(stderr, "glfs_set_volfile_server failed ret:%d (%s)\n", ret,
+ strerror(errno));
+ return -1;
+ }
- ret = glfs_set_logging (fs, logfile, 7);
- if (ret < 0) {
- fprintf (stderr, "glfs_set_logging failed with ret: %d (%s)\n",
- ret, strerror (errno));
- return -1;
- }
+ ret = glfs_set_logging(fs, logfile, 7);
+ if (ret < 0) {
+ fprintf(stderr, "glfs_set_logging failed with ret: %d (%s)\n", ret,
+ strerror(errno));
+ return -1;
+ }
- ret = glfs_init (fs);
- if (ret < 0) {
- fprintf (stderr, "glfs_init failed with ret: %d (%s)\n",
- ret, strerror (errno));
- return -1;
- }
+ ret = glfs_init(fs);
+ if (ret < 0) {
+ fprintf(stderr, "glfs_init failed with ret: %d (%s)\n", ret,
+ strerror(errno));
+ return -1;
+ }
- fd = glfs_opendir (fs, "/");
- if (!fd) {
- fprintf (stderr, "glfs_opendir failed with (%s)\n",
- strerror (errno));
- return -1;
- }
+ fd = glfs_opendir(fs, "/");
+ if (!fd) {
+ fprintf(stderr, "glfs_opendir failed with (%s)\n", strerror(errno));
+ return -1;
+ }
- ret = glfs_fremovexattr (fd, "trusted.gfid");
- if (ret == 0 || errno != EPERM) {
- fprintf (stderr, "glfs_fremovexattr gfid exited with ret: "
- "%d (%s)\n", ret, strerror (errno));
- return -1;
- }
+ ret = glfs_fremovexattr(fd, "trusted.gfid");
+ if (ret == 0 || errno != EPERM) {
+ fprintf(stderr,
+ "glfs_fremovexattr gfid exited with ret: "
+ "%d (%s)\n",
+ ret, strerror(errno));
+ return -1;
+ }
- ret = glfs_fremovexattr (fd, "trusted.glusterfs.volume-id");
- if (ret == 0 || errno != EPERM) {
- fprintf (stderr, "glfs_fremovexattr volume-id exited with ret: "
- "%d (%s)\n", ret, strerror (errno));
- return -1;
- }
+ ret = glfs_fremovexattr(fd, "trusted.glusterfs.volume-id");
+ if (ret == 0 || errno != EPERM) {
+ fprintf(stderr,
+ "glfs_fremovexattr volume-id exited with ret: "
+ "%d (%s)\n",
+ ret, strerror(errno));
+ return -1;
+ }
- ret = glfs_fsetxattr (fd, "trusted.abc", "abc", 3, 0);
- if (ret < 0) {
- fprintf (stderr, "glfs_fsetxattr trusted.abc exited with ret: "
- "%d (%s)\n", ret, strerror (errno));
- return -1;
- }
+ ret = glfs_fsetxattr(fd, "trusted.abc", "abc", 3, 0);
+ if (ret < 0) {
+ fprintf(stderr,
+ "glfs_fsetxattr trusted.abc exited with ret: "
+ "%d (%s)\n",
+ ret, strerror(errno));
+ return -1;
+ }
- ret = glfs_fremovexattr (fd, "trusted.abc");
- if (ret < 0) {
- fprintf (stderr, "glfs_fremovexattr trusted.abc exited with "
- "ret: %d (%s)\n", ret, strerror (errno));
- return -1;
- }
+ ret = glfs_fremovexattr(fd, "trusted.abc");
+ if (ret < 0) {
+ fprintf(stderr,
+ "glfs_fremovexattr trusted.abc exited with "
+ "ret: %d (%s)\n",
+ ret, strerror(errno));
+ return -1;
+ }
- (void) glfs_closedir(fd);
- ret = glfs_fini (fs);
- if (ret < 0) {
- fprintf (stderr, "glfs_fini failed with ret: %d (%s)\n",
- ret, strerror (errno));
- return -1;
- }
- return 0;
+ (void)glfs_closedir(fd);
+ ret = glfs_fini(fs);
+ if (ret < 0) {
+ fprintf(stderr, "glfs_fini failed with ret: %d (%s)\n", ret,
+ strerror(errno));
+ return -1;
+ }
+ return 0;
}
diff --git a/tests/bugs/protocol/bug-808400-fcntl.c b/tests/bugs/protocol/bug-808400-fcntl.c
index 87a83f317b8..a703ca5c120 100644
--- a/tests/bugs/protocol/bug-808400-fcntl.c
+++ b/tests/bugs/protocol/bug-808400-fcntl.c
@@ -12,106 +12,113 @@
#endif
int
-run_child (char *filename)
+run_child(char *filename)
{
- int fd = -1, ret = -1;
- struct flock lock = {0, };
- int ppid = 0;
-
- fd = open (filename, O_RDWR);
- if (fd < 0) {
- fprintf (stderr, "open failed (%s)\n", strerror (errno));
- goto out;
- }
-
- ppid = getppid ();
-
- lock.l_type = F_WRLCK;
- lock.l_whence = SEEK_SET;
- lock.l_start = 0;
- lock.l_len = 0;
-
- ret = fcntl (fd, F_GETLK, &lock);
- if (ret < 0) {
- fprintf (stderr, "GETLK failed (%s)\n", strerror (errno));
- goto out;
- }
-
- if ((lock.l_type == F_UNLCK) ||
- (ppid != lock.l_pid)) {
- fprintf (stderr, "no locks present, though parent has held "
- "one\n");
- ret = -1;
- goto out;
- }
-
- ret = 0;
+ int fd = -1, ret = -1;
+ struct flock lock = {
+ 0,
+ };
+ int ppid = 0;
+
+ fd = open(filename, O_RDWR);
+ if (fd < 0) {
+ fprintf(stderr, "open failed (%s)\n", strerror(errno));
+ goto out;
+ }
+
+ ppid = getppid();
+
+ lock.l_type = F_WRLCK;
+ lock.l_whence = SEEK_SET;
+ lock.l_start = 0;
+ lock.l_len = 0;
+
+ ret = fcntl(fd, F_GETLK, &lock);
+ if (ret < 0) {
+ fprintf(stderr, "GETLK failed (%s)\n", strerror(errno));
+ goto out;
+ }
+
+ if ((lock.l_type == F_UNLCK) || (ppid != lock.l_pid)) {
+ fprintf(stderr,
+ "no locks present, though parent has held "
+ "one\n");
+ ret = -1;
+ goto out;
+ }
+
+ ret = 0;
out:
- return ret;
+ return ret;
}
int
-main (int argc, char *argv[])
+main(int argc, char *argv[])
{
- int fd = -1, ret = -1, status = 0;
- char *filename = NULL, *cmd = NULL;
- struct stat stbuf = {0, };
- struct flock lock = {0, };
-
- if (argc != 3) {
- fprintf (stderr, "Usage: %s <filename> "
- "<gluster-cmd-to-trigger-graph-switch>\n", argv[0]);
- goto out;
- }
-
- filename = argv[1];
- cmd = argv[2];
-
- fd = open (filename, O_RDWR | O_CREAT, 0);
- if (fd < 0) {
- fprintf (stderr, "open (%s) failed (%s)\n", filename,
- strerror (errno));
- goto out;
- }
-
- lock.l_type = F_WRLCK;
- lock.l_whence = SEEK_SET;
- lock.l_start = 0;
- lock.l_len = 0;
-
- ret = fcntl (fd, F_SETLK, &lock);
- if (ret < 0) {
- fprintf (stderr, "fcntl failed (%s)\n", strerror (errno));
- goto out;
- }
-
- system (cmd);
-
- /* wait till graph switch completes */
- ret = fstat64 (fd, &stbuf);
- if (ret < 0) {
- fprintf (stderr, "fstat64 failure (%s)\n", strerror (errno));
- goto out;
- }
-
- sleep (10);
-
- /* By now old-graph would be disconnected and locks should be cleaned
- * up if they are not migrated. Check that by trying to acquire a lock
- * on a new fd opened by another process on same file.
- */
- ret = fork ();
- if (ret == 0) {
- ret = run_child (filename);
+ int fd = -1, ret = -1, status = 0;
+ char *filename = NULL, *cmd = NULL;
+ struct stat stbuf = {
+ 0,
+ };
+ struct flock lock = {
+ 0,
+ };
+
+ if (argc != 3) {
+ fprintf(stderr,
+ "Usage: %s <filename> "
+ "<gluster-cmd-to-trigger-graph-switch>\n",
+ argv[0]);
+ goto out;
+ }
+
+ filename = argv[1];
+ cmd = argv[2];
+
+ fd = open(filename, O_RDWR | O_CREAT, 0);
+ if (fd < 0) {
+ fprintf(stderr, "open (%s) failed (%s)\n", filename, strerror(errno));
+ goto out;
+ }
+
+ lock.l_type = F_WRLCK;
+ lock.l_whence = SEEK_SET;
+ lock.l_start = 0;
+ lock.l_len = 0;
+
+ ret = fcntl(fd, F_SETLK, &lock);
+ if (ret < 0) {
+ fprintf(stderr, "fcntl failed (%s)\n", strerror(errno));
+ goto out;
+ }
+
+ system(cmd);
+
+ /* wait till graph switch completes */
+ ret = fstat64(fd, &stbuf);
+ if (ret < 0) {
+ fprintf(stderr, "fstat64 failure (%s)\n", strerror(errno));
+ goto out;
+ }
+
+ sleep(10);
+
+ /* By now old-graph would be disconnected and locks should be cleaned
+ * up if they are not migrated. Check that by trying to acquire a lock
+ * on a new fd opened by another process on same file.
+ */
+ ret = fork();
+ if (ret == 0) {
+ ret = run_child(filename);
+ } else {
+ wait(&status);
+ if (WIFEXITED(status)) {
+ ret = WEXITSTATUS(status);
} else {
- wait (&status);
- if (WIFEXITED(status)) {
- ret = WEXITSTATUS(status);
- } else {
- ret = 0;
- }
+ ret = 0;
}
+ }
out:
- return ret;
+ return ret;
}
diff --git a/tests/bugs/protocol/bug-808400-flock.c b/tests/bugs/protocol/bug-808400-flock.c
index bd2ce8cfb01..54a507cc227 100644
--- a/tests/bugs/protocol/bug-808400-flock.c
+++ b/tests/bugs/protocol/bug-808400-flock.c
@@ -12,85 +12,89 @@
#endif
int
-run_child (char *filename)
+run_child(char *filename)
{
- int fd = -1, ret = -1;
+ int fd = -1, ret = -1;
- fd = open (filename, O_RDWR);
- if (fd < 0) {
- fprintf (stderr, "open failed (%s)\n", strerror (errno));
- goto out;
- }
+ fd = open(filename, O_RDWR);
+ if (fd < 0) {
+ fprintf(stderr, "open failed (%s)\n", strerror(errno));
+ goto out;
+ }
- ret = flock (fd, LOCK_EX | LOCK_NB);
- if ((ret == 0) || (errno != EWOULDBLOCK)) {
- fprintf (stderr, "no locks present, though parent has held "
- "one\n");
- ret = -1;
- goto out;
- }
+ ret = flock(fd, LOCK_EX | LOCK_NB);
+ if ((ret == 0) || (errno != EWOULDBLOCK)) {
+ fprintf(stderr,
+ "no locks present, though parent has held "
+ "one\n");
+ ret = -1;
+ goto out;
+ }
- ret = 0;
+ ret = 0;
out:
- return ret;
+ return ret;
}
int
-main (int argc, char *argv[])
+main(int argc, char *argv[])
{
- int fd = -1, ret = -1, status = 0;
- char *filename = NULL, *cmd = NULL;
- struct stat stbuf = {0, };
+ int fd = -1, ret = -1, status = 0;
+ char *filename = NULL, *cmd = NULL;
+ struct stat stbuf = {
+ 0,
+ };
- if (argc != 3) {
- fprintf (stderr, "Usage: %s <filename> "
- "<gluster-cmd-to-trigger-graph-switch>\n", argv[0]);
- goto out;
- }
+ if (argc != 3) {
+ fprintf(stderr,
+ "Usage: %s <filename> "
+ "<gluster-cmd-to-trigger-graph-switch>\n",
+ argv[0]);
+ goto out;
+ }
- filename = argv[1];
- cmd = argv[2];
+ filename = argv[1];
+ cmd = argv[2];
- fd = open (filename, O_RDWR | O_CREAT, 0);
- if (fd < 0) {
- fprintf (stderr, "open (%s) failed (%s)\n", filename,
- strerror (errno));
- goto out;
- }
+ fd = open(filename, O_RDWR | O_CREAT, 0);
+ if (fd < 0) {
+ fprintf(stderr, "open (%s) failed (%s)\n", filename, strerror(errno));
+ goto out;
+ }
- ret = flock (fd, LOCK_EX);
- if (ret < 0) {
- fprintf (stderr, "flock failed (%s)\n", strerror (errno));
- goto out;
- }
+ ret = flock(fd, LOCK_EX);
+ if (ret < 0) {
+ fprintf(stderr, "flock failed (%s)\n", strerror(errno));
+ goto out;
+ }
- system (cmd);
+ system(cmd);
- /* wait till graph switch completes */
- ret = fstat64 (fd, &stbuf);
- if (ret < 0) {
- fprintf (stderr, "fstat64 failure (%s)\n", strerror (errno));
- goto out;
- }
+ /* wait till graph switch completes */
+ ret = fstat64(fd, &stbuf);
+ if (ret < 0) {
+ fprintf(stderr, "fstat64 failure (%s)\n", strerror(errno));
+ goto out;
+ }
- sleep (10);
+ sleep(10);
- /* By now old-graph would be disconnected and locks should be cleaned
- * up if they are not migrated. Check that by trying to acquire a lock
- * on a new fd opened by another process on same file
- */
- ret = fork ();
- if (ret == 0) {
- ret = run_child (filename);
+ /* By now old-graph would be disconnected and locks should be cleaned
+ * up if they are not migrated. Check that by trying to acquire a lock
+ * on a new fd opened by another process on same file
+ */
+ ret = fork();
+ if (ret == 0) {
+ ret = run_child(filename);
+ } else {
+ wait(&status);
+ if (WIFEXITED(status)) {
+ ret = WEXITSTATUS(status);
} else {
- wait (&status);
- if (WIFEXITED(status)) {
- ret = WEXITSTATUS(status);
- } else {
- ret = 0;
- }
+ ret = 0;
}
+ }
out:
- return ret;
+ return ret;
}
diff --git a/tests/bugs/quick-read/bz1523599/test_bz1523599.c b/tests/bugs/quick-read/bz1523599/test_bz1523599.c
index 843408680a7..5076a9447f3 100644
--- a/tests/bugs/quick-read/bz1523599/test_bz1523599.c
+++ b/tests/bugs/quick-read/bz1523599/test_bz1523599.c
@@ -1,7 +1,8 @@
/*
* ./test_bz1523599 0 vm140-111 gv0 test211 log
* ./test_bz1523599 1 vm140-111 gv0 test211 log
- * Open - Discard - Read - Then check read information to see if the initial TEST_STR_LEN/2 bytes read zero
+ * Open - Discard - Read - Then check read information to see if the initial
+ * TEST_STR_LEN/2 bytes read zero
*/
#define _GNU_SOURCE
@@ -15,182 +16,183 @@
#define TEST_STR_LEN 2048
enum fallocate_flag {
- TEST_WRITE,
- TEST_DISCARD,
- TEST_ZEROFILL,
+ TEST_WRITE,
+ TEST_DISCARD,
+ TEST_ZEROFILL,
};
-void print_str(char *str, int len)
+void
+print_str(char *str, int len)
{
- int i, addr;
-
- printf("%07x\t", 0);
- for (i = 0; i < len; i++) {
- printf("%02x", str[i]);
- if (i) {
- if ((i + 1) % 16 == 0)
- printf("\n%07x\t", i+1);
- else if ((i + 1) % 4 == 0)
- printf(" ");
- }
- }
- printf("\n");
+ int i, addr;
+
+ printf("%07x\t", 0);
+ for (i = 0; i < len; i++) {
+ printf("%02x", str[i]);
+ if (i) {
+ if ((i + 1) % 16 == 0)
+ printf("\n%07x\t", i + 1);
+ else if ((i + 1) % 4 == 0)
+ printf(" ");
+ }
+ }
+ printf("\n");
}
int
test_read(char *str, int total_length, int len_zero)
{
- int i;
- int ret = 0;
-
- for (i = 0; i < len_zero; i++) {
- if (str[i]) {
- fprintf(stderr, "char at position %d not zeroed out\n",
- i);
- ret = -EIO;
- goto out;
- }
- }
-
- for (i = len_zero; i < total_length; i++) {
- if (str[i] != 0x11) {
- fprintf(stderr,
- "char at position %d does not contain pattern\n",
- i);
- ret = -EIO;
- goto out;
- }
- }
+ int i;
+ int ret = 0;
+
+ for (i = 0; i < len_zero; i++) {
+ if (str[i]) {
+ fprintf(stderr, "char at position %d not zeroed out\n", i);
+ ret = -EIO;
+ goto out;
+ }
+ }
+
+ for (i = len_zero; i < total_length; i++) {
+ if (str[i] != 0x11) {
+ fprintf(stderr, "char at position %d does not contain pattern\n",
+ i);
+ ret = -EIO;
+ goto out;
+ }
+ }
out:
- return ret;
+ return ret;
}
-int main(int argc, char *argv[])
+int
+main(int argc, char *argv[])
{
- int opcode;
- char *host_name, *volume_name, *file_path, *glfs_log_path;
- glfs_t *fs = NULL;
- glfs_fd_t *fd = NULL;
- off_t offset = 0;
- size_t len_zero = TEST_STR_LEN / 2;
- char writestr[TEST_STR_LEN];
- char readstr[TEST_STR_LEN];
- struct iovec iov = {&readstr, TEST_STR_LEN};
- int i;
- int ret = 1;
-
- for (i = 0; i < TEST_STR_LEN; i++)
- writestr[i] = 0x11;
- for (i = 0; i < TEST_STR_LEN; i++)
- readstr[i] = 0x22;
-
- if (argc != 6) {
- fprintf(stderr,
- "Syntax: %s <test type> <host> <volname> <file-path> <log-file>\n",
- argv[0]);
- return 1;
- }
-
- opcode = atoi(argv[1]);
- host_name = argv[2];
- volume_name = argv[3];
- file_path = argv[4];
- glfs_log_path = argv[5];
-
- fs = glfs_new(volume_name);
- if (!fs) {
- perror("glfs_new");
- return 1;
- }
-
- ret = glfs_set_volfile_server(fs, "tcp", host_name, 24007);
- if (ret != 0) {
- perror("glfs_set_volfile_server");
- goto out;
- }
-
- ret = glfs_set_logging(fs, glfs_log_path, 7);
- if (ret != 0) {
- perror("glfs_set_logging");
- goto out;
- }
-
- ret = glfs_init(fs);
- if (ret != 0) {
- perror("glfs_init");
- goto out;
- }
-
- fd = glfs_creat(fs, file_path, O_RDWR, 0777);
- if (fd == NULL) {
- perror("glfs_creat");
- ret = -1;
- goto out;
- }
-
- switch (opcode) {
- case TEST_WRITE:
- fprintf(stderr, "Test Write\n");
- ret = glfs_write(fd, writestr, TEST_STR_LEN, 0);
- if (ret < 0) {
- perror("glfs_write");
- goto out;
- } else if (ret != TEST_STR_LEN) {
- fprintf(stderr, "insufficient data written %d \n", ret);
- ret = -EIO;
- goto out;
- }
- ret = 0;
- goto out;
- case TEST_DISCARD:
- fprintf(stderr, "Test Discard\n");
- ret = glfs_discard(fd, offset, len_zero);
- if (ret < 0) {
- if (errno == EOPNOTSUPP) {
- fprintf(stderr, "Operation not supported\n");
- ret = 0;
- goto out;
- }
- perror("glfs_discard");
- goto out;
- }
- goto test_read;
- case TEST_ZEROFILL:
- fprintf(stderr, "Test Zerofill\n");
- ret = glfs_zerofill(fd, offset, len_zero);
- if (ret < 0) {
- if (errno == EOPNOTSUPP) {
- fprintf(stderr, "Operation not supported\n");
- ret = 0;
- goto out;
- }
- perror("glfs_zerofill");
- goto out;
- }
- goto test_read;
- default:
- ret = -1;
- fprintf(stderr, "Incorrect test code %d\n", opcode);
- goto out;
- }
+ int opcode;
+ char *host_name, *volume_name, *file_path, *glfs_log_path;
+ glfs_t *fs = NULL;
+ glfs_fd_t *fd = NULL;
+ off_t offset = 0;
+ size_t len_zero = TEST_STR_LEN / 2;
+ char writestr[TEST_STR_LEN];
+ char readstr[TEST_STR_LEN];
+ struct iovec iov = {&readstr, TEST_STR_LEN};
+ int i;
+ int ret = 1;
+
+ for (i = 0; i < TEST_STR_LEN; i++)
+ writestr[i] = 0x11;
+ for (i = 0; i < TEST_STR_LEN; i++)
+ readstr[i] = 0x22;
+
+ if (argc != 6) {
+ fprintf(
+ stderr,
+ "Syntax: %s <test type> <host> <volname> <file-path> <log-file>\n",
+ argv[0]);
+ return 1;
+ }
+
+ opcode = atoi(argv[1]);
+ host_name = argv[2];
+ volume_name = argv[3];
+ file_path = argv[4];
+ glfs_log_path = argv[5];
+
+ fs = glfs_new(volume_name);
+ if (!fs) {
+ perror("glfs_new");
+ return 1;
+ }
+
+ ret = glfs_set_volfile_server(fs, "tcp", host_name, 24007);
+ if (ret != 0) {
+ perror("glfs_set_volfile_server");
+ goto out;
+ }
+
+ ret = glfs_set_logging(fs, glfs_log_path, 7);
+ if (ret != 0) {
+ perror("glfs_set_logging");
+ goto out;
+ }
+
+ ret = glfs_init(fs);
+ if (ret != 0) {
+ perror("glfs_init");
+ goto out;
+ }
+
+ fd = glfs_creat(fs, file_path, O_RDWR, 0777);
+ if (fd == NULL) {
+ perror("glfs_creat");
+ ret = -1;
+ goto out;
+ }
+
+ switch (opcode) {
+ case TEST_WRITE:
+ fprintf(stderr, "Test Write\n");
+ ret = glfs_write(fd, writestr, TEST_STR_LEN, 0);
+ if (ret < 0) {
+ perror("glfs_write");
+ goto out;
+ } else if (ret != TEST_STR_LEN) {
+ fprintf(stderr, "insufficient data written %d \n", ret);
+ ret = -EIO;
+ goto out;
+ }
+ ret = 0;
+ goto out;
+ case TEST_DISCARD:
+ fprintf(stderr, "Test Discard\n");
+ ret = glfs_discard(fd, offset, len_zero);
+ if (ret < 0) {
+ if (errno == EOPNOTSUPP) {
+ fprintf(stderr, "Operation not supported\n");
+ ret = 0;
+ goto out;
+ }
+ perror("glfs_discard");
+ goto out;
+ }
+ goto test_read;
+ case TEST_ZEROFILL:
+ fprintf(stderr, "Test Zerofill\n");
+ ret = glfs_zerofill(fd, offset, len_zero);
+ if (ret < 0) {
+ if (errno == EOPNOTSUPP) {
+ fprintf(stderr, "Operation not supported\n");
+ ret = 0;
+ goto out;
+ }
+ perror("glfs_zerofill");
+ goto out;
+ }
+ goto test_read;
+ default:
+ ret = -1;
+ fprintf(stderr, "Incorrect test code %d\n", opcode);
+ goto out;
+ }
test_read:
- ret = glfs_readv(fd, &iov, 1, 0);
- if (ret < 0) {
- perror("glfs_readv");
- goto out;
- }
+ ret = glfs_readv(fd, &iov, 1, 0);
+ if (ret < 0) {
+ perror("glfs_readv");
+ goto out;
+ }
- /* printf("Read str\n"); print_str(readstr, TEST_STR_LEN); printf("\n"); */
- ret = test_read(readstr, TEST_STR_LEN, len_zero);
+ /* printf("Read str\n"); print_str(readstr, TEST_STR_LEN); printf("\n"); */
+ ret = test_read(readstr, TEST_STR_LEN, len_zero);
out:
- if (fd)
- glfs_close(fd);
- glfs_fini(fs);
+ if (fd)
+ glfs_close(fd);
+ glfs_fini(fs);
- if (ret)
- return -1;
+ if (ret)
+ return -1;
- return 0;
+ return 0;
}
diff --git a/tests/bugs/readdir-ahead/bug-1390050.c b/tests/bugs/readdir-ahead/bug-1390050.c
index 5593a1d4c0c..9578df2dd90 100644
--- a/tests/bugs/readdir-ahead/bug-1390050.c
+++ b/tests/bugs/readdir-ahead/bug-1390050.c
@@ -8,63 +8,65 @@
#include <errno.h>
int
-main (int argc, char *argv[])
+main(int argc, char *argv[])
{
- const char *glfs_dir = NULL, *filepath = NULL;
- DIR *dirfd = NULL;
- int filefd = 0, ret = 0;
- struct stat stbuf = {0, };
- size_t size_before_write = 0;
+ const char *glfs_dir = NULL, *filepath = NULL;
+ DIR *dirfd = NULL;
+ int filefd = 0, ret = 0;
+ struct stat stbuf = {
+ 0,
+ };
+ size_t size_before_write = 0;
- glfs_dir = argv[1];
- filepath = argv[2];
- dirfd = opendir (glfs_dir);
- if (dirfd == NULL) {
- fprintf (stderr, "opening directory failed (%s)\n",
- strerror (errno));
- goto err;
- }
+ glfs_dir = argv[1];
+ filepath = argv[2];
+ dirfd = opendir(glfs_dir);
+ if (dirfd == NULL) {
+ fprintf(stderr, "opening directory failed (%s)\n", strerror(errno));
+ goto err;
+ }
- filefd = open (filepath, O_RDWR);
- if (filefd < 0) {
- fprintf (stderr, "open failed on path %s (%s)\n", filepath,
- strerror (errno));
- goto err;
- }
+ filefd = open(filepath, O_RDWR);
+ if (filefd < 0) {
+ fprintf(stderr, "open failed on path %s (%s)\n", filepath,
+ strerror(errno));
+ goto err;
+ }
- ret = stat (filepath, &stbuf);
- if (ret < 0) {
- fprintf (stderr, "stat failed on path %s (%s)\n", filepath,
- strerror (errno));
- goto err;
- }
+ ret = stat(filepath, &stbuf);
+ if (ret < 0) {
+ fprintf(stderr, "stat failed on path %s (%s)\n", filepath,
+ strerror(errno));
+ goto err;
+ }
- size_before_write = stbuf.st_size;
+ size_before_write = stbuf.st_size;
- ret = write (filefd, "testdata", strlen ("testdata123") + 1);
- if (ret <= 0) {
- fprintf (stderr, "write failed (%s)\n", strerror (errno));
- goto err;
- }
+ ret = write(filefd, "testdata", strlen("testdata123") + 1);
+ if (ret <= 0) {
+ fprintf(stderr, "write failed (%s)\n", strerror(errno));
+ goto err;
+ }
- while (readdir (dirfd)) {
- /* do nothing */
- }
+ while (readdir(dirfd)) {
+ /* do nothing */
+ }
- ret = stat (filepath, &stbuf);
- if (ret < 0) {
- fprintf (stderr, "stat failed on path %s (%s)\n",
- strerror (errno));
- goto err;
- }
+ ret = stat(filepath, &stbuf);
+ if (ret < 0) {
+ fprintf(stderr, "stat failed on path %s (%s)\n", strerror(errno));
+ goto err;
+ }
- if (stbuf.st_size == size_before_write) {
- fprintf (stderr, "file size (%lu) has not changed even after "
- "its written to\n", stbuf.st_size);
- goto err;
- }
+ if (stbuf.st_size == size_before_write) {
+ fprintf(stderr,
+ "file size (%lu) has not changed even after "
+ "its written to\n",
+ stbuf.st_size);
+ goto err;
+ }
- return 0;
+ return 0;
err:
- return -1;
+ return -1;
}
diff --git a/tests/bugs/replicate/bug-1250170-fsync.c b/tests/bugs/replicate/bug-1250170-fsync.c
index 421fb5c5067..21fd96594aa 100644
--- a/tests/bugs/replicate/bug-1250170-fsync.c
+++ b/tests/bugs/replicate/bug-1250170-fsync.c
@@ -7,50 +7,50 @@
#include <unistd.h>
#include <string.h>
-int main (int argc, char **argv)
+int
+main(int argc, char **argv)
{
- char *file = NULL;
- int fd = -1;
- char *buffer = NULL;
- size_t buf_size = 0;
- size_t written = 0;
- int ret = 0;
- off_t offset = 0;
- int i = 0;
- int loop_count = 5;
+ char *file = NULL;
+ int fd = -1;
+ char *buffer = NULL;
+ size_t buf_size = 0;
+ size_t written = 0;
+ int ret = 0;
+ off_t offset = 0;
+ int i = 0;
+ int loop_count = 5;
- if (argc < 2) {
- printf ("Usage:%s <filename>\n", argv[0]);
- return -1;
- }
+ if (argc < 2) {
+ printf("Usage:%s <filename>\n", argv[0]);
+ return -1;
+ }
- file = argv[1];
- buf_size = 1024;
- buffer = malloc(buf_size);
- if (!buffer) {
- perror("malloc");
- return -1;
- }
- memset (buffer, 'R', buf_size);
+ file = argv[1];
+ buf_size = 1024;
+ buffer = malloc(buf_size);
+ if (!buffer) {
+ perror("malloc");
+ return -1;
+ }
+ memset(buffer, 'R', buf_size);
- fd = open(file, O_WRONLY);
- if (fd == -1) {
- perror("open");
- return -1;
- }
+ fd = open(file, O_WRONLY);
+ if (fd == -1) {
+ perror("open");
+ return -1;
+ }
- for (i = 0; i < loop_count; i++) {
- ret = write (fd, buffer, buf_size);
- if (ret == -1) {
- perror("write");
- return ret;
- } else {
- written += ret;
- }
- offset = lseek (fd, 0 , SEEK_SET);
+ for (i = 0; i < loop_count; i++) {
+ ret = write(fd, buffer, buf_size);
+ if (ret == -1) {
+ perror("write");
+ return ret;
+ } else {
+ written += ret;
}
+ offset = lseek(fd, 0, SEEK_SET);
+ }
- free(buffer);
- return 0;
-
+ free(buffer);
+ return 0;
}
diff --git a/tests/bugs/shard/bug-shard-discard.c b/tests/bugs/shard/bug-shard-discard.c
index b1268278fa5..15dca6c2181 100644
--- a/tests/bugs/shard/bug-shard-discard.c
+++ b/tests/bugs/shard/bug-shard-discard.c
@@ -4,63 +4,66 @@
#include <glusterfs/api/glfs-handles.h>
int
-main (int argc, char *argv[])
+main(int argc, char *argv[])
{
- int ret = 0;
- off_t off = 0;
- size_t len = 0;
- glfs_t *fs = NULL;
- glfs_fd_t *fd = NULL;
+ int ret = 0;
+ off_t off = 0;
+ size_t len = 0;
+ glfs_t *fs = NULL;
+ glfs_fd_t *fd = NULL;
- if (argc != 7) {
- fprintf (stderr, "Syntax: %s <host> <volname> <file-path> <off> <len> <log-file>\n", argv[0]);
- return 1;
- }
+ if (argc != 7) {
+ fprintf(
+ stderr,
+ "Syntax: %s <host> <volname> <file-path> <off> <len> <log-file>\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_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[6], 7);
- if (ret != 0) {
- fprintf (stderr, "glfs_set_logging: returned %d\n", ret);
- goto out;
- }
+ ret = glfs_set_logging(fs, argv[6], 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_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;
+ }
- off = atoi (argv[4]);
- len = atoi (argv[5]);
+ off = atoi(argv[4]);
+ len = atoi(argv[5]);
- ret = glfs_discard (fd, off, len);
- if (ret <= 0) {
- fprintf (stderr, "glfs_discard: returned %d\n", ret);
- goto out;
- }
+ ret = glfs_discard(fd, off, len);
+ if (ret <= 0) {
+ fprintf(stderr, "glfs_discard: 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/bugs/shard/bug-shard-zerofill.c b/tests/bugs/shard/bug-shard-zerofill.c
index c0525a58afc..ed4c8c54dc2 100644
--- a/tests/bugs/shard/bug-shard-zerofill.c
+++ b/tests/bugs/shard/bug-shard-zerofill.c
@@ -3,57 +3,58 @@
#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;
-
- if (argc != 5) {
- fprintf (stderr, "Syntax: %s <host> <volname> <file-path> <log-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, 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;
- }
-
- /* Zero-fill "foo" with 10MB of data */
- ret = glfs_zerofill (fd, 0, 10485760);
- if (ret <= 0) {
- fprintf (stderr, "glfs_zerofill: returned %d\n", ret);
- goto out;
- }
-
- ret = 0;
+ glfs_t *fs = NULL;
+ glfs_fd_t *fd = NULL;
+ int ret = 1;
+
+ if (argc != 5) {
+ fprintf(stderr, "Syntax: %s <host> <volname> <file-path> <log-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, 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;
+ }
+
+ /* Zero-fill "foo" with 10MB of data */
+ ret = glfs_zerofill(fd, 0, 10485760);
+ if (ret <= 0) {
+ fprintf(stderr, "glfs_zerofill: returned %d\n", ret);
+ goto out;
+ }
+
+ 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/bugs/shard/shard-append-test.c b/tests/bugs/shard/shard-append-test.c
index 92dff3d078d..c7debb2b182 100644
--- a/tests/bugs/shard/shard-append-test.c
+++ b/tests/bugs/shard/shard-append-test.c
@@ -10,9 +10,10 @@
#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)
/*This test tests that shard xlator handles offset in appending writes
* correctly. This test performs writes of 1025 bytes 1025 times, in 5 threads
@@ -26,154 +27,157 @@ pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
int thread_data = '1';
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;
+ 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;
+ 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_data (void *data)
+void *
+write_data(void *data)
{
- char buf[1025] = {0};
- glfs_fd_t *glfd = NULL;
- glfs_t *fs = data;
- int i = 0;
-
- pthread_mutex_lock (&lock);
- {
- memset(buf, thread_data, sizeof(buf));
- thread_data++;
+ char buf[1025] = {0};
+ glfs_fd_t *glfd = NULL;
+ glfs_t *fs = data;
+ int i = 0;
+
+ pthread_mutex_lock(&lock);
+ {
+ memset(buf, thread_data, sizeof(buf));
+ thread_data++;
+ }
+ pthread_mutex_unlock(&lock);
+
+ for (i = 0; i < 1025; i++) {
+ glfd = glfs_creat(fs, "parallel-write.txt", O_WRONLY | O_APPEND,
+ S_IRUSR | S_IWUSR | O_SYNC);
+ if (!glfd) {
+ LOG_ERR("Failed to create file");
+ exit(1);
}
- pthread_mutex_unlock (&lock);
-
- for (i = 0; i < 1025; i++) {
- glfd = glfs_creat(fs, "parallel-write.txt", O_WRONLY | O_APPEND,
- S_IRUSR | S_IWUSR | O_SYNC);
- if (!glfd) {
- LOG_ERR ("Failed to create file");
- exit(1);
- }
-
- if (glfs_write (glfd, buf, sizeof(buf), 0) < 0) {
- LOG_ERR ("Failed to write to file");
- exit(1);
- }
- if (glfs_close(glfd) != 0) {
- LOG_ERR ("Failed to close file");
- exit(1);
- }
+
+ if (glfs_write(glfd, buf, sizeof(buf), 0) < 0) {
+ LOG_ERR("Failed to write to file");
+ exit(1);
}
- return NULL;
+ if (glfs_close(glfd) != 0) {
+ LOG_ERR("Failed to close file");
+ exit(1);
+ }
+ }
+ return NULL;
}
int
-main (int argc, char *argv[])
+main(int argc, char *argv[])
{
- pthread_t tid[5] = {0};
- char buf[1025] = {0};
- char cmp_buf[1025] = {0};
- int ret = 0;
- char *hostname = NULL;
- char *volname = NULL;
- char *logfile = NULL;
- glfs_t *fs = NULL;
- glfs_fd_t *glfd = NULL;
- ssize_t bytes_read = 0;
- ssize_t total_bytes_read = 0;
- int i = 0;
-
- 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;
- }
-
- for (i = 0; i < 5; i++) {
- pthread_create(&tid[i], NULL, write_data, fs);
- }
-
- for (i = 0; i < 5; i++) {
- pthread_join(tid[i], NULL);
- }
- glfd = glfs_open(fs, "parallel-write.txt", O_RDONLY);
- if (!glfd) {
- LOG_ERR ("Failed to open file for reading");
- exit(1);
+ pthread_t tid[5] = {0};
+ char buf[1025] = {0};
+ char cmp_buf[1025] = {0};
+ int ret = 0;
+ char *hostname = NULL;
+ char *volname = NULL;
+ char *logfile = NULL;
+ glfs_t *fs = NULL;
+ glfs_fd_t *glfd = NULL;
+ ssize_t bytes_read = 0;
+ ssize_t total_bytes_read = 0;
+ int i = 0;
+
+ 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;
+ }
+
+ for (i = 0; i < 5; i++) {
+ pthread_create(&tid[i], NULL, write_data, fs);
+ }
+
+ for (i = 0; i < 5; i++) {
+ pthread_join(tid[i], NULL);
+ }
+ glfd = glfs_open(fs, "parallel-write.txt", O_RDONLY);
+ if (!glfd) {
+ LOG_ERR("Failed to open file for reading");
+ exit(1);
+ }
+
+ while ((bytes_read = glfs_read(glfd, buf, sizeof(buf), 0)) > 0) {
+ if (bytes_read != sizeof(buf)) {
+ fprintf(stderr,
+ "Didn't read complete data read: %zd "
+ "expected: %lu",
+ bytes_read, sizeof(buf));
+ exit(1);
}
- while ((bytes_read = glfs_read (glfd, buf, sizeof(buf), 0)) > 0) {
- if (bytes_read != sizeof(buf)) {
- fprintf (stderr, "Didn't read complete data read: %zd "
- "expected: %lu", bytes_read, sizeof(buf));
- exit(1);
- }
-
- total_bytes_read += bytes_read;
- if (buf[0] < '1' || buf[0] >= thread_data) {
- fprintf(stderr, "Invalid character found: %c", buf[0]);
- exit(1);
- }
- memset(cmp_buf, buf[0], sizeof(cmp_buf));
- if (memcmp(cmp_buf, buf, sizeof(cmp_buf))) {
- LOG_ERR ("Data corrupted");
- exit(1);
- }
- memset(cmp_buf, 0, sizeof(cmp_buf));
+ total_bytes_read += bytes_read;
+ if (buf[0] < '1' || buf[0] >= thread_data) {
+ fprintf(stderr, "Invalid character found: %c", buf[0]);
+ exit(1);
}
-
- if (total_bytes_read != 5*1025*1025) {
- fprintf(stderr, "Failed to read what is written, read; %zd, "
- "expected %zu", total_bytes_read, 5*1025*1025);
- exit(1);
- }
-
- if (glfs_close(glfd) != 0) {
- LOG_ERR ("Failed to close");
- exit(1);
+ memset(cmp_buf, buf[0], sizeof(cmp_buf));
+ if (memcmp(cmp_buf, buf, sizeof(cmp_buf))) {
+ LOG_ERR("Data corrupted");
+ exit(1);
}
- return 0;
+ memset(cmp_buf, 0, sizeof(cmp_buf));
+ }
+
+ if (total_bytes_read != 5 * 1025 * 1025) {
+ fprintf(stderr,
+ "Failed to read what is written, read; %zd, "
+ "expected %zu",
+ total_bytes_read, 5 * 1025 * 1025);
+ exit(1);
+ }
+
+ if (glfs_close(glfd) != 0) {
+ LOG_ERR("Failed to close");
+ exit(1);
+ }
+ return 0;
}
diff --git a/tests/bugs/shard/shard-fallocate.c b/tests/bugs/shard/shard-fallocate.c
index 8745c0ece1d..3a784d3c02c 100644
--- a/tests/bugs/shard/shard-fallocate.c
+++ b/tests/bugs/shard/shard-fallocate.c
@@ -6,104 +6,107 @@
#include <glusterfs/api/glfs-handles.h>
enum fallocate_flag {
- TEST_FALLOCATE_NONE,
- TEST_FALLOCATE_KEEP_SIZE,
- TEST_FALLOCATE_ZERO_RANGE,
- TEST_FALLOCATE_PUNCH_HOLE,
- TEST_FALLOCATE_MAX,
+ TEST_FALLOCATE_NONE,
+ TEST_FALLOCATE_KEEP_SIZE,
+ TEST_FALLOCATE_ZERO_RANGE,
+ TEST_FALLOCATE_PUNCH_HOLE,
+ TEST_FALLOCATE_MAX,
};
int
-get_fallocate_flag (int opcode)
+get_fallocate_flag(int opcode)
{
- int ret = 0;
+ int ret = 0;
- switch (opcode) {
+ switch (opcode) {
case TEST_FALLOCATE_NONE:
- ret = 0;
- break;
+ ret = 0;
+ break;
case TEST_FALLOCATE_KEEP_SIZE:
- ret = FALLOC_FL_KEEP_SIZE;
- break;
+ ret = FALLOC_FL_KEEP_SIZE;
+ break;
case TEST_FALLOCATE_ZERO_RANGE:
- ret = FALLOC_FL_ZERO_RANGE;
- break;
+ ret = FALLOC_FL_ZERO_RANGE;
+ break;
case TEST_FALLOCATE_PUNCH_HOLE:
- ret = FALLOC_FL_PUNCH_HOLE;
- break;
+ ret = FALLOC_FL_PUNCH_HOLE;
+ break;
default:
- ret = -1;
- break;
- }
- return ret;
+ ret = -1;
+ break;
+ }
+ return ret;
}
int
-main (int argc, char *argv[])
+main(int argc, char *argv[])
{
- int ret = 1;
- int opcode = -1;
- off_t offset = 0;
- size_t len = 0;
- glfs_t *fs = NULL;
- glfs_fd_t *fd = NULL;
+ int ret = 1;
+ int opcode = -1;
+ off_t offset = 0;
+ size_t len = 0;
+ glfs_t *fs = NULL;
+ glfs_fd_t *fd = NULL;
- if (argc != 8) {
- fprintf (stderr, "Syntax: %s <host> <volname> <opcode> <offset> <len> <file-path> <log-file>\n", argv[0]);
- return 1;
- }
+ if (argc != 8) {
+ fprintf(stderr,
+ "Syntax: %s <host> <volname> <opcode> <offset> <len> "
+ "<file-path> <log-file>\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_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[7], 7);
- if (ret != 0) {
- fprintf (stderr, "glfs_set_logging: returned %d\n", ret);
- goto out;
- }
+ ret = glfs_set_logging(fs, argv[7], 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_init(fs);
+ if (ret != 0) {
+ fprintf(stderr, "glfs_init: returned %d\n", ret);
+ goto out;
+ }
- opcode = atoi (argv[3]);
- opcode = get_fallocate_flag (opcode);
- if (opcode < 0) {
- fprintf (stderr, "get_fallocate_flag: invalid flag \n");
- goto out;
- }
+ opcode = atoi(argv[3]);
+ opcode = get_fallocate_flag(opcode);
+ if (opcode < 0) {
+ fprintf(stderr, "get_fallocate_flag: invalid flag \n");
+ goto out;
+ }
- offset = atoi (argv[4]);
- len = atoi (argv[5]);
+ offset = atoi(argv[4]);
+ len = atoi(argv[5]);
- fd = glfs_open (fs, argv[6], O_RDWR);
- if (fd == NULL) {
- fprintf (stderr, "glfs_open: returned NULL\n");
- goto out;
- }
+ fd = glfs_open(fs, argv[6], O_RDWR);
+ if (fd == NULL) {
+ fprintf(stderr, "glfs_open: returned NULL\n");
+ goto out;
+ }
- ret = glfs_fallocate (fd, opcode, offset, len);
- if (ret <= 0) {
- fprintf (stderr, "glfs_fallocate: returned %d\n", ret);
- goto out;
- }
+ ret = glfs_fallocate(fd, opcode, offset, len);
+ if (ret <= 0) {
+ fprintf(stderr, "glfs_fallocate: 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/bugs/write-behind/bug-1058663.c b/tests/bugs/write-behind/bug-1058663.c
index 5e522e98048..aedf97d7487 100644
--- a/tests/bugs/write-behind/bug-1058663.c
+++ b/tests/bugs/write-behind/bug-1058663.c
@@ -19,101 +19,105 @@ static int sigbus_received;
/* test for truncate()/seek()/write()/mmap()
* There should ne no SIGBUS triggered.
*/
-void seek_write(char *filename)
+void
+seek_write(char *filename)
{
- int fd;
- uint8_t *map;
- int i;
-
- fd = open(filename, O_RDWR|O_CREAT|O_TRUNC, 0600);
- lseek(fd, FILE_SIZE - 1, SEEK_SET);
- write(fd, "\xff", 1);
-
- map = mmap(NULL, FILE_SIZE, PROT_READ, MAP_PRIVATE, fd, 0);
- for (i = 0; i < (FILE_SIZE - 1); i++) {
- if (map[i] != 0) /* should never be true */
- abort();
- }
- munmap(map, FILE_SIZE);
-
- close(fd);
+ int fd;
+ uint8_t *map;
+ int i;
+
+ fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, 0600);
+ lseek(fd, FILE_SIZE - 1, SEEK_SET);
+ write(fd, "\xff", 1);
+
+ map = mmap(NULL, FILE_SIZE, PROT_READ, MAP_PRIVATE, fd, 0);
+ for (i = 0; i < (FILE_SIZE - 1); i++) {
+ if (map[i] != 0) /* should never be true */
+ abort();
+ }
+ munmap(map, FILE_SIZE);
+
+ close(fd);
}
-int read_after_eof(char *filename)
+int
+read_after_eof(char *filename)
{
- int ret = 0;
- int fd;
- char *data;
- uint8_t *map;
-
- fd = open(filename, O_RDWR|O_CREAT|O_TRUNC, 0600);
- lseek(fd, FILE_SIZE - 1, SEEK_SET);
- write(fd, "\xff", 1);
-
- /* trigger verify that reading after EOF fails */
- ret = read(fd, data, FILE_SIZE / 2);
- if (ret != 0)
- return 1;
-
- /* map an area of 1 byte after FILE_SIZE */
- map = mmap(NULL, 1, PROT_READ, MAP_PRIVATE, fd, FILE_SIZE);
- /* map[0] is an access after EOF, it should trigger SIGBUS */
- if (map[0] != 0)
- /* it is expected that we exit before we get here */
- if (!sigbus_received)
- return 1;
- munmap(map, FILE_SIZE);
-
- close(fd);
-
- return ret;
+ int ret = 0;
+ int fd;
+ char *data;
+ uint8_t *map;
+
+ fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, 0600);
+ lseek(fd, FILE_SIZE - 1, SEEK_SET);
+ write(fd, "\xff", 1);
+
+ /* trigger verify that reading after EOF fails */
+ ret = read(fd, data, FILE_SIZE / 2);
+ if (ret != 0)
+ return 1;
+
+ /* map an area of 1 byte after FILE_SIZE */
+ map = mmap(NULL, 1, PROT_READ, MAP_PRIVATE, fd, FILE_SIZE);
+ /* map[0] is an access after EOF, it should trigger SIGBUS */
+ if (map[0] != 0)
+ /* it is expected that we exit before we get here */
+ if (!sigbus_received)
+ return 1;
+ munmap(map, FILE_SIZE);
+
+ close(fd);
+
+ return ret;
}
/* signal handler for SIGBUS */
-void catch_sigbus(int signum)
+void
+catch_sigbus(int signum)
{
- switch (signum) {
+ switch (signum) {
#ifdef __NetBSD__
- /* Depending on architecture, we can get SIGSEGV */
- case SIGSEGV: /* FALLTHROUGH */
+ /* Depending on architecture, we can get SIGSEGV */
+ case SIGSEGV: /* FALLTHROUGH */
#endif
- case SIGBUS:
- sigbus_received++;
- if (!expect_sigbus)
- exit(EXIT_FAILURE);
- if (sigbus_received >= MAX_SIGBUS)
- exit(EXIT_SUCCESS);
- break;
- default:
- printf("Unexpected signal received: %d\n", signum);
- }
+ case SIGBUS:
+ sigbus_received++;
+ if (!expect_sigbus)
+ exit(EXIT_FAILURE);
+ if (sigbus_received >= MAX_SIGBUS)
+ exit(EXIT_SUCCESS);
+ break;
+ default:
+ printf("Unexpected signal received: %d\n", signum);
+ }
}
-int main(int argc, char **argv)
+int
+main(int argc, char **argv)
{
- int i = 0;
+ int i = 0;
- if (argc == 1) {
- printf("Usage: %s <filename>\n", argv[0]);
- return EXIT_FAILURE;
- }
+ if (argc == 1) {
+ printf("Usage: %s <filename>\n", argv[0]);
+ return EXIT_FAILURE;
+ }
#ifdef __NetBSD__
- /* Depending on architecture, we can get SIGSEGV */
- signal(SIGSEGV, catch_sigbus);
+ /* Depending on architecture, we can get SIGSEGV */
+ signal(SIGSEGV, catch_sigbus);
#endif
- signal(SIGBUS, catch_sigbus);
+ signal(SIGBUS, catch_sigbus);
- /* the next test should not trigger SIGBUS */
- expect_sigbus = 0;
- for (i = 0; i < RUN_LOOP; i++) {
- seek_write(argv[1]);
- }
+ /* the next test should not trigger SIGBUS */
+ expect_sigbus = 0;
+ for (i = 0; i < RUN_LOOP; i++) {
+ seek_write(argv[1]);
+ }
- /* the next test should trigger SIGBUS */
- expect_sigbus = 1;
- if (read_after_eof(argv[1]))
- return EXIT_FAILURE;
+ /* the next test should trigger SIGBUS */
+ expect_sigbus = 1;
+ if (read_after_eof(argv[1]))
+ return EXIT_FAILURE;
- return EXIT_SUCCESS;
+ return EXIT_SUCCESS;
}
diff --git a/tests/bugs/write-behind/bug-1279730.c b/tests/bugs/write-behind/bug-1279730.c
index 535d289c582..706ae67b102 100644
--- a/tests/bugs/write-behind/bug-1279730.c
+++ b/tests/bugs/write-behind/bug-1279730.c
@@ -8,124 +8,142 @@
#include <assert.h>
int
-main (int argc, char *argv[])
+main(int argc, char *argv[])
{
- int fd = -1, ret = -1, len = 0;
- char *path = NULL, buf[128] = {0, }, *cmd = NULL;
- struct stat stbuf = {0, };
- int write_to_child[2] = {0, }, write_to_parent[2] = {0, };
+ int fd = -1, ret = -1, len = 0;
+ char *path = NULL,
+ buf[128] =
+ {
+ 0,
+ },
+ *cmd = NULL;
+ struct stat stbuf = {
+ 0,
+ };
+ int write_to_child[2] =
+ {
+ 0,
+ },
+ write_to_parent[2] = {
+ 0,
+ };
+
+ path = argv[1];
+ cmd = argv[2];
+
+ assert(argc == 3);
+
+ ret = pipe(write_to_child);
+ if (ret < 0) {
+ fprintf(stderr,
+ "creation of write-to-child pipe failed "
+ "(%s)\n",
+ strerror(errno));
+ goto out;
+ }
+
+ ret = pipe(write_to_parent);
+ if (ret < 0) {
+ fprintf(stderr,
+ "creation of write-to-parent pipe failed "
+ "(%s)\n",
+ strerror(errno));
+ goto out;
+ }
+
+ ret = fork();
+ switch (ret) {
+ case 0:
+ close(write_to_child[1]);
+ close(write_to_parent[0]);
+
+ /* child, wait for instructions to execute command */
+ ret = read(write_to_child[0], buf, 128);
+ if (ret < 0) {
+ fprintf(stderr, "child: read on pipe failed (%s)\n",
+ strerror(errno));
+ goto out;
+ }
- path = argv[1];
- cmd = argv[2];
+ system(cmd);
+
+ ret = write(write_to_parent[1], "1", 2);
+ if (ret < 0) {
+ fprintf(stderr, "child: write to pipe failed (%s)\n",
+ strerror(errno));
+ goto out;
+ }
+ break;
- assert (argc == 3);
+ case -1:
+ fprintf(stderr, "fork failed (%s)\n", strerror(errno));
+ goto out;
+
+ default:
+ close(write_to_parent[1]);
+ close(write_to_child[0]);
- ret = pipe (write_to_child);
- if (ret < 0) {
- fprintf (stderr, "creation of write-to-child pipe failed "
- "(%s)\n", strerror (errno));
+ fd = open(path, O_CREAT | O_RDWR | O_APPEND, S_IRWXU);
+ if (fd < 0) {
+ fprintf(stderr, "open failed (%s)\n", strerror(errno));
goto out;
- }
+ }
+
+ len = strlen("test-content") + 1;
+ ret = write(fd, "test-content", len);
+
+ if (ret < len) {
+ fprintf(stderr, "write failed %d (%s)\n", ret, strerror(errno));
+ }
+
+ ret = pread(fd, buf, 128, 0);
+ if ((ret == len) && (strcmp(buf, "test-content") == 0)) {
+ fprintf(stderr,
+ "read should've failed as previous "
+ "write would've failed with EDQUOT, but its "
+ "successful");
+ ret = -1;
+ goto out;
+ }
- ret = pipe (write_to_parent);
- if (ret < 0) {
- fprintf (stderr, "creation of write-to-parent pipe failed "
- "(%s)\n", strerror (errno));
+ ret = write(write_to_child[1], "1", 2);
+ if (ret < 0) {
+ fprintf(stderr, "parent: write to pipe failed (%s)\n",
+ strerror(errno));
goto out;
- }
+ }
- ret = fork ();
- switch (ret) {
- case 0:
- close (write_to_child[1]);
- close (write_to_parent[0]);
-
- /* child, wait for instructions to execute command */
- ret = read (write_to_child[0], buf, 128);
- if (ret < 0) {
- fprintf (stderr, "child: read on pipe failed (%s)\n",
- strerror (errno));
- goto out;
- }
-
- system (cmd);
-
- ret = write (write_to_parent[1], "1", 2);
- if (ret < 0) {
- fprintf (stderr, "child: write to pipe failed (%s)\n",
- strerror (errno));
- goto out;
- }
- break;
+ ret = read(write_to_parent[0], buf, 128);
+ if (ret < 0) {
+ fprintf(stderr, "parent: read from pipe failed (%s)\n",
+ strerror(errno));
+ goto out;
+ }
+
+ /* this will force a sync on cached-write and now that quota
+ limit is increased, sync will be successful. ignore return
+ value as fstat would fail with EDQUOT (picked up from
+ cached-write because of previous sync failure.
+ */
+ fstat(fd, &stbuf);
+
+ ret = pread(fd, buf, 128, 0);
+ if (ret != len) {
+ fprintf(stderr,
+ "post cmd read failed %d (data:%s) "
+ "(error:%s)\n",
+ ret, buf, strerror(errno));
+ goto out;
+ }
- case -1:
- fprintf (stderr, "fork failed (%s)\n", strerror (errno));
+ if (strcmp(buf, "test-content")) {
+ fprintf(stderr, "wrong data (%s)\n", buf);
goto out;
+ }
+ }
- default:
- close (write_to_parent[1]);
- close (write_to_child[0]);
-
- fd = open (path, O_CREAT | O_RDWR | O_APPEND, S_IRWXU);
- if (fd < 0) {
- fprintf (stderr, "open failed (%s)\n",
- strerror (errno));
- goto out;
- }
-
- len = strlen ("test-content") + 1;
- ret = write (fd, "test-content", len);
-
- if (ret < len) {
- fprintf (stderr, "write failed %d (%s)\n", ret,
- strerror (errno));
- }
-
- ret = pread (fd, buf, 128, 0);
- if ((ret == len) && (strcmp (buf, "test-content") == 0)) {
- fprintf (stderr, "read should've failed as previous "
- "write would've failed with EDQUOT, but its "
- "successful");
- ret = -1;
- goto out;
- }
-
- ret = write (write_to_child[1], "1", 2);
- if (ret < 0) {
- fprintf (stderr, "parent: write to pipe failed (%s)\n",
- strerror (errno));
- goto out;
- }
-
- ret = read (write_to_parent[0], buf, 128);
- if (ret < 0) {
- fprintf (stderr, "parent: read from pipe failed (%s)\n",
- strerror (errno));
- goto out;
- }
-
- /* this will force a sync on cached-write and now that quota
- limit is increased, sync will be successful. ignore return
- value as fstat would fail with EDQUOT (picked up from
- cached-write because of previous sync failure.
- */
- fstat (fd, &stbuf);
-
- ret = pread (fd, buf, 128, 0);
- if (ret != len) {
- fprintf (stderr, "post cmd read failed %d (data:%s) "
- "(error:%s)\n", ret, buf, strerror (errno));
- goto out;
- }
-
- if (strcmp (buf, "test-content")) {
- fprintf (stderr, "wrong data (%s)\n", buf);
- goto out;
- }
- }
-
- ret = 0;
+ ret = 0;
out:
- return ret;
+ return ret;
}