From 8fe3c6107a2b431d7cc0b8cfaeeb7941cf9590f9 Mon Sep 17 00:00:00 2001 From: Soumya Koduri Date: Tue, 18 Dec 2018 22:07:55 +0530 Subject: gfapi: Access fs->oldvolfile under mutex lock In some cases (for eg., when there are multiple RPC_CLNT_CONNECT notifications), multiple threads may fetch volfile and try to update it in 'fs' object simultaneously. Hence protect those variables' access under fs->mutex lock. Change-Id: Idaee9548560db32d83f4c04ebb1f375fee7864a9 fixes: bz#1660577 Signed-off-by: Soumya Koduri --- api/src/glfs-mgmt.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/api/src/glfs-mgmt.c b/api/src/glfs-mgmt.c index bf99005cbc3..7ef5ec93af1 100644 --- a/api/src/glfs-mgmt.c +++ b/api/src/glfs-mgmt.c @@ -653,12 +653,15 @@ volfile: ret = 0; size = rsp.op_ret; + pthread_mutex_lock(&fs->mutex); if ((size == fs->oldvollen) && (memcmp(fs->oldvolfile, rsp.spec, size) == 0)) { gf_msg(frame->this->name, GF_LOG_INFO, 0, API_MSG_VOLFILE_INFO, "No change in volfile, continuing"); + pthread_mutex_unlock(&fs->mutex); goto out; } + pthread_mutex_unlock(&fs->mutex); /* coverity[secure_temp] mkstemp uses 0600 as the mode and is safe */ tmp_fd = mkstemp(template); @@ -699,7 +702,10 @@ volfile: * occurred during the operation */ + pthread_mutex_lock(&fs->mutex); ret = gf_volfile_reconfigure(fs->oldvollen, tmpfp, fs->ctx, fs->oldvolfile); + pthread_mutex_unlock(&fs->mutex); + if (ret == 0) { gf_msg_debug("glusterfsd-mgmt", 0, "No need to re-load " -- cgit