lib/nvme: stop all NVMe io producers on detach

Now all registered producers should be stopped (unregistered) before
NVMe detach, otherwise NVMe controller cannot be safely detached.

This patch allows to stop all not unregistered io producers before
NVMe detach:

1. Callback to the "struct nvme_io_msg_producer" to stop producer
   started on selected controller.
2. On nvme_io_msg_ctrlr_detach() if there's some unregistered producers,
   stop all before freeing resources.


This approach also fixes issue with not to stop CUSE device when
NVMe controller is detached without unregistering producer (github
issue #1033).

	Fixes #1033

Change-Id: Ia1ffef566bb745edb55c54d6786ea481a35bbefd
Signed-off-by: Tomasz Kulasek <tomaszx.kulasek@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/474273
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
This commit is contained in:
Tomasz Kulasek 2019-11-14 11:18:40 -05:00 committed by Tomasz Zawadzki
parent 155c3babce
commit fd2af7afa9
3 changed files with 10 additions and 0 deletions

View File

@ -784,6 +784,7 @@ nvme_cuse_stop(struct spdk_nvme_ctrlr *ctrlr)
static struct nvme_io_msg_producer cuse_nvme_io_msg_producer = {
.name = "cuse",
.stop = nvme_cuse_stop,
};
int

View File

@ -147,6 +147,14 @@ nvme_io_msg_ctrlr_register(struct spdk_nvme_ctrlr *ctrlr,
void
nvme_io_msg_ctrlr_detach(struct spdk_nvme_ctrlr *ctrlr)
{
struct nvme_io_msg_producer *io_msg_producer, *tmp;
/* Stop all producers */
STAILQ_FOREACH_SAFE(io_msg_producer, &ctrlr->io_producers, link, tmp) {
io_msg_producer->stop(ctrlr);
STAILQ_REMOVE(&ctrlr->io_producers, io_msg_producer, nvme_io_msg_producer, link);
}
if (ctrlr->external_io_msgs) {
spdk_ring_free(ctrlr->external_io_msgs);
}

View File

@ -52,6 +52,7 @@ struct spdk_nvme_io_msg {
struct nvme_io_msg_producer {
const char *name;
void (*stop)(struct spdk_nvme_ctrlr *ctrlr);
STAILQ_ENTRY(nvme_io_msg_producer) link;
};