190130
From 175c99dccc47d2b4267a8819404e5cbeb8cfba11 Mon Sep 17 00:00:00 2001
190130
From: Mohit Agrawal <moagrawal@redhat.com>
190130
Date: Thu, 12 Mar 2020 21:12:13 +0530
190130
Subject: [PATCH 448/449] Posix: Use simple approach to close fd
190130
190130
Problem: posix_release(dir) functions add the fd's into a ctx->janitor_fds
190130
         and janitor thread closes the fd's.In brick_mux environment it is
190130
         difficult to handle race condition in janitor threads because brick
190130
         spawns a single janitor thread for all bricks.
190130
190130
Solution: Use synctask to execute posix_release(dir) functions instead of
190130
          using background a thread to close fds.
190130
190130
> Credits: Pranith Karampuri <pkarampu@redhat.com>
190130
> Change-Id: Iffb031f0695a7da83d5a2f6bac8863dad225317e
190130
> Fixes: bz#1811631
190130
> Signed-off-by: Mohit Agrawal <moagrawal@redhat.com>
190130
> (Cherry pick from commit fb20713b380e1df8d7f9e9df96563be2f9144fd6)
190130
> (Reviewed on upstream link https://review.gluster.org/#/c/glusterfs/+/24221/)
190130
190130
BUG: 1790336
190130
Change-Id: Iffb031f0695a7da83d5a2f6bac8863dad225317e
190130
Signed-off-by: Mohit Agrawal <moagrawal@redhat.com>
190130
Reviewed-on: https://code.engineering.redhat.com/gerrit/202791
190130
Tested-by: Mohit Agrawal <moagrawa@redhat.com>
190130
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
190130
---
190130
 libglusterfs/src/glusterfs/glusterfs.h         |  6 +-
190130
 libglusterfs/src/glusterfs/syncop.h            |  7 +-
190130
 rpc/rpc-lib/src/rpcsvc.c                       |  6 ++
190130
 run-tests.sh                                   |  2 +-
190130
 tests/features/ssl-authz.t                     |  7 +-
190130
 xlators/storage/posix/src/posix-common.c       |  4 --
190130
 xlators/storage/posix/src/posix-helpers.c      | 98 --------------------------
190130
 xlators/storage/posix/src/posix-inode-fd-ops.c | 28 ++------
190130
 xlators/storage/posix/src/posix.h              |  3 -
190130
 9 files changed, 20 insertions(+), 141 deletions(-)
190130
190130
diff --git a/libglusterfs/src/glusterfs/glusterfs.h b/libglusterfs/src/glusterfs/glusterfs.h
190130
index 584846e..495a4d7 100644
190130
--- a/libglusterfs/src/glusterfs/glusterfs.h
190130
+++ b/libglusterfs/src/glusterfs/glusterfs.h
190130
@@ -734,11 +734,7 @@ struct _glusterfs_ctx {
190130
 
190130
     struct list_head volfile_list;
190130
 
190130
-    /* Add members to manage janitor threads for cleanup fd */
190130
-    struct list_head janitor_fds;
190130
-    pthread_cond_t janitor_cond;
190130
-    pthread_mutex_t janitor_lock;
190130
-    pthread_t janitor;
190130
+    char volume_id[GF_UUID_BUF_SIZE]; /* Used only in protocol/client */
190130
 };
190130
 typedef struct _glusterfs_ctx glusterfs_ctx_t;
190130
 
190130
diff --git a/libglusterfs/src/glusterfs/syncop.h b/libglusterfs/src/glusterfs/syncop.h
190130
index 3011b4c..1e4c73b 100644
190130
--- a/libglusterfs/src/glusterfs/syncop.h
190130
+++ b/libglusterfs/src/glusterfs/syncop.h
190130
@@ -254,7 +254,7 @@ struct syncopctx {
190130
         task = synctask_get();                                                 \
190130
         stb->task = task;                                                      \
190130
         if (task)                                                              \
190130
-            frame = task->opframe;                                             \
190130
+            frame = copy_frame(task->opframe);                                 \
190130
         else                                                                   \
190130
             frame = syncop_create_frame(THIS);                                 \
190130
                                                                                \
190130
@@ -269,10 +269,7 @@ struct syncopctx {
190130
         STACK_WIND_COOKIE(frame, cbk, (void *)stb, subvol, fn_op, params);     \
190130
                                                                                \
190130
         __yield(stb);                                                          \
190130
-        if (task)                                                              \
190130
-            STACK_RESET(frame->root);                                          \
190130
-        else                                                                   \
190130
-            STACK_DESTROY(frame->root);                                        \
190130
+        STACK_DESTROY(frame->root);                                            \
190130
     } while (0)
190130
 
190130
 /*
190130
diff --git a/rpc/rpc-lib/src/rpcsvc.c b/rpc/rpc-lib/src/rpcsvc.c
190130
index 3f184bf..23ca1fd 100644
190130
--- a/rpc/rpc-lib/src/rpcsvc.c
190130
+++ b/rpc/rpc-lib/src/rpcsvc.c
190130
@@ -375,6 +375,12 @@ rpcsvc_program_actor(rpcsvc_request_t *req)
190130
 
190130
     req->ownthread = program->ownthread;
190130
     req->synctask = program->synctask;
190130
+    if (((req->procnum == GFS3_OP_RELEASE) ||
190130
+         (req->procnum == GFS3_OP_RELEASEDIR)) &&
190130
+        (program->prognum == GLUSTER_FOP_PROGRAM)) {
190130
+        req->ownthread = _gf_false;
190130
+        req->synctask = _gf_true;
190130
+    }
190130
 
190130
     err = SUCCESS;
190130
     gf_log(GF_RPCSVC, GF_LOG_TRACE, "Actor found: %s - %s for %s",
190130
diff --git a/run-tests.sh b/run-tests.sh
190130
index 5683b21..c835d93 100755
190130
--- a/run-tests.sh
190130
+++ b/run-tests.sh
190130
@@ -356,7 +356,7 @@ function run_tests()
190130
             selected_tests=$((selected_tests+1))
190130
             echo
190130
             echo $section_separator$section_separator
190130
-            if [[ $(get_test_status $t) == "BAD_TEST" ]] && \
190130
+            if [[ $(get_test_status $t) =~ "BAD_TEST" ]] && \
190130
                [[ $skip_bad_tests == "yes" ]]
190130
             then
190130
                 skipped_bad_tests=$((skipped_bad_tests+1))
190130
diff --git a/tests/features/ssl-authz.t b/tests/features/ssl-authz.t
190130
index 132b598..497083e 100755
190130
--- a/tests/features/ssl-authz.t
190130
+++ b/tests/features/ssl-authz.t
190130
@@ -67,13 +67,14 @@ echo "Memory consumption for glusterfsd process"
190130
 for i in $(seq 1 100); do
190130
         gluster v heal $V0 info >/dev/null
190130
 done
190130
-
190130
+#Wait to cleanup memory
190130
+sleep 10
190130
 end=`pmap -x $glusterfsd_pid | grep total | awk -F " " '{print $4}'`
190130
 diff=$((end-start))
190130
 
190130
-# If memory consumption is more than 5M some leak in SSL code path
190130
+# If memory consumption is more than 15M some leak in SSL code path
190130
 
190130
-TEST [ $diff -lt 5000 ]
190130
+TEST [ $diff -lt 15000 ]
190130
 
190130
 
190130
 # Set ssl-allow to a wildcard that includes our identity.
190130
diff --git a/xlators/storage/posix/src/posix-common.c b/xlators/storage/posix/src/posix-common.c
190130
index 2cb58ba..ac53796 100644
190130
--- a/xlators/storage/posix/src/posix-common.c
190130
+++ b/xlators/storage/posix/src/posix-common.c
190130
@@ -1041,10 +1041,6 @@ posix_init(xlator_t *this)
190130
     pthread_mutex_init(&_private->janitor_mutex, NULL);
190130
     pthread_cond_init(&_private->janitor_cond, NULL);
190130
     INIT_LIST_HEAD(&_private->fsyncs);
190130
-    ret = posix_spawn_ctx_janitor_thread(this);
190130
-    if (ret)
190130
-        goto out;
190130
-
190130
     ret = gf_thread_create(&_private->fsyncer, NULL, posix_fsyncer, this,
190130
                            "posixfsy");
190130
     if (ret) {
190130
diff --git a/xlators/storage/posix/src/posix-helpers.c b/xlators/storage/posix/src/posix-helpers.c
190130
index 2336add..39dbcce 100644
190130
--- a/xlators/storage/posix/src/posix-helpers.c
190130
+++ b/xlators/storage/posix/src/posix-helpers.c
190130
@@ -1582,104 +1582,6 @@ unlock:
190130
     return;
190130
 }
190130
 
190130
-static struct posix_fd *
190130
-janitor_get_next_fd(glusterfs_ctx_t *ctx, int32_t janitor_sleep)
190130
-{
190130
-    struct posix_fd *pfd = NULL;
190130
-
190130
-    struct timespec timeout;
190130
-
190130
-    pthread_mutex_lock(&ctx->janitor_lock);
190130
-    {
190130
-        if (list_empty(&ctx->janitor_fds)) {
190130
-            time(&timeout.tv_sec);
190130
-            timeout.tv_sec += janitor_sleep;
190130
-            timeout.tv_nsec = 0;
190130
-
190130
-            pthread_cond_timedwait(&ctx->janitor_cond, &ctx->janitor_lock,
190130
-                                   &timeout);
190130
-            goto unlock;
190130
-        }
190130
-
190130
-        pfd = list_entry(ctx->janitor_fds.next, struct posix_fd, list);
190130
-
190130
-        list_del(ctx->janitor_fds.next);
190130
-    }
190130
-unlock:
190130
-    pthread_mutex_unlock(&ctx->janitor_lock);
190130
-
190130
-    return pfd;
190130
-}
190130
-
190130
-static void *
190130
-posix_ctx_janitor_thread_proc(void *data)
190130
-{
190130
-    xlator_t *this = NULL;
190130
-    struct posix_fd *pfd;
190130
-    glusterfs_ctx_t *ctx = NULL;
190130
-    struct posix_private *priv = NULL;
190130
-    int32_t sleep_duration = 0;
190130
-
190130
-    this = data;
190130
-    ctx = THIS->ctx;
190130
-    THIS = this;
190130
-
190130
-    priv = this->private;
190130
-    sleep_duration = priv->janitor_sleep_duration;
190130
-    while (1) {
190130
-        pfd = janitor_get_next_fd(ctx, sleep_duration);
190130
-        if (pfd) {
190130
-            if (pfd->dir == NULL) {
190130
-                gf_msg_trace(this->name, 0, "janitor: closing file fd=%d",
190130
-                             pfd->fd);
190130
-                sys_close(pfd->fd);
190130
-            } else {
190130
-                gf_msg_debug(this->name, 0, "janitor: closing dir fd=%p",
190130
-                             pfd->dir);
190130
-                sys_closedir(pfd->dir);
190130
-            }
190130
-
190130
-            GF_FREE(pfd);
190130
-        }
190130
-    }
190130
-
190130
-    return NULL;
190130
-}
190130
-
190130
-int
190130
-posix_spawn_ctx_janitor_thread(xlator_t *this)
190130
-{
190130
-    struct posix_private *priv = NULL;
190130
-    int ret = 0;
190130
-    glusterfs_ctx_t *ctx = NULL;
190130
-
190130
-    priv = this->private;
190130
-    ctx = THIS->ctx;
190130
-
190130
-    LOCK(&priv->lock);
190130
-    {
190130
-        if (!ctx->janitor) {
190130
-            pthread_mutex_init(&ctx->janitor_lock, NULL);
190130
-            pthread_cond_init(&ctx->janitor_cond, NULL);
190130
-            INIT_LIST_HEAD(&ctx->janitor_fds);
190130
-
190130
-            ret = gf_thread_create(&ctx->janitor, NULL,
190130
-                                   posix_ctx_janitor_thread_proc, this,
190130
-                                   "posixctxjan");
190130
-
190130
-            if (ret) {
190130
-                gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_THREAD_FAILED,
190130
-                       "spawning janitor "
190130
-                       "thread failed");
190130
-                goto unlock;
190130
-            }
190130
-        }
190130
-    }
190130
-unlock:
190130
-    UNLOCK(&priv->lock);
190130
-    return ret;
190130
-}
190130
-
190130
 static int
190130
 is_fresh_file(int64_t ctime_sec)
190130
 {
190130
diff --git a/xlators/storage/posix/src/posix-inode-fd-ops.c b/xlators/storage/posix/src/posix-inode-fd-ops.c
190130
index 5748b9f..d135d8b 100644
190130
--- a/xlators/storage/posix/src/posix-inode-fd-ops.c
190130
+++ b/xlators/storage/posix/src/posix-inode-fd-ops.c
190130
@@ -1358,7 +1358,6 @@ posix_releasedir(xlator_t *this, fd_t *fd)
190130
     struct posix_fd *pfd = NULL;
190130
     uint64_t tmp_pfd = 0;
190130
     int ret = 0;
190130
-    glusterfs_ctx_t *ctx = NULL;
190130
 
190130
     VALIDATE_OR_GOTO(this, out);
190130
     VALIDATE_OR_GOTO(fd, out);
190130
@@ -1376,21 +1375,11 @@ posix_releasedir(xlator_t *this, fd_t *fd)
190130
         goto out;
190130
     }
190130
 
190130
-    ctx = THIS->ctx;
190130
-
190130
-    pthread_mutex_lock(&ctx->janitor_lock);
190130
-    {
190130
-        INIT_LIST_HEAD(&pfd->list);
190130
-        list_add_tail(&pfd->list, &ctx->janitor_fds);
190130
-        pthread_cond_signal(&ctx->janitor_cond);
190130
-    }
190130
-    pthread_mutex_unlock(&ctx->janitor_lock);
190130
-
190130
-    /*gf_msg_debug(this->name, 0, "janitor: closing dir fd=%p", pfd->dir);
190130
+    gf_msg_debug(this->name, 0, "janitor: closing dir fd=%p", pfd->dir);
190130
 
190130
     sys_closedir(pfd->dir);
190130
     GF_FREE(pfd);
190130
-    */
190130
+
190130
 out:
190130
     return 0;
190130
 }
190130
@@ -2510,13 +2499,11 @@ posix_release(xlator_t *this, fd_t *fd)
190130
     struct posix_fd *pfd = NULL;
190130
     int ret = -1;
190130
     uint64_t tmp_pfd = 0;
190130
-    glusterfs_ctx_t *ctx = NULL;
190130
 
190130
     VALIDATE_OR_GOTO(this, out);
190130
     VALIDATE_OR_GOTO(fd, out);
190130
 
190130
     priv = this->private;
190130
-    ctx = THIS->ctx;
190130
 
190130
     ret = fd_ctx_del(fd, this, &tmp_pfd);
190130
     if (ret < 0) {
190130
@@ -2531,13 +2518,10 @@ posix_release(xlator_t *this, fd_t *fd)
190130
                "pfd->dir is %p (not NULL) for file fd=%p", pfd->dir, fd);
190130
     }
190130
 
190130
-    pthread_mutex_lock(&ctx->janitor_lock);
190130
-    {
190130
-        INIT_LIST_HEAD(&pfd->list);
190130
-        list_add_tail(&pfd->list, &ctx->janitor_fds);
190130
-        pthread_cond_signal(&ctx->janitor_cond);
190130
-    }
190130
-    pthread_mutex_unlock(&ctx->janitor_lock);
190130
+    gf_msg_debug(this->name, 0, "janitor: closing dir fd=%p", pfd->dir);
190130
+
190130
+    sys_close(pfd->fd);
190130
+    GF_FREE(pfd);
190130
 
190130
     if (!priv)
190130
         goto out;
190130
diff --git a/xlators/storage/posix/src/posix.h b/xlators/storage/posix/src/posix.h
190130
index ac9d83c..61495a7 100644
190130
--- a/xlators/storage/posix/src/posix.h
190130
+++ b/xlators/storage/posix/src/posix.h
190130
@@ -666,9 +666,6 @@ posix_cs_maintenance(xlator_t *this, fd_t *fd, loc_t *loc, int *pfd,
190130
 int
190130
 posix_check_dev_file(xlator_t *this, inode_t *inode, char *fop, int *op_errno);
190130
 
190130
-int
190130
-posix_spawn_ctx_janitor_thread(xlator_t *this);
190130
-
190130
 void
190130
 posix_update_iatt_buf(struct iatt *buf, int fd, char *loc, dict_t *xdata);
190130
 
190130
-- 
190130
1.8.3.1
190130