diff options
Diffstat (limited to 'xlators/features/leases/src')
| -rw-r--r-- | xlators/features/leases/src/leases-internal.c | 139 | ||||
| -rw-r--r-- | xlators/features/leases/src/leases-mem-types.h | 5 | ||||
| -rw-r--r-- | xlators/features/leases/src/leases-messages.h | 2 | ||||
| -rw-r--r-- | xlators/features/leases/src/leases.c | 45 | ||||
| -rw-r--r-- | xlators/features/leases/src/leases.h | 65 |
5 files changed, 179 insertions, 77 deletions
diff --git a/xlators/features/leases/src/leases-internal.c b/xlators/features/leases/src/leases-internal.c index 296799b8dff..56dee244281 100644 --- a/xlators/features/leases/src/leases-internal.c +++ b/xlators/features/leases/src/leases-internal.c @@ -73,7 +73,7 @@ out: * timeout value(in seconds) set as an option to this xlator. * -1 error case */ -int32_t +static int32_t get_recall_lease_timeout(xlator_t *this) { leases_private_t *priv = NULL; @@ -356,9 +356,8 @@ out: static lease_inode_t * new_lease_inode(inode_t *inode) { - lease_inode_t *l_inode = NULL; - - l_inode = GF_CALLOC(1, sizeof(*l_inode), gf_leases_mt_lease_inode_t); + lease_inode_t *l_inode = GF_MALLOC(sizeof(*l_inode), + gf_leases_mt_lease_inode_t); if (!l_inode) goto out; @@ -379,9 +378,8 @@ __destroy_lease_inode(lease_inode_t *l_inode) static lease_client_t * new_lease_client(const char *client_uid) { - lease_client_t *clnt = NULL; - - clnt = GF_CALLOC(1, sizeof(*clnt), gf_leases_mt_lease_client_t); + lease_client_t *clnt = GF_MALLOC(sizeof(*clnt), + gf_leases_mt_lease_client_t); if (!clnt) goto out; @@ -448,29 +446,29 @@ out: static int add_inode_to_client_list(xlator_t *this, inode_t *inode, const char *client_uid) { - int ret = 0; - leases_private_t *priv = NULL; + leases_private_t *priv = this->private; lease_client_t *clnt = NULL; - lease_inode_t *lease_inode = NULL; - priv = this->private; + lease_inode_t *lease_inode = new_lease_inode(inode); + if (!lease_inode) + return -ENOMEM; + pthread_mutex_lock(&priv->mutex); { clnt = __get_or_new_lease_client(this, priv, client_uid); - GF_CHECK_ALLOC(clnt, ret, out); - - lease_inode = new_lease_inode(inode); - GF_CHECK_ALLOC(lease_inode, ret, out); - + if (!clnt) { + pthread_mutex_unlock(&priv->mutex); + __destroy_lease_inode(lease_inode); + return -ENOMEM; + } list_add_tail(&clnt->inode_list, &lease_inode->list); - gf_msg_debug(this->name, 0, - "Added a new inode:%p to the client(%s) " - "cleanup list, gfid(%s)", - inode, client_uid, uuid_utoa(inode->gfid)); } -out: pthread_mutex_unlock(&priv->mutex); - return ret; + gf_msg_debug(this->name, 0, + "Added a new inode:%p to the client(%s) " + "cleanup list, gfid(%s)", + inode, client_uid, uuid_utoa(inode->gfid)); + return 0; } /* Add lease entry to the corresponding client entry. @@ -587,15 +585,17 @@ remove_from_clnt_list(xlator_t *this, const char *client_uid, inode_t *inode) { clnt = __get_lease_client(this, priv, client_uid); if (!clnt) { + pthread_mutex_unlock(&priv->mutex); gf_msg(this->name, GF_LOG_ERROR, 0, LEASE_MSG_CLNT_NOTFOUND, "There is no client entry found in the cleanup list"); - pthread_mutex_unlock(&priv->mutex); goto out; } ret = __remove_inode_from_clnt_list(this, clnt, inode); if (ret) { + pthread_mutex_unlock(&priv->mutex); gf_msg(this->name, GF_LOG_ERROR, 0, LEASE_MSG_INODE_NOTFOUND, "There is no inode entry found in the cleanup list"); + goto out; } } pthread_mutex_unlock(&priv->mutex); @@ -624,17 +624,29 @@ __remove_lease(xlator_t *this, inode_t *inode, lease_inode_ctx_t *lease_ctx, "lease type:%d, lease id:%s", client_uid, lease->lease_type, leaseid_utoa(lease->lease_id)); + /* There could be a race where in server recalled the lease and by the time + * client sends lease_unlock request, server may have revoked it. To handle + * such cases, if lease doesnt exist treat it as noop and return success. + */ lease_entry = __get_lease_id_entry(lease_ctx, lease->lease_id); - if (!lease_entry || !(lease_entry->lease_type & lease->lease_type)) { + if (!lease_entry) { 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); + ret = 0; + goto out; + } + + if (!(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 for an invalid " + "lease_type", + client_uid); ret = -EINVAL; errno = EINVAL; goto out; } - lease_type = lease->lease_type; lease_entry->lease_type_cnt[lease_type]--; lease_entry->lease_cnt--; @@ -658,11 +670,13 @@ __remove_lease(xlator_t *this, inode_t *inode, lease_inode_ctx_t *lease_ctx, remove_from_clnt_list(this, client_uid, lease_ctx->inode); } __destroy_lease_id_entry(lease_entry); + lease_ctx->blocked_fops_resuming = _gf_true; } if (lease_ctx->lease_cnt == 0 && lease_ctx->timer) { ret = gf_tw_del_timer(priv->timer_wheel, lease_ctx->timer); lease_ctx->recall_in_progress = _gf_false; + lease_ctx->timer = NULL; } out: return ret; @@ -692,6 +706,14 @@ __is_lease_grantable(xlator_t *this, lease_inode_ctx_t *lease_ctx, goto out; } + if (lease_ctx->blocked_fops_resuming) { + gf_msg_debug(this->name, 0, + "Previously blocked fops resuming, hence " + "failing the lease request"); + grant = _gf_false; + goto out; + } + LOCK(&inode->lock); { list_for_each_entry(iter_fd, &inode->fd_list, inode_list) @@ -776,6 +798,17 @@ do_blocked_fops(xlator_t *this, lease_inode_ctx_t *lease_ctx) pthread_mutex_lock(&lease_ctx->lock); { + if (!lease_ctx->blocked_fops_resuming) { + /* lease_ctx->blocked_fops_resuming will be set + * only when the last lease is released. That + * is when we need to resume blocked fops and unref + * the inode taken in __add_lease (when lease_cnt == 1). + * Return otherwise. + */ + pthread_mutex_unlock(&lease_ctx->lock); + return; + } + list_for_each_entry_safe(blk_fop, tmp, &lease_ctx->blocked_list, list) { list_del_init(&blk_fop->list); @@ -797,6 +830,9 @@ do_blocked_fops(xlator_t *this, lease_inode_ctx_t *lease_ctx) pthread_mutex_lock(&lease_ctx->lock); { lease_ctx->lease_type = NONE; + /* unref the inode taken in __add_lease + * (when lease_cnt == 1) */ + lease_ctx->blocked_fops_resuming = _gf_false; inode_unref(lease_ctx->inode); lease_ctx->inode = NULL; } @@ -818,18 +854,20 @@ recall_lease_timer_handler(struct gf_tw_timer_list *timer, void *data, priv = timer_data->this->private; inode = timer_data->inode; + lease_inode = new_lease_inode(inode); + if (!lease_inode) { + errno = ENOMEM; + goto out; + } pthread_mutex_lock(&priv->mutex); { - lease_inode = new_lease_inode(inode); - if (!lease_inode) { - errno = ENOMEM; - goto out; - } list_add_tail(&lease_inode->list, &priv->recall_list); pthread_cond_broadcast(&priv->cond); } -out: pthread_mutex_unlock(&priv->mutex); +out: + /* unref the inode_ref taken by timer_data in __recall_lease */ + inode_unref(timer_data->inode); GF_FREE(timer); } @@ -849,6 +887,7 @@ __recall_lease(xlator_t *this, lease_inode_ctx_t *lease_ctx) struct gf_tw_timer_list *timer = NULL; leases_private_t *priv = NULL; lease_timer_data_t *timer_data = NULL; + time_t recall_time; if (lease_ctx->recall_in_progress) { gf_msg_debug(this->name, 0, @@ -858,6 +897,7 @@ __recall_lease(xlator_t *this, lease_inode_ctx_t *lease_ctx) } priv = this->private; + recall_time = gf_time(); list_for_each_entry_safe(lease_entry, tmp, &lease_ctx->lease_id_list, lease_id_list) { @@ -881,9 +921,9 @@ __recall_lease(xlator_t *this, lease_inode_ctx_t *lease_ctx) } lease_ctx->recall_in_progress = _gf_true; - lease_entry->recall_time = time(NULL); + lease_entry->recall_time = recall_time; } - timer = GF_CALLOC(1, sizeof(*timer), gf_common_mt_tw_timer_list); + timer = GF_MALLOC(sizeof(*timer), gf_common_mt_tw_timer_list); if (!timer) { goto out; } @@ -1031,6 +1071,17 @@ __check_lease_conflict(call_frame_t *frame, lease_inode_ctx_t *lease_ctx, goto recall; } + /* As internal fops are used to maintain data integrity but do not + * make modififications to the client data, no need to conflict with + * them. + * + * @todo: like for locks, even lease state has to be handled by + * rebalance or self-heal daemon process. */ + if (frame->root->pid < 0) { + conflicts = _gf_false; + goto recall; + } + /* If lease_id is not sent, set conflicts = true if there is * an existing lease */ if (!lease_id && (lease_ctx->lease_cnt > 0)) { @@ -1097,12 +1148,13 @@ check_lease_conflict(call_frame_t *frame, inode_t *inode, const char *lease_id, pthread_mutex_lock(&lease_ctx->lock); { if (lease_ctx->lease_type == NONE) { + pthread_mutex_unlock(&lease_ctx->lock); gf_msg_debug(frame->this->name, 0, "No leases found continuing with the" " fop:%s", gf_fop_list[frame->root->op]); ret = WIND_FOP; - goto unlock; + goto out; } conflicts = __check_lease_conflict(frame, lease_ctx, lease_id, is_write_fop); @@ -1129,7 +1181,6 @@ check_lease_conflict(call_frame_t *frame, inode_t *inode, const char *lease_id, } } } -unlock: pthread_mutex_unlock(&lease_ctx->lock); out: return ret; @@ -1166,6 +1217,7 @@ remove_clnt_leases(const char *client_uid, inode_t *inode, xlator_t *this) lease_ctx->lease_cnt -= lease_entry->lease_cnt; __destroy_lease_id_entry(lease_entry); if (lease_ctx->lease_cnt == 0) { + lease_ctx->blocked_fops_resuming = _gf_true; pthread_mutex_unlock(&lease_ctx->lock); goto unblock; } @@ -1212,9 +1264,9 @@ cleanup_client_leases(xlator_t *this, const char *client_uid) list_del_init(&l_inode->list); list_add_tail(&l_inode->list, &cleanup_list); } + __destroy_lease_client(clnt); break; } - __destroy_lease_client(clnt); } } pthread_mutex_unlock(&priv->mutex); @@ -1223,6 +1275,7 @@ cleanup_client_leases(xlator_t *this, const char *client_uid) list_for_each_entry_safe(l_inode, tmp1, &cleanup_list, list) { remove_clnt_leases(client_uid, l_inode->inode, this); + __destroy_lease_inode(l_inode); } out: return ret; @@ -1235,6 +1288,10 @@ __remove_all_leases(xlator_t *this, lease_inode_ctx_t *lease_ctx) lease_id_entry_t *lease_entry = NULL; lease_id_entry_t *tmp = NULL; + if (lease_ctx->lease_cnt == 0) { + /* No leases to remove. Return */ + return; + } __dump_leases_info(this, lease_ctx); list_for_each_entry_safe(lease_entry, tmp, &lease_ctx->lease_id_list, @@ -1250,8 +1307,8 @@ __remove_all_leases(xlator_t *this, lease_inode_ctx_t *lease_ctx) lease_ctx->lease_type = 0; lease_ctx->lease_cnt = 0; lease_ctx->recall_in_progress = _gf_false; - inode_unref(lease_ctx->inode); lease_ctx->timer = NULL; + lease_ctx->blocked_fops_resuming = _gf_true; /* TODO: * - Mark the corresponding fd bad. Could be done on client side @@ -1300,6 +1357,7 @@ expired_recall_cleanup(void *data) lease_inode_t *tmp = NULL; leases_private_t *priv = NULL; xlator_t *this = NULL; + time_t time_now; GF_VALIDATE_OR_GOTO("leases", data, out); @@ -1309,6 +1367,7 @@ expired_recall_cleanup(void *data) gf_msg_debug(this->name, 0, "Started the expired_recall_cleanup thread"); while (1) { + time_now = gf_time(); pthread_mutex_lock(&priv->mutex); { if (priv->fini) { @@ -1317,7 +1376,7 @@ expired_recall_cleanup(void *data) } INIT_LIST_HEAD(&recall_cleanup_list); if (list_empty(&priv->recall_list)) { - sleep_till.tv_sec = time(NULL) + 600; + sleep_till.tv_sec = time_now + 600; pthread_cond_timedwait(&priv->cond, &priv->mutex, &sleep_till); } if (!list_empty(&priv->recall_list)) { @@ -1342,7 +1401,9 @@ expired_recall_cleanup(void *data) " hence cleaning up leases on the inode", recall_entry->inode); remove_all_leases(this, recall_entry->inode); - list_del_init(&recall_entry->list); + /* no need to take priv->mutex lock as this entry + * reference is removed from global recall list. */ + __destroy_lease_inode(recall_entry); } } diff --git a/xlators/features/leases/src/leases-mem-types.h b/xlators/features/leases/src/leases-mem-types.h index 59d3cbaf0b3..25664b44156 100644 --- a/xlators/features/leases/src/leases-mem-types.h +++ b/xlators/features/leases/src/leases-mem-types.h @@ -11,11 +11,10 @@ #ifndef __LEASES_MEM_TYPES_H__ #define __LEASES_MEM_TYPES_H__ -#include "mem-types.h" +#include <glusterfs/mem-types.h> enum gf_leases_mem_types_ { - gf_leases_mt_conf_t = gf_common_mt_end + 1, - gf_leases_mt_private_t, + gf_leases_mt_private_t = gf_common_mt_end + 1, gf_leases_mt_lease_client_t, gf_leases_mt_lease_inode_t, gf_leases_mt_fd_ctx_t, diff --git a/xlators/features/leases/src/leases-messages.h b/xlators/features/leases/src/leases-messages.h index 81a517f63cd..da696b832de 100644 --- a/xlators/features/leases/src/leases-messages.h +++ b/xlators/features/leases/src/leases-messages.h @@ -11,7 +11,7 @@ #ifndef _LEASES_MESSAGES_H_ #define _LEASES_MESSAGES_H_ -#include "glfs-message-id.h" +#include <glusterfs/glfs-message-id.h> /* To add new message IDs, append new identifiers at the end of the list. * diff --git a/xlators/features/leases/src/leases.c b/xlators/features/leases/src/leases.c index be0f48fd2a2..04bee50ba3f 100644 --- a/xlators/features/leases/src/leases.c +++ b/xlators/features/leases/src/leases.c @@ -35,6 +35,7 @@ leases_open(call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags, char *lease_id = NULL; EXIT_IF_LEASES_OFF(this, out); + EXIT_IF_INTERNAL_FOP(frame, xdata, out); fd_ctx = GF_CALLOC(1, sizeof(*fd_ctx), gf_leases_mt_fd_ctx_t); if (!fd_ctx) { @@ -55,7 +56,7 @@ leases_open(call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags, else memset(fd_ctx->lease_id, 0, LEASE_ID_SIZE); - ret = fd_ctx_set(fd, this, (uint64_t)fd_ctx); + ret = fd_ctx_set(fd, this, (uint64_t)(uintptr_t)fd_ctx); if (ret) { op_errno = ENOMEM; goto err; @@ -109,6 +110,7 @@ leases_writev(call_frame_t *frame, xlator_t *this, fd_t *fd, int ret = 0; EXIT_IF_LEASES_OFF(this, out); + EXIT_IF_INTERNAL_FOP(frame, xdata, out); GET_LEASE_ID(xdata, lease_id, frame->root->client->client_uid); GET_FLAGS(frame->root->op, fd->flags); @@ -157,6 +159,7 @@ leases_readv(call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, int ret = 0; EXIT_IF_LEASES_OFF(this, out); + EXIT_IF_INTERNAL_FOP(frame, xdata, out); GET_LEASE_ID(xdata, lease_id, frame->root->client->client_uid); GET_FLAGS(frame->root->op, fd->flags); @@ -202,6 +205,7 @@ leases_lk(call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t cmd, int ret = 0; EXIT_IF_LEASES_OFF(this, out); + EXIT_IF_INTERNAL_FOP(frame, xdata, out); GET_LEASE_ID(xdata, lease_id, frame->root->client->client_uid); GET_FLAGS_LK(cmd, flock->l_type, fd->flags); @@ -240,6 +244,7 @@ leases_lease(call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t op_ret = 0; EXIT_IF_LEASES_OFF(this, out); + EXIT_IF_INTERNAL_FOP(frame, xdata, out); ret = process_lease_req(frame, this, loc->inode, lease); if (ret < 0) { @@ -282,6 +287,7 @@ leases_truncate(call_frame_t *frame, xlator_t *this, loc_t *loc, off_t offset, int ret = 0; EXIT_IF_LEASES_OFF(this, out); + EXIT_IF_INTERNAL_FOP(frame, xdata, out); GET_LEASE_ID(xdata, lease_id, frame->root->client->client_uid); GET_FLAGS(frame->root->op, 0); @@ -328,6 +334,7 @@ leases_setattr(call_frame_t *frame, xlator_t *this, loc_t *loc, int ret = 0; EXIT_IF_LEASES_OFF(this, out); + EXIT_IF_INTERNAL_FOP(frame, xdata, out); GET_LEASE_ID(xdata, lease_id, frame->root->client->client_uid); GET_FLAGS(frame->root->op, 0); @@ -376,6 +383,7 @@ leases_rename(call_frame_t *frame, xlator_t *this, loc_t *oldloc, loc_t *newloc, int ret = 0; EXIT_IF_LEASES_OFF(this, out); + EXIT_IF_INTERNAL_FOP(frame, xdata, out); /* should the lease be also checked for newloc */ GET_LEASE_ID(xdata, lease_id, frame->root->client->client_uid); @@ -424,6 +432,7 @@ leases_unlink(call_frame_t *frame, xlator_t *this, loc_t *loc, int xflag, int ret = 0; EXIT_IF_LEASES_OFF(this, out); + EXIT_IF_INTERNAL_FOP(frame, xdata, out); GET_LEASE_ID(xdata, lease_id, frame->root->client->client_uid); GET_FLAGS(frame->root->op, 0); @@ -470,6 +479,7 @@ leases_link(call_frame_t *frame, xlator_t *this, loc_t *oldloc, loc_t *newloc, int ret = 0; EXIT_IF_LEASES_OFF(this, out); + EXIT_IF_INTERNAL_FOP(frame, xdata, out); GET_LEASE_ID(xdata, lease_id, frame->root->client->client_uid); GET_FLAGS(frame->root->op, 0); @@ -516,6 +526,7 @@ leases_create(call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags, int ret = 0; EXIT_IF_LEASES_OFF(this, out); + EXIT_IF_INTERNAL_FOP(frame, xdata, out); GET_LEASE_ID(xdata, lease_id, frame->root->client->client_uid); GET_FLAGS(frame->root->op, flags); @@ -563,6 +574,7 @@ leases_fsync(call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t flags, int ret = 0; EXIT_IF_LEASES_OFF(this, out); + EXIT_IF_INTERNAL_FOP(frame, xdata, out); GET_LEASE_ID(xdata, lease_id, frame->root->client->client_uid); GET_FLAGS(frame->root->op, fd->flags); @@ -607,6 +619,7 @@ leases_ftruncate(call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset, int ret = 0; EXIT_IF_LEASES_OFF(this, out); + EXIT_IF_INTERNAL_FOP(frame, xdata, out); GET_LEASE_ID(xdata, lease_id, frame->root->client->client_uid); GET_FLAGS(frame->root->op, 0); /* TODO:fd->flags?*/ @@ -652,6 +665,7 @@ leases_fsetattr(call_frame_t *frame, xlator_t *this, fd_t *fd, int ret = 0; EXIT_IF_LEASES_OFF(this, out); + EXIT_IF_INTERNAL_FOP(frame, xdata, out); GET_LEASE_ID(xdata, lease_id, frame->root->client->client_uid); GET_FLAGS(frame->root->op, fd->flags); @@ -697,6 +711,7 @@ leases_fallocate(call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t mode, int ret = 0; EXIT_IF_LEASES_OFF(this, out); + EXIT_IF_INTERNAL_FOP(frame, xdata, out); GET_LEASE_ID(xdata, lease_id, frame->root->client->client_uid); GET_FLAGS(frame->root->op, fd->flags); @@ -744,6 +759,7 @@ leases_discard(call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset, int ret = 0; EXIT_IF_LEASES_OFF(this, out); + EXIT_IF_INTERNAL_FOP(frame, xdata, out); GET_LEASE_ID(xdata, lease_id, frame->root->client->client_uid); GET_FLAGS(frame->root->op, fd->flags); @@ -789,6 +805,7 @@ leases_zerofill(call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset, int ret = 0; EXIT_IF_LEASES_OFF(this, out); + EXIT_IF_INTERNAL_FOP(frame, xdata, out); GET_LEASE_ID(xdata, lease_id, frame->root->client->client_uid); GET_FLAGS(frame->root->op, fd->flags); @@ -834,6 +851,7 @@ leases_flush(call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *xdata) uint64_t ctx = 0; EXIT_IF_LEASES_OFF(this, out); + EXIT_IF_INTERNAL_FOP(frame, xdata, out); GET_LEASE_ID(xdata, lease_id, frame->root->client->client_uid); GET_FLAGS(frame->root->op, fd->flags); @@ -1000,14 +1018,14 @@ out: return ret; } -int +void fini(xlator_t *this) { leases_private_t *priv = NULL; priv = this->private; if (!priv) { - return 0; + return; } this->private = NULL; @@ -1019,12 +1037,12 @@ fini(xlator_t *this) priv->inited_recall_thr = _gf_false; } - GF_FREE(priv); - if (this->ctx->tw) { + if (priv->timer_wheel) { glusterfs_ctx_tw_put(this->ctx); - this->ctx->tw = NULL; } - return 0; + + GF_FREE(priv); + return; } static int @@ -1135,3 +1153,16 @@ struct volume_options options[] = { " will be forcefully purged by the server."}, {.key = {NULL}}, }; + +xlator_api_t xlator_api = { + .init = init, + .fini = fini, + .reconfigure = reconfigure, + .mem_acct_init = mem_acct_init, + .op_version = {1}, /* Present from the initial version */ + .fops = &fops, + .cbks = &cbks, + .options = options, + .identifier = "leases", + .category = GF_MAINTAINED, +}; diff --git a/xlators/features/leases/src/leases.h b/xlators/features/leases/src/leases.h index d5fc451289d..a6e8a6824cc 100644 --- a/xlators/features/leases/src/leases.h +++ b/xlators/features/leases/src/leases.h @@ -16,15 +16,15 @@ #include "config.h" #endif -#include "common-utils.h" -#include "glusterfs.h" -#include "xlator.h" -#include "call-stub.h" -#include "logging.h" -#include "client_t.h" -#include "lkowner.h" -#include "locking.h" -#include "upcall-utils.h" +#include <glusterfs/common-utils.h> +#include <glusterfs/glusterfs.h> +#include <glusterfs/xlator.h> +#include <glusterfs/call-stub.h> +#include <glusterfs/logging.h> +#include <glusterfs/client_t.h> +#include <glusterfs/lkowner.h> +#include <glusterfs/locking.h> +#include <glusterfs/upcall-utils.h> #include "timer-wheel.h" #include "leases-mem-types.h" #include "leases-messages.h" @@ -45,6 +45,14 @@ goto label; \ } while (0) +#define EXIT_IF_INTERNAL_FOP(frame, xdata, label) \ + do { \ + if (frame->root->pid < 0) \ + goto label; \ + if (xdata && dict_get(xdata, GLUSTERFS_INTERNAL_FOP_KEY)) \ + goto label; \ + } while (0) + #define GET_LEASE_ID(xdata, lease_id, client_uid) \ do { \ int ret_val = -1; \ @@ -144,17 +152,19 @@ } while (0) struct _leases_private { - gf_boolean_t leases_enabled; - int32_t recall_lease_timeout; struct list_head client_list; struct list_head recall_list; struct tvec_base *timer_wheel; /* timer wheel where the recall request is qued and waits for unlock/expiry */ - gf_boolean_t fini; pthread_t recall_thr; - gf_boolean_t inited_recall_thr; pthread_mutex_t mutex; pthread_cond_t cond; + int32_t recall_lease_timeout; + gf_boolean_t inited_recall_thr; + gf_boolean_t fini; + gf_boolean_t leases_enabled; + + char _pad[1]; /* manual padding */ }; typedef struct _leases_private leases_private_t; @@ -181,17 +191,20 @@ typedef struct _lease_fd_ctx lease_fd_ctx_t; struct _lease_inode_ctx { struct list_head lease_id_list; /* clients that have taken leases */ int lease_type_cnt[GF_LEASE_MAX_TYPE + 1]; - int lease_type; /* Types of leases acquired */ - uint64_t lease_cnt; /* Total number of leases on this inode */ - uint64_t openfd_cnt; /* number of fds open */ - gf_boolean_t recall_in_progress; /* if lease recall is sent on this inode */ - struct list_head blocked_list; /* List of fops blocked until the - lease recall is complete */ - inode_t *inode; /* this represents the inode on which the - lock was taken, required mainly during - disconnect cleanup */ + uint64_t lease_cnt; /* Total number of leases on this inode */ + uint64_t openfd_cnt; /* number of fds open */ + struct list_head blocked_list; /* List of fops blocked until the + lease recall is complete */ + inode_t *inode; /* this represents the inode on which the + lock was taken, required mainly during + disconnect cleanup */ struct gf_tw_timer_list *timer; pthread_mutex_t lock; + int lease_type; /* Types of leases acquired */ + gf_boolean_t recall_in_progress; /* if lease recall is sent on this inode */ + gf_boolean_t blocked_fops_resuming; /* if blocked fops are being resumed */ + + char _pad[2]; /* manual padding */ }; typedef struct _lease_inode_ctx lease_inode_ctx_t; @@ -201,11 +214,12 @@ struct _lease_id_entry { char *client_uid; /* uid of the client that has taken the lease */ int lease_type_cnt[GF_LEASE_MAX_TYPE + 1]; /* count of each lease type */ - int lease_type; /* Union of all the leases taken - under the given lease id */ uint64_t lease_cnt; /* Number of leases taken under the given lease id */ time_t recall_time; /* time @ which recall was sent */ + int lease_type; /* Union of all the leases taken + under the given lease id */ + char _pad[4]; /* manual padding */ }; typedef struct _lease_id_entry lease_id_entry_t; @@ -225,9 +239,6 @@ typedef struct __lease_timer_data lease_timer_data_t; gf_boolean_t is_leases_enabled(xlator_t *this); -int32_t -get_recall_lease_timeout(xlator_t *this); - lease_inode_ctx_t * lease_ctx_get(inode_t *inode, xlator_t *this); |
