From 11279aacbda1f05c3405a85583973f24ce20d103 Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Thu, 29 Sep 2016 10:19:26 +0200 Subject: 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 > Reviewed-on: http://review.gluster.org/14701 > Smoke: Gluster Build System > NetBSD-regression: NetBSD Build System > CentOS-regression: Gluster Build System > Reviewed-by: Kaleb KEITHLEY > Reviewed-by: soumya k > Reviewed-by: jiffin tony Thottan Change-Id: I2b8bd5a0a82036d2abea1a217f5e5975a1d4fe93 BUG: 1378948 Signed-off-by: Niels de Vos Reviewed-on: http://review.gluster.org/15597 NetBSD-regression: NetBSD Build System Reviewed-by: jiffin tony Thottan CentOS-regression: Gluster Build System Smoke: Gluster Build System Reviewed-by: Kaleb KEITHLEY --- tests/basic/gfapi/bug1291259.c | 64 ++++++++++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 24 deletions(-) (limited to 'tests/basic/gfapi/bug1291259.c') diff --git a/tests/basic/gfapi/bug1291259.c b/tests/basic/gfapi/bug1291259.c index 9fbe02ba34d..26fc1e01449 100644 --- a/tests/basic/gfapi/bug1291259.c +++ b/tests/basic/gfapi/bug1291259.c @@ -33,23 +33,22 @@ int gfapi = 1; int main (int argc, char *argv[]) { - glfs_t *fs = NULL; - glfs_t *fs2 = NULL; - int ret = 0, i; - glfs_fd_t *fd = NULL; - char *filename = "/a1"; - char *filename2 = "/a2"; - struct stat sb = {0, }; - struct glfs_callback_arg cbk; - char *logfile = NULL; - char *volname = NULL; - char *hostname = NULL; - int cnt = 1; - int upcall_received = 0; - struct glfs_callback_inode_arg *in_arg = NULL; - struct glfs_object *root = NULL, *leaf = NULL; - unsigned char globjhdl[GFAPI_HANDLE_LENGTH]; - unsigned char globjhdl2[GFAPI_HANDLE_LENGTH]; + glfs_t *fs = NULL; + glfs_t *fs2 = NULL; + int ret = 0, i; + glfs_fd_t *fd = NULL; + char *filename = "/a1"; + char *filename2 = "/a2"; + struct stat sb = {0, }; + char *logfile = NULL; + char *volname = NULL; + char *hostname = NULL; + int cnt = 1; + int upcall_received = 0; + struct glfs_upcall *cbk = NULL; + struct glfs_object *root = NULL, *leaf = NULL; + unsigned char globjhdl[GFAPI_HANDLE_LENGTH]; + unsigned char globjhdl2[GFAPI_HANDLE_LENGTH]; fprintf (stderr, "Starting libgfapi_fini\n"); if (argc != 4) { @@ -82,7 +81,6 @@ main (int argc, char *argv[]) * on the fs (through this instance) happens. */ ret = glfs_h_poll_upcall(fs, &cbk); LOG_ERR ("glfs_h_poll_upcall", ret); - cbk.reason = 0; fs2 = glfs_new (volname); if (!fs) { @@ -123,21 +121,30 @@ main (int argc, char *argv[]) } fprintf (stderr, "glfs_h_create leaf - %p\n", leaf); - while (cnt++ < 5) { + while (cnt++ < 5 && !upcall_received) { + enum glfs_upcall_reason reason = 0; + struct glfs_upcall_inode *in_arg = NULL; + ret = glfs_h_poll_upcall(fs, &cbk); LOG_ERR ("glfs_h_poll_upcall", ret); + if (ret) + goto retry; + + reason = glfs_upcall_get_reason (cbk); + fprintf (stderr, "Upcall received(%d)\n", reason); + + if (reason == GLFS_UPCALL_INODE_INVALIDATE) { + struct glfs_object *object = NULL; - if (cbk.reason == GFAPI_INODE_INVALIDATE) { - fprintf (stderr, "Upcall received(%d)\n", - cbk.reason); - in_arg = (struct glfs_callback_inode_arg *)(cbk.event_arg); + in_arg = glfs_upcall_get_event (cbk); + object = glfs_upcall_inode_get_object (in_arg); ret = glfs_h_extract_handle (root, globjhdl+GLAPI_UUID_LENGTH, GFAPI_HANDLE_LENGTH); LOG_ERR("glfs_h_extract_handle", (ret != 16)); - ret = glfs_h_extract_handle (in_arg->object, + ret = glfs_h_extract_handle (object, globjhdl2+GLAPI_UUID_LENGTH, GFAPI_HANDLE_LENGTH); LOG_ERR("glfs_h_extract_handle", (ret != 16)); @@ -149,6 +156,15 @@ main (int argc, char *argv[]) } upcall_received = 1; } + +retry: + if (!upcall_received) + sleep (1); /* glfs_h_poll_upcall() does not block */ + + if (!ret) { + glfs_free (cbk); + cbk = NULL; + } } if (!upcall_received) { -- cgit