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: Shuhei 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: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
This commit is contained in:
Shuhei Matsumoto 2021-03-04 01:07:18 +09:00 committed by Tomasz Zawadzki
parent 620e0ea043
commit 3eb0b6b167

View File

@ -1680,21 +1680,44 @@ _nvme_bdev_ctrlr_destruct(void *ctx)
nvme_bdev_ctrlr_destruct(nvme_bdev_ctrlr);
}
static int
_bdev_nvme_delete(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr, bool hotplug)
{
struct nvme_probe_skip_entry *entry;
pthread_mutex_lock(&g_bdev_nvme_mutex);
/* The controller's destruction was already started */
if (nvme_bdev_ctrlr->destruct) {
pthread_mutex_unlock(&g_bdev_nvme_mutex);
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;
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;
}
nvme_bdev_ctrlr->destruct = true;
pthread_mutex_unlock(&g_bdev_nvme_mutex);
_nvme_bdev_ctrlr_destruct(nvme_bdev_ctrlr);
_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