nvme: do not allow the same nvme_io_msg_producer to register twice
Previous to this change it was possible to register
same nvme_io_msg_producer twice. This kind of functionality does
not make sense in current scope of it, as each message to/from
io_msg_producer does not have identifier other than this pointer.
In case of nvme_cuse this allowed creation of multiple /dev/spdk/nvme*
devices and caused an infinite loop when detaching an nvme controller.
This patch disallows that and adds test for nvme_cuse.
Signed-off-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/1938 (master)
(cherry picked from commit 7fbdeacc9e
)
Change-Id: I5f56548d1bce878417323c12909d6970416d2020
Signed-off-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/2160
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
parent
3f5f09db46
commit
b8446bb66d
@ -106,6 +106,20 @@ spdk_nvme_io_msg_process(struct spdk_nvme_ctrlr *ctrlr)
|
||||
return count;
|
||||
}
|
||||
|
||||
static bool
|
||||
nvme_io_msg_is_producer_registered(struct spdk_nvme_ctrlr *ctrlr,
|
||||
struct nvme_io_msg_producer *io_msg_producer)
|
||||
{
|
||||
struct nvme_io_msg_producer *tmp;
|
||||
|
||||
STAILQ_FOREACH(tmp, &ctrlr->io_producers, link) {
|
||||
if (tmp == io_msg_producer) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int
|
||||
nvme_io_msg_ctrlr_register(struct spdk_nvme_ctrlr *ctrlr,
|
||||
struct nvme_io_msg_producer *io_msg_producer)
|
||||
@ -115,6 +129,10 @@ nvme_io_msg_ctrlr_register(struct spdk_nvme_ctrlr *ctrlr,
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (nvme_io_msg_is_producer_registered(ctrlr, io_msg_producer)) {
|
||||
return -EEXIST;
|
||||
}
|
||||
|
||||
if (!STAILQ_EMPTY(&ctrlr->io_producers) || ctrlr->is_resetting) {
|
||||
/* There are registered producers - IO messaging already started */
|
||||
STAILQ_INSERT_TAIL(&ctrlr->io_producers, io_msg_producer, link);
|
||||
@ -173,6 +191,10 @@ nvme_io_msg_ctrlr_unregister(struct spdk_nvme_ctrlr *ctrlr,
|
||||
{
|
||||
assert(io_msg_producer != NULL);
|
||||
|
||||
if (!nvme_io_msg_is_producer_registered(ctrlr, io_msg_producer)) {
|
||||
return;
|
||||
}
|
||||
|
||||
STAILQ_REMOVE(&ctrlr->io_producers, io_msg_producer, nvme_io_msg_producer, link);
|
||||
if (STAILQ_EMPTY(&ctrlr->io_producers)) {
|
||||
nvme_io_msg_ctrlr_detach(ctrlr);
|
||||
|
Loading…
Reference in New Issue
Block a user