bdev/nvme: Factor out deleting a ctrlr from bdev_nvme_delete()

Factor out path deletion operation for one nvme_ctrlr into _bdev_nvme_delete().

_bdev_nvme_delete() traverses all remaining nvme_ctrlrs even after one
nvme_ctrlr was successfully deleted. To remember the successfule
deletion, use two return value variables, rc and _rc. For _rc returned by
_bdev_nvme_delete(), copy _rc to rc if _rc is zero, return _rc immediately
if _rc is not -ENXIO, or do nothing otherwise.

This improves the readability and makes us easier to add more changes.

Additionally, for _bdev_nvme_reset_io(), it is simpler to overwrite rc
to 0 if rc is -EBUSY rather than to return 0 if rc is -EBUSY. This is
very small change and hence done together.

Signed-off-by: Shuhei Matsumoto <smatsumoto@nvidia.com>
Change-Id: I57eafd22918c8c976b9c51bedb9e4369976c1d5c
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/16819
Reviewed-by: Aleksey Marchuk <alexeymar@nvidia.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
Shuhei Matsumoto 2023-02-09 16:44:21 +09:00 committed by Tomasz Zawadzki
parent 8173930051
commit 422f5f3d11

View File

@ -2199,11 +2199,10 @@ _bdev_nvme_reset_io(struct nvme_io_path *io_path, struct nvme_bdev_io *bio)
*/ */
bdev_io = spdk_bdev_io_from_ctx(bio); bdev_io = spdk_bdev_io_from_ctx(bio);
TAILQ_INSERT_TAIL(&ctrlr_ch->pending_resets, bdev_io, module_link); TAILQ_INSERT_TAIL(&ctrlr_ch->pending_resets, bdev_io, module_link);
} else { rc = 0;
return rc;
} }
return 0; return rc;
} }
static void static void
@ -5359,25 +5358,12 @@ nvme_path_should_delete(struct nvme_path_id *p, const struct nvme_path_id *path_
return true; return true;
} }
int static int
bdev_nvme_delete(const char *name, const struct nvme_path_id *path_id) _bdev_nvme_delete(struct nvme_ctrlr *nvme_ctrlr, const struct nvme_path_id *path_id)
{ {
struct nvme_bdev_ctrlr *nbdev_ctrlr;
struct nvme_ctrlr *nvme_ctrlr, *tmp_nvme_ctrlr;
struct nvme_path_id *p, *t; struct nvme_path_id *p, *t;
int rc = -ENXIO; int rc = -ENXIO;
if (name == NULL || path_id == NULL) {
return -EINVAL;
}
nbdev_ctrlr = nvme_bdev_ctrlr_get_by_name(name);
if (nbdev_ctrlr == NULL) {
SPDK_ERRLOG("Failed to find NVMe bdev controller\n");
return -ENODEV;
}
TAILQ_FOREACH_SAFE(nvme_ctrlr, &nbdev_ctrlr->ctrlrs, tailq, tmp_nvme_ctrlr) {
TAILQ_FOREACH_REVERSE_SAFE(p, &nvme_ctrlr->trids, nvme_paths, link, t) { TAILQ_FOREACH_REVERSE_SAFE(p, &nvme_ctrlr->trids, nvme_paths, link, t) {
if (!nvme_path_should_delete(p, path_id)) { if (!nvme_path_should_delete(p, path_id)) {
continue; continue;
@ -5386,7 +5372,6 @@ bdev_nvme_delete(const char *name, const struct nvme_path_id *path_id)
/* If we made it here, then this path is a match! Now we need to remove it. */ /* If we made it here, then this path is a match! Now we need to remove it. */
if (p == nvme_ctrlr->active_path_id) { if (p == nvme_ctrlr->active_path_id) {
/* This is the active path in use right now. The active path is always the first in the list. */ /* This is the active path in use right now. The active path is always the first in the list. */
if (!TAILQ_NEXT(p, link)) { if (!TAILQ_NEXT(p, link)) {
/* The current path is the only path. */ /* The current path is the only path. */
rc = bdev_nvme_delete_ctrlr(nvme_ctrlr, false); rc = bdev_nvme_delete_ctrlr(nvme_ctrlr, false);
@ -5405,6 +5390,38 @@ bdev_nvme_delete(const char *name, const struct nvme_path_id *path_id)
return rc; return rc;
} }
} }
return rc;
}
int
bdev_nvme_delete(const char *name, const struct nvme_path_id *path_id)
{
struct nvme_bdev_ctrlr *nbdev_ctrlr;
struct nvme_ctrlr *nvme_ctrlr, *tmp_nvme_ctrlr;
int rc = -ENXIO, _rc;
if (name == NULL || path_id == NULL) {
return -EINVAL;
}
nbdev_ctrlr = nvme_bdev_ctrlr_get_by_name(name);
if (nbdev_ctrlr == NULL) {
SPDK_ERRLOG("Failed to find NVMe bdev controller\n");
return -ENODEV;
}
TAILQ_FOREACH_SAFE(nvme_ctrlr, &nbdev_ctrlr->ctrlrs, tailq, tmp_nvme_ctrlr) {
_rc = _bdev_nvme_delete(nvme_ctrlr, path_id);
if (_rc < 0 && _rc != -ENXIO) {
return _rc;
} else if (_rc == 0) {
/* We traverse all remaining nvme_ctrlrs even if one nvme_ctrlr
* was deleted successfully. To remember the successful deletion,
* overwrite rc only if _rc is zero.
*/
rc = 0;
}
} }
/* All nvme_ctrlrs were deleted or no nvme_ctrlr which had the trid was found. */ /* All nvme_ctrlrs were deleted or no nvme_ctrlr which had the trid was found. */