Commit a51f4d49 authored by Jim Harris's avatar Jim Harris Committed by Tomasz Zawadzki
Browse files

nvme: add lock_depth for ctrlr_lock



This supplements checking pthread_mutex_destroy() return code for
detecting if the ctrlr lock is destroy while it is held. At least
on some systems, pthread_mutex_destroy() returns success even if
the lock is currently held.

Note: this is part of patch series that reproduced issue #3401,
and this patch reliably catches that the lock is held when
destroyed after a controller loss timeout from the bdev nvme module.

Signed-off-by: default avatarJim Harris <jim.harris@samsung.com>
Change-Id: Id2a4e3dd9f5d52b3038143ff9c0dceb779b55b56
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/23735


Community-CI: Mellanox Build Bot
Reviewed-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <smatsumoto@nvidia.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent 6b7c4ce1
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -4211,6 +4211,11 @@ nvme_ctrlr_destruct_finish(struct spdk_nvme_ctrlr *ctrlr)
{
	int rc;

	if (ctrlr->lock_depth > 0) {
		SPDK_ERRLOG("lock currently held (depth=%d)!\n", ctrlr->lock_depth);
		assert(false);
	}

	rc = pthread_mutex_destroy(&ctrlr->ctrlr_lock);
	if (rc) {
		SPDK_ERRLOG("could not destroy ctrlr_lock: %s\n", spdk_strerror(rc));
+8 −1
Original line number Diff line number Diff line
@@ -1034,6 +1034,8 @@ struct spdk_nvme_ctrlr {
	STAILQ_HEAD(, nvme_request)	queued_aborts;
	uint32_t			outstanding_aborts;

	uint32_t			lock_depth;

	/* CB to notify the user when the ctrlr is removed/failed. */
	spdk_nvme_remove_cb			remove_cb;
	void					*cb_ctx;
@@ -1165,7 +1167,11 @@ nvme_robust_mutex_lock(pthread_mutex_t *mtx)
static inline int
nvme_ctrlr_lock(struct spdk_nvme_ctrlr *ctrlr)
{
	return nvme_robust_mutex_lock(&ctrlr->ctrlr_lock);
	int rc;

	rc = nvme_robust_mutex_lock(&ctrlr->ctrlr_lock);
	ctrlr->lock_depth++;
	return rc;
}

static inline int
@@ -1177,6 +1183,7 @@ nvme_robust_mutex_unlock(pthread_mutex_t *mtx)
static inline int
nvme_ctrlr_unlock(struct spdk_nvme_ctrlr *ctrlr)
{
	ctrlr->lock_depth--;
	return nvme_robust_mutex_unlock(&ctrlr->ctrlr_lock);
}