io_channel: protect critial variables under mutex

Change-Id: If5e16c2ac148fd4818c942e8f57b02671e76ed62
Signed-off-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-on: https://review.gerrithub.io/403153
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
This commit is contained in:
Changpeng Liu 2018-03-08 19:29:26 -05:00 committed by Jim Harris
parent 4d36735401
commit 7448f89536

View File

@ -334,6 +334,12 @@ _spdk_io_device_attempt_free(struct io_device *dev)
struct spdk_io_channel *ch;
pthread_mutex_lock(&g_devlist_mutex);
if (!dev->unregistered) {
pthread_mutex_unlock(&g_devlist_mutex);
return;
}
TAILQ_FOREACH(thread, &g_threads, tailq) {
TAILQ_FOREACH(ch, &thread->io_channels, tailq) {
if (ch->dev == dev) {
@ -457,6 +463,8 @@ _spdk_put_io_channel(void *arg)
{
struct spdk_io_channel *ch = arg;
assert(ch->thread == spdk_get_thread());
if (ch->ref == 0) {
SPDK_ERRLOG("ref already zero\n");
return;
@ -474,9 +482,7 @@ _spdk_put_io_channel(void *arg)
TAILQ_REMOVE(&ch->thread->io_channels, ch, tailq);
pthread_mutex_unlock(&g_devlist_mutex);
if (ch->dev->unregistered) {
_spdk_io_device_attempt_free(ch->dev);
}
_spdk_io_device_attempt_free(ch->dev);
free(ch);
}