From 0143ff6b13b1842801eb623e27b46410176e879a Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Sun, 10 Feb 2019 17:20:40 +0900 Subject: [PATCH] bdev/nvme: Set per-controller prchk options by .INI config file Add "prchk:reftag|guard" to the 3rd item of the TransportID row in [Nvme] section. apptag is not supported yet as same as JSON RPC. These two patches cannot control hot added NVMe controllers, but we should not set prchk options to hot added NVMe controllers automatically. Hence the next patch will document this behavior explicitly. Change-Id: I74a73ac52779aa50c5b45e20ffb61002e95f33ef Signed-off-by: Shuhei Matsumoto Reviewed-on: https://review.gerrithub.io/c/443835 Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Changpeng Liu Reviewed-by: Darek Stojaczyk --- lib/bdev/nvme/bdev_nvme.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/lib/bdev/nvme/bdev_nvme.c b/lib/bdev/nvme/bdev_nvme.c index 61480a5f4..80859347c 100644 --- a/lib/bdev/nvme/bdev_nvme.c +++ b/lib/bdev/nvme/bdev_nvme.c @@ -92,6 +92,7 @@ struct nvme_probe_ctx { struct spdk_nvme_transport_id trids[NVME_MAX_CONTROLLERS]; struct spdk_nvme_host_id hostids[NVME_MAX_CONTROLLERS]; const char *names[NVME_MAX_CONTROLLERS]; + uint32_t prchk_flags[NVME_MAX_CONTROLLERS]; const char *hostnqn; }; @@ -1074,11 +1075,13 @@ attach_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid, { struct nvme_probe_ctx *ctx = cb_ctx; char *name = NULL; + uint32_t prchk_flags = 0; size_t i; if (ctx) { for (i = 0; i < ctx->count; i++) { if (spdk_nvme_transport_id_compare(trid, &ctx->trids[i]) == 0) { + prchk_flags = ctx->prchk_flags[i]; name = strdup(ctx->names[i]); break; } @@ -1093,7 +1096,7 @@ attach_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid, SPDK_DEBUGLOG(SPDK_LOG_BDEV_NVME, "Attached to %s (%s)\n", trid->traddr, name); - create_ctrlr(ctrlr, name, trid, 0); + create_ctrlr(ctrlr, name, trid, prchk_flags); free(name); } @@ -1428,6 +1431,17 @@ bdev_nvme_library_init(void) } probe_ctx->names[i] = val; + + val = spdk_conf_section_get_nmval(sp, "TransportID", i, 2); + if (val != NULL) { + rc = spdk_nvme_prchk_flags_parse(&probe_ctx->prchk_flags[i], val); + if (rc < 0) { + SPDK_ERRLOG("Unable to parse prchk: %s\n", val); + rc = -1; + goto end; + } + } + probe_ctx->count++; if (probe_ctx->trids[i].trtype != SPDK_NVME_TRANSPORT_PCIE) { @@ -1799,6 +1813,7 @@ bdev_nvme_get_spdk_running_config(FILE *fp) TAILQ_FOREACH(nvme_ctrlr, &g_nvme_ctrlrs, tailq) { const char *trtype; + const char *prchk_flags; trtype = spdk_nvme_transport_id_trtype_str(nvme_ctrlr->trid.trtype); if (!trtype) { @@ -1813,19 +1828,25 @@ bdev_nvme_get_spdk_running_config(FILE *fp) const char *adrfam; adrfam = spdk_nvme_transport_id_adrfam_str(nvme_ctrlr->trid.adrfam); + prchk_flags = spdk_nvme_prchk_flags_str(nvme_ctrlr->prchk_flags); if (adrfam) { - fprintf(fp, "TransportID \"trtype:%s adrfam:%s traddr:%s trsvcid:%s subnqn:%s\" %s\n", + fprintf(fp, "TransportID \"trtype:%s adrfam:%s traddr:%s trsvcid:%s subnqn:%s\" %s", trtype, adrfam, nvme_ctrlr->trid.traddr, nvme_ctrlr->trid.trsvcid, nvme_ctrlr->trid.subnqn, nvme_ctrlr->name); } else { - fprintf(fp, "TransportID \"trtype:%s traddr:%s trsvcid:%s subnqn:%s\" %s\n", + fprintf(fp, "TransportID \"trtype:%s traddr:%s trsvcid:%s subnqn:%s\" %s", trtype, nvme_ctrlr->trid.traddr, nvme_ctrlr->trid.trsvcid, nvme_ctrlr->trid.subnqn, nvme_ctrlr->name); } + if (prchk_flags) { + fprintf(fp, " \"%s\"\n", prchk_flags); + } else { + fprintf(fp, "\n"); + } } }