diff options
author | Soumya Koduri <skoduri@redhat.com> | 2018-04-27 15:12:08 +0530 |
---|---|---|
committer | Poornima G <pgurusid@redhat.com> | 2018-05-04 17:12:19 +0000 |
commit | b04066721bf4a240f61b83bd87bbb27437c5fe4f (patch) | |
tree | dd1a4c7dcfe372f3182e51a5d8f1dba6af82ea94 /api/src/glfs.c | |
parent | b42a048d3a76c7f377399f18d30f0a8a930f9d05 (diff) |
gfapi : RECALL_LEASE implementation
Right now there are two types of upcalls
* poll method
* registering callback
But callback can be registered per fs and same callback fn shall be used
for any lease recall with object handle as argument as done for cache
invalidation.
TODO: RECALL LEASE for each glfd (for future reference)
(may be needed fo Samba as they do not deal with
object handles.
In case of RECALL_LEASE, we could associate separate
cbk function for each glfd either by
- extending pub_glfs_lease to accept new args (recall_cbk_fn, cookie)
- or by defining new API "glfs_register_recall_cbk_fn (glfd, recall_cbk_fn, cookie)
. In such cases, flag it and instead of calling below upcall functions, define
a new one to go through the glfd list and invoke each of theirs recall_cbk_fn.
Plus added following as well
* passed lease id to dict in required arguments
* added flag check in pub_glfs_open
Updates: #350
Change-Id: I07a971f0f26ec6aae0b9f9a5613504317dee153b
Signed-off-by: Soumya Koduri <skoduri@redhat.com>
Signed-off-by: Poornima G <pgurusid@redhat.com>
Signed-off-by: Jiffin Tony Thottan <jthottan@redhat.com>
Diffstat (limited to 'api/src/glfs.c')
-rw-r--r-- | api/src/glfs.c | 103 |
1 files changed, 101 insertions, 2 deletions
diff --git a/api/src/glfs.c b/api/src/glfs.c index 6724534fb31..da6bc3a07ba 100644 --- a/api/src/glfs.c +++ b/api/src/glfs.c @@ -578,7 +578,7 @@ pub_glfs_setfsleaseid (glfs_leaseid_t leaseid) GF_VALIDATE_OR_GOTO (THIS->name, leaseid, out); - gleaseid = glusterfs_leaseid_buf_get(); + gleaseid = gf_leaseid_get(); if (gleaseid) { memcpy (gleaseid, leaseid, LEASE_ID_SIZE); ret = 0; @@ -589,6 +589,87 @@ out: GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_setfsleaseid, 4.0.0); +int +get_fop_attr_glfd (dict_t **fop_attr, struct glfs_fd *glfd) +{ + char *leaseid = NULL; + int ret = 0; + gf_boolean_t dict_create = _gf_false; + + leaseid = GF_CALLOC (1, LEASE_ID_SIZE, gf_common_mt_char); + GF_CHECK_ALLOC_AND_LOG("gfapi", leaseid, ret, "lease id alloc failed", out); + memcpy (leaseid, glfd->lease_id, LEASE_ID_SIZE); + if (*fop_attr == NULL) { + *fop_attr = dict_new (); + dict_create = _gf_true; + } + GF_CHECK_ALLOC_AND_LOG("gfapi", *fop_attr, ret, "dict_new failed", out); + ret = dict_set_static_bin (*fop_attr, "lease-id", leaseid, LEASE_ID_SIZE); +out: + if (ret) { + GF_FREE (leaseid); + if (dict_create) { + if (*fop_attr) + dict_unref (*fop_attr); + *fop_attr = NULL; + } + } + return ret; +} + +int +set_fop_attr_glfd (struct glfs_fd *glfd) +{ + char *lease_id = NULL; + int ret = -1; + + lease_id = gf_existing_leaseid (); + if (lease_id) { + memcpy (glfd->lease_id, lease_id, LEASE_ID_SIZE); + ret = 0; + } + return ret; +} + +int +get_fop_attr_thrd_key (dict_t **fop_attr) +{ + char *lease_id = NULL; + int ret = 0; + gf_boolean_t dict_create = _gf_false; + + lease_id = gf_existing_leaseid (); + if (lease_id) { + if (*fop_attr == NULL) { + *fop_attr = dict_new (); + dict_create = _gf_true; + } + GF_CHECK_ALLOC_AND_LOG("gfapi", *fop_attr, ret, "dict_new failed", out); + ret = dict_set_bin (*fop_attr, "lease-id", gf_strdup (lease_id), + LEASE_ID_SIZE); + } + +out: + if (ret && dict_create) { + if (*fop_attr) + dict_unref (*fop_attr); + *fop_attr = NULL; + } + return ret; +} + +void +unset_fop_attr (dict_t **fop_attr) +{ + char *lease_id = NULL; + lease_id = gf_existing_leaseid (); + if (lease_id) + memset (lease_id, 0, LEASE_ID_SIZE); + if (*fop_attr) { + dict_unref (*fop_attr); + *fop_attr = NULL; + } +} struct glfs * pub_glfs_from_glfd (struct glfs_fd *glfd) { @@ -1486,6 +1567,22 @@ 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) +{ + return arg->object; +} + +GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_upcall_lease_get_object, 4.0.0); +*/ + +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); + /* definitions of the GLFS_SYSRQ_* chars are in glfs.h */ static struct glfs_sysrq_help { char sysrq; @@ -1578,8 +1675,10 @@ glfs_upcall_register (struct glfs *fs, uint32_t event_list, */ 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; } - /* Override cbk function if existing */ fs->up_cbk = cbk; fs->up_data = data; |