lvol: lock g_lvol_stores_mutex when access g_lvol_stores

Since we lock g_lvol_stores_mutex when add lvs to g_lvol_stores, so
logically speaking, we shoud lock g_lvol_stores_mutex whenever access
g_lvol_stores_mutex. Although I can't figure out specific scenario that
will cause contention if we don't lock it.

Change-Id: If3bdba91407f5c9d09fc16c5ec7dcb919ff9647d
Signed-off-by: wuzhouhui <wuzhouhui@kingsoft.com>
Reviewed-on: https://review.gerrithub.io/426147
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
wuzhouhui 2018-09-20 10:01:20 +08:00 committed by Changpeng Liu
parent dfb7f70f0b
commit fdaea1fa5a

View File

@ -79,9 +79,12 @@ _spdk_add_lvs_to_list(struct spdk_lvol_store *lvs)
static void
_spdk_lvs_free(struct spdk_lvol_store *lvs)
{
pthread_mutex_lock(&g_lvol_stores_mutex);
if (lvs->on_list) {
TAILQ_REMOVE(&g_lvol_stores, lvs, link);
}
pthread_mutex_unlock(&g_lvol_stores_mutex);
free(lvs);
}
@ -712,13 +715,16 @@ spdk_lvs_rename(struct spdk_lvol_store *lvs, const char *new_name,
}
/* Check if new or new_name is already used in other lvs */
pthread_mutex_lock(&g_lvol_stores_mutex);
TAILQ_FOREACH(tmp, &g_lvol_stores, link) {
if (!strncmp(new_name, tmp->name, SPDK_LVS_NAME_MAX) ||
!strncmp(new_name, tmp->new_name, SPDK_LVS_NAME_MAX)) {
pthread_mutex_unlock(&g_lvol_stores_mutex);
cb_fn(cb_arg, -EEXIST);
return;
}
}
pthread_mutex_unlock(&g_lvol_stores_mutex);
req = calloc(1, sizeof(*req));
if (!req) {