From fb20713b380e1df8d7f9e9df96563be2f9144fd6 Mon Sep 17 00:00:00 2001 From: Mohit Agrawal Date: Thu, 12 Mar 2020 21:12:13 +0530 Subject: Posix: Use simple approach to close fd Problem: posix_release(dir) functions add the fd's into a ctx->janitor_fds and janitor thread closes the fd's.In brick_mux environment it is difficult to handle race condition in janitor threads because brick spawns a single janitor thread for all bricks. Solution: Use synctask to execute posix_release(dir) functions instead of using background a thread to close fds. Credits: Pranith Karampuri Change-Id: Iffb031f0695a7da83d5a2f6bac8863dad225317e Fixes: bz#1811631 Signed-off-by: Mohit Agrawal --- xlators/storage/posix/src/posix-helpers.c | 98 ------------------------------- 1 file changed, 98 deletions(-) (limited to 'xlators/storage/posix/src/posix-helpers.c') diff --git a/xlators/storage/posix/src/posix-helpers.c b/xlators/storage/posix/src/posix-helpers.c index 4919cbdf2e9..d18db1098fc 100644 --- a/xlators/storage/posix/src/posix-helpers.c +++ b/xlators/storage/posix/src/posix-helpers.c @@ -1587,104 +1587,6 @@ unlock: return; } -static struct posix_fd * -janitor_get_next_fd(glusterfs_ctx_t *ctx, int32_t janitor_sleep) -{ - struct posix_fd *pfd = NULL; - - struct timespec timeout; - - pthread_mutex_lock(&ctx->janitor_lock); - { - if (list_empty(&ctx->janitor_fds)) { - time(&timeout.tv_sec); - timeout.tv_sec += janitor_sleep; - timeout.tv_nsec = 0; - - pthread_cond_timedwait(&ctx->janitor_cond, &ctx->janitor_lock, - &timeout); - goto unlock; - } - - pfd = list_entry(ctx->janitor_fds.next, struct posix_fd, list); - - list_del(ctx->janitor_fds.next); - } -unlock: - pthread_mutex_unlock(&ctx->janitor_lock); - - return pfd; -} - -static void * -posix_ctx_janitor_thread_proc(void *data) -{ - xlator_t *this = NULL; - struct posix_fd *pfd; - glusterfs_ctx_t *ctx = NULL; - struct posix_private *priv = NULL; - int32_t sleep_duration = 0; - - this = data; - ctx = THIS->ctx; - THIS = this; - - priv = this->private; - sleep_duration = priv->janitor_sleep_duration; - while (1) { - pfd = janitor_get_next_fd(ctx, sleep_duration); - if (pfd) { - if (pfd->dir == NULL) { - gf_msg_trace(this->name, 0, "janitor: closing file fd=%d", - pfd->fd); - sys_close(pfd->fd); - } else { - gf_msg_debug(this->name, 0, "janitor: closing dir fd=%p", - pfd->dir); - sys_closedir(pfd->dir); - } - - GF_FREE(pfd); - } - } - - return NULL; -} - -int -posix_spawn_ctx_janitor_thread(xlator_t *this) -{ - struct posix_private *priv = NULL; - int ret = 0; - glusterfs_ctx_t *ctx = NULL; - - priv = this->private; - ctx = THIS->ctx; - - LOCK(&priv->lock); - { - if (!ctx->janitor) { - pthread_mutex_init(&ctx->janitor_lock, NULL); - pthread_cond_init(&ctx->janitor_cond, NULL); - INIT_LIST_HEAD(&ctx->janitor_fds); - - ret = gf_thread_create(&ctx->janitor, NULL, - posix_ctx_janitor_thread_proc, this, - "posixctxjan"); - - if (ret) { - gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_THREAD_FAILED, - "spawning janitor " - "thread failed"); - goto unlock; - } - } - } -unlock: - UNLOCK(&priv->lock); - return ret; -} - static int is_fresh_file(int64_t sec, int64_t ns) { -- cgit