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>
This commit is contained in:
Soumya Koduri 2018-10-10 21:37:07 +05:30 committed by Amar Tumballi
parent 593bbb28d9
commit a303cd1acc
7 changed files with 65 additions and 24 deletions

View File

@ -167,6 +167,8 @@ _pub_glfs_setfsleaseid _glfs_setfsleaseid$GFAPI_4.0.0
_pub_glfs_file_lock _glfs_file_lock$GFAPI_4.0.0
_pub_glfs_lease _glfs_lease$GFAPI_4.0.0
_pub_glfs_h_lease _glfs_h_lease$GFAPI_4.0.0
_pub_glfs_upcall_lease_get_object _glfs_upcall_lease_get_object$GFAPI_4.1.6
_pub_glfs_upcall_lease_get_lease_type _glfs_upcall_lease_get_lease_type$GFAPI_4.1.6
_pub_glfs_read_async _glfs_read_async$GFAPI_future
_pub_glfs_write_async _glfs_write_async$GFAPI_future

View File

@ -230,6 +230,11 @@ GFAPI_4.0.0 {
glfs_h_lease;
} GFAPI_3.13.0;
GFAPI_4.1.6 {
glfs_upcall_lease_get_object;
glfs_upcall_lease_get_lease_type;
} GFAPI_4.0.0;
GFAPI_future {
global:
glfs_read_async;
@ -250,5 +255,5 @@ GFAPI_future {
glfs_ftruncate_async;
glfs_discard_async;
glfs_zerofill_async;
} GFAPI_4.0.0;
} GFAPI_4.1.6;

View File

@ -5268,7 +5268,7 @@ glfs_recall_lease_upcall(struct glfs *fs, struct glfs_upcall *up_arg,
up_lease_arg->lease_type = recall_lease->lease_type;
up_arg->reason = GF_UPCALL_RECALL_LEASE;
up_arg->reason = GLFS_UPCALL_RECALL_LEASE;
up_arg->event = up_lease_arg;
up_arg->free_event = glfs_free_upcall_lease;

View File

@ -336,6 +336,26 @@ glfs_h_lease(glfs_t *fs, glfs_object_t *object, glfs_lease_t *lease) __THROW
glfs_object_t *
glfs_h_find_handle(glfs_t *fs, unsigned char *handle, int len) __THROW
GFAPI_PUBLIC(glfs_h_lease, 4.0.0);
/* Functions for getting details about the glfs_upcall_lease
*
* 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_lease;
typedef struct glfs_upcall_lease glfs_upcall_lease_t;
glfs_object_t *
glfs_upcall_lease_get_object(glfs_upcall_lease_t *arg) __THROW
GFAPI_PUBLIC(glfs_upcall_lease_get_object, 4.1.6);
uint32_t
glfs_upcall_lease_get_lease_type(glfs_upcall_lease_t *arg) __THROW
GFAPI_PUBLIC(glfs_upcall_lease_get_lease_type, 4.1.6);
__END_DECLS
#endif /* !_GLFS_HANDLES_H */

View File

@ -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) {

View File

@ -1042,6 +1042,7 @@ glfs_upcall_get_fs(glfs_upcall_t *arg) __THROW
enum glfs_upcall_reason {
GLFS_UPCALL_EVENT_NULL = 0,
GLFS_UPCALL_INODE_INVALIDATE, /* invalidate cache entry */
GLFS_UPCALL_RECALL_LEASE, /* recall lease */
};
typedef enum glfs_upcall_reason glfs_upcall_reason_t;
@ -1061,6 +1062,7 @@ glfs_upcall_get_reason(glfs_upcall_t *arg) __THROW
* ==========================================================
* GLFS_UPCALL_EVENT_NULL - NULL
* GLFS_UPCALL_INODE_INVALIDATE - struct glfs_upcall_inode
* GLFS_UPCALL_RECALL_LEASE - struct glfs_upcall_lease
*
* After processing upcall event, glfs_free() should be called on the
* glfs_upcall.
@ -1094,6 +1096,7 @@ typedef void (*glfs_upcall_cbk)(glfs_upcall_t *up_arg, void *data);
* List of upcall events supported by gluster/gfapi
*/
#define GLFS_EVENT_INODE_INVALIDATE 0x00000001 /* invalidate cache entry */
#define GLFS_EVENT_RECALL_LEASE 0x00000002 /* Recall lease */
#define GLFS_EVENT_ANY 0xffffffff /* for all the above events */
/*
@ -1118,7 +1121,8 @@ typedef void (*glfs_upcall_cbk)(glfs_upcall_t *up_arg, void *data);
*
* @event_list: List of upcall events to be registered.
* Current available values are:
* - GFAPI_UPCALL_INODE_INVALIDATE
* - GLFS_EVENT_INODE_INVALIDATE
* - GLFS_EVENT_RECALL_LEASE
*
* @cbk: The cbk routine to be invoked in case of any upcall received
* @data: Any opaque pointer provided by caller which shall be using while
@ -1152,7 +1156,8 @@ glfs_upcall_register(glfs_t *fs, uint32_t event_list, glfs_upcall_cbk cbk,
*
* @event_list: List of upcall events to be unregistered.
* Current available values are:
* - GFAPI_UPCALL_INODE_INVALIDATE
* - GLFS_EVENT_INODE_INVALIDATE
* - GLFS_EVENT_RECALL_LEASE
* RETURN VALUE:
* >0: SUCCESS (value contains the events successfully unregistered)
* -1: FAILURE
@ -1163,6 +1168,7 @@ glfs_upcall_unregister(glfs_t *fs, uint32_t event_list) __THROW
/* Lease Types */
enum glfs_lease_types {
GLFS_LEASE_NONE = 0,
GLFS_RD_LEASE = 1,
GLFS_RW_LEASE = 2,
};

View File

@ -238,7 +238,7 @@ main(int argc, char *argv[])
/* Check if the return mask contains the event */
if ((ret < 0) || !(ret & GLFS_EVENT_INODE_INVALIDATE)) {
fprintf(stderr,
"glfs_upcall_register return doesn't contain"
"glfs_upcall_unregister return doesn't contain"
" upcall event\n");
return -1;
}
@ -248,7 +248,7 @@ main(int argc, char *argv[])
/* Check if the return mask contains the event */
if ((ret < 0) || !(ret & GLFS_EVENT_INODE_INVALIDATE)) {
fprintf(stderr,
"glfs_upcall_register return doesn't contain"
"glfs_upcall_unregister return doesn't contain"
" upcall event\n");
return -1;
}