summaryrefslogtreecommitdiffstats
path: root/tests/bugs/shard/shard-fallocate.c
diff options
context:
space:
mode:
authorKrutika Dhananjay <kdhananj@redhat.com>2016-02-09 16:40:36 +0530
committerPranith Kumar Karampuri <pkarampu@redhat.com>2016-03-10 03:16:55 -0800
commit6df883cef3e69b37a192aae9e979f95b32f8ad41 (patch)
tree33729a013e69528861e8449c24c056cf5e21d211 /tests/bugs/shard/shard-fallocate.c
parented98d128a9413f7b8af328ca27bf4b27514d61e9 (diff)
tests, shard: fallocate tests refactor
Change-Id: I3f275185f4dcb1939e8074851c8f140c5e40b28d BUG: 1261841 Signed-off-by: Krutika Dhananjay <kdhananj@redhat.com> Reviewed-on: http://review.gluster.org/13405 Smoke: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Pranith Kumar Karampuri <pkarampu@redhat.com> Reviewed-by: Ravishankar N <ravishankar@redhat.com> CentOS-regression: Gluster Build System <jenkins@build.gluster.com> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
Diffstat (limited to 'tests/bugs/shard/shard-fallocate.c')
-rw-r--r--tests/bugs/shard/shard-fallocate.c113
1 files changed, 113 insertions, 0 deletions
diff --git a/tests/bugs/shard/shard-fallocate.c b/tests/bugs/shard/shard-fallocate.c
new file mode 100644
index 00000000000..fded6236552
--- /dev/null
+++ b/tests/bugs/shard/shard-fallocate.c
@@ -0,0 +1,113 @@
+#define _GNU_SOURCE
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "glfs.h"
+#include "glfs-handles.h"
+
+enum fallocate_flag {
+ TEST_FALLOCATE_NONE,
+ TEST_FALLOCATE_KEEP_SIZE,
+ TEST_FALLOCATE_ZERO_RANGE,
+ TEST_FALLOCATE_PUNCH_HOLE,
+ TEST_FALLOCATE_MAX,
+};
+
+int
+get_fallocate_flag (int opcode)
+{
+ int ret = 0;
+
+ switch (opcode) {
+ case TEST_FALLOCATE_NONE:
+ ret = 0;
+ break;
+ case TEST_FALLOCATE_KEEP_SIZE:
+ ret = FALLOC_FL_KEEP_SIZE;
+ break;
+ case TEST_FALLOCATE_ZERO_RANGE:
+ ret = FALLOC_FL_ZERO_RANGE;
+ break;
+ case TEST_FALLOCATE_PUNCH_HOLE:
+ ret = FALLOC_FL_PUNCH_HOLE;
+ break;
+ default:
+ ret = -1;
+ break;
+ }
+ return ret;
+}
+
+int
+main (int argc, char *argv[])
+{
+ int ret = 1;
+ int opcode = -1;
+ off_t offset = 0;
+ size_t len = 0;
+ char logpath[PATH_MAX] = {0,};
+ glfs_t *fs = NULL;
+ glfs_fd_t *fd = NULL;
+
+ if (argc != 7) {
+ fprintf (stderr, "Syntax: %s <host> <volname> <opcode> <offset> <len> <file-path>\n", argv[0]);
+ return 1;
+ }
+
+ fs = glfs_new (argv[2]);
+ if (!fs) {
+ fprintf (stderr, "glfs_new: returned NULL\n");
+ return 1;
+ }
+
+ snprintf (logpath, sizeof (logpath), "/var/log/glusterfs/glfs-%s.log",
+ argv[2]);
+
+ ret = glfs_set_volfile_server (fs, "tcp", argv[1], 24007);
+ if (ret != 0) {
+ fprintf (stderr, "glfs_set_volfile_server: retuned %d\n", ret);
+ goto out;
+ }
+
+ ret = glfs_set_logging (fs, logpath, 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;
+ }
+
+ 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]);
+
+ 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 = 0;
+
+out:
+ if (fd)
+ glfs_close(fd);
+ glfs_fini (fs);
+ return ret;
+}