Spdk/module/bdev/nvme
Shuhei Matsumoto 01f769c62a bdev/nvme: Ensure ctrlr->destruct is set only once
Checking if destruct is false and setting destruct to true are
separated by mutex in remove_cb() and bdev_nvme_library_fini().

It was possible that multiple threads called nvme_bdev_ctrlr_destruct()
because the caller could call nvme_bdev_ctrlr_destruct() before
setting destruct to true after knowing it was false.

This patch ensures that nvme_bdev_ctrlr_destruct() is called only once.

Set ctrlr->destruct to true without releasing mutex after checking
if ctrlr->destruct is false.

If destruct is set to true before calling nvme_ctrlr_depopulate_namespaces(),
nvme_ctrlr_depopulate_namespace_done() may call nvme_bdev_ctrlr_destruct()
because it is likely that reference count is zero and destruct is true.
In this case, remove_cb() or bdev_nvme_library_fini() cannot call
nvme_bdev_destruct() after returning from nvme_ctrlr_depopulate_namespaces().

On the other hand, if a controller has no namespace,
nvme_ctrlr_depopulate_namespaces() does nothing and
nvme_ctrlr_depopulate_namespace_done() is not called. Hence
remove_cb() or bdev_nvme_library_fini() has to call nvme_bdev_destruct()
after returning nvme_ctrlr_depopulate_namespaces().

To unify both cases, initialize reference count to one as a sentinel value
and remove_cb() and bdev_nvme_library_fini() decrement reference count
and then calls nvme_bdev_ctrlr_destruct() if reference count is zero
after returning from nvme_ctrlr_depopulate_namespaces().

Additionally, add assert to check if reference count is not negative
to find bug in future.

Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: I8a617b5aa4d0a9faff832e63c2ed4b353341dd6b
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/4817
Community-CI: Broadcom CI
Community-CI: Mellanox Build Bot
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
2020-11-16 12:23:04 +00:00
..
bdev_nvme_cuse_rpc.c log: remove internal log.h header 2020-10-15 08:23:39 +00:00
bdev_nvme_rpc.c bdev/rpc: use goto to make code reuse. 2020-11-11 01:02:31 +00:00
bdev_nvme.c bdev/nvme: Ensure ctrlr->destruct is set only once 2020-11-16 12:23:04 +00:00
bdev_nvme.h bdev/nvme: Make bdev_nvme_add_trid() static function 2020-09-30 07:25:54 +00:00
bdev_ocssd_rpc.c bdev/ocssd: fixed leaking range buffer 2019-12-23 08:43:34 +00:00
bdev_ocssd.c bdev/nvme: Consolidate nvme_ctrlr_populate_namespace_done() calls 2020-11-06 08:11:50 +00:00
bdev_ocssd.h bdev/ocssd: media management events 2019-12-20 10:02:15 +00:00
common.c bdev/nvme: Ensure ctrlr->destruct is set only once 2020-11-16 12:23:04 +00:00
common.h bdev/ocssd: Rename the local and member variables ocssd_ioch by ocssd_ch 2020-10-19 10:00:16 +00:00
Makefile mk/lib: add a check that major and minor version is set for libs. 2020-05-21 09:19:00 +00:00
nvme_rpc.c module/nvme: Fix warning about scanbuild. 2020-10-27 08:42:32 +00:00
vbdev_opal_rpc.c log: remove internal log.h header 2020-10-15 08:23:39 +00:00
vbdev_opal.c bdev_nvme/opal: Use spdk_bdev_part_base_construct_ext() to pass bdev_name 2020-10-16 08:14:34 +00:00
vbdev_opal.h module/bdev_nvme: remove spdk prefix from static/internal functions. 2020-05-15 07:58:03 +00:00