diff options
author | Niels de Vos <ndevos@redhat.com> | 2016-08-06 16:04:48 +0200 |
---|---|---|
committer | Niels de Vos <ndevos@redhat.com> | 2016-09-28 11:00:38 -0700 |
commit | 4721188a154acd9a0a4c096d8d73e97f3bf1b2a9 (patch) | |
tree | 6f957b9cfd21c9fc9e72390d85520bc627e7fa9e /api/src/glfs-handles.h | |
parent | 7407266684334203c21e260bb0b3527ca94bb507 (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.
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>
Diffstat (limited to 'api/src/glfs-handles.h')
-rw-r--r-- | api/src/glfs-handles.h | 107 |
1 files changed, 71 insertions, 36 deletions
diff --git a/api/src/glfs-handles.h b/api/src/glfs-handles.h index 557934503d2..740b759d0a0 100644 --- a/api/src/glfs-handles.h +++ b/api/src/glfs-handles.h @@ -12,6 +12,7 @@ #define _GLFS_HANDLES_H #include "glfs.h" +#include <inttypes.h> /* GLFS OBJECT BASED OPERATIONS * @@ -110,45 +111,82 @@ typedef struct glfs_object glfs_object_t; * * Currently supported upcall_events - * GFAPI_INODE_INVALIDATE - - * 'event_arg' - glfs_callback_inode_arg + * 'event_arg' - glfs_upcall_inode * - * After processing the event, applications need to free 'event_arg'. + * After processing the event, applications need to free 'event_arg' with + * glfs_free(). * * Also similar to I/Os, the application should ideally stop polling * before calling glfs_fini(..). Hence making an assumption that * 'fs' & ctx structures cannot be freed while in this routine. */ -struct glfs_callback_arg { - struct glfs *fs; /* glfs object */ - int reason; /* Upcall event type */ - void *event_arg; /* changes based in the event type */ +struct glfs_upcall; + +struct glfs* +glfs_upcall_get_fs (struct glfs_upcall *arg) __THROW + GFAPI_PUBLIC(glfs_upcall_get_fs, 3.7.16); + +enum glfs_upcall_reason { + GLFS_UPCALL_EVENT_NULL = 0, + GLFS_UPCALL_INODE_INVALIDATE, /* invalidate cache entry */ }; +enum glfs_upcall_reason +glfs_upcall_get_reason (struct glfs_upcall *arg) __THROW + GFAPI_PUBLIC(glfs_upcall_get_reason, 3.7.16); + + /* - * After processing upcall event, they need to free "object" , "p_object", - * "oldp_object" using glfs_h_close(..). + * After processing upcall event, glfs_free() should be called on the + * glfs_upcall. */ -struct glfs_callback_inode_arg { - struct glfs_object *object; /* Object which need to be acted upon */ - int flags; /* Cache UPDATE/INVALIDATE flags */ - struct stat buf; /* Latest stat of this entry */ - unsigned int expire_time_attr; /* the amount of time for which - * the application need to cache - * this entry - */ - struct glfs_object *p_object; /* parent Object to be updated */ - struct stat p_buf; /* Latest stat of parent dir handle */ - struct glfs_object *oldp_object; /* Old parent Object - * to be updated */ - struct stat oldp_buf; /* Latest stat of old parent - * dir handle */ -}; +void* +glfs_upcall_get_event (struct glfs_upcall *arg) __THROW + GFAPI_PUBLIC(glfs_upcall_get_event, 3.7.16); + + +/* Functions for getting details about the glfs_upcall_inode + * + * None of the pointers returned by the below functions should be free()'d, + * glfs_free()'d or glfs_h_close()'d by the application. + * + * Releasing of the structures is done by passing the glfs_upcall pointer + * to glfs_free(). + */ +struct glfs_upcall_inode; + +struct glfs_object* +glfs_upcall_inode_get_object (struct glfs_upcall_inode *arg) __THROW + GFAPI_PUBLIC(glfs_upcall_inode_get_object, 3.7.16); + +uint64_t +glfs_upcall_inode_get_flags (struct glfs_upcall_inode *arg) __THROW + GFAPI_PUBLIC(glfs_upcall_inode_get_flags, 3.7.16); + +struct stat* +glfs_upcall_inode_get_stat (struct glfs_upcall_inode *arg) __THROW + GFAPI_PUBLIC(glfs_upcall_inode_get_stat, 3.7.16); + +uint64_t +glfs_upcall_inode_get_expire (struct glfs_upcall_inode *arg) __THROW + GFAPI_PUBLIC(glfs_upcall_inode_get_expire, 3.7.16); + +struct glfs_object* +glfs_upcall_inode_get_pobject (struct glfs_upcall_inode *arg) __THROW + GFAPI_PUBLIC(glfs_upcall_inode_get_pobject, 3.7.16); + +struct stat* +glfs_upcall_inode_get_pstat (struct glfs_upcall_inode *arg) __THROW + GFAPI_PUBLIC(glfs_upcall_inode_get_pstat, 3.7.16); + +struct glfs_object* +glfs_upcall_inode_get_oldpobject (struct glfs_upcall_inode *arg) __THROW + GFAPI_PUBLIC(glfs_upcall_inode_get_oldpobject, 3.7.16); + +struct stat* +glfs_upcall_inode_get_oldpstat (struct glfs_upcall_inode *arg) __THROW + GFAPI_PUBLIC(glfs_upcall_inode_get_oldpstat, 3.7.16); -/* reason list in glfs_callback_arg */ -enum gfapi_callback_type { - GFAPI_CBK_EVENT_NULL, - GFAPI_INODE_INVALIDATE, /* invalidate cache entry */ -}; /* Handle based operations */ /* Operations that generate handles */ @@ -273,7 +311,7 @@ glfs_h_access (struct glfs *fs, struct glfs_object *object, int mask) __THROW This API is used to poll for upcall events stored in the upcall list. Current users of this API is NFS-Ganesha. Incase of any event received, it will be mapped appropriately - into 'glfs_callback_arg' along with the handle('glfs_object') to be + into 'glfs_upcall' along with the handle('glfs_object') to be passed to NFS-Ganesha. In case of success, applications need to check the value of @@ -283,11 +321,8 @@ glfs_h_access (struct glfs *fs, struct glfs_object *object, int mask) __THROW PARAMETERS @fs: glfs object to poll the upcall events for - @cbk: Structure to store upcall events as desired by the application. - Application is responsible for allocating and passing the - references of all the pointers of this structure except for - "handle". In case of any events received, it needs to free - "handle" + @cbk: Pointer that will contain an upcall event for use by the application. + Application is responsible for free'ing the structure with glfs_free(). RETURN VALUES @@ -297,8 +332,8 @@ glfs_h_access (struct glfs *fs, struct glfs_object *object, int mask) __THROW */ int -glfs_h_poll_upcall (struct glfs *fs, struct glfs_callback_arg *cbk) __THROW - GFAPI_PUBLIC(glfs_h_poll_upcall, 3.7.0); +glfs_h_poll_upcall (struct glfs *fs, struct glfs_upcall **cbk) __THROW + GFAPI_PUBLIC(glfs_h_poll_upcall, 3.7.16); int glfs_h_acl_set (struct glfs *fs, struct glfs_object *object, |