throttle: add throttle_detach/attach_aio_context()

Block I/O throttling uses timers and currently always adds them to the
main loop.  Throttling will break if bdrv_set_aio_context() is used to
move a BlockDriverState to a different AioContext.

This patch adds throttle_detach/attach_aio_context() interfaces so the
throttling timers and uses them to move timers to the new AioContext.
Note that bdrv_set_aio_context() already drains all requests so we're
sure no throttled requests are pending.

The test cases need to be updated since the throttle_init() interface
has changed.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Benoit Canet <benoit@irqsave.net>
This commit is contained in:
Stefan Hajnoczi
2014-06-04 09:56:12 +02:00
parent c9f87b20b9
commit 13af91ebf0
4 changed files with 60 additions and 9 deletions
+10
View File
@@ -67,6 +67,11 @@ typedef struct ThrottleState {
int64_t previous_leak; /* timestamp of the last leak done */
QEMUTimer * timers[2]; /* timers used to do the throttling */
QEMUClockType clock_type; /* the clock used */
/* Callbacks */
QEMUTimerCB *read_timer_cb;
QEMUTimerCB *write_timer_cb;
void *timer_opaque;
} ThrottleState;
/* operations on single leaky buckets */
@@ -82,6 +87,7 @@ bool throttle_compute_timer(ThrottleState *ts,
/* init/destroy cycle */
void throttle_init(ThrottleState *ts,
AioContext *aio_context,
QEMUClockType clock_type,
void (read_timer)(void *),
void (write_timer)(void *),
@@ -89,6 +95,10 @@ void throttle_init(ThrottleState *ts,
void throttle_destroy(ThrottleState *ts);
void throttle_detach_aio_context(ThrottleState *ts);
void throttle_attach_aio_context(ThrottleState *ts, AioContext *new_context);
bool throttle_have_timer(ThrottleState *ts);
/* configuration */