|
|
14f8ab |
From 2f5969a77493814e242e6bac3c6bf7acf3202e0f Mon Sep 17 00:00:00 2001
|
|
|
14f8ab |
From: Xavi Hernandez <xhernandez@redhat.com>
|
|
|
14f8ab |
Date: Tue, 5 Mar 2019 18:58:20 +0100
|
|
|
14f8ab |
Subject: [PATCH 209/221] core: avoid dynamic TLS allocation when possible
|
|
|
14f8ab |
|
|
|
14f8ab |
Some interdependencies between logging and memory management functions
|
|
|
14f8ab |
make it impossible to use the logging framework before initializing
|
|
|
14f8ab |
memory subsystem because they both depend on Thread Local Storage
|
|
|
14f8ab |
allocated through pthread_key_create() during initialization.
|
|
|
14f8ab |
|
|
|
14f8ab |
This causes a crash when we try to log something very early in the
|
|
|
14f8ab |
initialization phase.
|
|
|
14f8ab |
|
|
|
14f8ab |
To prevent this, several dynamically allocated TLS structures have
|
|
|
14f8ab |
been replaced by static TLS reserved at compile time using '__thread'
|
|
|
14f8ab |
keyword. This also reduces the number of error sources, making
|
|
|
14f8ab |
initialization simpler.
|
|
|
14f8ab |
|
|
|
14f8ab |
Upstream patch:
|
|
|
14f8ab |
> BUG: 1193929
|
|
|
14f8ab |
> Upstream patch link: https://review.gluster.org/c/glusterfs/+/22302
|
|
|
14f8ab |
> Change-Id: I8ea2e072411e30790d50084b6b7e909c7bb01d50
|
|
|
14f8ab |
> Signed-off-by: Xavi Hernandez <xhernandez@redhat.com>
|
|
|
14f8ab |
|
|
|
14f8ab |
Change-Id: I8ea2e072411e30790d50084b6b7e909c7bb01d50
|
|
|
14f8ab |
Updates: bz#1722801
|
|
|
14f8ab |
Signed-off-by: Xavi Hernandez <xhernandez@redhat.com>
|
|
|
14f8ab |
Reviewed-on: https://code.engineering.redhat.com/gerrit/174711
|
|
|
14f8ab |
Tested-by: RHGS Build Bot <nigelb@redhat.com>
|
|
|
14f8ab |
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
|
|
|
14f8ab |
---
|
|
|
14f8ab |
api/src/glfs.c | 3 +-
|
|
|
14f8ab |
cli/src/cli.c | 3 +-
|
|
|
14f8ab |
glusterfsd/src/glusterfsd.c | 4 +-
|
|
|
14f8ab |
libglusterfs/src/globals.c | 289 ++++-----------------
|
|
|
14f8ab |
libglusterfs/src/glusterfs/globals.h | 6 +-
|
|
|
14f8ab |
libglusterfs/src/glusterfs/mem-pool.h | 7 +-
|
|
|
14f8ab |
libglusterfs/src/libglusterfs.sym | 3 +-
|
|
|
14f8ab |
libglusterfs/src/mem-pool.c | 98 +++----
|
|
|
14f8ab |
libglusterfs/src/syncop.c | 133 ++--------
|
|
|
14f8ab |
.../changelog/lib/src/gf-changelog-helpers.c | 51 +---
|
|
|
14f8ab |
xlators/features/changelog/lib/src/gf-changelog.c | 3 +-
|
|
|
14f8ab |
xlators/nfs/server/src/mount3udp_svc.c | 6 +-
|
|
|
14f8ab |
12 files changed, 114 insertions(+), 492 deletions(-)
|
|
|
14f8ab |
|
|
|
14f8ab |
diff --git a/api/src/glfs.c b/api/src/glfs.c
|
|
|
14f8ab |
index 6bbb620..f36616d 100644
|
|
|
14f8ab |
--- a/api/src/glfs.c
|
|
|
14f8ab |
+++ b/api/src/glfs.c
|
|
|
14f8ab |
@@ -829,8 +829,7 @@ pub_glfs_new(const char *volname)
|
|
|
14f8ab |
* Do this as soon as possible in case something else depends on
|
|
|
14f8ab |
* pool allocations.
|
|
|
14f8ab |
*/
|
|
|
14f8ab |
- mem_pools_init_early();
|
|
|
14f8ab |
- mem_pools_init_late();
|
|
|
14f8ab |
+ mem_pools_init();
|
|
|
14f8ab |
|
|
|
14f8ab |
fs = glfs_new_fs(volname);
|
|
|
14f8ab |
if (!fs)
|
|
|
14f8ab |
diff --git a/cli/src/cli.c b/cli/src/cli.c
|
|
|
14f8ab |
index ff39a98..99a16a0 100644
|
|
|
14f8ab |
--- a/cli/src/cli.c
|
|
|
14f8ab |
+++ b/cli/src/cli.c
|
|
|
14f8ab |
@@ -795,8 +795,7 @@ main(int argc, char *argv[])
|
|
|
14f8ab |
int ret = -1;
|
|
|
14f8ab |
glusterfs_ctx_t *ctx = NULL;
|
|
|
14f8ab |
|
|
|
14f8ab |
- mem_pools_init_early();
|
|
|
14f8ab |
- mem_pools_init_late();
|
|
|
14f8ab |
+ mem_pools_init();
|
|
|
14f8ab |
|
|
|
14f8ab |
ctx = glusterfs_ctx_new();
|
|
|
14f8ab |
if (!ctx)
|
|
|
14f8ab |
diff --git a/glusterfsd/src/glusterfsd.c b/glusterfsd/src/glusterfsd.c
|
|
|
14f8ab |
index 6aee4c1..2172af4 100644
|
|
|
14f8ab |
--- a/glusterfsd/src/glusterfsd.c
|
|
|
14f8ab |
+++ b/glusterfsd/src/glusterfsd.c
|
|
|
14f8ab |
@@ -2722,8 +2722,6 @@ main(int argc, char *argv[])
|
|
|
14f8ab |
};
|
|
|
14f8ab |
cmd_args_t *cmd = NULL;
|
|
|
14f8ab |
|
|
|
14f8ab |
- mem_pools_init_early();
|
|
|
14f8ab |
-
|
|
|
14f8ab |
gf_check_and_set_mem_acct(argc, argv);
|
|
|
14f8ab |
|
|
|
14f8ab |
ctx = glusterfs_ctx_new();
|
|
|
14f8ab |
@@ -2838,7 +2836,7 @@ main(int argc, char *argv[])
|
|
|
14f8ab |
* the parent, but we want to do it as soon as possible after that in
|
|
|
14f8ab |
* case something else depends on pool allocations.
|
|
|
14f8ab |
*/
|
|
|
14f8ab |
- mem_pools_init_late();
|
|
|
14f8ab |
+ mem_pools_init();
|
|
|
14f8ab |
|
|
|
14f8ab |
#ifdef GF_LINUX_HOST_OS
|
|
|
14f8ab |
ret = set_oom_score_adj(ctx);
|
|
|
14f8ab |
diff --git a/libglusterfs/src/globals.c b/libglusterfs/src/globals.c
|
|
|
14f8ab |
index 4fec063..02098e6 100644
|
|
|
14f8ab |
--- a/libglusterfs/src/globals.c
|
|
|
14f8ab |
+++ b/libglusterfs/src/globals.c
|
|
|
14f8ab |
@@ -99,16 +99,19 @@ const char *gf_upcall_list[GF_UPCALL_FLAGS_MAXVALUE] = {
|
|
|
14f8ab |
glusterfs_ctx_t *global_ctx = NULL;
|
|
|
14f8ab |
pthread_mutex_t global_ctx_mutex = PTHREAD_MUTEX_INITIALIZER;
|
|
|
14f8ab |
xlator_t global_xlator;
|
|
|
14f8ab |
-static pthread_key_t this_xlator_key;
|
|
|
14f8ab |
-static pthread_key_t synctask_key;
|
|
|
14f8ab |
-static pthread_key_t uuid_buf_key;
|
|
|
14f8ab |
-static char global_uuid_buf[GF_UUID_BUF_SIZE];
|
|
|
14f8ab |
-static pthread_key_t lkowner_buf_key;
|
|
|
14f8ab |
-static char global_lkowner_buf[GF_LKOWNER_BUF_SIZE];
|
|
|
14f8ab |
-static pthread_key_t leaseid_buf_key;
|
|
|
14f8ab |
static int gf_global_mem_acct_enable = 1;
|
|
|
14f8ab |
static pthread_once_t globals_inited = PTHREAD_ONCE_INIT;
|
|
|
14f8ab |
|
|
|
14f8ab |
+static pthread_key_t free_key;
|
|
|
14f8ab |
+
|
|
|
14f8ab |
+static __thread xlator_t *thread_xlator = NULL;
|
|
|
14f8ab |
+static __thread void *thread_synctask = NULL;
|
|
|
14f8ab |
+static __thread void *thread_leaseid = NULL;
|
|
|
14f8ab |
+static __thread struct syncopctx thread_syncopctx = {};
|
|
|
14f8ab |
+static __thread char thread_uuid_buf[GF_UUID_BUF_SIZE] = {};
|
|
|
14f8ab |
+static __thread char thread_lkowner_buf[GF_LKOWNER_BUF_SIZE] = {};
|
|
|
14f8ab |
+static __thread char thread_leaseid_buf[GF_LEASE_ID_BUF_SIZE] = {};
|
|
|
14f8ab |
+
|
|
|
14f8ab |
int
|
|
|
14f8ab |
gf_global_mem_acct_enable_get(void)
|
|
|
14f8ab |
{
|
|
|
14f8ab |
@@ -122,12 +125,6 @@ gf_global_mem_acct_enable_set(int val)
|
|
|
14f8ab |
return 0;
|
|
|
14f8ab |
}
|
|
|
14f8ab |
|
|
|
14f8ab |
-void
|
|
|
14f8ab |
-glusterfs_this_destroy(void *ptr)
|
|
|
14f8ab |
-{
|
|
|
14f8ab |
- FREE(ptr);
|
|
|
14f8ab |
-}
|
|
|
14f8ab |
-
|
|
|
14f8ab |
static struct xlator_cbks global_cbks = {
|
|
|
14f8ab |
.forget = NULL,
|
|
|
14f8ab |
.release = NULL,
|
|
|
14f8ab |
@@ -212,18 +209,9 @@ struct volume_options global_xl_options[] = {
|
|
|
14f8ab |
|
|
|
14f8ab |
static volume_opt_list_t global_xl_opt_list;
|
|
|
14f8ab |
|
|
|
14f8ab |
-int
|
|
|
14f8ab |
+void
|
|
|
14f8ab |
glusterfs_this_init()
|
|
|
14f8ab |
{
|
|
|
14f8ab |
- int ret = 0;
|
|
|
14f8ab |
- ret = pthread_key_create(&this_xlator_key, glusterfs_this_destroy);
|
|
|
14f8ab |
- if (ret != 0) {
|
|
|
14f8ab |
- gf_msg("", GF_LOG_WARNING, ret, LG_MSG_PTHREAD_KEY_CREATE_FAILED,
|
|
|
14f8ab |
- "failed to create "
|
|
|
14f8ab |
- "the pthread key");
|
|
|
14f8ab |
- return ret;
|
|
|
14f8ab |
- }
|
|
|
14f8ab |
-
|
|
|
14f8ab |
global_xlator.name = "glusterfs";
|
|
|
14f8ab |
global_xlator.type = GF_GLOBAL_XLATOR_NAME;
|
|
|
14f8ab |
global_xlator.cbks = &global_cbks;
|
|
|
14f8ab |
@@ -237,301 +225,120 @@ glusterfs_this_init()
|
|
|
14f8ab |
global_xl_opt_list.given_opt = global_xl_options;
|
|
|
14f8ab |
|
|
|
14f8ab |
list_add_tail(&global_xl_opt_list.list, &global_xlator.volume_options);
|
|
|
14f8ab |
-
|
|
|
14f8ab |
- return ret;
|
|
|
14f8ab |
}
|
|
|
14f8ab |
|
|
|
14f8ab |
xlator_t **
|
|
|
14f8ab |
__glusterfs_this_location()
|
|
|
14f8ab |
{
|
|
|
14f8ab |
- xlator_t **this_location = NULL;
|
|
|
14f8ab |
- int ret = 0;
|
|
|
14f8ab |
-
|
|
|
14f8ab |
- this_location = pthread_getspecific(this_xlator_key);
|
|
|
14f8ab |
-
|
|
|
14f8ab |
- if (!this_location) {
|
|
|
14f8ab |
- this_location = CALLOC(1, sizeof(*this_location));
|
|
|
14f8ab |
- if (!this_location)
|
|
|
14f8ab |
- goto out;
|
|
|
14f8ab |
+ xlator_t **this_location;
|
|
|
14f8ab |
|
|
|
14f8ab |
- ret = pthread_setspecific(this_xlator_key, this_location);
|
|
|
14f8ab |
- if (ret != 0) {
|
|
|
14f8ab |
- FREE(this_location);
|
|
|
14f8ab |
- this_location = NULL;
|
|
|
14f8ab |
- goto out;
|
|
|
14f8ab |
- }
|
|
|
14f8ab |
- }
|
|
|
14f8ab |
-out:
|
|
|
14f8ab |
- if (this_location) {
|
|
|
14f8ab |
- if (!*this_location)
|
|
|
14f8ab |
- *this_location = &global_xlator;
|
|
|
14f8ab |
+ this_location = &thread_xlator;
|
|
|
14f8ab |
+ if (*this_location == NULL) {
|
|
|
14f8ab |
+ thread_xlator = &global_xlator;
|
|
|
14f8ab |
}
|
|
|
14f8ab |
+
|
|
|
14f8ab |
return this_location;
|
|
|
14f8ab |
}
|
|
|
14f8ab |
|
|
|
14f8ab |
xlator_t *
|
|
|
14f8ab |
glusterfs_this_get()
|
|
|
14f8ab |
{
|
|
|
14f8ab |
- xlator_t **this_location = NULL;
|
|
|
14f8ab |
-
|
|
|
14f8ab |
- this_location = __glusterfs_this_location();
|
|
|
14f8ab |
- if (!this_location)
|
|
|
14f8ab |
- return &global_xlator;
|
|
|
14f8ab |
-
|
|
|
14f8ab |
- return *this_location;
|
|
|
14f8ab |
+ return *__glusterfs_this_location();
|
|
|
14f8ab |
}
|
|
|
14f8ab |
|
|
|
14f8ab |
-int
|
|
|
14f8ab |
+void
|
|
|
14f8ab |
glusterfs_this_set(xlator_t *this)
|
|
|
14f8ab |
{
|
|
|
14f8ab |
- xlator_t **this_location = NULL;
|
|
|
14f8ab |
-
|
|
|
14f8ab |
- this_location = __glusterfs_this_location();
|
|
|
14f8ab |
- if (!this_location)
|
|
|
14f8ab |
- return -ENOMEM;
|
|
|
14f8ab |
-
|
|
|
14f8ab |
- *this_location = this;
|
|
|
14f8ab |
-
|
|
|
14f8ab |
- return 0;
|
|
|
14f8ab |
+ thread_xlator = this;
|
|
|
14f8ab |
}
|
|
|
14f8ab |
|
|
|
14f8ab |
/* SYNCOPCTX */
|
|
|
14f8ab |
-static pthread_key_t syncopctx_key;
|
|
|
14f8ab |
-
|
|
|
14f8ab |
-static void
|
|
|
14f8ab |
-syncopctx_key_destroy(void *ptr)
|
|
|
14f8ab |
-{
|
|
|
14f8ab |
- struct syncopctx *opctx = ptr;
|
|
|
14f8ab |
-
|
|
|
14f8ab |
- if (opctx) {
|
|
|
14f8ab |
- if (opctx->groups)
|
|
|
14f8ab |
- GF_FREE(opctx->groups);
|
|
|
14f8ab |
-
|
|
|
14f8ab |
- GF_FREE(opctx);
|
|
|
14f8ab |
- }
|
|
|
14f8ab |
-
|
|
|
14f8ab |
- return;
|
|
|
14f8ab |
-}
|
|
|
14f8ab |
|
|
|
14f8ab |
void *
|
|
|
14f8ab |
syncopctx_getctx()
|
|
|
14f8ab |
{
|
|
|
14f8ab |
- void *opctx = NULL;
|
|
|
14f8ab |
-
|
|
|
14f8ab |
- opctx = pthread_getspecific(syncopctx_key);
|
|
|
14f8ab |
-
|
|
|
14f8ab |
- return opctx;
|
|
|
14f8ab |
-}
|
|
|
14f8ab |
-
|
|
|
14f8ab |
-int
|
|
|
14f8ab |
-syncopctx_setctx(void *ctx)
|
|
|
14f8ab |
-{
|
|
|
14f8ab |
- int ret = 0;
|
|
|
14f8ab |
-
|
|
|
14f8ab |
- ret = pthread_setspecific(syncopctx_key, ctx);
|
|
|
14f8ab |
-
|
|
|
14f8ab |
- return ret;
|
|
|
14f8ab |
-}
|
|
|
14f8ab |
-
|
|
|
14f8ab |
-static int
|
|
|
14f8ab |
-syncopctx_init(void)
|
|
|
14f8ab |
-{
|
|
|
14f8ab |
- int ret;
|
|
|
14f8ab |
-
|
|
|
14f8ab |
- ret = pthread_key_create(&syncopctx_key, syncopctx_key_destroy);
|
|
|
14f8ab |
-
|
|
|
14f8ab |
- return ret;
|
|
|
14f8ab |
+ return &thread_syncopctx;
|
|
|
14f8ab |
}
|
|
|
14f8ab |
|
|
|
14f8ab |
/* SYNCTASK */
|
|
|
14f8ab |
|
|
|
14f8ab |
-int
|
|
|
14f8ab |
-synctask_init()
|
|
|
14f8ab |
-{
|
|
|
14f8ab |
- int ret = 0;
|
|
|
14f8ab |
-
|
|
|
14f8ab |
- ret = pthread_key_create(&synctask_key, NULL);
|
|
|
14f8ab |
-
|
|
|
14f8ab |
- return ret;
|
|
|
14f8ab |
-}
|
|
|
14f8ab |
-
|
|
|
14f8ab |
void *
|
|
|
14f8ab |
synctask_get()
|
|
|
14f8ab |
{
|
|
|
14f8ab |
- void *synctask = NULL;
|
|
|
14f8ab |
-
|
|
|
14f8ab |
- synctask = pthread_getspecific(synctask_key);
|
|
|
14f8ab |
-
|
|
|
14f8ab |
- return synctask;
|
|
|
14f8ab |
+ return thread_synctask;
|
|
|
14f8ab |
}
|
|
|
14f8ab |
|
|
|
14f8ab |
-int
|
|
|
14f8ab |
+void
|
|
|
14f8ab |
synctask_set(void *synctask)
|
|
|
14f8ab |
{
|
|
|
14f8ab |
- int ret = 0;
|
|
|
14f8ab |
-
|
|
|
14f8ab |
- pthread_setspecific(synctask_key, synctask);
|
|
|
14f8ab |
-
|
|
|
14f8ab |
- return ret;
|
|
|
14f8ab |
+ thread_synctask = synctask;
|
|
|
14f8ab |
}
|
|
|
14f8ab |
|
|
|
14f8ab |
// UUID_BUFFER
|
|
|
14f8ab |
|
|
|
14f8ab |
-void
|
|
|
14f8ab |
-glusterfs_uuid_buf_destroy(void *ptr)
|
|
|
14f8ab |
-{
|
|
|
14f8ab |
- FREE(ptr);
|
|
|
14f8ab |
-}
|
|
|
14f8ab |
-
|
|
|
14f8ab |
-int
|
|
|
14f8ab |
-glusterfs_uuid_buf_init()
|
|
|
14f8ab |
-{
|
|
|
14f8ab |
- int ret = 0;
|
|
|
14f8ab |
-
|
|
|
14f8ab |
- ret = pthread_key_create(&uuid_buf_key, glusterfs_uuid_buf_destroy);
|
|
|
14f8ab |
- return ret;
|
|
|
14f8ab |
-}
|
|
|
14f8ab |
-
|
|
|
14f8ab |
char *
|
|
|
14f8ab |
glusterfs_uuid_buf_get()
|
|
|
14f8ab |
{
|
|
|
14f8ab |
- char *buf;
|
|
|
14f8ab |
- int ret = 0;
|
|
|
14f8ab |
-
|
|
|
14f8ab |
- buf = pthread_getspecific(uuid_buf_key);
|
|
|
14f8ab |
- if (!buf) {
|
|
|
14f8ab |
- buf = MALLOC(GF_UUID_BUF_SIZE);
|
|
|
14f8ab |
- ret = pthread_setspecific(uuid_buf_key, (void *)buf);
|
|
|
14f8ab |
- if (ret)
|
|
|
14f8ab |
- buf = global_uuid_buf;
|
|
|
14f8ab |
- }
|
|
|
14f8ab |
- return buf;
|
|
|
14f8ab |
+ return thread_uuid_buf;
|
|
|
14f8ab |
}
|
|
|
14f8ab |
|
|
|
14f8ab |
/* LKOWNER_BUFFER */
|
|
|
14f8ab |
|
|
|
14f8ab |
-void
|
|
|
14f8ab |
-glusterfs_lkowner_buf_destroy(void *ptr)
|
|
|
14f8ab |
-{
|
|
|
14f8ab |
- FREE(ptr);
|
|
|
14f8ab |
-}
|
|
|
14f8ab |
-
|
|
|
14f8ab |
-int
|
|
|
14f8ab |
-glusterfs_lkowner_buf_init()
|
|
|
14f8ab |
-{
|
|
|
14f8ab |
- int ret = 0;
|
|
|
14f8ab |
-
|
|
|
14f8ab |
- ret = pthread_key_create(&lkowner_buf_key, glusterfs_lkowner_buf_destroy);
|
|
|
14f8ab |
- return ret;
|
|
|
14f8ab |
-}
|
|
|
14f8ab |
-
|
|
|
14f8ab |
char *
|
|
|
14f8ab |
glusterfs_lkowner_buf_get()
|
|
|
14f8ab |
{
|
|
|
14f8ab |
- char *buf;
|
|
|
14f8ab |
- int ret = 0;
|
|
|
14f8ab |
-
|
|
|
14f8ab |
- buf = pthread_getspecific(lkowner_buf_key);
|
|
|
14f8ab |
- if (!buf) {
|
|
|
14f8ab |
- buf = MALLOC(GF_LKOWNER_BUF_SIZE);
|
|
|
14f8ab |
- ret = pthread_setspecific(lkowner_buf_key, (void *)buf);
|
|
|
14f8ab |
- if (ret)
|
|
|
14f8ab |
- buf = global_lkowner_buf;
|
|
|
14f8ab |
- }
|
|
|
14f8ab |
- return buf;
|
|
|
14f8ab |
+ return thread_lkowner_buf;
|
|
|
14f8ab |
}
|
|
|
14f8ab |
|
|
|
14f8ab |
/* Leaseid buffer */
|
|
|
14f8ab |
-void
|
|
|
14f8ab |
-glusterfs_leaseid_buf_destroy(void *ptr)
|
|
|
14f8ab |
-{
|
|
|
14f8ab |
- FREE(ptr);
|
|
|
14f8ab |
-}
|
|
|
14f8ab |
-
|
|
|
14f8ab |
-int
|
|
|
14f8ab |
-glusterfs_leaseid_buf_init()
|
|
|
14f8ab |
-{
|
|
|
14f8ab |
- int ret = 0;
|
|
|
14f8ab |
-
|
|
|
14f8ab |
- ret = pthread_key_create(&leaseid_buf_key, glusterfs_leaseid_buf_destroy);
|
|
|
14f8ab |
- return ret;
|
|
|
14f8ab |
-}
|
|
|
14f8ab |
|
|
|
14f8ab |
char *
|
|
|
14f8ab |
glusterfs_leaseid_buf_get()
|
|
|
14f8ab |
{
|
|
|
14f8ab |
char *buf = NULL;
|
|
|
14f8ab |
- int ret = 0;
|
|
|
14f8ab |
|
|
|
14f8ab |
- buf = pthread_getspecific(leaseid_buf_key);
|
|
|
14f8ab |
- if (!buf) {
|
|
|
14f8ab |
- buf = CALLOC(1, GF_LEASE_ID_BUF_SIZE);
|
|
|
14f8ab |
- ret = pthread_setspecific(leaseid_buf_key, (void *)buf);
|
|
|
14f8ab |
- if (ret) {
|
|
|
14f8ab |
- FREE(buf);
|
|
|
14f8ab |
- buf = NULL;
|
|
|
14f8ab |
- }
|
|
|
14f8ab |
+ buf = thread_leaseid;
|
|
|
14f8ab |
+ if (buf == NULL) {
|
|
|
14f8ab |
+ buf = thread_leaseid_buf;
|
|
|
14f8ab |
+ thread_leaseid = buf;
|
|
|
14f8ab |
}
|
|
|
14f8ab |
+
|
|
|
14f8ab |
return buf;
|
|
|
14f8ab |
}
|
|
|
14f8ab |
|
|
|
14f8ab |
char *
|
|
|
14f8ab |
glusterfs_leaseid_exist()
|
|
|
14f8ab |
{
|
|
|
14f8ab |
- return pthread_getspecific(leaseid_buf_key);
|
|
|
14f8ab |
+ return thread_leaseid;
|
|
|
14f8ab |
}
|
|
|
14f8ab |
|
|
|
14f8ab |
static void
|
|
|
14f8ab |
-gf_globals_init_once()
|
|
|
14f8ab |
+glusterfs_cleanup(void *ptr)
|
|
|
14f8ab |
{
|
|
|
14f8ab |
- int ret = 0;
|
|
|
14f8ab |
-
|
|
|
14f8ab |
- ret = glusterfs_this_init();
|
|
|
14f8ab |
- if (ret) {
|
|
|
14f8ab |
- gf_msg("", GF_LOG_CRITICAL, 0, LG_MSG_TRANSLATOR_INIT_FAILED,
|
|
|
14f8ab |
- "ERROR: glusterfs-translator init failed");
|
|
|
14f8ab |
- goto out;
|
|
|
14f8ab |
- }
|
|
|
14f8ab |
-
|
|
|
14f8ab |
- ret = glusterfs_uuid_buf_init();
|
|
|
14f8ab |
- if (ret) {
|
|
|
14f8ab |
- gf_msg("", GF_LOG_CRITICAL, 0, LG_MSG_UUID_BUF_INIT_FAILED,
|
|
|
14f8ab |
- "ERROR: glusterfs uuid buffer init failed");
|
|
|
14f8ab |
- goto out;
|
|
|
14f8ab |
+ if (thread_syncopctx.groups != NULL) {
|
|
|
14f8ab |
+ GF_FREE(thread_syncopctx.groups);
|
|
|
14f8ab |
}
|
|
|
14f8ab |
|
|
|
14f8ab |
- ret = glusterfs_lkowner_buf_init();
|
|
|
14f8ab |
- if (ret) {
|
|
|
14f8ab |
- gf_msg("", GF_LOG_CRITICAL, 0, LG_MSG_LKOWNER_BUF_INIT_FAILED,
|
|
|
14f8ab |
- "ERROR: glusterfs lkowner buffer init failed");
|
|
|
14f8ab |
- goto out;
|
|
|
14f8ab |
- }
|
|
|
14f8ab |
+ mem_pool_thread_destructor();
|
|
|
14f8ab |
+}
|
|
|
14f8ab |
|
|
|
14f8ab |
- ret = glusterfs_leaseid_buf_init();
|
|
|
14f8ab |
- if (ret) {
|
|
|
14f8ab |
- gf_msg("", GF_LOG_CRITICAL, 0, LG_MSG_LEASEID_BUF_INIT_FAILED,
|
|
|
14f8ab |
- "ERROR: glusterfs leaseid buffer init failed");
|
|
|
14f8ab |
- goto out;
|
|
|
14f8ab |
- }
|
|
|
14f8ab |
+static void
|
|
|
14f8ab |
+gf_globals_init_once()
|
|
|
14f8ab |
+{
|
|
|
14f8ab |
+ int ret = 0;
|
|
|
14f8ab |
|
|
|
14f8ab |
- ret = synctask_init();
|
|
|
14f8ab |
- if (ret) {
|
|
|
14f8ab |
- gf_msg("", GF_LOG_CRITICAL, 0, LG_MSG_SYNCTASK_INIT_FAILED,
|
|
|
14f8ab |
- "ERROR: glusterfs synctask init failed");
|
|
|
14f8ab |
- goto out;
|
|
|
14f8ab |
- }
|
|
|
14f8ab |
+ glusterfs_this_init();
|
|
|
14f8ab |
|
|
|
14f8ab |
- ret = syncopctx_init();
|
|
|
14f8ab |
- if (ret) {
|
|
|
14f8ab |
- gf_msg("", GF_LOG_CRITICAL, 0, LG_MSG_SYNCOPCTX_INIT_FAILED,
|
|
|
14f8ab |
- "ERROR: glusterfs syncopctx init failed");
|
|
|
14f8ab |
- goto out;
|
|
|
14f8ab |
- }
|
|
|
14f8ab |
-out:
|
|
|
14f8ab |
+ /* This is needed only to cleanup the potential allocation of
|
|
|
14f8ab |
+ * thread_syncopctx.groups. */
|
|
|
14f8ab |
+ ret = pthread_key_create(&free_key, glusterfs_cleanup);
|
|
|
14f8ab |
+ if (ret != 0) {
|
|
|
14f8ab |
+ gf_msg("", GF_LOG_ERROR, ret, LG_MSG_PTHREAD_KEY_CREATE_FAILED,
|
|
|
14f8ab |
+ "failed to create the pthread key");
|
|
|
14f8ab |
|
|
|
14f8ab |
- if (ret) {
|
|
|
14f8ab |
gf_msg("", GF_LOG_CRITICAL, 0, LG_MSG_GLOBAL_INIT_FAILED,
|
|
|
14f8ab |
"Exiting as global initialization failed");
|
|
|
14f8ab |
+
|
|
|
14f8ab |
exit(ret);
|
|
|
14f8ab |
}
|
|
|
14f8ab |
}
|
|
|
14f8ab |
diff --git a/libglusterfs/src/glusterfs/globals.h b/libglusterfs/src/glusterfs/globals.h
|
|
|
14f8ab |
index e45db14..55476f6 100644
|
|
|
14f8ab |
--- a/libglusterfs/src/glusterfs/globals.h
|
|
|
14f8ab |
+++ b/libglusterfs/src/glusterfs/globals.h
|
|
|
14f8ab |
@@ -147,7 +147,7 @@ xlator_t **
|
|
|
14f8ab |
__glusterfs_this_location(void);
|
|
|
14f8ab |
xlator_t *
|
|
|
14f8ab |
glusterfs_this_get(void);
|
|
|
14f8ab |
-int
|
|
|
14f8ab |
+void
|
|
|
14f8ab |
glusterfs_this_set(xlator_t *);
|
|
|
14f8ab |
|
|
|
14f8ab |
extern xlator_t global_xlator;
|
|
|
14f8ab |
@@ -156,13 +156,11 @@ extern struct volume_options global_xl_options[];
|
|
|
14f8ab |
/* syncopctx */
|
|
|
14f8ab |
void *
|
|
|
14f8ab |
syncopctx_getctx(void);
|
|
|
14f8ab |
-int
|
|
|
14f8ab |
-syncopctx_setctx(void *ctx);
|
|
|
14f8ab |
|
|
|
14f8ab |
/* task */
|
|
|
14f8ab |
void *
|
|
|
14f8ab |
synctask_get(void);
|
|
|
14f8ab |
-int
|
|
|
14f8ab |
+void
|
|
|
14f8ab |
synctask_set(void *);
|
|
|
14f8ab |
|
|
|
14f8ab |
/* uuid_buf */
|
|
|
14f8ab |
diff --git a/libglusterfs/src/glusterfs/mem-pool.h b/libglusterfs/src/glusterfs/mem-pool.h
|
|
|
14f8ab |
index 0250b59..c5a486b 100644
|
|
|
14f8ab |
--- a/libglusterfs/src/glusterfs/mem-pool.h
|
|
|
14f8ab |
+++ b/libglusterfs/src/glusterfs/mem-pool.h
|
|
|
14f8ab |
@@ -279,9 +279,7 @@ struct mem_pool_shared {
|
|
|
14f8ab |
};
|
|
|
14f8ab |
|
|
|
14f8ab |
void
|
|
|
14f8ab |
-mem_pools_init_early(void); /* basic initialization of memory pools */
|
|
|
14f8ab |
-void
|
|
|
14f8ab |
-mem_pools_init_late(void); /* start the pool_sweeper thread */
|
|
|
14f8ab |
+mem_pools_init(void); /* start the pool_sweeper thread */
|
|
|
14f8ab |
void
|
|
|
14f8ab |
mem_pools_fini(void); /* cleanup memory pools */
|
|
|
14f8ab |
|
|
|
14f8ab |
@@ -306,6 +304,9 @@ void
|
|
|
14f8ab |
mem_pool_destroy(struct mem_pool *pool);
|
|
|
14f8ab |
|
|
|
14f8ab |
void
|
|
|
14f8ab |
+mem_pool_thread_destructor(void);
|
|
|
14f8ab |
+
|
|
|
14f8ab |
+void
|
|
|
14f8ab |
gf_mem_acct_enable_set(void *ctx);
|
|
|
14f8ab |
|
|
|
14f8ab |
#endif /* _MEM_POOL_H */
|
|
|
14f8ab |
diff --git a/libglusterfs/src/libglusterfs.sym b/libglusterfs/src/libglusterfs.sym
|
|
|
14f8ab |
index 7a2edef..86215d2 100644
|
|
|
14f8ab |
--- a/libglusterfs/src/libglusterfs.sym
|
|
|
14f8ab |
+++ b/libglusterfs/src/libglusterfs.sym
|
|
|
14f8ab |
@@ -872,8 +872,7 @@ mem_get0
|
|
|
14f8ab |
mem_pool_destroy
|
|
|
14f8ab |
mem_pool_new_fn
|
|
|
14f8ab |
mem_pools_fini
|
|
|
14f8ab |
-mem_pools_init_early
|
|
|
14f8ab |
-mem_pools_init_late
|
|
|
14f8ab |
+mem_pools_init
|
|
|
14f8ab |
mem_put
|
|
|
14f8ab |
mkdir_p
|
|
|
14f8ab |
next_token
|
|
|
14f8ab |
diff --git a/libglusterfs/src/mem-pool.c b/libglusterfs/src/mem-pool.c
|
|
|
14f8ab |
index 9b4ea52..ab78804 100644
|
|
|
14f8ab |
--- a/libglusterfs/src/mem-pool.c
|
|
|
14f8ab |
+++ b/libglusterfs/src/mem-pool.c
|
|
|
14f8ab |
@@ -353,7 +353,6 @@ free:
|
|
|
14f8ab |
FREE(ptr);
|
|
|
14f8ab |
}
|
|
|
14f8ab |
|
|
|
14f8ab |
-static pthread_key_t pool_key;
|
|
|
14f8ab |
static pthread_mutex_t pool_lock = PTHREAD_MUTEX_INITIALIZER;
|
|
|
14f8ab |
static struct list_head pool_threads;
|
|
|
14f8ab |
static pthread_mutex_t pool_free_lock = PTHREAD_MUTEX_INITIALIZER;
|
|
|
14f8ab |
@@ -361,6 +360,8 @@ static struct list_head pool_free_threads;
|
|
|
14f8ab |
static struct mem_pool_shared pools[NPOOLS];
|
|
|
14f8ab |
static size_t pool_list_size;
|
|
|
14f8ab |
|
|
|
14f8ab |
+static __thread per_thread_pool_list_t *thread_pool_list = NULL;
|
|
|
14f8ab |
+
|
|
|
14f8ab |
#if !defined(GF_DISABLE_MEMPOOL)
|
|
|
14f8ab |
#define N_COLD_LISTS 1024
|
|
|
14f8ab |
#define POOL_SWEEP_SECS 30
|
|
|
14f8ab |
@@ -373,7 +374,6 @@ typedef struct {
|
|
|
14f8ab |
|
|
|
14f8ab |
enum init_state {
|
|
|
14f8ab |
GF_MEMPOOL_INIT_NONE = 0,
|
|
|
14f8ab |
- GF_MEMPOOL_INIT_PREINIT,
|
|
|
14f8ab |
GF_MEMPOOL_INIT_EARLY,
|
|
|
14f8ab |
GF_MEMPOOL_INIT_LATE,
|
|
|
14f8ab |
GF_MEMPOOL_INIT_DESTROY
|
|
|
14f8ab |
@@ -486,9 +486,9 @@ pool_sweeper(void *arg)
|
|
|
14f8ab |
}
|
|
|
14f8ab |
|
|
|
14f8ab |
void
|
|
|
14f8ab |
-pool_destructor(void *arg)
|
|
|
14f8ab |
+mem_pool_thread_destructor(void)
|
|
|
14f8ab |
{
|
|
|
14f8ab |
- per_thread_pool_list_t *pool_list = arg;
|
|
|
14f8ab |
+ per_thread_pool_list_t *pool_list = thread_pool_list;
|
|
|
14f8ab |
|
|
|
14f8ab |
/* The pool-sweeper thread will take it from here.
|
|
|
14f8ab |
*
|
|
|
14f8ab |
@@ -499,7 +499,10 @@ pool_destructor(void *arg)
|
|
|
14f8ab |
* This change can modify what mem_put() does, but both possibilities are
|
|
|
14f8ab |
* fine until the sweeper thread kicks in. The real synchronization must be
|
|
|
14f8ab |
* between mem_put() and the sweeper thread. */
|
|
|
14f8ab |
- pool_list->poison = 1;
|
|
|
14f8ab |
+ if (pool_list != NULL) {
|
|
|
14f8ab |
+ pool_list->poison = 1;
|
|
|
14f8ab |
+ thread_pool_list = NULL;
|
|
|
14f8ab |
+ }
|
|
|
14f8ab |
}
|
|
|
14f8ab |
|
|
|
14f8ab |
static __attribute__((constructor)) void
|
|
|
14f8ab |
@@ -522,46 +525,14 @@ mem_pools_preinit(void)
|
|
|
14f8ab |
pool_list_size = sizeof(per_thread_pool_list_t) +
|
|
|
14f8ab |
sizeof(per_thread_pool_t) * (NPOOLS - 1);
|
|
|
14f8ab |
|
|
|
14f8ab |
- init_done = GF_MEMPOOL_INIT_PREINIT;
|
|
|
14f8ab |
+ init_done = GF_MEMPOOL_INIT_EARLY;
|
|
|
14f8ab |
}
|
|
|
14f8ab |
|
|
|
14f8ab |
-/* Use mem_pools_init_early() function for basic initialization. There will be
|
|
|
14f8ab |
- * no cleanup done by the pool_sweeper thread until mem_pools_init_late() has
|
|
|
14f8ab |
- * been called. Calling mem_get() will be possible after this function has
|
|
|
14f8ab |
- * setup the basic structures. */
|
|
|
14f8ab |
+/* Call mem_pools_init() once threading has been configured completely. This
|
|
|
14f8ab |
+ * prevent the pool_sweeper thread from getting killed once the main() thread
|
|
|
14f8ab |
+ * exits during deamonizing. */
|
|
|
14f8ab |
void
|
|
|
14f8ab |
-mem_pools_init_early(void)
|
|
|
14f8ab |
-{
|
|
|
14f8ab |
- pthread_mutex_lock(&init_mutex);
|
|
|
14f8ab |
- /* Use a pthread_key destructor to clean up when a thread exits.
|
|
|
14f8ab |
- *
|
|
|
14f8ab |
- * We won't increase init_count here, that is only done when the
|
|
|
14f8ab |
- * pool_sweeper thread is started too.
|
|
|
14f8ab |
- */
|
|
|
14f8ab |
- if (init_done == GF_MEMPOOL_INIT_PREINIT ||
|
|
|
14f8ab |
- init_done == GF_MEMPOOL_INIT_DESTROY) {
|
|
|
14f8ab |
- /* key has not been created yet */
|
|
|
14f8ab |
- if (pthread_key_create(&pool_key, pool_destructor) != 0) {
|
|
|
14f8ab |
- gf_log("mem-pool", GF_LOG_CRITICAL,
|
|
|
14f8ab |
- "failed to initialize mem-pool key");
|
|
|
14f8ab |
- }
|
|
|
14f8ab |
-
|
|
|
14f8ab |
- init_done = GF_MEMPOOL_INIT_EARLY;
|
|
|
14f8ab |
- } else {
|
|
|
14f8ab |
- gf_log("mem-pool", GF_LOG_CRITICAL,
|
|
|
14f8ab |
- "incorrect order of mem-pool initialization "
|
|
|
14f8ab |
- "(init_done=%d)",
|
|
|
14f8ab |
- init_done);
|
|
|
14f8ab |
- }
|
|
|
14f8ab |
-
|
|
|
14f8ab |
- pthread_mutex_unlock(&init_mutex);
|
|
|
14f8ab |
-}
|
|
|
14f8ab |
-
|
|
|
14f8ab |
-/* Call mem_pools_init_late() once threading has been configured completely.
|
|
|
14f8ab |
- * This prevent the pool_sweeper thread from getting killed once the main()
|
|
|
14f8ab |
- * thread exits during deamonizing. */
|
|
|
14f8ab |
-void
|
|
|
14f8ab |
-mem_pools_init_late(void)
|
|
|
14f8ab |
+mem_pools_init(void)
|
|
|
14f8ab |
{
|
|
|
14f8ab |
pthread_mutex_lock(&init_mutex);
|
|
|
14f8ab |
if ((init_count++) == 0) {
|
|
|
14f8ab |
@@ -580,13 +551,12 @@ mem_pools_fini(void)
|
|
|
14f8ab |
switch (init_count) {
|
|
|
14f8ab |
case 0:
|
|
|
14f8ab |
/*
|
|
|
14f8ab |
- * If init_count is already zero (as e.g. if somebody called
|
|
|
14f8ab |
- * this before mem_pools_init_late) then the sweeper was
|
|
|
14f8ab |
- * probably never even started so we don't need to stop it.
|
|
|
14f8ab |
- * Even if there's some crazy circumstance where there is a
|
|
|
14f8ab |
- * sweeper but init_count is still zero, that just means we'll
|
|
|
14f8ab |
- * leave it running. Not perfect, but far better than any
|
|
|
14f8ab |
- * known alternative.
|
|
|
14f8ab |
+ * If init_count is already zero (as e.g. if somebody called this
|
|
|
14f8ab |
+ * before mem_pools_init) then the sweeper was probably never even
|
|
|
14f8ab |
+ * started so we don't need to stop it. Even if there's some crazy
|
|
|
14f8ab |
+ * circumstance where there is a sweeper but init_count is still
|
|
|
14f8ab |
+ * zero, that just means we'll leave it running. Not perfect, but
|
|
|
14f8ab |
+ * far better than any known alternative.
|
|
|
14f8ab |
*/
|
|
|
14f8ab |
break;
|
|
|
14f8ab |
case 1: {
|
|
|
14f8ab |
@@ -594,20 +564,17 @@ mem_pools_fini(void)
|
|
|
14f8ab |
per_thread_pool_list_t *next_pl;
|
|
|
14f8ab |
unsigned int i;
|
|
|
14f8ab |
|
|
|
14f8ab |
- /* if only mem_pools_init_early() was called, sweeper_tid will
|
|
|
14f8ab |
- * be invalid and the functions will error out. That is not
|
|
|
14f8ab |
- * critical. In all other cases, the sweeper_tid will be valid
|
|
|
14f8ab |
- * and the thread gets stopped. */
|
|
|
14f8ab |
+ /* if mem_pools_init() was not called, sweeper_tid will be invalid
|
|
|
14f8ab |
+ * and the functions will error out. That is not critical. In all
|
|
|
14f8ab |
+ * other cases, the sweeper_tid will be valid and the thread gets
|
|
|
14f8ab |
+ * stopped. */
|
|
|
14f8ab |
(void)pthread_cancel(sweeper_tid);
|
|
|
14f8ab |
(void)pthread_join(sweeper_tid, NULL);
|
|
|
14f8ab |
|
|
|
14f8ab |
- /* Need to clean the pool_key to prevent further usage of the
|
|
|
14f8ab |
- * per_thread_pool_list_t structure that is stored for each
|
|
|
14f8ab |
- * thread.
|
|
|
14f8ab |
- * This also prevents calling pool_destructor() when a thread
|
|
|
14f8ab |
- * exits, so there is no chance on a use-after-free of the
|
|
|
14f8ab |
- * per_thread_pool_list_t structure. */
|
|
|
14f8ab |
- (void)pthread_key_delete(pool_key);
|
|
|
14f8ab |
+ /* At this point all threads should have already terminated, so
|
|
|
14f8ab |
+ * it should be safe to destroy all pending per_thread_pool_list_t
|
|
|
14f8ab |
+ * structures that are stored for each thread. */
|
|
|
14f8ab |
+ mem_pool_thread_destructor();
|
|
|
14f8ab |
|
|
|
14f8ab |
/* free all objects from all pools */
|
|
|
14f8ab |
list_for_each_entry_safe(pool_list, next_pl, &pool_threads,
|
|
|
14f8ab |
@@ -642,11 +609,7 @@ mem_pools_fini(void)
|
|
|
14f8ab |
|
|
|
14f8ab |
#else
|
|
|
14f8ab |
void
|
|
|
14f8ab |
-mem_pools_init_early(void)
|
|
|
14f8ab |
-{
|
|
|
14f8ab |
-}
|
|
|
14f8ab |
-void
|
|
|
14f8ab |
-mem_pools_init_late(void)
|
|
|
14f8ab |
+mem_pools_init(void)
|
|
|
14f8ab |
{
|
|
|
14f8ab |
}
|
|
|
14f8ab |
void
|
|
|
14f8ab |
@@ -734,7 +697,7 @@ mem_get_pool_list(void)
|
|
|
14f8ab |
per_thread_pool_list_t *pool_list;
|
|
|
14f8ab |
unsigned int i;
|
|
|
14f8ab |
|
|
|
14f8ab |
- pool_list = pthread_getspecific(pool_key);
|
|
|
14f8ab |
+ pool_list = thread_pool_list;
|
|
|
14f8ab |
if (pool_list) {
|
|
|
14f8ab |
return pool_list;
|
|
|
14f8ab |
}
|
|
|
14f8ab |
@@ -767,7 +730,8 @@ mem_get_pool_list(void)
|
|
|
14f8ab |
list_add(&pool_list->thr_list, &pool_threads);
|
|
|
14f8ab |
(void)pthread_mutex_unlock(&pool_lock);
|
|
|
14f8ab |
|
|
|
14f8ab |
- (void)pthread_setspecific(pool_key, pool_list);
|
|
|
14f8ab |
+ thread_pool_list = pool_list;
|
|
|
14f8ab |
+
|
|
|
14f8ab |
return pool_list;
|
|
|
14f8ab |
}
|
|
|
14f8ab |
|
|
|
14f8ab |
diff --git a/libglusterfs/src/syncop.c b/libglusterfs/src/syncop.c
|
|
|
14f8ab |
index c05939a..2eb7b49 100644
|
|
|
14f8ab |
--- a/libglusterfs/src/syncop.c
|
|
|
14f8ab |
+++ b/libglusterfs/src/syncop.c
|
|
|
14f8ab |
@@ -26,28 +26,10 @@ syncopctx_setfsuid(void *uid)
|
|
|
14f8ab |
|
|
|
14f8ab |
opctx = syncopctx_getctx();
|
|
|
14f8ab |
|
|
|
14f8ab |
- /* alloc for this thread the first time */
|
|
|
14f8ab |
- if (!opctx) {
|
|
|
14f8ab |
- opctx = GF_CALLOC(1, sizeof(*opctx), gf_common_mt_syncopctx);
|
|
|
14f8ab |
- if (!opctx) {
|
|
|
14f8ab |
- ret = -1;
|
|
|
14f8ab |
- goto out;
|
|
|
14f8ab |
- }
|
|
|
14f8ab |
-
|
|
|
14f8ab |
- ret = syncopctx_setctx(opctx);
|
|
|
14f8ab |
- if (ret != 0) {
|
|
|
14f8ab |
- GF_FREE(opctx);
|
|
|
14f8ab |
- opctx = NULL;
|
|
|
14f8ab |
- goto out;
|
|
|
14f8ab |
- }
|
|
|
14f8ab |
- }
|
|
|
14f8ab |
+ opctx->uid = *(uid_t *)uid;
|
|
|
14f8ab |
+ opctx->valid |= SYNCOPCTX_UID;
|
|
|
14f8ab |
|
|
|
14f8ab |
out:
|
|
|
14f8ab |
- if (opctx && uid) {
|
|
|
14f8ab |
- opctx->uid = *(uid_t *)uid;
|
|
|
14f8ab |
- opctx->valid |= SYNCOPCTX_UID;
|
|
|
14f8ab |
- }
|
|
|
14f8ab |
-
|
|
|
14f8ab |
return ret;
|
|
|
14f8ab |
}
|
|
|
14f8ab |
|
|
|
14f8ab |
@@ -66,28 +48,10 @@ syncopctx_setfsgid(void *gid)
|
|
|
14f8ab |
|
|
|
14f8ab |
opctx = syncopctx_getctx();
|
|
|
14f8ab |
|
|
|
14f8ab |
- /* alloc for this thread the first time */
|
|
|
14f8ab |
- if (!opctx) {
|
|
|
14f8ab |
- opctx = GF_CALLOC(1, sizeof(*opctx), gf_common_mt_syncopctx);
|
|
|
14f8ab |
- if (!opctx) {
|
|
|
14f8ab |
- ret = -1;
|
|
|
14f8ab |
- goto out;
|
|
|
14f8ab |
- }
|
|
|
14f8ab |
-
|
|
|
14f8ab |
- ret = syncopctx_setctx(opctx);
|
|
|
14f8ab |
- if (ret != 0) {
|
|
|
14f8ab |
- GF_FREE(opctx);
|
|
|
14f8ab |
- opctx = NULL;
|
|
|
14f8ab |
- goto out;
|
|
|
14f8ab |
- }
|
|
|
14f8ab |
- }
|
|
|
14f8ab |
+ opctx->gid = *(gid_t *)gid;
|
|
|
14f8ab |
+ opctx->valid |= SYNCOPCTX_GID;
|
|
|
14f8ab |
|
|
|
14f8ab |
out:
|
|
|
14f8ab |
- if (opctx && gid) {
|
|
|
14f8ab |
- opctx->gid = *(gid_t *)gid;
|
|
|
14f8ab |
- opctx->valid |= SYNCOPCTX_GID;
|
|
|
14f8ab |
- }
|
|
|
14f8ab |
-
|
|
|
14f8ab |
return ret;
|
|
|
14f8ab |
}
|
|
|
14f8ab |
|
|
|
14f8ab |
@@ -107,43 +71,20 @@ syncopctx_setfsgroups(int count, const void *groups)
|
|
|
14f8ab |
|
|
|
14f8ab |
opctx = syncopctx_getctx();
|
|
|
14f8ab |
|
|
|
14f8ab |
- /* alloc for this thread the first time */
|
|
|
14f8ab |
- if (!opctx) {
|
|
|
14f8ab |
- opctx = GF_CALLOC(1, sizeof(*opctx), gf_common_mt_syncopctx);
|
|
|
14f8ab |
- if (!opctx) {
|
|
|
14f8ab |
- ret = -1;
|
|
|
14f8ab |
- goto out;
|
|
|
14f8ab |
- }
|
|
|
14f8ab |
-
|
|
|
14f8ab |
- ret = syncopctx_setctx(opctx);
|
|
|
14f8ab |
- if (ret != 0) {
|
|
|
14f8ab |
- GF_FREE(opctx);
|
|
|
14f8ab |
- opctx = NULL;
|
|
|
14f8ab |
- goto out;
|
|
|
14f8ab |
- }
|
|
|
14f8ab |
- }
|
|
|
14f8ab |
-
|
|
|
14f8ab |
/* resize internal groups as required */
|
|
|
14f8ab |
if (count && opctx->grpsize < count) {
|
|
|
14f8ab |
if (opctx->groups) {
|
|
|
14f8ab |
- tmpgroups = GF_REALLOC(opctx->groups, (sizeof(gid_t) * count));
|
|
|
14f8ab |
- /* NOTE: Not really required to zero the reallocation,
|
|
|
14f8ab |
- * as ngrps controls the validity of data,
|
|
|
14f8ab |
- * making a note irrespective */
|
|
|
14f8ab |
- if (tmpgroups == NULL) {
|
|
|
14f8ab |
- opctx->grpsize = 0;
|
|
|
14f8ab |
- GF_FREE(opctx->groups);
|
|
|
14f8ab |
- opctx->groups = NULL;
|
|
|
14f8ab |
- ret = -1;
|
|
|
14f8ab |
- goto out;
|
|
|
14f8ab |
- }
|
|
|
14f8ab |
- } else {
|
|
|
14f8ab |
- tmpgroups = GF_CALLOC(count, sizeof(gid_t), gf_common_mt_syncopctx);
|
|
|
14f8ab |
- if (tmpgroups == NULL) {
|
|
|
14f8ab |
- opctx->grpsize = 0;
|
|
|
14f8ab |
- ret = -1;
|
|
|
14f8ab |
- goto out;
|
|
|
14f8ab |
- }
|
|
|
14f8ab |
+ /* Group list will be updated later, so no need to keep current
|
|
|
14f8ab |
+ * data and waste time copying it. It's better to free the current
|
|
|
14f8ab |
+ * allocation and then allocate a fresh new memory block. */
|
|
|
14f8ab |
+ GF_FREE(opctx->groups);
|
|
|
14f8ab |
+ opctx->groups = NULL;
|
|
|
14f8ab |
+ opctx->grpsize = 0;
|
|
|
14f8ab |
+ }
|
|
|
14f8ab |
+ tmpgroups = GF_MALLOC(count * sizeof(gid_t), gf_common_mt_syncopctx);
|
|
|
14f8ab |
+ if (tmpgroups == NULL) {
|
|
|
14f8ab |
+ ret = -1;
|
|
|
14f8ab |
+ goto out;
|
|
|
14f8ab |
}
|
|
|
14f8ab |
|
|
|
14f8ab |
opctx->groups = tmpgroups;
|
|
|
14f8ab |
@@ -177,28 +118,10 @@ syncopctx_setfspid(void *pid)
|
|
|
14f8ab |
|
|
|
14f8ab |
opctx = syncopctx_getctx();
|
|
|
14f8ab |
|
|
|
14f8ab |
- /* alloc for this thread the first time */
|
|
|
14f8ab |
- if (!opctx) {
|
|
|
14f8ab |
- opctx = GF_CALLOC(1, sizeof(*opctx), gf_common_mt_syncopctx);
|
|
|
14f8ab |
- if (!opctx) {
|
|
|
14f8ab |
- ret = -1;
|
|
|
14f8ab |
- goto out;
|
|
|
14f8ab |
- }
|
|
|
14f8ab |
-
|
|
|
14f8ab |
- ret = syncopctx_setctx(opctx);
|
|
|
14f8ab |
- if (ret != 0) {
|
|
|
14f8ab |
- GF_FREE(opctx);
|
|
|
14f8ab |
- opctx = NULL;
|
|
|
14f8ab |
- goto out;
|
|
|
14f8ab |
- }
|
|
|
14f8ab |
- }
|
|
|
14f8ab |
+ opctx->pid = *(pid_t *)pid;
|
|
|
14f8ab |
+ opctx->valid |= SYNCOPCTX_PID;
|
|
|
14f8ab |
|
|
|
14f8ab |
out:
|
|
|
14f8ab |
- if (opctx && pid) {
|
|
|
14f8ab |
- opctx->pid = *(pid_t *)pid;
|
|
|
14f8ab |
- opctx->valid |= SYNCOPCTX_PID;
|
|
|
14f8ab |
- }
|
|
|
14f8ab |
-
|
|
|
14f8ab |
return ret;
|
|
|
14f8ab |
}
|
|
|
14f8ab |
|
|
|
14f8ab |
@@ -217,28 +140,10 @@ syncopctx_setfslkowner(gf_lkowner_t *lk_owner)
|
|
|
14f8ab |
|
|
|
14f8ab |
opctx = syncopctx_getctx();
|
|
|
14f8ab |
|
|
|
14f8ab |
- /* alloc for this thread the first time */
|
|
|
14f8ab |
- if (!opctx) {
|
|
|
14f8ab |
- opctx = GF_CALLOC(1, sizeof(*opctx), gf_common_mt_syncopctx);
|
|
|
14f8ab |
- if (!opctx) {
|
|
|
14f8ab |
- ret = -1;
|
|
|
14f8ab |
- goto out;
|
|
|
14f8ab |
- }
|
|
|
14f8ab |
-
|
|
|
14f8ab |
- ret = syncopctx_setctx(opctx);
|
|
|
14f8ab |
- if (ret != 0) {
|
|
|
14f8ab |
- GF_FREE(opctx);
|
|
|
14f8ab |
- opctx = NULL;
|
|
|
14f8ab |
- goto out;
|
|
|
14f8ab |
- }
|
|
|
14f8ab |
- }
|
|
|
14f8ab |
+ opctx->lk_owner = *lk_owner;
|
|
|
14f8ab |
+ opctx->valid |= SYNCOPCTX_LKOWNER;
|
|
|
14f8ab |
|
|
|
14f8ab |
out:
|
|
|
14f8ab |
- if (opctx && lk_owner) {
|
|
|
14f8ab |
- opctx->lk_owner = *lk_owner;
|
|
|
14f8ab |
- opctx->valid |= SYNCOPCTX_LKOWNER;
|
|
|
14f8ab |
- }
|
|
|
14f8ab |
-
|
|
|
14f8ab |
return ret;
|
|
|
14f8ab |
}
|
|
|
14f8ab |
|
|
|
14f8ab |
diff --git a/xlators/features/changelog/lib/src/gf-changelog-helpers.c b/xlators/features/changelog/lib/src/gf-changelog-helpers.c
|
|
|
14f8ab |
index 03dac5e..e5a9db4 100644
|
|
|
14f8ab |
--- a/xlators/features/changelog/lib/src/gf-changelog-helpers.c
|
|
|
14f8ab |
+++ b/xlators/features/changelog/lib/src/gf-changelog-helpers.c
|
|
|
14f8ab |
@@ -64,20 +64,7 @@ gf_rfc3986_encode_space_newline(unsigned char *s, char *enc, char *estr)
|
|
|
14f8ab |
* made a part of libglusterfs.
|
|
|
14f8ab |
*/
|
|
|
14f8ab |
|
|
|
14f8ab |
-static pthread_key_t rl_key;
|
|
|
14f8ab |
-static pthread_once_t rl_once = PTHREAD_ONCE_INIT;
|
|
|
14f8ab |
-
|
|
|
14f8ab |
-static void
|
|
|
14f8ab |
-readline_destructor(void *ptr)
|
|
|
14f8ab |
-{
|
|
|
14f8ab |
- GF_FREE(ptr);
|
|
|
14f8ab |
-}
|
|
|
14f8ab |
-
|
|
|
14f8ab |
-static void
|
|
|
14f8ab |
-readline_once(void)
|
|
|
14f8ab |
-{
|
|
|
14f8ab |
- pthread_key_create(&rl_key, readline_destructor);
|
|
|
14f8ab |
-}
|
|
|
14f8ab |
+static __thread read_line_t thread_tsd = {};
|
|
|
14f8ab |
|
|
|
14f8ab |
static ssize_t
|
|
|
14f8ab |
my_read(read_line_t *tsd, int fd, char *ptr)
|
|
|
14f8ab |
@@ -97,27 +84,6 @@ my_read(read_line_t *tsd, int fd, char *ptr)
|
|
|
14f8ab |
return 1;
|
|
|
14f8ab |
}
|
|
|
14f8ab |
|
|
|
14f8ab |
-static int
|
|
|
14f8ab |
-gf_readline_init_once(read_line_t **tsd)
|
|
|
14f8ab |
-{
|
|
|
14f8ab |
- if (pthread_once(&rl_once, readline_once) != 0)
|
|
|
14f8ab |
- return -1;
|
|
|
14f8ab |
-
|
|
|
14f8ab |
- *tsd = pthread_getspecific(rl_key);
|
|
|
14f8ab |
- if (*tsd)
|
|
|
14f8ab |
- goto out;
|
|
|
14f8ab |
-
|
|
|
14f8ab |
- *tsd = GF_CALLOC(1, sizeof(**tsd), gf_changelog_mt_libgfchangelog_rl_t);
|
|
|
14f8ab |
- if (!*tsd)
|
|
|
14f8ab |
- return -1;
|
|
|
14f8ab |
-
|
|
|
14f8ab |
- if (pthread_setspecific(rl_key, *tsd) != 0)
|
|
|
14f8ab |
- return -1;
|
|
|
14f8ab |
-
|
|
|
14f8ab |
-out:
|
|
|
14f8ab |
- return 0;
|
|
|
14f8ab |
-}
|
|
|
14f8ab |
-
|
|
|
14f8ab |
ssize_t
|
|
|
14f8ab |
gf_readline(int fd, void *vptr, size_t maxlen)
|
|
|
14f8ab |
{
|
|
|
14f8ab |
@@ -125,10 +91,7 @@ gf_readline(int fd, void *vptr, size_t maxlen)
|
|
|
14f8ab |
size_t rc = 0;
|
|
|
14f8ab |
char c = ' ';
|
|
|
14f8ab |
char *ptr = NULL;
|
|
|
14f8ab |
- read_line_t *tsd = NULL;
|
|
|
14f8ab |
-
|
|
|
14f8ab |
- if (gf_readline_init_once(&tsd))
|
|
|
14f8ab |
- return -1;
|
|
|
14f8ab |
+ read_line_t *tsd = &thread_tsd;
|
|
|
14f8ab |
|
|
|
14f8ab |
ptr = vptr;
|
|
|
14f8ab |
for (n = 1; n < maxlen; n++) {
|
|
|
14f8ab |
@@ -151,10 +114,7 @@ off_t
|
|
|
14f8ab |
gf_lseek(int fd, off_t offset, int whence)
|
|
|
14f8ab |
{
|
|
|
14f8ab |
off_t off = 0;
|
|
|
14f8ab |
- read_line_t *tsd = NULL;
|
|
|
14f8ab |
-
|
|
|
14f8ab |
- if (gf_readline_init_once(&tsd))
|
|
|
14f8ab |
- return -1;
|
|
|
14f8ab |
+ read_line_t *tsd = &thread_tsd;
|
|
|
14f8ab |
|
|
|
14f8ab |
off = sys_lseek(fd, offset, whence);
|
|
|
14f8ab |
if (off == -1)
|
|
|
14f8ab |
@@ -169,10 +129,7 @@ gf_lseek(int fd, off_t offset, int whence)
|
|
|
14f8ab |
int
|
|
|
14f8ab |
gf_ftruncate(int fd, off_t length)
|
|
|
14f8ab |
{
|
|
|
14f8ab |
- read_line_t *tsd = NULL;
|
|
|
14f8ab |
-
|
|
|
14f8ab |
- if (gf_readline_init_once(&tsd))
|
|
|
14f8ab |
- return -1;
|
|
|
14f8ab |
+ read_line_t *tsd = &thread_tsd;
|
|
|
14f8ab |
|
|
|
14f8ab |
if (sys_ftruncate(fd, 0))
|
|
|
14f8ab |
return -1;
|
|
|
14f8ab |
diff --git a/xlators/features/changelog/lib/src/gf-changelog.c b/xlators/features/changelog/lib/src/gf-changelog.c
|
|
|
14f8ab |
index 7ed9e55..d6acb37 100644
|
|
|
14f8ab |
--- a/xlators/features/changelog/lib/src/gf-changelog.c
|
|
|
14f8ab |
+++ b/xlators/features/changelog/lib/src/gf-changelog.c
|
|
|
14f8ab |
@@ -237,9 +237,8 @@ gf_changelog_init_master()
|
|
|
14f8ab |
{
|
|
|
14f8ab |
int ret = 0;
|
|
|
14f8ab |
|
|
|
14f8ab |
- mem_pools_init_early();
|
|
|
14f8ab |
ret = gf_changelog_init_context();
|
|
|
14f8ab |
- mem_pools_init_late();
|
|
|
14f8ab |
+ mem_pools_init();
|
|
|
14f8ab |
|
|
|
14f8ab |
return ret;
|
|
|
14f8ab |
}
|
|
|
14f8ab |
diff --git a/xlators/nfs/server/src/mount3udp_svc.c b/xlators/nfs/server/src/mount3udp_svc.c
|
|
|
14f8ab |
index d5e4169..0688779eb 100644
|
|
|
14f8ab |
--- a/xlators/nfs/server/src/mount3udp_svc.c
|
|
|
14f8ab |
+++ b/xlators/nfs/server/src/mount3udp_svc.c
|
|
|
14f8ab |
@@ -216,11 +216,7 @@ mount3udp_thread(void *argv)
|
|
|
14f8ab |
|
|
|
14f8ab |
GF_ASSERT(nfsx);
|
|
|
14f8ab |
|
|
|
14f8ab |
- if (glusterfs_this_set(nfsx)) {
|
|
|
14f8ab |
- gf_msg(GF_MNT, GF_LOG_ERROR, ENOMEM, NFS_MSG_XLATOR_SET_FAIL,
|
|
|
14f8ab |
- "Failed to set xlator, nfs.mount-udp will not work");
|
|
|
14f8ab |
- return NULL;
|
|
|
14f8ab |
- }
|
|
|
14f8ab |
+ glusterfs_this_set(nfsx);
|
|
|
14f8ab |
|
|
|
14f8ab |
transp = svcudp_create(RPC_ANYSOCK);
|
|
|
14f8ab |
if (transp == NULL) {
|
|
|
14f8ab |
--
|
|
|
14f8ab |
1.8.3.1
|
|
|
14f8ab |
|