bdev/nvme: Check if a controller with the same TRID exists first in bdev_nvme_create()

This simpifies the code a little without any degradation.

Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: I6006266e250f2d083aa12424809d04fac6a9f8f0
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/4385
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Shuhei Matsumoto 2020-09-24 10:47:54 +09:00 committed by Tomasz Zawadzki
parent 7b9b1eefc0
commit 66f74eb9f7

View File

@ -1914,6 +1914,14 @@ bdev_nvme_create(struct spdk_nvme_transport_id *trid,
struct nvme_bdev_ctrlr *existing_ctrlr; struct nvme_bdev_ctrlr *existing_ctrlr;
int rc; int rc;
/* TODO expand this check to include both the host and target TRIDs.
* Only if both are the same should we fail.
*/
if (nvme_bdev_ctrlr_get(trid) != NULL) {
SPDK_ERRLOG("A controller with the provided trid (traddr: %s) already exists.\n", trid->traddr);
return -EEXIST;
}
existing_ctrlr = nvme_bdev_ctrlr_get_by_name(base_name); existing_ctrlr = nvme_bdev_ctrlr_get_by_name(base_name);
if (existing_ctrlr) { if (existing_ctrlr) {
if (trid->trtype == SPDK_NVME_TRANSPORT_PCIE) { if (trid->trtype == SPDK_NVME_TRANSPORT_PCIE) {
@ -1925,10 +1933,6 @@ bdev_nvme_create(struct spdk_nvme_transport_id *trid,
if (rc) { if (rc) {
return rc; return rc;
} }
/* TODO expand this check to include both the host and target TRIDs. Only if both are the same should we fail. */
} else if (nvme_bdev_ctrlr_get(trid) != NULL) {
SPDK_ERRLOG("A controller with the provided trid (traddr: %s) already exists.\n", trid->traddr);
return -EEXIST;
} }
if (trid->trtype == SPDK_NVME_TRANSPORT_PCIE) { if (trid->trtype == SPDK_NVME_TRANSPORT_PCIE) {