diff options
author | Soumya Koduri <skoduri@redhat.com> | 2018-10-10 21:37:07 +0530 |
---|---|---|
committer | Amar Tumballi <amarts@redhat.com> | 2018-10-16 06:34:21 +0000 |
commit | a303cd1acc3c9ff475fe5ece643de4cbea1c1a51 (patch) | |
tree | 305ef3bebbeaf1696b5b800a74e5f3ad40088afc /api/src/glfs.c | |
parent | 593bbb28d95d1ebf11aa6f4d1f256529ed2dba88 (diff) |
gfapi: Bug fixes in leases processing code-path
This patch fixes below issues in gfapi lease code-path
* 'glfs_setfsleasid' should allow NULL input to be
able to reset leaseid
* Applications should be allowed to (un)register for
upcall notifications of type GLFS_EVENT_LEASE_RECALL
* APIs added to read contents of GLFS_EVENT_LEASE_RECALL
argument which is of type "struct glfs_upcall_lease"
Change-Id: I3320ddf235cc82fad561e13b9457ebd64db6c76b
updates: #350
Signed-off-by: Soumya Koduri <skoduri@redhat.com>
Diffstat (limited to 'api/src/glfs.c')
-rw-r--r-- | api/src/glfs.c | 44 |
1 files changed, 26 insertions, 18 deletions
diff --git a/api/src/glfs.c b/api/src/glfs.c index 7b2a10dfa63..2365fac13f9 100644 --- a/api/src/glfs.c +++ b/api/src/glfs.c @@ -551,14 +551,18 @@ pub_glfs_setfsleaseid(glfs_leaseid_t leaseid) int ret = -1; char *gleaseid = NULL; - GF_VALIDATE_OR_GOTO(THIS->name, leaseid, out); - gleaseid = gf_leaseid_get(); if (gleaseid) { - memcpy(gleaseid, leaseid, LEASE_ID_SIZE); + if (leaseid) + memcpy(gleaseid, leaseid, LEASE_ID_SIZE); + else /* reset leaseid */ + memset(gleaseid, 0, LEASE_ID_SIZE); ret = 0; } -out: + + if (ret) + gf_log("glfs", GF_LOG_ERROR, "failed to set leaseid: %s", + strerror(errno)); return ret; } @@ -1536,21 +1540,20 @@ pub_glfs_upcall_inode_get_oldpstat(struct glfs_upcall_inode *arg) } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_upcall_inode_get_oldpstat, 3.7.16); -/*struct glfs_object* -pub_glfs_upcall_lease_get_object (struct glfs_upcall_recall_inode *arg) +struct glfs_object * +pub_glfs_upcall_lease_get_object(struct glfs_upcall_lease *arg) { return arg->object; } -GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_upcall_lease_get_object, 4.0.0); -*/ +GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_upcall_lease_get_object, 4.1.6); uint32_t pub_glfs_upcall_lease_get_lease_type(struct glfs_upcall_lease *arg) { return arg->lease_type; } -GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_upcall_lease_get_lease_type, 4.0.0); +GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_upcall_lease_get_lease_type, 4.1.6); /* definitions of the GLFS_SYSRQ_* chars are in glfs.h */ static struct glfs_sysrq_help { @@ -1617,7 +1620,8 @@ pub_glfs_upcall_register(struct glfs *fs, uint32_t event_list, int ret = 0; /* list of supported upcall events */ - uint32_t up_events = GLFS_EVENT_INODE_INVALIDATE; + uint32_t up_events = (GLFS_EVENT_INODE_INVALIDATE | + GLFS_EVENT_RECALL_LEASE); DECLARE_OLD_THIS; __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); @@ -1643,10 +1647,12 @@ pub_glfs_upcall_register(struct glfs *fs, uint32_t event_list, * enabled. */ fs->upcall_events |= GF_UPCALL_CACHE_INVALIDATION; - ret |= GF_UPCALL_CACHE_INVALIDATION; - } else if (event_list & GLFS_EVENT_INODE_INVALIDATE) { + ret |= GLFS_EVENT_INODE_INVALIDATE; + } + if (event_list & GLFS_EVENT_RECALL_LEASE) { + /* @todo: Check if features.leases is enabled */ fs->upcall_events |= GF_UPCALL_RECALL_LEASE; - ret |= GF_UPCALL_RECALL_LEASE; + ret |= GLFS_EVENT_RECALL_LEASE; } /* Override cbk function if existing */ fs->up_cbk = cbk; @@ -1669,7 +1675,8 @@ pub_glfs_upcall_unregister(struct glfs *fs, uint32_t event_list) { int ret = 0; /* list of supported upcall events */ - uint32_t up_events = GLFS_EVENT_INODE_INVALIDATE; + uint32_t up_events = (GLFS_EVENT_INODE_INVALIDATE | + GLFS_EVENT_RECALL_LEASE); DECLARE_OLD_THIS; __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); @@ -1687,10 +1694,11 @@ pub_glfs_upcall_unregister(struct glfs *fs, uint32_t event_list) pthread_mutex_lock(&fs->mutex); { - if (event_list & GLFS_EVENT_INODE_INVALIDATE) { - fs->upcall_events &= ~GF_UPCALL_CACHE_INVALIDATION; - ret |= GF_UPCALL_CACHE_INVALIDATION; - } + /* We already checked if event_list contains list of supported + * upcall events. No other specific checks needed as of now for + * unregister */ + fs->upcall_events &= ~(event_list); + ret |= ((event_list == GLFS_EVENT_ANY) ? up_events : event_list); /* If there are no upcall events registered, reset cbk */ if (fs->upcall_events == 0) { |