From 3befb518b0cd0f8c193ce6b024e35ee2488250f5 Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Tue, 22 Sep 2020 23:20:19 +0900 Subject: [PATCH] lib/nvme: Add an internal API nvme_ctrlr_parse_ana_log_page() Add an internal API nvme_ctrlr_parse_ana_log_page() to parse an ANA log page and execute the specified callback function for each ANA group descriptor in the ANA log page. We will be able to copy the ANA group descriptor to the caller instead. To do that, we will need to inform the size of the descriptor first, but the size will not be constant. Passing parser to the API will be more convenient. Signed-off-by: Shuhei Matsumoto Change-Id: Ifd8fda30a83965948017fb8ad992c0d889197cde Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/4279 Tested-by: SPDK CI Jenkins Reviewed-by: Ben Walker Reviewed-by: Aleksey Marchuk --- lib/nvme/nvme_ctrlr.c | 26 ++++++++++++++++++++++++++ lib/nvme/nvme_internal.h | 5 +++++ 2 files changed, 31 insertions(+) diff --git a/lib/nvme/nvme_ctrlr.c b/lib/nvme/nvme_ctrlr.c index 5f6626dad..ce33f9290 100644 --- a/lib/nvme/nvme_ctrlr.c +++ b/lib/nvme/nvme_ctrlr.c @@ -725,6 +725,32 @@ nvme_ctrlr_init_ana_log_page(struct spdk_nvme_ctrlr *ctrlr) return nvme_ctrlr_update_ana_log_page(ctrlr); } +int +nvme_ctrlr_parse_ana_log_page(struct spdk_nvme_ctrlr *ctrlr, + spdk_nvme_parse_ana_log_page_cb cb_fn, void *cb_arg) +{ + struct spdk_nvme_ana_group_descriptor *desc; + uint32_t i; + int rc = 0; + + if (ctrlr->ana_log_page == NULL) { + return -EINVAL; + } + + desc = (void *)((uint8_t *)ctrlr->ana_log_page + sizeof(struct spdk_nvme_ana_page)); + + for (i = 0; i < ctrlr->ana_log_page->num_ana_group_desc; i++) { + rc = cb_fn(desc, cb_arg); + if (rc != 0) { + break; + } + desc = (void *)((uint8_t *)desc + sizeof(struct spdk_nvme_ana_group_descriptor) + + desc->num_of_nsid * sizeof(uint32_t)); + } + + return rc; +} + static int nvme_ctrlr_set_supported_log_pages(struct spdk_nvme_ctrlr *ctrlr) { diff --git a/lib/nvme/nvme_internal.h b/lib/nvme/nvme_internal.h index d705ee9ae..ba54da1a4 100644 --- a/lib/nvme/nvme_internal.h +++ b/lib/nvme/nvme_internal.h @@ -972,6 +972,11 @@ int nvme_fabric_ctrlr_discover(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_probe_ctx *probe_ctx); int nvme_fabric_qpair_connect(struct spdk_nvme_qpair *qpair, uint32_t num_entries); +typedef int (*spdk_nvme_parse_ana_log_page_cb)( + const struct spdk_nvme_ana_group_descriptor *desc, void *cb_arg); +int nvme_ctrlr_parse_ana_log_page(struct spdk_nvme_ctrlr *ctrlr, + spdk_nvme_parse_ana_log_page_cb cb_fn, void *cb_arg); + static inline struct nvme_request * nvme_allocate_request(struct spdk_nvme_qpair *qpair, const struct nvme_payload *payload, uint32_t payload_size, uint32_t md_size,