From 70a34886574ad2f56b2e69aca19f10139398fc75 Mon Sep 17 00:00:00 2001 From: GangCao Date: Mon, 17 Dec 2018 22:24:16 -0500 Subject: [PATCH] bdev/qos: enable and disable when the QoS thread is not set In the case the QoS thread has not properly initialized yet, needs to go through the regular QoS enabling process to notify all the channels and also disable the QoS properly. The channel and poller related staff also needs to be handled together with the thread. Change-Id: Ifc2b2cdfb1181aa6418ad1d43ae5905c0c317549 Signed-off-by: GangCao Reviewed-on: https://review.gerrithub.io/437519 Chandler-Test-Pool: SPDK Automated Test System Tested-by: SPDK CI Jenkins Reviewed-by: Xiaodong Liu Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto --- lib/bdev/bdev.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/bdev/bdev.c b/lib/bdev/bdev.c index b8871e757..239dc3dd1 100644 --- a/lib/bdev/bdev.c +++ b/lib/bdev/bdev.c @@ -3895,8 +3895,10 @@ _spdk_bdev_disable_qos_done(void *cb_arg) _spdk_bdev_io_submit, bdev_io); } - spdk_put_io_channel(spdk_io_channel_from_ctx(qos->ch)); - spdk_poller_unregister(&qos->poller); + if (qos->thread != NULL) { + spdk_put_io_channel(spdk_io_channel_from_ctx(qos->ch)); + spdk_poller_unregister(&qos->poller); + } free(qos); @@ -3915,7 +3917,11 @@ _spdk_bdev_disable_qos_msg_done(struct spdk_io_channel_iter *i, int status) thread = bdev->internal.qos->thread; pthread_mutex_unlock(&bdev->internal.mutex); - spdk_thread_send_msg(thread, _spdk_bdev_disable_qos_done, ctx); + if (thread != NULL) { + spdk_thread_send_msg(thread, _spdk_bdev_disable_qos_done, ctx); + } else { + _spdk_bdev_disable_qos_done(ctx); + } } static void @@ -4052,7 +4058,6 @@ spdk_bdev_set_qos_rate_limits(struct spdk_bdev *bdev, uint64_t *limits, if (disable_rate_limit == false) { if (bdev->internal.qos == NULL) { - /* Enabling */ bdev->internal.qos = calloc(1, sizeof(*bdev->internal.qos)); if (!bdev->internal.qos) { pthread_mutex_unlock(&bdev->internal.mutex); @@ -4061,7 +4066,10 @@ spdk_bdev_set_qos_rate_limits(struct spdk_bdev *bdev, uint64_t *limits, cb_fn(cb_arg, -ENOMEM); return; } + } + if (bdev->internal.qos->thread == NULL) { + /* Enabling */ _spdk_bdev_set_qos_rate_limits(bdev, limits); spdk_for_each_channel(__bdev_to_io_dev(bdev),