diff options
author | Niels de Vos <ndevos@redhat.com> | 2015-06-21 23:36:12 +0200 |
---|---|---|
committer | Jeff Darcy <jdarcy@redhat.com> | 2016-02-04 14:35:40 -0800 |
commit | cdcd3dc96b412967ba68a56aa2607d86365fbfe6 (patch) | |
tree | 1cbfd84be0562428c6aea61e30fc8c9edddf0f45 /tests | |
parent | 8fdfa0c17cf492f39e675f7502596754f6e5aeb4 (diff) |
gfapi: add test for glfs_lseek() SEEK_DATA/SEEK_HOLE
Change-Id: I8d0573ed8b2ea5ce976ad140a24be7974dbad0e3
BUG: 1220173
Signed-off-by: Niels de Vos <ndevos@redhat.com>
Reviewed-on: http://review.gluster.org/11486
Smoke: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: jiffin tony Thottan <jthottan@redhat.com>
Reviewed-by: Kaleb KEITHLEY <kkeithle@redhat.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>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/basic/gfapi/Makefile.am | 11 | ||||
-rw-r--r-- | tests/basic/gfapi/seek.c | 95 |
2 files changed, 103 insertions, 3 deletions
diff --git a/tests/basic/gfapi/Makefile.am b/tests/basic/gfapi/Makefile.am index cdb0e543803..b166fcc3fa6 100644 --- a/tests/basic/gfapi/Makefile.am +++ b/tests/basic/gfapi/Makefile.am @@ -4,12 +4,17 @@ CFLAGS = -Wall -g $(shell pkg-config --cflags glusterfs-api) LDFLAGS = $(shell pkg-config --libs glusterfs-api) -BINARIES = upcall-cache-invalidate libgfapi-fini-hang anonymous_fd +BINARIES = upcall-cache-invalidate libgfapi-fini-hang anonymous_fd seek %: %.c + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ -all: $(BINARIES) +all: check-pkgconfig $(BINARIES) clean: - -$(RM) $(BINARIES) + -$(RM) $(BINARIES) +.phony: check-pkgconfig + +check-pkgconfig: + pkg-config --exists glusterfs-api diff --git a/tests/basic/gfapi/seek.c b/tests/basic/gfapi/seek.c new file mode 100644 index 00000000000..a0fec7d990a --- /dev/null +++ b/tests/basic/gfapi/seek.c @@ -0,0 +1,95 @@ +/* seek.c - use glfs_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 <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +#include <api/glfs.h> +#include <api/glfs-handles.h> + +int +main (int argc, char **argv) +{ + glfs_t *fs = NULL; + int ret = 0; + glfs_fd_t *fd = NULL; + char *filename = NULL; + char *volname = NULL; + struct stat st = { 0, }; + off_t hole_start = 0; + off_t hole_end = 0; + + if (argc != 3) { + fprintf (stderr, "Invalid argument, use %s <vol> <file>\n", + argv[0]); + exit (1); + } + + volname = argv[1]; + filename = argv[2]; + + fs = glfs_new (volname); + if (!fs) { + perror ("glfs_new() returned NULL"); + return 1; + } + + if (glfs_set_volfile_server (fs, "tcp", "localhost", 24007)) { + perror ("glfs_set_volfile_server"); + return 1; + } + + if (glfs_init (fs)) { + perror ("glfs_init"); + return 1; + } + + fd = glfs_open (fs, filename, O_RDONLY); + if (fd <= 0) { + perror ("glfs_open"); + return 1; + } + + if (glfs_fstat (fd, &st)) { + perror ("glfs_fstat"); + return 1; + } + + while (hole_end < st.st_size) { + hole_start = glfs_lseek (fd, hole_end, SEEK_HOLE); + if (hole_start == -1 && errno == ENXIO) + /* no more holes */ + break; + if (hole_start == -1) { + perror ("no more holes"); + break; + } + + hole_end = glfs_lseek (fd, hole_start, SEEK_DATA); + if (hole_end == -1 && errno == ENXIO) { + /* no more data */ + break; + } + + printf ("HOLE found: %ld - %ld%s\n", hole_start, hole_end, + (hole_end == st.st_size) ? " (EOF)" : ""); + } + + glfs_close (fd); + + if (fs) { + glfs_fini (fs); + } + + return ret; +} |