gfapi: fix issue when glfs_set_logging is called concurrently

glfs_set_logging changes THIS->ctx without lock, during initialization
THIS refers to global_xlator. Concurrently changing it could result in
global_xlator.ctx being some fs->ctx. After that fs->ctx is destroyed,
global_xlator.ctx refers to an invalid pointer and that causes crash in
sbusequent access.

Change-Id: I6682173811799bafd525d9ab371874f3803baa0e
BUG: 1521213
Signed-off-by: Zhang Huan <zhanghuan@open-fs.com>
This commit is contained in:
Zhang Huan 2017-12-05 12:54:04 +08:00 committed by Jeff Darcy
parent 28202631fe
commit 4eb49de567

View File

@ -929,14 +929,10 @@ pub_glfs_set_logging (struct glfs *fs, const char *logfile, int loglevel)
{
int ret = -1;
char *tmplog = NULL;
glusterfs_ctx_t *old_ctx = NULL;
DECLARE_OLD_THIS;
__GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
old_ctx = THIS->ctx;
THIS->ctx = fs->ctx;
if (!logfile) {
ret = gf_set_log_file_path (&fs->ctx->cmd_args, fs->ctx);
if (ret)
@ -959,7 +955,6 @@ pub_glfs_set_logging (struct glfs *fs, const char *logfile, int loglevel)
goto out;
out:
THIS->ctx = old_ctx;
__GLFS_EXIT_FS;
invalid_fs: