Commit 8db3c5cc authored by Jacek Kalwas's avatar Jacek Kalwas Committed by Tomasz Zawadzki
Browse files

bdev/nvme: make nvme_ctrlr's mutex recursive



Wider critical sections are needed, and unlocking/locking again is not
always possible due to potential thread races.

With recursive mutex, there is also no need to define _unsafe
equivalents of some functions.

Change-Id: I2cecaae9e318c3bc2f1d313c87356e09cbae59db
Signed-off-by: default avatarJacek Kalwas <jacek.kalwas@nutanix.com>
Reviewed-on: https://review.spdk.io/c/spdk/spdk/+/26929


Tested-by: default avatarSPDK Automated Test System <spdkbot@gmail.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarShuhei Matsumoto <smatsumoto@nvidia.com>
Reviewed-by: default avatarJim Harris <jim.harris@nvidia.com>
parent 3df67370
Loading
Loading
Loading
Loading
+19 −1
Original line number Diff line number Diff line
@@ -5976,6 +5976,24 @@ exit:
	return rc;
}

static int
nvme_ctrlr_mutex_init(pthread_mutex_t *mtx)
{
	pthread_mutexattr_t attr;
	int rc = 0;

	if (pthread_mutexattr_init(&attr)) {
		return -1;
	}

	if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) || pthread_mutex_init(mtx, &attr)) {
		rc = -1;
	}

	pthread_mutexattr_destroy(&attr);
	return rc;
}

static int
nvme_ctrlr_create(struct spdk_nvme_ctrlr *ctrlr,
		  const char *name,
@@ -5997,7 +6015,7 @@ nvme_ctrlr_create(struct spdk_nvme_ctrlr *ctrlr,
		return -ENOMEM;
	}

	rc = pthread_mutex_init(&nvme_ctrlr->mutex, NULL);
	rc = nvme_ctrlr_mutex_init(&nvme_ctrlr->mutex);
	if (rc != 0) {
		free(nvme_ctrlr);
		return rc;