Commit 528cec83 authored by Shuhei Matsumoto's avatar Shuhei Matsumoto Committed by Tomasz Zawadzki
Browse files

bdev/nvme: Merge decrementing ref. count into nvme_bdev_ctrlr_destruct()



For further simplification, merge decrementing reference count of
nvme_bdev_ctrlr into nvme_bdev_ctrlr_destruct().

Signed-off-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: I604039c3f38a60b316ae465d4649e9eb11bfb6cc
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/5573


Community-CI: Broadcom CI
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
parent 2caff467
Loading
Loading
Loading
Loading
+2 −22
Original line number Diff line number Diff line
@@ -1313,17 +1313,7 @@ nvme_ctrlr_depopulate_namespace_done(struct nvme_bdev_ns *nvme_ns)
{
	struct nvme_bdev_ctrlr *nvme_bdev_ctrlr = nvme_ns->ctrlr;

	pthread_mutex_lock(&g_bdev_nvme_mutex);
	assert(nvme_bdev_ctrlr->ref > 0);
	nvme_bdev_ctrlr->ref--;

	if (nvme_bdev_ctrlr->ref == 0 && nvme_bdev_ctrlr->destruct) {
		pthread_mutex_unlock(&g_bdev_nvme_mutex);
	nvme_bdev_ctrlr_destruct(nvme_bdev_ctrlr);
		return;
	}

	pthread_mutex_unlock(&g_bdev_nvme_mutex);
}

static void
@@ -1650,17 +1640,7 @@ _nvme_bdev_ctrlr_destruct(void *ctx)
	struct nvme_bdev_ctrlr *nvme_bdev_ctrlr = ctx;

	nvme_ctrlr_depopulate_namespaces(nvme_bdev_ctrlr);

	pthread_mutex_lock(&g_bdev_nvme_mutex);
	assert(nvme_bdev_ctrlr->ref > 0);
	nvme_bdev_ctrlr->ref--;
	if (nvme_bdev_ctrlr->ref == 0) {
		pthread_mutex_unlock(&g_bdev_nvme_mutex);

	nvme_bdev_ctrlr_destruct(nvme_bdev_ctrlr);
	} else {
		pthread_mutex_unlock(&g_bdev_nvme_mutex);
	}
}

static void
+9 −13
Original line number Diff line number Diff line
@@ -168,13 +168,17 @@ nvme_bdev_ctrlr_do_destruct(void *ctx)
void
nvme_bdev_ctrlr_destruct(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr)
{
	assert(nvme_bdev_ctrlr->destruct);

	pthread_mutex_lock(&g_bdev_nvme_mutex);
	if (nvme_bdev_ctrlr->resetting) {

	assert(nvme_bdev_ctrlr->ref > 0);
	nvme_bdev_ctrlr->ref--;

	if (nvme_bdev_ctrlr->ref > 0 || !nvme_bdev_ctrlr->destruct ||
	    nvme_bdev_ctrlr->resetting) {
		pthread_mutex_unlock(&g_bdev_nvme_mutex);
		return;
	}

	pthread_mutex_unlock(&g_bdev_nvme_mutex);

	nvme_bdev_ctrlr_do_destruct(nvme_bdev_ctrlr);
@@ -196,16 +200,8 @@ nvme_bdev_detach_bdev_from_ns(struct nvme_bdev *nvme_disk)
	struct nvme_bdev_ctrlr *ctrlr = nvme_disk->nvme_ns->ctrlr;

	pthread_mutex_lock(&g_bdev_nvme_mutex);
	assert(ctrlr->ref > 0);
	ctrlr->ref--;

	TAILQ_REMOVE(&nvme_disk->nvme_ns->bdevs, nvme_disk, tailq);

	if (ctrlr->ref == 0 && ctrlr->destruct) {
	pthread_mutex_unlock(&g_bdev_nvme_mutex);
		nvme_bdev_ctrlr_destruct(ctrlr);
		return;
	}

	pthread_mutex_unlock(&g_bdev_nvme_mutex);
	nvme_bdev_ctrlr_destruct(ctrlr);
}
+1 −8
Original line number Diff line number Diff line
@@ -199,13 +199,8 @@ nvme_ctrlr_depopulate_namespace_done(struct nvme_bdev_ns *ns)
{
	struct nvme_bdev_ctrlr *ctrlr = ns->ctrlr;

	CU_ASSERT(ctrlr->ref > 0);
	ctrlr->ref--;

	if (ctrlr->ref == 0 && ctrlr->destruct) {
	nvme_bdev_ctrlr_destruct(ctrlr);
}
}

static struct nvme_bdev_ctrlr *
create_nvme_bdev_controller(const struct spdk_nvme_transport_id *trid, const char *name)
@@ -542,8 +537,6 @@ delete_nvme_bdev_controller(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr)
		bdev_ocssd_depopulate_namespace(nvme_bdev_ctrlr->namespaces[nsid]);
	}

	CU_ASSERT(nvme_bdev_ctrlr->ref == 1);
	nvme_bdev_ctrlr->ref--;
	nvme_bdev_ctrlr_destruct(nvme_bdev_ctrlr);
	spdk_delay_us(1000);