block: Move actual I/O throttling to BlockBackend
Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Alberto Garcia <berto@igalia.com> Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
parent
27ccdd5259
commit
441565b279
|
@ -716,6 +716,11 @@ static int coroutine_fn blk_co_preadv(BlockBackend *blk, int64_t offset,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* throttling disk I/O */
|
||||||
|
if (blk->public.throttle_state) {
|
||||||
|
throttle_group_co_io_limits_intercept(blk, bytes, false);
|
||||||
|
}
|
||||||
|
|
||||||
return bdrv_co_preadv(blk_bs(blk), offset, bytes, qiov, flags);
|
return bdrv_co_preadv(blk_bs(blk), offset, bytes, qiov, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -730,6 +735,11 @@ static int coroutine_fn blk_co_pwritev(BlockBackend *blk, int64_t offset,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* throttling disk I/O */
|
||||||
|
if (blk->public.throttle_state) {
|
||||||
|
throttle_group_co_io_limits_intercept(blk, bytes, true);
|
||||||
|
}
|
||||||
|
|
||||||
if (!blk->enable_write_cache) {
|
if (!blk->enable_write_cache) {
|
||||||
flags |= BDRV_REQ_FUA;
|
flags |= BDRV_REQ_FUA;
|
||||||
}
|
}
|
||||||
|
|
10
block/io.c
10
block/io.c
|
@ -1083,11 +1083,6 @@ int coroutine_fn bdrv_co_preadv(BlockDriverState *bs,
|
||||||
flags |= BDRV_REQ_COPY_ON_READ;
|
flags |= BDRV_REQ_COPY_ON_READ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* throttling disk I/O */
|
|
||||||
if (bs->blk && blk_get_public(bs->blk)->throttle_state) {
|
|
||||||
throttle_group_co_io_limits_intercept(bs, bytes, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Align read if necessary by padding qiov */
|
/* Align read if necessary by padding qiov */
|
||||||
if (offset & (align - 1)) {
|
if (offset & (align - 1)) {
|
||||||
head_buf = qemu_blockalign(bs, align);
|
head_buf = qemu_blockalign(bs, align);
|
||||||
|
@ -1444,11 +1439,6 @@ int coroutine_fn bdrv_co_pwritev(BlockDriverState *bs,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* throttling disk I/O */
|
|
||||||
if (bs->blk && blk_get_public(bs->blk)->throttle_state) {
|
|
||||||
throttle_group_co_io_limits_intercept(bs, bytes, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Align write if necessary by performing a read-modify-write cycle.
|
* Align write if necessary by performing a read-modify-write cycle.
|
||||||
* Pad qiov with the read parts and be sure to have a tracked request not
|
* Pad qiov with the read parts and be sure to have a tracked request not
|
||||||
|
|
|
@ -284,18 +284,17 @@ static void schedule_next_request(BlockBackend *blk, bool is_write)
|
||||||
* if necessary, and schedule the next request using a round robin
|
* if necessary, and schedule the next request using a round robin
|
||||||
* algorithm.
|
* algorithm.
|
||||||
*
|
*
|
||||||
* @bs: the current BlockDriverState
|
* @blk: the current BlockBackend
|
||||||
* @bytes: the number of bytes for this I/O
|
* @bytes: the number of bytes for this I/O
|
||||||
* @is_write: the type of operation (read/write)
|
* @is_write: the type of operation (read/write)
|
||||||
*/
|
*/
|
||||||
void coroutine_fn throttle_group_co_io_limits_intercept(BlockDriverState *bs,
|
void coroutine_fn throttle_group_co_io_limits_intercept(BlockBackend *blk,
|
||||||
unsigned int bytes,
|
unsigned int bytes,
|
||||||
bool is_write)
|
bool is_write)
|
||||||
{
|
{
|
||||||
bool must_wait;
|
bool must_wait;
|
||||||
BlockBackend *token;
|
BlockBackend *token;
|
||||||
|
|
||||||
BlockBackend *blk = bs->blk;
|
|
||||||
BlockBackendPublic *blkp = blk_get_public(blk);
|
BlockBackendPublic *blkp = blk_get_public(blk);
|
||||||
ThrottleGroup *tg = container_of(blkp->throttle_state, ThrottleGroup, ts);
|
ThrottleGroup *tg = container_of(blkp->throttle_state, ThrottleGroup, ts);
|
||||||
qemu_mutex_lock(&tg->lock);
|
qemu_mutex_lock(&tg->lock);
|
||||||
|
|
|
@ -40,7 +40,7 @@ void throttle_group_register_blk(BlockBackend *blk, const char *groupname);
|
||||||
void throttle_group_unregister_blk(BlockBackend *blk);
|
void throttle_group_unregister_blk(BlockBackend *blk);
|
||||||
void throttle_group_restart_blk(BlockBackend *blk);
|
void throttle_group_restart_blk(BlockBackend *blk);
|
||||||
|
|
||||||
void coroutine_fn throttle_group_co_io_limits_intercept(BlockDriverState *bs,
|
void coroutine_fn throttle_group_co_io_limits_intercept(BlockBackend *blk,
|
||||||
unsigned int bytes,
|
unsigned int bytes,
|
||||||
bool is_write);
|
bool is_write);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue