Commit ca4dfff9 authored by Shuhei Matsumoto's avatar Shuhei Matsumoto Committed by Tomasz Zawadzki
Browse files

bdev/nvme: Replace nvme_bdev_first/next_ctrlr() by nvme_ctrlr_for_each()



Replace two helper functions, nvme_bdev_first_ctrlr() and
nvme_bdev_next_ctrlr() by an new helper function nvme_ctrlr_for_each().

This will make us easier to guard data structure correctly in the
following patches.

Signed-off-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: Ibd81286e454fd6127fd150a7d48d8381bd1b89d3
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/8721


Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@mellanox.com>
parent 4af68ead
Loading
Loading
Loading
Loading
+4 −6
Original line number Diff line number Diff line
@@ -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);
+6 −8
Original line number Diff line number Diff line
@@ -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
+4 −2
Original line number Diff line number Diff line
@@ -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);