diff options
author | Jiffin Tony Thottan <jthottan@redhat.com> | 2015-03-11 14:20:48 +0530 |
---|---|---|
committer | Kaleb KEITHLEY <kkeithle@redhat.com> | 2015-05-05 18:05:24 -0700 |
commit | fa0ad231745846918b2625d0e1a89c0a5c3c24dc (patch) | |
tree | 35ff8022e965847d19198277414636f785172e61 /tests | |
parent | a5fc34604aef973606431bf7d873abb91ee03d5a (diff) |
libgfapi : anonymous fd support
Anonymous fd's are floating fd assigned to a glusterfs client
without a explicit file open. Here either it will create a new
anonymous fd or existing anonymous fd in the client stack for
requested file.The anonymous fd's are mainly used for IO's.
This patch introduces two api's glfs_h_anonymous_read and
glfs_h_anonymous_write which performs read and write respectively
Change-Id: Id646f2220e8387b2f8bb244c848dc1db6761444f
BUG: 1204651
Signed-off-by: Jiffin Tony Thottan <jthottan@redhat.com>
Reviewed-by: Niels de Vos <ndevos@redhat.com>
Reviewed-on: http://review.gluster.org/9971
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/basic/gfapi/Makefile.am | 2 | ||||
-rwxr-xr-x | tests/basic/gfapi/anonymous_fd.sh | 26 | ||||
-rw-r--r-- | tests/basic/gfapi/anonymous_fd_read_write.c | 101 |
3 files changed, 128 insertions, 1 deletions
diff --git a/tests/basic/gfapi/Makefile.am b/tests/basic/gfapi/Makefile.am index 39fc04b0f39..cdb0e543803 100644 --- a/tests/basic/gfapi/Makefile.am +++ b/tests/basic/gfapi/Makefile.am @@ -4,7 +4,7 @@ CFLAGS = -Wall -g $(shell pkg-config --cflags glusterfs-api) LDFLAGS = $(shell pkg-config --libs glusterfs-api) -BINARIES = upcall-cache-invalidate libgfapi-fini-hang +BINARIES = upcall-cache-invalidate libgfapi-fini-hang anonymous_fd %: %.c diff --git a/tests/basic/gfapi/anonymous_fd.sh b/tests/basic/gfapi/anonymous_fd.sh new file mode 100755 index 00000000000..2184f8efc8e --- /dev/null +++ b/tests/basic/gfapi/anonymous_fd.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +. $(dirname $0)/../../include.rc +. $(dirname $0)/../../volume.rc + +cleanup; + +TEST glusterd + +TEST $CLI volume create $V0 $H0:$B0/brick1; +EXPECT 'Created' volinfo_field $V0 'Status'; + +TEST $CLI volume start $V0; +EXPECT 'Started' volinfo_field $V0 'Status'; + +logdir=`gluster --print-logdir` + +TEST build_tester $(dirname $0)/anonymous_fd_read_write.c -lgfapi -o $(dirname $0)/anonymous_fd +TEST ./$(dirname $0)/anonymous_fd $V0 $logdir/anonymous_fd.log + +cleanup_tester $(dirname $0)/anonymous_fd + +TEST $CLI volume stop $V0 +TEST $CLI volume delete $V0 + +cleanup; diff --git a/tests/basic/gfapi/anonymous_fd_read_write.c b/tests/basic/gfapi/anonymous_fd_read_write.c new file mode 100644 index 00000000000..281184e8223 --- /dev/null +++ b/tests/basic/gfapi/anonymous_fd_read_write.c @@ -0,0 +1,101 @@ +#include <fcntl.h> +#include <unistd.h> +#include <time.h> +#include <limits.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <errno.h> +#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) + +int +main (int argc, char *argv[]) +{ + int ret = 0; + glfs_t *fs = NULL; + struct glfs_object *root = NULL, *file_obj = NULL; + struct stat sb = {0, }; + char readbuf[32], writebuf[32]; + char *filename = "file.txt"; + char *logfile = NULL; + char *volname = NULL; + + if (argc != 3) { + fprintf (stderr, "Invalid argument\n"); + exit(1); + } + + volname = argv[1]; + logfile = argv[2]; + + fs = glfs_new (volname); + if (!fs) { + fprintf (stderr, "glfs_new: returned NULL\n"); + ret = -1; + } + + ret = glfs_set_volfile_server (fs, "tcp", "localhost", 24007); + LOG_ERR("glfs_set_volfile_server", ret); + + ret = glfs_set_logging (fs, logfile, 7); + LOG_ERR("glfs_set_logging", ret); + + ret = glfs_init (fs); + LOG_ERR("glfs_init", ret); + + root = glfs_h_lookupat (fs, NULL, "/", &sb); + if (root == NULL) { + fprintf (stderr, "glfs_h_lookupat: error on lookup of / ,%s\n", + strerror (errno)); + goto out; + } + + file_obj = glfs_h_creat (fs, root, filename, O_CREAT, 0644, &sb); + if (file_obj == NULL) { + fprintf (stderr, "glfs_h_creat: error on create of %s: from (%p),%s\n", + filename, root, strerror (errno)); + goto out; + } + + /* test read/write based on anonymous fd */ + memcpy (writebuf, "abcdefghijklmnopqrstuvwxyz012345", 32); + + ret = glfs_h_anonymous_write (fs, file_obj, writebuf, 32, 0); + if (ret < 0) + LOG_ERR ("glfs_h_anonymous_write", ret); + + ret = glfs_h_anonymous_read (fs, file_obj, readbuf, 32, 0); + if (ret < 0) + LOG_ERR ("glfs_h_anonymous_read", ret); + + if (memcmp (readbuf, writebuf, 32)) { + fprintf (stderr, "Failed to read what I wrote: %s %s\n", readbuf, + writebuf); + ret = -1; + goto out; + } + + ret = 0; +out: + if (file_obj) + glfs_h_close (file_obj); + + if (fs) { + ret = glfs_fini(fs); + fprintf (stderr, "glfs_fini(fs) returned %d \n", ret); + } + if (ret) + exit(1); + exit(0); +} |