Commit 3eb0b6b1 authored by Shuhei Matsumoto's avatar Shuhei Matsumoto Committed by Tomasz Zawadzki
Browse files

bdev/nvme: Factor out the common part of remove_cb() and bdev_nvme_delete()



By adding the second parameter, hotplug, factor out the common part
of remove_cb() and bdev_nvme_delete() into a helper function
_bdev_nvme_delete().

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


Community-CI: Broadcom CI
Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@mellanox.com>
parent 620e0ea0
Loading
Loading
Loading
Loading
+29 −26
Original line number Diff line number Diff line
@@ -1680,21 +1680,44 @@ _nvme_bdev_ctrlr_destruct(void *ctx)
	nvme_bdev_ctrlr_destruct(nvme_bdev_ctrlr);
}

static void
remove_cb(void *cb_ctx, struct spdk_nvme_ctrlr *ctrlr)
static int
_bdev_nvme_delete(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr, bool hotplug)
{
	struct nvme_bdev_ctrlr *nvme_bdev_ctrlr = cb_ctx;
	struct nvme_probe_skip_entry *entry;

	pthread_mutex_lock(&g_bdev_nvme_mutex);
	assert(nvme_bdev_ctrlr->ctrlr == ctrlr);

	/* The controller's destruction was already started */
	if (nvme_bdev_ctrlr->destruct) {
		pthread_mutex_unlock(&g_bdev_nvme_mutex);
		return;
		return 0;
	}

	if (!hotplug &&
	    nvme_bdev_ctrlr->connected_trid->trtype == SPDK_NVME_TRANSPORT_PCIE) {
		entry = calloc(1, sizeof(*entry));
		if (!entry) {
			pthread_mutex_unlock(&g_bdev_nvme_mutex);
			return -ENOMEM;
		}
		entry->trid = *nvme_bdev_ctrlr->connected_trid;
		TAILQ_INSERT_TAIL(&g_skipped_nvme_ctrlrs, entry, tailq);
	}

	nvme_bdev_ctrlr->destruct = true;
	pthread_mutex_unlock(&g_bdev_nvme_mutex);

	_nvme_bdev_ctrlr_destruct(nvme_bdev_ctrlr);

	return 0;
}

static void
remove_cb(void *cb_ctx, struct spdk_nvme_ctrlr *ctrlr)
{
	struct nvme_bdev_ctrlr *nvme_bdev_ctrlr = cb_ctx;

	_bdev_nvme_delete(nvme_bdev_ctrlr, true);
}

static int
@@ -2143,7 +2166,6 @@ int
bdev_nvme_delete(const char *name)
{
	struct nvme_bdev_ctrlr *nvme_bdev_ctrlr;
	struct nvme_probe_skip_entry *entry;

	if (name == NULL) {
		return -EINVAL;
@@ -2158,28 +2180,9 @@ bdev_nvme_delete(const char *name)
		return -ENODEV;
	}

	/* The controller's destruction was already started */
	if (nvme_bdev_ctrlr->destruct) {
		pthread_mutex_unlock(&g_bdev_nvme_mutex);
		return 0;
	}

	if (nvme_bdev_ctrlr->connected_trid->trtype == SPDK_NVME_TRANSPORT_PCIE) {
		entry = calloc(1, sizeof(*entry));
		if (!entry) {
			pthread_mutex_unlock(&g_bdev_nvme_mutex);
			return -ENOMEM;
		}
		entry->trid = *nvme_bdev_ctrlr->connected_trid;
		TAILQ_INSERT_TAIL(&g_skipped_nvme_ctrlrs, entry, tailq);
	}

	nvme_bdev_ctrlr->destruct = true;
	pthread_mutex_unlock(&g_bdev_nvme_mutex);

	_nvme_bdev_ctrlr_destruct(nvme_bdev_ctrlr);

	return 0;
	return _bdev_nvme_delete(nvme_bdev_ctrlr, false);
}

static int