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:
parent
8173930051
commit
422f5f3d11
@ -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,13 +5358,48 @@ nvme_path_should_delete(struct nvme_path_id *p, const struct nvme_path_id *path_
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
_bdev_nvme_delete(struct nvme_ctrlr *nvme_ctrlr, const struct nvme_path_id *path_id)
|
||||||
|
{
|
||||||
|
struct nvme_path_id *p, *t;
|
||||||
|
int rc = -ENXIO;
|
||||||
|
|
||||||
|
TAILQ_FOREACH_REVERSE_SAFE(p, &nvme_ctrlr->trids, nvme_paths, link, t) {
|
||||||
|
if (!nvme_path_should_delete(p, path_id)) {
|
||||||
|
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) {
|
||||||
|
/* This is the active path in use right now. The active path is always the first in the list. */
|
||||||
|
if (!TAILQ_NEXT(p, link)) {
|
||||||
|
/* The current path is the only path. */
|
||||||
|
rc = bdev_nvme_delete_ctrlr(nvme_ctrlr, false);
|
||||||
|
} else {
|
||||||
|
/* There is an alternative path. */
|
||||||
|
rc = bdev_nvme_failover(nvme_ctrlr, true);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/* We are not using the specified path. */
|
||||||
|
TAILQ_REMOVE(&nvme_ctrlr->trids, p, link);
|
||||||
|
free(p);
|
||||||
|
rc = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rc < 0 && rc != -ENXIO) {
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
bdev_nvme_delete(const char *name, const struct nvme_path_id *path_id)
|
bdev_nvme_delete(const char *name, const struct nvme_path_id *path_id)
|
||||||
{
|
{
|
||||||
struct nvme_bdev_ctrlr *nbdev_ctrlr;
|
struct nvme_bdev_ctrlr *nbdev_ctrlr;
|
||||||
struct nvme_ctrlr *nvme_ctrlr, *tmp_nvme_ctrlr;
|
struct nvme_ctrlr *nvme_ctrlr, *tmp_nvme_ctrlr;
|
||||||
struct nvme_path_id *p, *t;
|
int rc = -ENXIO, _rc;
|
||||||
int rc = -ENXIO;
|
|
||||||
|
|
||||||
if (name == NULL || path_id == NULL) {
|
if (name == NULL || path_id == NULL) {
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
@ -5378,32 +5412,15 @@ 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_SAFE(nvme_ctrlr, &nbdev_ctrlr->ctrlrs, tailq, tmp_nvme_ctrlr) {
|
||||||
TAILQ_FOREACH_REVERSE_SAFE(p, &nvme_ctrlr->trids, nvme_paths, link, t) {
|
_rc = _bdev_nvme_delete(nvme_ctrlr, path_id);
|
||||||
if (!nvme_path_should_delete(p, path_id)) {
|
if (_rc < 0 && _rc != -ENXIO) {
|
||||||
continue;
|
return _rc;
|
||||||
}
|
} else if (_rc == 0) {
|
||||||
|
/* We traverse all remaining nvme_ctrlrs even if one nvme_ctrlr
|
||||||
/* If we made it here, then this path is a match! Now we need to remove it. */
|
* was deleted successfully. To remember the successful deletion,
|
||||||
if (p == nvme_ctrlr->active_path_id) {
|
* overwrite rc only if _rc is zero.
|
||||||
/* This is the active path in use right now. The active path is always the first in the list. */
|
*/
|
||||||
|
rc = 0;
|
||||||
if (!TAILQ_NEXT(p, link)) {
|
|
||||||
/* The current path is the only path. */
|
|
||||||
rc = bdev_nvme_delete_ctrlr(nvme_ctrlr, false);
|
|
||||||
} else {
|
|
||||||
/* There is an alternative path. */
|
|
||||||
rc = bdev_nvme_failover(nvme_ctrlr, true);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
/* We are not using the specified path. */
|
|
||||||
TAILQ_REMOVE(&nvme_ctrlr->trids, p, link);
|
|
||||||
free(p);
|
|
||||||
rc = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rc < 0 && rc != -ENXIO) {
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user