bdev/nvme: per-namespace config_json callback

Added per-namespace config_json callbacks, so that each namespace can
dump its own configuration.  This is a nop for regular NVMe namespaces,
but it will be used by Open Channel ones to save their bdev configuration.

The callbacks are executed after controller configuration has been
saved.  This ensures that when a config is loaded, any namespace related
RPC calls (e.g. creating bdevs) are run after associated controller has
already been attached.

Change-Id: Ia18e15b46f10b058c1b6a9b74edb386e1b4874de
Signed-off-by: Konrad Sztyber <konrad.sztyber@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/477436
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Broadcom SPDK FC-NVMe CI <spdk-ci.pdl@broadcom.com>
Community-CI: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
Konrad Sztyber 2019-12-10 10:27:02 +01:00 committed by Tomasz Zawadzki
parent 0468ce5343
commit ba4b326cda

View File

@ -163,6 +163,18 @@ static depopulate_namespace_fn g_depopulate_namespace_fn[] = {
bdev_ocssd_depopulate_namespace,
};
typedef void (*config_json_namespace_fn)(struct spdk_json_write_ctx *w, struct nvme_bdev_ns *ns);
static void nvme_ctrlr_config_json_standard_namespace(struct spdk_json_write_ctx *w,
struct nvme_bdev_ns *ns);
static void nvme_ctrlr_config_json_ocssd_namespace(struct spdk_json_write_ctx *w,
struct nvme_bdev_ns *ns);
static config_json_namespace_fn g_config_json_namespace_fn[] = {
NULL,
nvme_ctrlr_config_json_standard_namespace,
nvme_ctrlr_config_json_ocssd_namespace,
};
struct spdk_nvme_qpair *
spdk_bdev_nvme_get_io_qpair(struct spdk_io_channel *ctrlr_io_ch)
{
@ -2261,12 +2273,31 @@ bdev_nvme_get_spdk_running_config(FILE *fp)
fprintf(fp, "\n");
}
static void
nvme_ctrlr_config_json_standard_namespace(struct spdk_json_write_ctx *w, struct nvme_bdev_ns *ns)
{
/* nop */
}
static void
nvme_ctrlr_config_json_ocssd_namespace(struct spdk_json_write_ctx *w, struct nvme_bdev_ns *ns)
{
/* nop */
}
static void
nvme_namespace_config_json(struct spdk_json_write_ctx *w, struct nvme_bdev_ns *ns)
{
g_config_json_namespace_fn[ns->type](w, ns);
}
static int
bdev_nvme_config_json(struct spdk_json_write_ctx *w)
{
struct nvme_bdev_ctrlr *nvme_bdev_ctrlr;
struct spdk_nvme_transport_id *trid;
const char *action;
uint32_t nsid;
if (g_opts.action_on_timeout == SPDK_BDEV_NVME_TIMEOUT_ACTION_RESET) {
action = "reset";
@ -2319,6 +2350,14 @@ bdev_nvme_config_json(struct spdk_json_write_ctx *w)
spdk_json_write_object_end(w);
spdk_json_write_object_end(w);
for (nsid = 0; nsid < nvme_bdev_ctrlr->num_ns; ++nsid) {
if (!nvme_bdev_ctrlr->namespaces[nsid]->populated) {
continue;
}
nvme_namespace_config_json(w, nvme_bdev_ctrlr->namespaces[nsid]);
}
}
/* Dump as last parameter to give all NVMe bdevs chance to be constructed