bdev/nvme: Fix the race condition between destruct and reset controller

nvme_bdev_ctrlr_destruct() had checked first if poller is already
registered. On the other hand, nvme_bdev_ctrlr_destruct() had been
used as a poller function.

Hence nvme_bdev_ctrlr_destruct() had no way to unregister poller
if destruct and reset controller were raced.

This patch fixes the issue. The previous patch ensures nvme_bdev_ctrlr_destruct()
is called only once.

Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: Iba5424c42a4a3e5f03575df2616ec2a817e38f51
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/4827
Community-CI: Broadcom CI
Community-CI: Mellanox Build Bot
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
Reviewed-by: John Kariuki <John.K.Kariuki@intel.com>
Reviewed-by: Paul Luse <paul.e.luse@intel.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
Shuhei Matsumoto 2020-10-22 13:36:58 +09:00 committed by Tomasz Zawadzki
parent 0939c07505
commit f1fb19e332

View File

@ -154,21 +154,17 @@ nvme_bdev_ctrlr_destruct(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr)
assert(nvme_bdev_ctrlr->destruct);
pthread_mutex_lock(&g_bdev_nvme_mutex);
/* If we have already registered a poller, let that one take care of it. */
if (nvme_bdev_ctrlr->destruct_poller != NULL) {
pthread_mutex_unlock(&g_bdev_nvme_mutex);
return SPDK_POLLER_IDLE;
}
spdk_poller_unregister(&nvme_bdev_ctrlr->destruct_poller);
if (nvme_bdev_ctrlr->resetting) {
nvme_bdev_ctrlr->destruct_poller =
SPDK_POLLER_REGISTER((spdk_poller_fn)nvme_bdev_ctrlr_destruct, nvme_bdev_ctrlr, 1000);
SPDK_POLLER_REGISTER((spdk_poller_fn)nvme_bdev_ctrlr_destruct,
nvme_bdev_ctrlr, 1000);
pthread_mutex_unlock(&g_bdev_nvme_mutex);
return SPDK_POLLER_BUSY;
}
pthread_mutex_unlock(&g_bdev_nvme_mutex);
spdk_poller_unregister(&nvme_bdev_ctrlr->destruct_poller);
if (nvme_bdev_ctrlr->opal_dev) {
spdk_opal_dev_destruct(nvme_bdev_ctrlr->opal_dev);
nvme_bdev_ctrlr->opal_dev = NULL;