bdev/qos: Break out code to destroy the qos into a separate function

Minimizes a future diff.

Change-Id: Ibc68588f3da2a169863d61a3aa20f384fa33e3dc
Signed-off-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-on: https://review.gerrithub.io/409747
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
Ben Walker 2018-05-02 10:19:48 -07:00
parent fa68a0fdbd
commit 6cd524d87c

View File

@ -1241,17 +1241,9 @@ spdk_bdev_qos_channel_destroy(void *cb_arg)
free(qos);
}
static void
spdk_bdev_channel_destroy(void *io_device, void *ctx_buf)
static int
spdk_bdev_qos_destroy(struct spdk_bdev *bdev)
{
struct spdk_bdev_channel *ch = ctx_buf;
struct spdk_bdev *bdev = ch->bdev;
_spdk_bdev_channel_destroy(ch);
pthread_mutex_lock(&bdev->mutex);
bdev->channel_count--;
if (bdev->channel_count == 0 && bdev->qos && bdev->qos->ch != NULL) {
/*
* Cleanly shutting down the QoS poller is tricky, because
* during the asynchronous operation the user could open a
@ -1268,10 +1260,9 @@ spdk_bdev_channel_destroy(void *io_device, void *ctx_buf)
new_qos = calloc(1, sizeof(*new_qos));
if (!new_qos) {
SPDK_ERRLOG("Unable to allocate memory to shut down QoS.\n");
/* There isn't anything we can do to recover from here. Just let the
* old QoS poller keep running. The QoS handling won't change
* cores when the user allocates a new channel, but it won't break. */
} else {
return -ENOMEM;
}
/* Copy the old QoS data into the newly allocated structure */
memcpy(new_qos, old_qos, sizeof(*new_qos));
@ -1291,6 +1282,26 @@ spdk_bdev_channel_destroy(void *io_device, void *ctx_buf)
/* It is safe to continue with destroying the bdev even though the QoS channel hasn't
* been destroyed yet. The destruction path will end up waiting for the final
* channel to be put before it releases resources. */
return 0;
}
static void
spdk_bdev_channel_destroy(void *io_device, void *ctx_buf)
{
struct spdk_bdev_channel *ch = ctx_buf;
struct spdk_bdev *bdev = ch->bdev;
_spdk_bdev_channel_destroy(ch);
pthread_mutex_lock(&bdev->mutex);
bdev->channel_count--;
if (bdev->channel_count == 0 && bdev->qos && bdev->qos->ch != NULL) {
if (spdk_bdev_qos_destroy(bdev)) {
/* There isn't anything we can do to recover from here. Just let the
* old QoS poller keep running. The QoS handling won't change
* cores when the user allocates a new channel, but it won't break. */
SPDK_ERRLOG("Unable to shut down QoS poller. It will continue running on the current thread.\n");
}
}
pthread_mutex_unlock(&bdev->mutex);