summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNiels de Vos <ndevos@redhat.com>2016-01-25 16:56:05 +0100
committerJeff Darcy <jdarcy@redhat.com>2016-02-05 07:00:52 -0800
commit4bde0b3db0e1f8fcbc782e29be2f2eb9e6d4c2fd (patch)
treeebbe6fa3f0d3b571efcf495e788608633d76c852
parentc8bbc24a8f3db253d9514210f8505e927bbbe7b0 (diff)
tests: add seek program for testing SEEK_DATA/SEEK_HOLE over FUSE
Note that this only works on Linux kernel 4.5 and newer. The program is not run by a test-case because of this. BUG: 1220173 Change-Id: Ifdee3c793e33f9d763940130e8d01a61eae5498a Signed-off-by: Niels de Vos <ndevos@redhat.com> Reviewed-on: http://review.gluster.org/13291 Smoke: Gluster Build System <jenkins@build.gluster.com> CentOS-regression: Gluster Build System <jenkins@build.gluster.com> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org> Reviewed-by: Jeff Darcy <jdarcy@redhat.com>
-rw-r--r--configure.ac1
-rw-r--r--tests/basic/fuse/Makefile.am12
-rw-r--r--tests/basic/fuse/seek.c80
3 files changed, 93 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac
index 4e6ef1b8c6a..bc59ef45ee5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -247,6 +247,7 @@ AC_CONFIG_FILES([Makefile
tools/glusterfind/glusterfind
tools/glusterfind/Makefile
tools/glusterfind/src/Makefile
+ tests/basic/fuse/Makefile
tests/basic/gfapi/Makefile])
AC_CANONICAL_HOST
diff --git a/tests/basic/fuse/Makefile.am b/tests/basic/fuse/Makefile.am
new file mode 100644
index 00000000000..c446d253228
--- /dev/null
+++ b/tests/basic/fuse/Makefile.am
@@ -0,0 +1,12 @@
+CFLAGS = -Wall -g
+LDFLAGS =
+
+BINARIES = seek
+
+%: %.c
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
+
+all: $(BINARIES)
+
+clean:
+ -$(RM) $(BINARIES)
diff --git a/tests/basic/fuse/seek.c b/tests/basic/fuse/seek.c
new file mode 100644
index 00000000000..e4db41c03d7
--- /dev/null
+++ b/tests/basic/fuse/seek.c
@@ -0,0 +1,80 @@
+/* seek.c - use lseek() to find holes in a file
+ *
+ * Author: Niels de Vos <ndevos@redhat.com>
+ */
+
+/* needed for SEEK_HOLE/SEEK_DATA */
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+int
+main (int argc, char **argv)
+{
+ int ret = EXIT_SUCCESS;
+ int fd = -1;
+ char *filename = NULL;
+ struct stat st = { 0, };
+ off_t hole_start = 0;
+ off_t hole_end = 0;
+
+ if (argc != 2) {
+ fprintf (stderr, "Invalid argument, use %s <file>\n", argv[0]);
+ return EXIT_FAILURE;
+ }
+
+ filename = argv[1];
+
+ fd = open (filename, O_RDONLY);
+ if (fd <= 0) {
+ perror ("open");
+ return EXIT_FAILURE;
+ }
+
+ if (fstat (fd, &st)) {
+ perror ("fstat");
+ return EXIT_FAILURE;
+ }
+
+ while (hole_end < st.st_size) {
+ hole_start = lseek (fd, hole_end, SEEK_HOLE);
+ if (hole_start == -1 && errno == ENXIO) {
+ /* no more holes */
+ break;
+ } else if (hole_start == -1 && errno == ENOTSUP) {
+ /* SEEK_HOLE is not supported */
+ perror ("lseek(SEEK_HOLE)");
+ ret = EXIT_FAILURE;
+ break;
+ } else if (hole_start == -1) {
+ perror ("no more holes");
+ break;
+ }
+
+ hole_end = lseek (fd, hole_start, SEEK_DATA);
+ if (hole_end == -1 && errno == ENXIO) {
+ /* no more data */
+ break;
+ } else if (hole_end == -1 && errno == ENOTSUP) {
+ /* SEEK_DATA is not supported */
+ perror ("lseek(SEEK_DATA)");
+ ret = EXIT_FAILURE;
+ break;
+ }
+
+ printf ("HOLE found: %ld - %ld%s\n", hole_start, hole_end,
+ (hole_end == st.st_size) ? " (EOF)" : "");
+ }
+
+ close (fd);
+
+ return ret;
+}