summaryrefslogtreecommitdiffstats
path: root/xlators/features/leases
diff options
context:
space:
mode:
Diffstat (limited to 'xlators/features/leases')
-rw-r--r--xlators/features/leases/src/leases-internal.c14
-rw-r--r--xlators/features/leases/src/leases.c54
2 files changed, 56 insertions, 12 deletions
diff --git a/xlators/features/leases/src/leases-internal.c b/xlators/features/leases/src/leases-internal.c
index 1f79e554489..475576eac79 100644
--- a/xlators/features/leases/src/leases-internal.c
+++ b/xlators/features/leases/src/leases-internal.c
@@ -263,7 +263,7 @@ out:
static inline gf_boolean_t
__is_same_lease_id (const char *k1, const char *k2)
{
- if (memcmp(k1, k2, LEASE_ID_SIZE) == 0)
+ if (memcmp(k1, k2, strlen(k1)) == 0)
return _gf_true;
return _gf_false;
@@ -642,7 +642,7 @@ __remove_lease (xlator_t *this, inode_t *inode, lease_inode_ctx_t *lease_ctx,
leaseid_utoa (lease->lease_id));
lease_entry = __get_lease_id_entry (lease_ctx, lease->lease_id);
- if (!lease_entry) {
+ if (!lease_entry || !(lease_entry->lease_type & lease->lease_type)) {
gf_msg (this->name, GF_LOG_INFO, 0, LEASE_MSG_INVAL_UNLK_LEASE,
"Got unlock lease request from client:%s, but has no "
"corresponding lock", client_uid);
@@ -666,7 +666,7 @@ __remove_lease (xlator_t *this, inode_t *inode, lease_inode_ctx_t *lease_ctx,
if (lease_entry->lease_cnt == 0) {
if (__is_clnt_lease_none (client_uid, lease_ctx)) {
- gf_msg_debug (this->name, 0, "Client(%s) has no leases"
+ gf_msg_trace (this->name, 0, "Client(%s) has no leases"
" on gfid (%s), hence removing the inode"
" from the client cleanup list",
client_uid, uuid_utoa (inode->gfid));
@@ -725,7 +725,8 @@ __is_lease_grantable (xlator_t *this, lease_inode_ctx_t *lease_ctx,
* the same lease id is not checked for conflict, as it is
* lease id based lease.
*/
- if (!__is_same_lease_id (fd_ctx->lease_id, lease->lease_id)) {
+ if (fd_ctx->client_uid != NULL
+ && !__is_same_lease_id (fd_ctx->lease_id, lease->lease_id)) {
fd_count++;
flags |= iter_fd->flags;
}
@@ -801,8 +802,7 @@ do_blocked_fops (xlator_t *this, lease_inode_ctx_t *lease_ctx)
pthread_mutex_unlock (&lease_ctx->lock);
gf_msg_trace (this->name, 0, "Executing the blocked stubs on gfid(%s)",
- uuid_utoa (lease_ctx->inode->gfid));
-
+ uuid_utoa (lease_ctx->inode->gfid));
list_for_each_entry_safe (blk_fop, tmp, &wind_list, list) {
list_del_init (&blk_fop->list);
gf_msg_trace (this->name, 0, "Executing fop:%d", blk_fop->stub->fop);
@@ -1085,7 +1085,7 @@ check_lease_conflict (call_frame_t *frame, inode_t *inode,
gf_boolean_t is_blocking_fop = _gf_false;
gf_boolean_t is_write_fop = _gf_false;
gf_boolean_t conflicts = _gf_false;
- int ret = -1;
+ int ret = WIND_FOP;
lease_ctx = lease_ctx_get (inode, frame->this);
if (!lease_ctx) {
diff --git a/xlators/features/leases/src/leases.c b/xlators/features/leases/src/leases.c
index ebee682a685..34143859c56 100644
--- a/xlators/features/leases/src/leases.c
+++ b/xlators/features/leases/src/leases.c
@@ -872,9 +872,11 @@ int
leases_flush (call_frame_t *frame, xlator_t *this,
fd_t *fd, dict_t *xdata)
{
- uint32_t fop_flags = 0;
- char *lease_id = NULL;
- int ret = 0;
+ uint32_t fop_flags = 0;
+ char *lease_id = NULL;
+ int ret = 0;
+ lease_fd_ctx_t *fd_ctx = NULL;
+ uint64_t ctx = 0;
EXIT_IF_LEASES_OFF (this, out);
@@ -895,6 +897,26 @@ block:
return 0;
out:
+ /* *
+ * currently release is not called after the close fop from the
+ * application. Hence lease fd ctx is resetted on here.
+ * This is actually not the right way, since flush can be called
+ * not only from the close op.
+ * TODO :
+ * - Either identify the flush is called from close call on fd from
+ * from the application.
+ * OR
+ * - Find why release is not called post the last close call
+ */
+ ret = fd_ctx_get (fd, this, &ctx);
+ if (ret == 0) {
+ fd_ctx = (lease_fd_ctx_t *)(long)ctx;
+ if (fd_ctx->client_uid) {
+ GF_FREE (fd_ctx->client_uid);
+ fd_ctx->client_uid = NULL;
+ }
+ memset (fd_ctx->lease_id, 0, LEASE_ID_SIZE);
+ }
STACK_WIND (frame, leases_flush_cbk, FIRST_CHILD(this),
FIRST_CHILD(this)->fops->flush, fd, xdata);
return 0;
@@ -1065,8 +1087,30 @@ leases_forget (xlator_t *this, inode_t *inode)
static int
leases_release (xlator_t *this, fd_t *fd)
{
- /* TODO:cleanup fd_ctx */
- return 0;
+ int ret = -1;
+ uint64_t tmp = 0;
+ lease_fd_ctx_t *fd_ctx = NULL;
+
+ if (fd == NULL) {
+ goto out;
+ }
+
+ gf_log (this->name, GF_LOG_TRACE,
+ "Releasing all leases with fd %p", fd);
+
+ ret = fd_ctx_del (fd, this, &tmp);
+ if (ret) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "Could not get fdctx");
+ goto out;
+ }
+
+ fd_ctx = (lease_fd_ctx_t *)(long)tmp;
+ if (fd_ctx)
+ GF_FREE (fd_ctx);
+out:
+ return ret;
+
}
static int