numam-spdk/lib/bdev
Nick Connolly 77573e830e lib/bdev: ensure mutex is initialized
For correct behaviour, pthread_mutex should not be locked after it has
been destroyed.

g_bdev_mgr.mutex is statically initialized. It is destroyed in
bdev_mgr_unregister_cb, but not re-initialized in spdk_bdev_initialize.
Repeated calls to initialize/unregister occur during unit tests.
Remove the destroy from bdev_mgr_unregister_cb, which seems
the simplest way of resolving the issue.

The sequence: spdk_put_io_channel(), spdk_bdev_close(),
spdk_bdev_unregister() occurs during unit tests.
spdk_bdev_unregister() destroys internal.mutex which is then
locked by a call to bdev_channel_destroy() resulting from the
earlier spdk_put_io_channel(). Move the destroy and the free of
internal.qos into bdev_destroy_cb so that they don't occur until
all of the channels have been released. Remove the no longer
required bdev_fini.

Repeat calls to spdk_bdev_unregister that occur after an unregister has
completed will lock internal.mutex which has been destroyed by the
previous unregister. This occurs during unit tests. Defer locking
internal.mutex until after the internal.status has been checked for
SPDK_BDEV_STATUS_REMOVING. This is the only place where
internal.status is set to removing and g_bdev_mgr.mutex alone is
sufficient to ensure atomicity here.

Tested with a pthreads library that contains debugging code to
check the mutex state and a modified version of bdev_io_types_test
to call get_io_channel on a different thread.

Suggested-by: Jim Harris <james.r.harris@intel.com>
Signed-off-by: Nick Connolly <nick.connolly@mayadata.io>
Change-Id: I81cc46a1b8a766700253829b19cc86c7f0eb79f2
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/6217
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Community-CI: Broadcom CI
Community-CI: Mellanox Build Bot
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
2021-02-16 08:39:17 +00:00
..
bdev_internal.h bdev: rename spdk_bdev_get_io to bdev_channel_get_io 2019-11-20 09:34:18 +00:00
bdev_rpc.c lib/bdev: add spdk_bdev_wait_for_examine() 2021-01-15 08:28:57 +00:00
bdev_zone.c lib/bdev: remove _spdk prefix from functions. 2020-05-27 07:35:02 +00:00
bdev.c lib/bdev: ensure mutex is initialized 2021-02-16 08:39:17 +00:00
Makefile so_ver: increase all major versions 2021-02-05 14:43:47 +00:00
part.c bdev/part: Add spdk_bdev_part_base_construct_ext() to pass bdev_name 2020-10-16 08:14:34 +00:00
scsi_nvme.c nvme: fix command specific status code 2020-02-20 09:49:24 +00:00
spdk_bdev.map bdev: add function to return aio's errno 2021-01-20 00:13:49 +00:00
vtune.c mk: don't use '-include spdk/config.h' 2018-10-02 23:13:32 +00:00