From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35936) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YGC6K-0006oM-6f for qemu-devel@nongnu.org; Tue, 27 Jan 2015 14:47:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YGC6D-0002A6-NF for qemu-devel@nongnu.org; Tue, 27 Jan 2015 14:47:04 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48491) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YGC6D-00029x-FN for qemu-devel@nongnu.org; Tue, 27 Jan 2015 14:46:57 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t0RJkulB011378 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Tue, 27 Jan 2015 14:46:56 -0500 From: Max Reitz Date: Tue, 27 Jan 2015 14:45:56 -0500 Message-Id: <1422387983-32153-24-git-send-email-mreitz@redhat.com> In-Reply-To: <1422387983-32153-1-git-send-email-mreitz@redhat.com> References: <1422387983-32153-1-git-send-email-mreitz@redhat.com> Subject: [Qemu-devel] [PATCH RESEND 23/50] blockdev: Catch NULL BDS in block_set_io_throttle List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Fam Zheng , Jeff Cody , Markus Armbruster , Max Reitz , Stefan Hajnoczi , John Snow Split bdrv_find() into blk_by_name() and blk_bs() to separate the "no medium inserted" case from the "device not found" case. Signed-off-by: Max Reitz --- blockdev.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/blockdev.c b/blockdev.c index 5f7eef5..9801a7e 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1922,15 +1922,25 @@ void qmp_block_set_io_throttle(const char *device, int64_t bps, int64_t bps_rd, int64_t iops_size, Error **errp) { ThrottleConfig cfg; + BlockBackend *blk; BlockDriverState *bs; AioContext *aio_context; - bs = bdrv_find(device); - if (!bs) { + blk = blk_by_name(device); + if (!blk) { error_set(errp, QERR_DEVICE_NOT_FOUND, device); return; } + aio_context = blk_get_aio_context(blk); + aio_context_acquire(aio_context); + + bs = blk_bs(blk); + if (!bs) { + error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, device); + goto out; + } + memset(&cfg, 0, sizeof(cfg)); cfg.buckets[THROTTLE_BPS_TOTAL].avg = bps; cfg.buckets[THROTTLE_BPS_READ].avg = bps_rd; @@ -1964,12 +1974,9 @@ void qmp_block_set_io_throttle(const char *device, int64_t bps, int64_t bps_rd, } if (!check_throttle_config(&cfg, errp)) { - return; + goto out; } - 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)) { @@ -1980,6 +1987,7 @@ void qmp_block_set_io_throttle(const char *device, int64_t bps, int64_t bps_rd, bdrv_set_io_limits(bs, &cfg); } +out: aio_context_release(aio_context); } -- 2.1.0