diff options
author | Niels de Vos <ndevos@redhat.com> | 2016-06-10 18:23:43 +0530 |
---|---|---|
committer | Kaushal M <kaushal@redhat.com> | 2016-10-03 05:20:43 -0700 |
commit | 55c92db32ba7d88359f0562953a3a6d8874dd1a5 (patch) | |
tree | c24041fbdd6a0239e4bcae042c2ab1a3ea482a8c /tests/basic/gfapi/upcall-cache-invalidate.c | |
parent | 2cee4a3e47518aeb28ac2b611c6f01c0f9d00dab (diff) |
gfapi: redesign the public interface for upcall consumers
The glfs_callback_arg and glfs_callback_inode_arg were allocated by
gfapi, and expected to be free()'d by the application. However it is not
reasonable to expect that applications use the same memory allocator to
as the compiled libgfapi.so. For instance, it is possible that gfapi
uses glibc malloc/free, and an application like NFS-Ganesha the versions
from jemalloc. Mismatching of the malloc() and free() functions causes
segmentation faults at best.
In order to prevent problems like this in the future, the API for
applications that consume upcalls has been remodeled. Any of the
structures that gfapi allocates, should be free'd with glfs_free(). The
members of the structures can not be accessed directly anymore, each
has its own function to access now.
Correcting the naming of the functions, structures and constants is a
continuation of commit 2775dc64101ed37c8d9809bf9852dbf0746ee2b6. These
new improvements not only have correct prefixes for the functions and
structures, the naming also reflects more to the upcall framework and
does not use "callback" anymore.
Cherry picked from commit 4721188a154acd9a0a4c096d8d73e97f3bf1b2a9:
> Change-Id: I2b8bd5a0a82036d2abea1a217f5e5975a1d4fe93
> BUG: 1344714
> Signed-off-by: Niels de Vos <ndevos@redhat.com>
> Reviewed-on: http://review.gluster.org/14701
> Smoke: Gluster Build System <jenkins@build.gluster.org>
> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
> CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
> Reviewed-by: Kaleb KEITHLEY <kkeithle@redhat.com>
> Reviewed-by: soumya k <skoduri@redhat.com>
> Reviewed-by: jiffin tony Thottan <jthottan@redhat.com>
Once difference with the version of this change in other branches is
that leases are not included in glusterfs-3.7. Hence there is a little
change that drops the handling of GF_UPCALL_RECALL_LEASE.
In addition, this backport contains commit 2775dc6410:
> libgfapi/upcall : prepend "glfs_" to callback_arg, callback_inode_arg
> Reviewed-on: http://review.gluster.org/14702
Change-Id: I2b8bd5a0a82036d2abea1a217f5e5975a1d4fe93
BUG: 1347715
Signed-off-by: Niels de Vos <ndevos@redhat.com>
Reviewed-on: http://review.gluster.org/15602
NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
Smoke: Gluster Build System <jenkins@build.gluster.org>
CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
Reviewed-by: Kaushal M <kaushal@redhat.com>
Diffstat (limited to 'tests/basic/gfapi/upcall-cache-invalidate.c')
-rw-r--r-- | tests/basic/gfapi/upcall-cache-invalidate.c | 72 |
1 files changed, 40 insertions, 32 deletions
diff --git a/tests/basic/gfapi/upcall-cache-invalidate.c b/tests/basic/gfapi/upcall-cache-invalidate.c index 13cca69da89..4d355e62278 100644 --- a/tests/basic/gfapi/upcall-cache-invalidate.c +++ b/tests/basic/gfapi/upcall-cache-invalidate.c @@ -9,7 +9,6 @@ #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) { \ @@ -24,26 +23,24 @@ int gfapi = 1; 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; - struct callback_inode_arg *in_arg = NULL; - - cbk.reason = 0; + 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 glfs_upcall *cbk = NULL; + char *logfile = NULL; + char *volname = NULL; + char *hostname = NULL; if (argc != 3) { fprintf (stderr, "Invalid argument\n"); @@ -73,7 +70,6 @@ main (int argc, char *argv[]) * on the fs (through this instance) happens. */ ret = glfs_h_poll_upcall(fs_tmp, &cbk); LOG_ERR ("glfs_h_poll_upcall", ret); - cbk.reason = 0; fs2 = glfs_new (volname); if (!fs2) { @@ -140,6 +136,7 @@ main (int argc, char *argv[]) ret = glfs_lseek (fd_tmp2, 0, SEEK_SET); LOG_ERR ("glfs_lseek", ret); + memset (readbuf, 0, sizeof(readbuf)); ret = glfs_pread (fd_tmp2, readbuf, 4, 0, 0); if (ret <= 0) { @@ -153,26 +150,37 @@ main (int argc, char *argv[]) * there are I/Os on that fd */ if (cnt > 2) { + struct glfs_upcall_inode *in_arg = NULL; + enum glfs_upcall_reason reason = 0; + struct glfs_object *object = NULL; + uint64_t flags = 0; + uint64_t expire = 0; + ret = glfs_h_poll_upcall(fs_tmp, &cbk); LOG_ERR ("glfs_h_poll_upcall", ret); - /* Expect 'GFAPI_INODE_INVALIDATE' upcall event. */ - if (cbk.reason == GFAPI_INODE_INVALIDATE) { - in_arg = cbk.event_arg; + + reason = glfs_upcall_get_reason (cbk); + + /* Expect 'GLFS_INODE_INVALIDATE' upcall event. */ + if (reason == GLFS_UPCALL_INODE_INVALIDATE) { + in_arg = glfs_upcall_get_event (cbk); + + object = glfs_upcall_inode_get_object (in_arg); + flags = glfs_upcall_inode_get_flags (in_arg); + expire = glfs_upcall_inode_get_expire (in_arg); + fprintf (stderr, " upcall event type - %d," " object(%p), flags(%d), " " expire_time_attr(%d)\n" , - cbk.reason, in_arg->object, - in_arg->flags, - in_arg->expire_time_attr); - ret = glfs_h_close (in_arg->object); - LOG_ERR ("glfs_h_close", ret); - free (in_arg); + reason, object, flags, expire); } else { fprintf (stderr, - "Dint receive upcall notify event"); + "Didnt receive upcall notify event"); ret = -1; goto err; } + + glfs_free (cbk); } sleep(5); |