diff --git a/module/bdev/nvme/bdev_nvme_rpc.c b/module/bdev/nvme/bdev_nvme_rpc.c index 90541ecdb..55dcde3c6 100644 --- a/module/bdev/nvme/bdev_nvme_rpc.c +++ b/module/bdev/nvme/bdev_nvme_rpc.c @@ -412,9 +412,9 @@ SPDK_RPC_REGISTER("bdev_nvme_attach_controller", rpc_bdev_nvme_attach_controller SPDK_RPC_REGISTER_ALIAS_DEPRECATED(bdev_nvme_attach_controller, construct_nvme_bdev) static void -rpc_dump_nvme_controller_info(struct spdk_json_write_ctx *w, - struct nvme_ctrlr *nvme_ctrlr) +rpc_dump_nvme_controller_info(struct nvme_ctrlr *nvme_ctrlr, void *ctx) { + struct spdk_json_write_ctx *w = ctx; struct spdk_nvme_transport_id *trid; trid = nvme_ctrlr->connected_trid; @@ -483,11 +483,9 @@ rpc_bdev_nvme_get_controllers(struct spdk_jsonrpc_request *request, spdk_json_write_array_begin(w); if (ctrlr != NULL) { - rpc_dump_nvme_controller_info(w, ctrlr); + rpc_dump_nvme_controller_info(ctrlr, w); } else { - for (ctrlr = nvme_bdev_first_ctrlr(); ctrlr; ctrlr = nvme_bdev_next_ctrlr(ctrlr)) { - rpc_dump_nvme_controller_info(w, ctrlr); - } + nvme_ctrlr_for_each(rpc_dump_nvme_controller_info, w); } spdk_json_write_array_end(w); diff --git a/module/bdev/nvme/common.c b/module/bdev/nvme/common.c index 4e753bc78..634bc7e02 100644 --- a/module/bdev/nvme/common.c +++ b/module/bdev/nvme/common.c @@ -71,16 +71,14 @@ nvme_ctrlr_get_by_name(const char *name) return NULL; } -struct nvme_ctrlr * -nvme_bdev_first_ctrlr(void) +void +nvme_ctrlr_for_each(nvme_ctrlr_for_each_fn fn, void *ctx) { - return TAILQ_FIRST(&g_nvme_ctrlrs); -} + struct nvme_ctrlr *nvme_ctrlr; -struct nvme_ctrlr * -nvme_bdev_next_ctrlr(struct nvme_ctrlr *prev) -{ - return TAILQ_NEXT(prev, tailq); + TAILQ_FOREACH(nvme_ctrlr, &g_nvme_ctrlrs, tailq) { + fn(nvme_ctrlr, ctx); + } } void diff --git a/module/bdev/nvme/common.h b/module/bdev/nvme/common.h index c10c51a9e..e0501e8bc 100644 --- a/module/bdev/nvme/common.h +++ b/module/bdev/nvme/common.h @@ -168,8 +168,10 @@ void nvme_ctrlr_depopulate_namespace_done(struct nvme_ns *nvme_ns); struct nvme_ctrlr *nvme_ctrlr_get(const struct spdk_nvme_transport_id *trid); struct nvme_ctrlr *nvme_ctrlr_get_by_name(const char *name); -struct nvme_ctrlr *nvme_bdev_first_ctrlr(void); -struct nvme_ctrlr *nvme_bdev_next_ctrlr(struct nvme_ctrlr *prev); + +typedef void (*nvme_ctrlr_for_each_fn)(struct nvme_ctrlr *nvme_ctrlr, void *ctx); + +void nvme_ctrlr_for_each(nvme_ctrlr_for_each_fn fn, void *ctx); void nvme_bdev_dump_trid_json(const struct spdk_nvme_transport_id *trid, struct spdk_json_write_ctx *w);