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) {