diff options
| author | Soumya Koduri <skoduri@redhat.com> | 2018-10-10 21:37:07 +0530 | 
|---|---|---|
| committer | Soumya Koduri <skoduri@redhat.com> | 2018-10-22 22:06:03 +0530 | 
| commit | fa4710bb8fbc852971d763d8727e3755436ea9c8 (patch) | |
| tree | ae1a24de2d7afd5fdef30e188a3c82515be44ee9 /api/src | |
| parent | b63dfd84fc8b3e08e3f005f71bf493c633452612 (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"
This is backport of below mainline path -
https://review.gluster.org/#/c/glusterfs/+/21391
Change-Id: I3320ddf235cc82fad561e13b9457ebd64db6c76b
updates: #350
Signed-off-by: Soumya Koduri <skoduri@redhat.com>
Diffstat (limited to 'api/src')
| -rw-r--r-- | api/src/gfapi.aliases | 2 | ||||
| -rw-r--r-- | api/src/gfapi.map | 5 | ||||
| -rw-r--r-- | api/src/glfs-fops.c | 2 | ||||
| -rw-r--r-- | api/src/glfs-handles.h | 20 | ||||
| -rw-r--r-- | api/src/glfs.c | 53 | ||||
| -rw-r--r-- | api/src/glfs.h | 16 | 
6 files changed, 69 insertions, 29 deletions
diff --git a/api/src/gfapi.aliases b/api/src/gfapi.aliases index 74053b9af6a..fd4f437ccc3 100644 --- a/api/src/gfapi.aliases +++ b/api/src/gfapi.aliases @@ -174,3 +174,5 @@ _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 diff --git a/api/src/gfapi.map b/api/src/gfapi.map index 4984479c57a..6dd907d2122 100644 --- a/api/src/gfapi.map +++ b/api/src/gfapi.map @@ -228,3 +228,8 @@ GFAPI_4.0.0 {                  glfs_lease;                  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; diff --git a/api/src/glfs-fops.c b/api/src/glfs-fops.c index f243999c0c8..50f32fae6f6 100644 --- a/api/src/glfs-fops.c +++ b/api/src/glfs-fops.c @@ -4841,7 +4841,7 @@ glfs_recall_lease_upcall (struct glfs *fs,          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; diff --git a/api/src/glfs-handles.h b/api/src/glfs-handles.h index 58ef85a9f47..6dfb027a9a4 100644 --- a/api/src/glfs-handles.h +++ b/api/src/glfs-handles.h @@ -337,6 +337,26 @@ struct glfs_object *  glfs_h_find_handle (struct glfs *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 */ diff --git a/api/src/glfs.c b/api/src/glfs.c index cc84842f286..508191ec8b1 100644 --- a/api/src/glfs.c +++ b/api/src/glfs.c @@ -576,14 +576,17 @@ 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;  } @@ -1566,22 +1569,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 { @@ -1647,7 +1648,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); @@ -1666,18 +1668,20 @@ pub_glfs_upcall_register (struct glfs *fs, uint32_t event_list,                  goto out;          } -        /* incase other thread does unregister */ -        pthread_mutex_lock (&fs->mutex); +        /* in case other thread does unregister */ +        pthread_mutex_lock(&fs->mutex);          {                  if (event_list & GLFS_EVENT_INODE_INVALIDATE) {                          /* @todo: Check if features.cache-invalidation is                           * enabled.                           */ -                        fs->upcall_events |=  GF_UPCALL_CACHE_INVALIDATION; -                        ret |= GF_UPCALL_CACHE_INVALIDATION; -                } else if (event_list & GLFS_EVENT_INODE_INVALIDATE) { -                        fs->upcall_events |=  GF_UPCALL_RECALL_LEASE; -                        ret |= GF_UPCALL_RECALL_LEASE; +                        fs->upcall_events |= GF_UPCALL_CACHE_INVALIDATION; +                        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 |= GLFS_EVENT_RECALL_LEASE;                  }                  /* Override cbk function if existing */                  fs->up_cbk = cbk; @@ -1700,7 +1704,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); @@ -1719,10 +1724,12 @@ 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) { diff --git a/api/src/glfs.h b/api/src/glfs.h index 16eae642906..dd6142757d6 100644 --- a/api/src/glfs.h +++ b/api/src/glfs.h @@ -960,7 +960,8 @@ glfs_upcall_get_fs (struct glfs_upcall *arg) __THROW  enum glfs_upcall_reason {          GLFS_UPCALL_EVENT_NULL = 0, -        GLFS_UPCALL_INODE_INVALIDATE,    /* invalidate cache entry */ +        GLFS_UPCALL_INODE_INVALIDATE, /* invalidate cache entry */ +        GLFS_UPCALL_RECALL_LEASE,     /* recall lease */  };  enum glfs_upcall_reason @@ -980,6 +981,7 @@ glfs_upcall_get_reason (struct glfs_upcall *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. @@ -1012,8 +1014,9 @@ typedef void (*glfs_upcall_cbk) (struct glfs_upcall *up_arg, void *data);  /*   * List of upcall events supported by gluster/gfapi   */ -#define GLFS_EVENT_INODE_INVALIDATE    0x00000001 /* invalidate cache entry */ -#define GLFS_EVENT_ANY                 0xffffffff /* for all the above events */ +#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 */  /*   * SYNOPSIS @@ -1037,7 +1040,8 @@ typedef void (*glfs_upcall_cbk) (struct glfs_upcall *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 incase of any upcall received   * @data: Any opaque pointer provided by caller which shall be using while @@ -1071,7 +1075,8 @@ glfs_upcall_register (struct glfs *fs, uint32_t event_list,   *   * @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 @@ -1082,6 +1087,7 @@ glfs_upcall_unregister (struct glfs *fs, uint32_t event_list) __THROW  /* Lease Types */  enum glfs_lease_types { +        GLFS_LEASE_NONE = 0,          GLFS_RD_LEASE = 1,          GLFS_RW_LEASE = 2,  };  | 
