diff --git a/module/bdev/nvme/bdev_nvme.c b/module/bdev/nvme/bdev_nvme.c index 650d88a3d3..ef6b3415ea 100644 --- a/module/bdev/nvme/bdev_nvme.c +++ b/module/bdev/nvme/bdev_nvme.c @@ -1151,6 +1151,25 @@ bdev_nvme_get_module_ctx(void *ctx) return bdev_nvme_get_ctrlr(&nvme_bdev->disk); } +static const char * +_nvme_ana_state_str(enum spdk_nvme_ana_state ana_state) +{ + switch (ana_state) { + case SPDK_NVME_ANA_OPTIMIZED_STATE: + return "optimized"; + case SPDK_NVME_ANA_NON_OPTIMIZED_STATE: + return "non_optimized"; + case SPDK_NVME_ANA_INACCESSIBLE_STATE: + return "inaccessible"; + case SPDK_NVME_ANA_PERSISTENT_LOSS_STATE: + return "persistent_loss"; + case SPDK_NVME_ANA_CHANGE_STATE: + return "change"; + default: + return NULL; + } +} + static int bdev_nvme_dump_info_json(void *ctx, struct spdk_json_write_ctx *w) { @@ -1250,6 +1269,11 @@ bdev_nvme_dump_info_json(void *ctx, struct spdk_json_write_ctx *w) spdk_json_write_named_uint32(w, "id", spdk_nvme_ns_get_id(ns)); + if (cdata->cmic.ana_reporting) { + spdk_json_write_named_string(w, "ana_state", + _nvme_ana_state_str(spdk_nvme_ns_get_ana_state(ns))); + } + spdk_json_write_object_end(w); if (cdata->oacs.security) { diff --git a/test/unit/lib/bdev/nvme/bdev_nvme.c/bdev_nvme_ut.c b/test/unit/lib/bdev/nvme/bdev_nvme.c/bdev_nvme_ut.c index c9f082c15a..271ad4bcfa 100644 --- a/test/unit/lib/bdev/nvme/bdev_nvme.c/bdev_nvme_ut.c +++ b/test/unit/lib/bdev/nvme/bdev_nvme.c/bdev_nvme_ut.c @@ -127,6 +127,9 @@ DEFINE_STUB(spdk_nvme_ns_get_dealloc_logical_block_read_value, DEFINE_STUB(spdk_nvme_ns_get_optimal_io_boundary, uint32_t, (struct spdk_nvme_ns *ns), 0); +DEFINE_STUB(spdk_nvme_ns_get_ana_state, enum spdk_nvme_ana_state, + (const struct spdk_nvme_ns *ns), 0); + DEFINE_STUB(spdk_nvme_ns_get_csi, enum spdk_nvme_csi, (const struct spdk_nvme_ns *ns), 0);