@@ -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);
}
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 <mreitz@redhat.com> --- blockdev.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)