From 7d3771f93c86f59a2e065d178482a6ff0e936933 Mon Sep 17 00:00:00 2001 From: Seth Howell Date: Thu, 17 Oct 2019 16:23:43 -0700 Subject: [PATCH] nvme_ctrlr: add get/set for ctrlr->is_failed. These will be useful helper functions for the trid modification code that gets introduced later. Change-Id: Ief73e3045710bf35c511794c19b4dfefb93018f1 Signed-off-by: Seth Howell Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/471780 Tested-by: SPDK CI Jenkins Reviewed-by: Shuhei Matsumoto Reviewed-by: Jim Harris --- include/spdk/nvme.h | 25 +++++++++++++++++++++++++ lib/nvme/nvme_ctrlr.c | 19 +++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/include/spdk/nvme.h b/include/spdk/nvme.h index f5d120226..4e44c926d 100644 --- a/include/spdk/nvme.h +++ b/include/spdk/nvme.h @@ -709,6 +709,31 @@ int spdk_nvme_detach(struct spdk_nvme_ctrlr *ctrlr); */ int spdk_nvme_ctrlr_reset(struct spdk_nvme_ctrlr *ctrlr); +/** + * Fail the given NVMe controller. + * + * This function gives the application the opportunity to fail a controller + * at will. When a controller is failed, any calls to process completions or + * submit I/O on qpairs associated with that controller will fail with an error + * code of -ENXIO. + * The controller can only be taken from the failed state by + * calling spdk_nvme_ctrlr_reset. After the controller has been successfully + * reset, any I/O pending when the controller was moved to failed will be + * aborted back to the application and can be resubmitted. I/O can then resume. + * + * \param ctrlr Opaque handle to an NVMe controller. + */ +void spdk_nvme_ctrlr_fail(struct spdk_nvme_ctrlr *ctrlr); + +/** + * This function returns the failed status of a given controller. + * + * \param ctrlr Opaque handle to an NVMe controller. + * + * \return True if the controller is failed, false otherwise. + */ +bool spdk_nvme_ctrlr_is_failed(struct spdk_nvme_ctrlr *ctrlr); + /** * Get the identify controller data as defined by the NVMe specification. * diff --git a/lib/nvme/nvme_ctrlr.c b/lib/nvme/nvme_ctrlr.c index 6bbdeaf5b..953f22a28 100644 --- a/lib/nvme/nvme_ctrlr.c +++ b/lib/nvme/nvme_ctrlr.c @@ -629,6 +629,12 @@ nvme_ctrlr_set_supported_features(struct spdk_nvme_ctrlr *ctrlr) nvme_ctrlr_set_arbitration_feature(ctrlr); } +bool +spdk_nvme_ctrlr_is_failed(struct spdk_nvme_ctrlr *ctrlr) +{ + return ctrlr->is_failed; +} + void nvme_ctrlr_fail(struct spdk_nvme_ctrlr *ctrlr, bool hot_remove) { @@ -643,6 +649,19 @@ nvme_ctrlr_fail(struct spdk_nvme_ctrlr *ctrlr, bool hot_remove) SPDK_ERRLOG("ctrlr %s in failed state.\n", ctrlr->trid.traddr); } +/** + * This public API function will try to take the controller lock. + * Any private functions being called from a thread already holding + * the ctrlr lock should call nvme_ctrlr_fail directly. + */ +void +spdk_nvme_ctrlr_fail(struct spdk_nvme_ctrlr *ctrlr) +{ + nvme_robust_mutex_lock(&ctrlr->ctrlr_lock); + nvme_ctrlr_fail(ctrlr, false); + nvme_robust_mutex_unlock(&ctrlr->ctrlr_lock); +} + static void nvme_ctrlr_shutdown(struct spdk_nvme_ctrlr *ctrlr) {