From 5bc41576647dd7f0e201e7e2951cf75702d8b623 Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Wed, 19 Oct 2016 12:55:30 +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 For the ease of backporting, this patch also includes the (mostly overwritten) changes from commit 2775dc64. Change-Id: I2b8bd5a0a82036d2abea1a217f5e5975a1d4fe93 BUG: 1347717 Signed-off-by: Niels de Vos Reviewed-on: http://review.gluster.org/15640 Smoke: Gluster Build System NetBSD-regression: NetBSD Build System Reviewed-by: Kaleb KEITHLEY CentOS-regression: Gluster Build System --- api/src/glfs.c | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) (limited to 'api/src/glfs.c') diff --git a/api/src/glfs.c b/api/src/glfs.c index 808acace16b..8464ee33d2b 100644 --- a/api/src/glfs.c +++ b/api/src/glfs.c @@ -1306,3 +1306,107 @@ invalid_fs: } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_ipc, 3.7.0); + + +void +pub_glfs_free (void *ptr) +{ + int mem_type = 0; + + mem_type = gf_get_mem_type (ptr); + + switch (mem_type) { + case glfs_mt_upcall_entry_t: + { + struct glfs_upcall *to_free = ptr; + + if (to_free->event) + to_free->free_event (to_free->event); + + GF_FREE (ptr); + break; + } + default: + GF_FREE (ptr); + } +} + +GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_free, 3.7.16); + + +struct glfs* +pub_glfs_upcall_get_fs (struct glfs_upcall *arg) +{ + return arg->fs; +} +GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_upcall_get_fs, 3.7.16); + +enum glfs_upcall_reason +pub_glfs_upcall_get_reason (struct glfs_upcall *arg) +{ + return arg->reason; +} +GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_upcall_get_reason, 3.7.16); + +void* +pub_glfs_upcall_get_event (struct glfs_upcall *arg) +{ + return arg->event; +} +GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_upcall_get_event, 3.7.16); + +struct glfs_object* +pub_glfs_upcall_inode_get_object (struct glfs_upcall_inode *arg) +{ + return arg->object; +} +GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_upcall_inode_get_object, 3.7.16); + +uint64_t +pub_glfs_upcall_inode_get_flags (struct glfs_upcall_inode *arg) +{ + return arg->flags; +} +GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_upcall_inode_get_flags, 3.7.16); + +struct stat* +pub_glfs_upcall_inode_get_stat (struct glfs_upcall_inode *arg) +{ + return &arg->buf; +} +GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_upcall_inode_get_stat, 3.7.16); + +uint64_t +pub_glfs_upcall_inode_get_expire (struct glfs_upcall_inode *arg) +{ + return arg->expire_time_attr; +} +GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_upcall_inode_get_expire, 3.7.16); + +struct glfs_object* +pub_glfs_upcall_inode_get_pobject (struct glfs_upcall_inode *arg) +{ + return arg->p_object; +} +GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_upcall_inode_get_pobject, 3.7.16); + +struct stat* +pub_glfs_upcall_inode_get_pstat (struct glfs_upcall_inode *arg) +{ + return &arg->p_buf; +} +GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_upcall_get_pstat, 3.7.16); + +struct glfs_object* +pub_glfs_upcall_inode_get_oldpobject (struct glfs_upcall_inode *arg) +{ + return arg->oldp_object; +} +GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_upcall_get_oldpobject, 3.7.16); + +struct stat* +pub_glfs_upcall_inode_get_oldpstat (struct glfs_upcall_inode *arg) +{ + return &arg->oldp_buf; +} +GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_upcall_get_oldpstat, 3.7.16); -- cgit