diff options
| -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 | 44 | ||||
| -rw-r--r-- | api/src/glfs.h | 10 | ||||
| -rw-r--r-- | tests/basic/gfapi/upcall-register-api.c | 4 | 
7 files changed, 64 insertions, 23 deletions
diff --git a/api/src/gfapi.aliases b/api/src/gfapi.aliases index 79f7e0fcb42..9eb1de86c14 100644 --- a/api/src/gfapi.aliases +++ b/api/src/gfapi.aliases @@ -175,3 +175,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 8eeec71fb53..0e886dd84b8 100644 --- a/api/src/gfapi.map +++ b/api/src/gfapi.map @@ -235,3 +235,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 cafbeb7f515..104d3ffd4b1 100644 --- a/api/src/glfs-fops.c +++ b/api/src/glfs-fops.c @@ -4845,7 +4845,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; diff --git a/api/src/glfs-handles.h b/api/src/glfs-handles.h index 97d90a138ac..09b3b2ed493 100644 --- a/api/src/glfs-handles.h +++ b/api/src/glfs-handles.h @@ -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 */ diff --git a/api/src/glfs.c b/api/src/glfs.c index d21cb8b334f..dc3233582c5 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;  } @@ -1526,21 +1530,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 { @@ -1607,7 +1610,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); @@ -1633,10 +1637,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; @@ -1659,7 +1665,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); @@ -1677,10 +1684,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) { diff --git a/api/src/glfs.h b/api/src/glfs.h index b54e050c9ed..ba57244f87f 100644 --- a/api/src/glfs.h +++ b/api/src/glfs.h @@ -1036,6 +1036,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; @@ -1055,6 +1056,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. @@ -1088,6 +1090,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 */  /* @@ -1112,7 +1115,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 @@ -1146,7 +1150,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 @@ -1157,6 +1162,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,  }; diff --git a/tests/basic/gfapi/upcall-register-api.c b/tests/basic/gfapi/upcall-register-api.c index 5127cea5b3f..68591fdc517 100644 --- a/tests/basic/gfapi/upcall-register-api.c +++ b/tests/basic/gfapi/upcall-register-api.c @@ -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;      }  | 
