bdev/nvme: Factor out check if path should be deleted into a helper function
This improves the readability and makes us easier to add more changes. Signed-off-by: Shuhei Matsumoto <smatsumoto@nvidia.com> Change-Id: I55d7925d70f2a204f65a81f3fc44cf96b69c3ebe Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/16709 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Aleksey Marchuk <alexeymar@nvidia.com> Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
parent
07ca24ec59
commit
4757c05fa1
@ -5305,6 +5305,60 @@ bdev_nvme_create(struct spdk_nvme_transport_id *trid,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool
|
||||
nvme_path_should_delete(struct nvme_path_id *p, const struct nvme_path_id *path_id)
|
||||
{
|
||||
if (path_id->trid.trtype != 0) {
|
||||
if (path_id->trid.trtype == SPDK_NVME_TRANSPORT_CUSTOM) {
|
||||
if (strcasecmp(path_id->trid.trstring, p->trid.trstring) != 0) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (path_id->trid.trtype != p->trid.trtype) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!spdk_mem_all_zero(path_id->trid.traddr, sizeof(path_id->trid.traddr))) {
|
||||
if (strcasecmp(path_id->trid.traddr, p->trid.traddr) != 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (path_id->trid.adrfam != 0) {
|
||||
if (path_id->trid.adrfam != p->trid.adrfam) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!spdk_mem_all_zero(path_id->trid.trsvcid, sizeof(path_id->trid.trsvcid))) {
|
||||
if (strcasecmp(path_id->trid.trsvcid, p->trid.trsvcid) != 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!spdk_mem_all_zero(path_id->trid.subnqn, sizeof(path_id->trid.subnqn))) {
|
||||
if (strcmp(path_id->trid.subnqn, p->trid.subnqn) != 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!spdk_mem_all_zero(path_id->hostid.hostaddr, sizeof(path_id->hostid.hostaddr))) {
|
||||
if (strcmp(path_id->hostid.hostaddr, p->hostid.hostaddr) != 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!spdk_mem_all_zero(path_id->hostid.hostsvcid, sizeof(path_id->hostid.hostsvcid))) {
|
||||
if (strcmp(path_id->hostid.hostsvcid, p->hostid.hostsvcid) != 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int
|
||||
bdev_nvme_delete(const char *name, const struct nvme_path_id *path_id)
|
||||
{
|
||||
@ -5325,53 +5379,9 @@ bdev_nvme_delete(const char *name, const struct nvme_path_id *path_id)
|
||||
|
||||
TAILQ_FOREACH_SAFE(nvme_ctrlr, &nbdev_ctrlr->ctrlrs, tailq, tmp_nvme_ctrlr) {
|
||||
TAILQ_FOREACH_REVERSE_SAFE(p, &nvme_ctrlr->trids, nvme_paths, link, t) {
|
||||
if (path_id->trid.trtype != 0) {
|
||||
if (path_id->trid.trtype == SPDK_NVME_TRANSPORT_CUSTOM) {
|
||||
if (strcasecmp(path_id->trid.trstring, p->trid.trstring) != 0) {
|
||||
if (!nvme_path_should_delete(p, path_id)) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if (path_id->trid.trtype != p->trid.trtype) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!spdk_mem_all_zero(path_id->trid.traddr, sizeof(path_id->trid.traddr))) {
|
||||
if (strcasecmp(path_id->trid.traddr, p->trid.traddr) != 0) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (path_id->trid.adrfam != 0) {
|
||||
if (path_id->trid.adrfam != p->trid.adrfam) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (!spdk_mem_all_zero(path_id->trid.trsvcid, sizeof(path_id->trid.trsvcid))) {
|
||||
if (strcasecmp(path_id->trid.trsvcid, p->trid.trsvcid) != 0) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (!spdk_mem_all_zero(path_id->trid.subnqn, sizeof(path_id->trid.subnqn))) {
|
||||
if (strcmp(path_id->trid.subnqn, p->trid.subnqn) != 0) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (!spdk_mem_all_zero(path_id->hostid.hostaddr, sizeof(path_id->hostid.hostaddr))) {
|
||||
if (strcmp(path_id->hostid.hostaddr, p->hostid.hostaddr) != 0) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (!spdk_mem_all_zero(path_id->hostid.hostsvcid, sizeof(path_id->hostid.hostsvcid))) {
|
||||
if (strcmp(path_id->hostid.hostsvcid, p->hostid.hostsvcid) != 0) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
/* If we made it here, then this path is a match! Now we need to remove it. */
|
||||
if (p == nvme_ctrlr->active_path_id) {
|
||||
@ -5394,8 +5404,6 @@ bdev_nvme_delete(const char *name, const struct nvme_path_id *path_id)
|
||||
if (rc < 0 && rc != -ENXIO) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user