summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSoumya Koduri <skoduri@redhat.com>2015-02-16 11:47:58 +0530
committerKaleb KEITHLEY <kkeithle@redhat.com>2015-03-17 14:01:21 -0700
commit2a4561ef08b8be3b7d79b951252e87ba8f987120 (patch)
treeed5cc0c87f6532b167ebb2b775389a9a391a3cf4 /tests
parentd81182cf69a4f188f304fcce6d651ffd56b67aac (diff)
gfapi: APIs to store and process upcall notifications received
In case of any upcall cbk events received by the protocol/client, gfapi will be notified which queues them up in a list (<gfapi_cbk_upcall>). Applicatons are responsible to provide APIs to process & notify them in case of any such upcall events queued. Added a new API which will be used by Ganesha to repeatedly poll for any such upcall event notified (<glfs_h_poll_upcall>). A new test-file has been added to test the cache_invalidation upcall events. Below link has a writeup which explains the code changes done - URL: https://soumyakoduri.wordpress.com/2015/02/25/glusterfs-understanding-upcall-infrastructure-and-cache-invalidation-support/ Change-Id: Iafc6880000c865fd4da22d0cfc388ec135b5a1c5 BUG: 1200262 Signed-off-by: Soumya Koduri <skoduri@redhat.com> Reviewed-on: http://review.gluster.org/9536 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Kaleb KEITHLEY <kkeithle@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/basic/gfapi/Makefile.am15
-rw-r--r--tests/basic/gfapi/upcall-cache-invalidate.c188
-rwxr-xr-xtests/basic/gfapi/upcall-cache-invalidate.sh34
3 files changed, 237 insertions, 0 deletions
diff --git a/tests/basic/gfapi/Makefile.am b/tests/basic/gfapi/Makefile.am
new file mode 100644
index 00000000000..2041112a7af
--- /dev/null
+++ b/tests/basic/gfapi/Makefile.am
@@ -0,0 +1,15 @@
+## compiles against the *system* version of libgfapi,
+## but not the libgfapi for the testcases
+
+CFLAGS = -Wall -g $(shell pkg-config --cflags glusterfs-api)
+LDFLAGS = $(shell pkg-config --libs glusterfs-api)
+
+BINARIES = upcall-cache-invalidate
+
+%: %.c
+
+all: $(BINARIES)
+
+clean:
+ -$(RM) $(BINARIES)
+
diff --git a/tests/basic/gfapi/upcall-cache-invalidate.c b/tests/basic/gfapi/upcall-cache-invalidate.c
new file mode 100644
index 00000000000..e91d05d4058
--- /dev/null
+++ b/tests/basic/gfapi/upcall-cache-invalidate.c
@@ -0,0 +1,188 @@
+#include <fcntl.h>
+#include <unistd.h>
+#include <time.h>
+#include <limits.h>
+#include <alloca.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <glusterfs/api/glfs.h>
+#include <glusterfs/api/glfs-handles.h>
+int gfapi = 1;
+
+#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[])
+{
+ glfs_t *fs = NULL;
+ glfs_t *fs2 = NULL;
+ glfs_t *fs_tmp = NULL;
+ glfs_t *fs_tmp2 = NULL;
+ int ret = 0, i;
+ glfs_fd_t *fd = NULL;
+ glfs_fd_t *fd2 = NULL;
+ glfs_fd_t *fd_tmp = NULL;
+ glfs_fd_t *fd_tmp2 = NULL;
+ char readbuf[32];
+ char *filename = "file_tmp";
+ char *writebuf = NULL;
+ char *vol_id = NULL;
+ unsigned int cnt = 1;
+ struct callback_arg cbk;
+ char *logfile = NULL;
+ char *volname = NULL;
+
+ cbk.handle = 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");
+ return -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);
+
+ fs2 = glfs_new (volname);
+ if (!fs2) {
+ fprintf (stderr, "glfs_new fs2: returned NULL\n");
+ return 1;
+ }
+
+ ret = glfs_set_volfile_server (fs2, "tcp", "localhost", 24007);
+ LOG_ERR("glfs_set_volfile_server-fs2", ret);
+
+ ret = glfs_set_logging (fs2, logfile, 7);
+ LOG_ERR("glfs_set_logging-fs2", ret);
+
+ ret = glfs_init (fs2);
+ LOG_ERR("glfs_init-fs2", ret);
+
+ fd = glfs_creat(fs, filename, O_RDWR|O_SYNC, 0644);
+ if (fd <= 0) {
+ ret = -1;
+ LOG_ERR ("glfs_creat", ret);
+ }
+ fprintf (stderr, "glfs-create fd - %d\n", fd);
+
+ fd2 = glfs_open(fs2, filename, O_SYNC|O_RDWR|O_CREAT);
+ if (fd2 <= 0) {
+ ret = -1;
+ LOG_ERR ("glfs_open-fs2", ret);
+ }
+ fprintf (stderr, "glfs-open fd2 - %d\n", fd2);
+
+ do {
+ if (cnt%2) {
+ fd_tmp = fd;
+ fs_tmp = fs;
+ fd_tmp2 = fd2;
+ fs_tmp2 = fs2;
+ } else {
+ fd_tmp = fd2;
+ fs_tmp = fs2;
+ fd_tmp2 = fd;
+ fs_tmp2 = fs;
+ }
+
+ /* WRITE on fd_tmp */
+ writebuf = malloc(10);
+ if (writebuf) {
+ memcpy (writebuf, "abcd", 4);
+ ret = glfs_write (fd_tmp, writebuf, 4, 0);
+ if (ret <= 0) {
+ ret = -1;
+ LOG_ERR ("glfs_write", ret);
+ } else {
+ fprintf (stderr,
+ "glfs_write suceeded\n");
+ }
+ free(writebuf);
+ } else {
+ fprintf (stderr,
+ "Could not allocate writebuf\n");
+ return -1;
+ }
+
+ /* READ on fd_tmp2 */
+ ret = glfs_lseek (fd_tmp2, 0, SEEK_SET);
+ LOG_ERR ("glfs_lseek", ret);
+
+ ret = glfs_pread (fd_tmp2, readbuf, 4, 0, 0);
+
+ if (ret <= 0) {
+ ret = -1;
+ LOG_ERR ("glfs_pread", ret);
+ } else {
+ fprintf (stderr, "glfs_read: %s\n", readbuf);
+ }
+
+ /* Open() fops seem to be not performed on server side until
+ * there are I/Os on that fd
+ */
+ if (cnt > 2) {
+ ret = glfs_h_poll_upcall(fs_tmp, &cbk);
+ LOG_ERR ("glfs_h_poll_upcall", ret);
+ if (cbk.handle) {
+ fprintf (stderr, " upcall event type - %d,"
+ " flags - %d, expire_time_attr - %d\n" ,
+ cbk.reason, cbk.flags, cbk.expire_time_attr);
+ } else {
+ fprintf (stderr,
+ "Dint receive upcall notify event");
+ ret = -1;
+ goto err;
+ }
+ }
+
+ sleep(5);
+ } while (++cnt < 5);
+
+err:
+ glfs_close(fd);
+ LOG_ERR ("glfs_close", ret);
+
+ glfs_close(fd2);
+ LOG_ERR ("glfs_close-fd2", ret);
+
+out:
+ if (fs) {
+ ret = glfs_fini(fs);
+ fprintf (stderr, "glfs_fini(fs) returned %d \n", ret);
+ }
+
+ if (fs2) {
+ ret = glfs_fini(fs2);
+ fprintf (stderr, "glfs_fini(fs2) returned %d \n", ret);
+ }
+
+ if (ret)
+ exit(1);
+ exit(0);
+}
+
+
diff --git a/tests/basic/gfapi/upcall-cache-invalidate.sh b/tests/basic/gfapi/upcall-cache-invalidate.sh
new file mode 100755
index 00000000000..20aeb1ec27a
--- /dev/null
+++ b/tests/basic/gfapi/upcall-cache-invalidate.sh
@@ -0,0 +1,34 @@
+#!/bin/bash
+
+. $(dirname $0)/../../include.rc
+. $(dirname $0)/../../volume.rc
+
+cleanup;
+
+# Upcall feature is disable for now. A new xlator option
+# will be introduced to turn it on. Skipping this test
+# till then.
+
+SKIP_TESTS;
+exit 0
+
+TEST glusterd
+
+TEST $CLI volume create $V0 localhost:$B0/brick1;
+EXPECT 'Created' volinfo_field $V0 'Status';
+
+TEST $CLI volume start $V0;
+EXPECT 'Started' volinfo_field $V0 'Status';
+
+logdir=`gluster --print-logdir`
+
+build_tester $(dirname $0)/upcall-cache-invalidate.c -lgfapi -o $(dirname $0)/upcall-cache-invalidate
+
+TEST ./$(dirname $0)/upcall-cache-invalidate $V0 $logdir/upcall-cache-invalidate.log
+
+cleanup_tester $(dirname $0)/upcall-cache-invalidate
+
+TEST $CLI volume stop $V0
+TEST $CLI volume delete $V0
+
+cleanup;