Commit 6a13d857 authored by Jim Harris's avatar Jim Harris Committed by Tomasz Zawadzki
Browse files

bdev/nvme: add per-ns-type populate/depopulate func ptrs



The OCSSD ones are just nops for now.

Signed-off-by: default avatarJim Harris <james.r.harris@intel.com>
Change-Id: Iab87bd8110dac2ba2f81d056f0034a53818e2b17

Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/475799


Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent d1f88939
Loading
Loading
Loading
Loading
+49 −6
Original line number Diff line number Diff line
@@ -146,10 +146,31 @@ static int bdev_nvme_io_passthru(struct nvme_bdev *nbdev, struct spdk_io_channel
static int bdev_nvme_io_passthru_md(struct nvme_bdev *nbdev, struct spdk_io_channel *ch,
				    struct nvme_bdev_io *bio,
				    struct spdk_nvme_cmd *cmd, void *buf, size_t nbytes, void *md_buf, size_t md_len);
static int nvme_ctrlr_populate_namespace(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr,
		struct nvme_bdev_ns *nvme_ns);
static int bdev_nvme_reset(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr, struct nvme_bdev_io *bio);

typedef int (*populate_namespace_fn)(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr,
				     struct nvme_bdev_ns *nvme_ns);
static int nvme_ctrlr_populate_standard_namespace(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr,
		struct nvme_bdev_ns *nvme_ns);
static int nvme_ctrlr_populate_ocssd_namespace(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr,
		struct nvme_bdev_ns *nvme_ns);

static populate_namespace_fn g_populate_namespace_fn[] = {
	NULL,
	nvme_ctrlr_populate_standard_namespace,
	nvme_ctrlr_populate_ocssd_namespace,
};

typedef void (*depopulate_namespace_fn)(struct nvme_bdev_ns *ns);
static void nvme_ctrlr_depopulate_standard_namespace(struct nvme_bdev_ns *ns);
static void nvme_ctrlr_depopulate_ocssd_namespace(struct nvme_bdev_ns *ns);

static depopulate_namespace_fn g_depopulate_namespace_fn[] = {
	NULL,
	nvme_ctrlr_depopulate_standard_namespace,
	nvme_ctrlr_depopulate_ocssd_namespace,
};

struct spdk_nvme_qpair *
spdk_bdev_nvme_get_io_qpair(struct spdk_io_channel *ctrlr_io_ch)
{
@@ -816,7 +837,8 @@ static const struct spdk_bdev_fn_table nvmelib_fn_table = {
};

static int
nvme_ctrlr_populate_namespace(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr, struct nvme_bdev_ns *nvme_ns)
nvme_ctrlr_populate_standard_namespace(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr,
				       struct nvme_bdev_ns *nvme_ns)
{
	struct spdk_nvme_ctrlr	*ctrlr = nvme_bdev_ctrlr->ctrlr;
	struct nvme_bdev	*bdev;
@@ -894,6 +916,12 @@ nvme_ctrlr_populate_namespace(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr, struct nv
	return 0;
}

static int
nvme_ctrlr_populate_ocssd_namespace(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr,
				    struct nvme_bdev_ns *nvme_ns)
{
	return 0;
}

static bool
hotplug_probe_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid,
@@ -1021,7 +1049,7 @@ timeout_cb(void *cb_arg, struct spdk_nvme_ctrlr *ctrlr,
}

static void
nvme_ctrlr_depopulate_namespace(struct nvme_bdev_ns *ns)
nvme_ctrlr_depopulate_standard_namespace(struct nvme_bdev_ns *ns)
{
	struct nvme_bdev *bdev, *tmp;

@@ -1032,6 +1060,21 @@ nvme_ctrlr_depopulate_namespace(struct nvme_bdev_ns *ns)
	ns->populated = false;
}

static void
nvme_ctrlr_depopulate_ocssd_namespace(struct nvme_bdev_ns *ns)
{
}

static int nvme_ctrlr_populate_namespace(struct nvme_bdev_ctrlr *ctrlr, struct nvme_bdev_ns *ns)
{
	return g_populate_namespace_fn[ns->type](ctrlr, ns);
}

static void nvme_ctrlr_depopulate_namespace(struct nvme_bdev_ctrlr *ctrlr, struct nvme_bdev_ns *ns)
{
	g_depopulate_namespace_fn[ns->type](ns);
}

static void
nvme_ctrlr_populate_namespaces(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr)
{
@@ -1064,7 +1107,7 @@ nvme_ctrlr_populate_namespaces(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr)
		}

		if (ns->populated && !spdk_nvme_ctrlr_is_active_ns(ctrlr, nsid)) {
			nvme_ctrlr_depopulate_namespace(ns);
			nvme_ctrlr_depopulate_namespace(nvme_bdev_ctrlr, ns);
		}
	}

@@ -1226,7 +1269,7 @@ remove_cb(void *cb_ctx, struct spdk_nvme_ctrlr *ctrlr)
				ns = nvme_bdev_ctrlr->namespaces[nsid - 1];
				if (ns->populated) {
					assert(ns->id == nsid);
					nvme_ctrlr_depopulate_namespace(ns);
					nvme_ctrlr_depopulate_namespace(nvme_bdev_ctrlr, ns);
				}
			}