libglusterfs: Avoid initializing per process globals more than once.
gfapi consumers can invoke glusters_globals_init() multiple times through glfs_new(). This will result in re-initialization of already inited variables and non deterministic behavior. To avoid this, a new function gf_globals_init_once() has been added. The invocation of this function is guarded through pthread_once(), thereby ensuring single initialization of per process globals. Change-Id: I0ecde02ee49e0c7379c2eb0f1c879d89774ec82f BUG: 1184366 Signed-off-by: Vijay Bellur <vbellur@redhat.com> Signed-off-by: Raghavendra Bhat <raghavendra@redhat.com> Reviewed-on: http://review.gluster.org/9430 Tested-by: Gluster Build System <jenkins@build.gluster.com>
This commit is contained in:
parent
c8a6904396
commit
88136b53f5
@ -82,6 +82,7 @@ static char global_uuid_buf[GF_UUID_BUF_SIZE];
|
||||
static pthread_key_t lkowner_buf_key;
|
||||
static char global_lkowner_buf[GF_LKOWNER_BUF_SIZE];
|
||||
static int gf_global_mem_acct_enable = 1;
|
||||
static pthread_once_t globals_inited = PTHREAD_ONCE_INIT;
|
||||
|
||||
|
||||
int
|
||||
@ -329,13 +330,11 @@ glusterfs_lkowner_buf_get ()
|
||||
return buf;
|
||||
}
|
||||
|
||||
int
|
||||
glusterfs_globals_init (glusterfs_ctx_t *ctx)
|
||||
static void
|
||||
gf_globals_init_once ()
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
gf_log_globals_init (ctx);
|
||||
|
||||
ret = glusterfs_this_init ();
|
||||
if (ret) {
|
||||
gf_log ("", GF_LOG_CRITICAL,
|
||||
@ -371,5 +370,26 @@ glusterfs_globals_init (glusterfs_ctx_t *ctx)
|
||||
goto out;
|
||||
}
|
||||
out:
|
||||
|
||||
if (ret) {
|
||||
gf_log ("", GF_LOG_CRITICAL, "Exiting as global "
|
||||
"initialization failed");
|
||||
exit (ret);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
glusterfs_globals_init (glusterfs_ctx_t *ctx)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
gf_log_globals_init (ctx);
|
||||
|
||||
ret = pthread_once (&globals_inited, gf_globals_init_once);
|
||||
|
||||
if (ret)
|
||||
gf_log ("", GF_LOG_CRITICAL, "pthread_once failed with: %d",
|
||||
ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user