From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49846) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wswnj-0005Yz-N4 for qemu-devel@nongnu.org; Fri, 06 Jun 2014 12:15:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wswne-0004rE-J2 for qemu-devel@nongnu.org; Fri, 06 Jun 2014 12:15:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:4878) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wswne-0004qp-Af for qemu-devel@nongnu.org; Fri, 06 Jun 2014 12:15:26 -0400 From: Stefan Hajnoczi Date: Fri, 6 Jun 2014 18:13:54 +0200 Message-Id: <1402071243-16702-34-git-send-email-stefanha@redhat.com> In-Reply-To: <1402071243-16702-1-git-send-email-stefanha@redhat.com> References: <1402071243-16702-1-git-send-email-stefanha@redhat.com> Subject: [Qemu-devel] [PULL 33/42] blockdev: acquire AioContext in block_set_io_throttle List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell , Stefan Hajnoczi The block_set_io_throttle QMP and HMP commands modify I/O throttling limits for block devices. Acquire the BlockDriverState's AioContext to protect against race conditions with an IOThread that is running I/O for this device. Signed-off-by: Stefan Hajnoczi Reviewed-by: Benoit Canet --- blockdev.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/blockdev.c b/blockdev.c index 9b5261b..4cbcc56 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1703,6 +1703,7 @@ void qmp_block_set_io_throttle(const char *device, int64_t bps, int64_t bps_rd, { ThrottleConfig cfg; BlockDriverState *bs; + AioContext *aio_context; bs = bdrv_find(device); if (!bs) { @@ -1746,6 +1747,9 @@ void qmp_block_set_io_throttle(const char *device, int64_t bps, int64_t bps_rd, return; } + aio_context = bdrv_get_aio_context(bs); + aio_context_acquire(aio_context); + if (!bs->io_limits_enabled && throttle_enabled(&cfg)) { bdrv_io_limits_enable(bs); } else if (bs->io_limits_enabled && !throttle_enabled(&cfg)) { @@ -1755,6 +1759,8 @@ void qmp_block_set_io_throttle(const char *device, int64_t bps, int64_t bps_rd, if (bs->io_limits_enabled) { bdrv_set_io_limits(bs, &cfg); } + + aio_context_release(aio_context); } int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data) -- 1.9.3