throttle_group_config(bs, cfg);
}
-static void bdrv_start_throttled_reqs(BlockDriverState *bs)
+void bdrv_no_throttling_begin(BlockDriverState *bs)
{
- bool enabled = bs->io_limits_enabled;
+ if (bs->io_limits_disabled++ == 0) {
+ throttle_group_restart_bs(bs);
+ }
+}
- bs->io_limits_enabled = false;
- throttle_group_restart_bs(bs);
- bs->io_limits_enabled = enabled;
+void bdrv_no_throttling_end(BlockDriverState *bs)
+{
+ assert(bs->io_limits_disabled);
+ --bs->io_limits_disabled;
}
void bdrv_io_limits_disable(BlockDriverState *bs)
{
- bs->io_limits_enabled = false;
- bdrv_start_throttled_reqs(bs);
+ assert(bs->throttle_state);
+ bdrv_no_throttling_begin(bs);
throttle_group_unregister_bs(bs);
+ bdrv_no_throttling_end(bs);
}
/* should be called before bdrv_set_io_limits if a limit is set */
void bdrv_io_limits_enable(BlockDriverState *bs, const char *group)
{
- assert(!bs->io_limits_enabled);
+ assert(!bs->throttle_state);
throttle_group_register_bs(bs, group);
- bs->io_limits_enabled = true;
}
void bdrv_io_limits_update_group(BlockDriverState *bs, const char *group)
*/
void coroutine_fn bdrv_co_drain(BlockDriverState *bs)
{
+ bdrv_no_throttling_begin(bs);
bdrv_drain_recurse(bs);
bdrv_co_yield_to_drain(bs);
+ bdrv_no_throttling_end(bs);
}
void bdrv_drain(BlockDriverState *bs)
{
+ bdrv_no_throttling_begin(bs);
bdrv_drain_recurse(bs);
if (qemu_in_coroutine()) {
bdrv_co_yield_to_drain(bs);
} else {
bdrv_drain_poll(bs);
}
+ bdrv_no_throttling_end(bs);
}
/*
if (bs->job) {
block_job_pause(bs->job);
}
+ bdrv_no_throttling_begin(bs);
bdrv_drain_recurse(bs);
aio_context_release(aio_context);
AioContext *aio_context = bdrv_get_aio_context(bs);
aio_context_acquire(aio_context);
+ bdrv_no_throttling_end(bs);
if (bs->job) {
block_job_resume(bs->job);
}
}
/* throttling disk I/O */
- if (bs->io_limits_enabled) {
+ if (bs->throttle_state) {
throttle_group_co_io_limits_intercept(bs, bytes, false);
}
}
/* throttling disk I/O */
- if (bs->io_limits_enabled) {
+ if (bs->throttle_state) {
throttle_group_co_io_limits_intercept(bs, bytes, true);
}
} else if (bs->file) {
bdrv_flush_io_queue(bs->file->bs);
}
- bdrv_start_throttled_reqs(bs);
}
void bdrv_drained_begin(BlockDriverState *bs)
/* I/O throttling.
* throttle_state tells us if this BDS has I/O limits configured.
- * io_limits_enabled tells us if they are currently being
- * enforced, but it can be temporarily set to false */
+ * io_limits_disabled tells us if they are currently being enforced */
CoQueue throttled_reqs[2];
- bool io_limits_enabled;
+ unsigned int io_limits_disabled;
+
/* The following fields are protected by the ThrottleGroup lock.
* See the ThrottleGroup documentation for details. */
ThrottleState *throttle_state;
const BdrvChildRole *child_role);
void bdrv_root_unref_child(BdrvChild *child);
+void bdrv_no_throttling_begin(BlockDriverState *bs);
+void bdrv_no_throttling_end(BlockDriverState *bs);
+
void blk_dev_change_media_cb(BlockBackend *blk, bool load);
bool blk_dev_has_removable_media(BlockBackend *blk);
bool blk_dev_has_tray(BlockBackend *blk);