add throttle block driver filter
v5 cover add throttle block driver filter
This series adds a throttle block driver filter. Currently throttling is done at the BlockBackend level. Using block driver interfaces we can move the throttling to any point in the BDS graph using a throttle node which uses the existing throttling code. This allows for potentially more complex configurations (throttling at any point in the graph, chained filters)
v5:
fix crash in 'add aio_context field in ThrottleGroupMember' fix suggestions in block/throttle.c
v4:
fix suggestions in block/throttle.c
fix suggestions in block/throttle_groups.c
add doc note in BlockDevOptionsThrottle
v3:
fix style error in 'add aio_context field in ThrottleGroupMember'
v2:
change QOM throttle group object name
print valid ranges for uint on error
move frees in throttle_group_obj_finalize()
split throttle_group_{set,get}()
add throttle_recurse_is_first_non_filter()
Manos Pitsidianakis (6):
block: move ThrottleGroup membership to ThrottleGroupMember
block: add aio_context field in ThrottleGroupMember
block: tidy ThrottleGroupMember initializations
block: convert ThrottleGroup to object with QOM
block: add throttle block filter driver
block: add iotest 184 for the throttle filter driver
qapi/block-core.json | 70 +++- include/block/throttle-groups.h | 47 ++- include/qemu/throttle-options.h | 60 ++-- include/qemu/throttle.h | 3 + include/sysemu/block-backend.h | 20 +- block/block-backend.c | 62 ++-- block/qapi.c | 8 +- block/throttle-groups.c | 734 +++++++++++++++++++++++++++++----------- block/throttle.c | 314 +++++++++++++++++ blockdev.c | 4 +- tests/test-throttle.c | 111 +++--- util/throttle.c | 151 +++++++++ block/Makefile.objs | 1 + tests/qemu-iotests/184 | 310 +++++++++++++++++ tests/qemu-iotests/184.out | 422 +++++++++++++++++++++++ tests/qemu-iotests/group | 1 + 16 files changed, 1997 insertions(+), 321 deletions(-) create mode 100644 block/throttle.c create mode 100755 tests/qemu-iotests/184 create mode 100644 tests/qemu-iotests/184.out
Signature · 1 line
2.11.0
PATCH v5 1/6 block: move ThrottleGroup membership to ThrottleGroupMember
This commit eliminates the 1:1 relationship between BlockBackend and throttle group state. Users will be able to create multiple throttle nodes, each with its own throttle group state, in the future. The throttle group state cannot be per-BlockBackend anymore, it must be per-throttle node. This is done by gathering ThrottleGroup membership details from BlockBackendPublic into ThrottleGroupMember and refactoring existing code to use the structure.
--- include/block/throttle-groups.h | 39 +++++- include/sysemu/block-backend.h | 20 +-- block/block-backend.c | 66 +++++---- block/qapi.c | 8 +- block/throttle-groups.c | 288 ++++++++++++++++++++-------------------- blockdev.c | 4 +- tests/test-throttle.c | 53 ++++---- 7 files changed, 252 insertions(+), 226 deletions(-)
include/block/throttle-groups.h +32 -7
@@ -28,19 +28,44 @@#include "qemu/throttle.h" #include "block/block_int.h" -const char *throttle_group_get_name (BlockBackend *blk); +/* The ThrottleGroupMember structure indicates membership in a ThrottleGroup +* and holds related data. +*/ + +typedef struct ThrottleGroupMember { +/* throttled_reqs_lock protects the CoQueues for throttled requests. */ +CoMutex throttled_reqs_lock; +CoQueue throttled_reqs[2 ]; + +/* Nonzero if the I/O limits are currently being ignored; generally +* it is zero. Accessed with atomic operations. +*/ +unsigned int io_limits_disabled; + +/* The following fields are protected by the ThrottleGroup lock. +* See the ThrottleGroup documentation for details. +* throttle_state tells us if I/O limits are configured. */ +ThrottleState *throttle_state; +ThrottleTimers throttle_timers; +unsigned pending_reqs[2 ]; +QLIST_ENTRY (ThrottleGroupMember) round_robin; + +}ThrottleGroupMember ; + +const char *throttle_group_get_name (ThrottleGroupMember *tgm);ThrottleState *throttle_group_incref (const char *name);void throttle_group_unref (ThrottleState *ts); -void throttle_group_config (BlockBackend *blk,ThrottleConfig *cfg); -void throttle_group_get_config (BlockBackend *blk,ThrottleConfig *cfg); +void throttle_group_config (ThrottleGroupMember *tgm,ThrottleConfig *cfg); +void throttle_group_get_config (ThrottleGroupMember *tgm,ThrottleConfig *cfg); -void throttle_group_register_blk (BlockBackend *blk,const char *groupname); -void throttle_group_unregister_blk (BlockBackend *blk); -void throttle_group_restart_blk (BlockBackend *blk); +void throttle_group_register_tgm (ThrottleGroupMember *tgm, +const char *groupname); +void throttle_group_unregister_tgm (ThrottleGroupMember *tgm); +void throttle_group_restart_tgm (ThrottleGroupMember *tgm); -void coroutine_fn throttle_group_co_io_limits_intercept(BlockBackend *blk, +void coroutine_fn throttle_group_co_io_limits_intercept(ThrottleGroupMember *tgm,unsigned int bytes,bool is_write);
include/sysemu/block-backend.h +3 -17
@@ -70,24 +70,10 @@ typedef struct BlockDevOps {/* This struct is embedded in (the private) BlockBackend struct and contains * fields that must be public. This is in particular for QLIST_ENTRY() and -* friends so that BlockBackends can be kept in lists outside block-backend.c */ +* friends so that BlockBackends can be kept in lists outside block-backend.c +* */ typedef struct BlockBackendPublic { -/* throttled_reqs_lock protects the CoQueues for throttled requests. */ -CoMutex throttled_reqs_lock; -CoQueue throttled_reqs[2 ]; - -/* Nonzero if the I/O limits are currently being ignored; generally -* it is zero. Accessed with atomic operations. -*/ -unsigned int io_limits_disabled; - -/* The following fields are protected by the ThrottleGroup lock. -* See the ThrottleGroup documentation for details. -* throttle_state tells us if I/O limits are configured. */ -ThrottleState *throttle_state; -ThrottleTimers throttle_timers; -unsigned pending_reqs[2 ]; -QLIST_ENTRY (BlockBackendPublic) round_robin; +ThrottleGroupMember throttle_group_member; }BlockBackendPublic ;BlockBackend *blk_new (uint64_t perm,uint64_t shared_perm);
block/block-backend.c +37 -29
153 lines not on this page · raw message
block/qapi.c +5 -3
@@ -66,10 +66,11 @@ BlockDeviceInfo *bdrv_block_device_info(BlockBackend *blk, info->detect_zeroes = bs->detect_zeroes; -if (blk &&blk_get_public (blk)->throttle_state) { +if (blk &&blk_get_public (blk)->throttle_group_member.throttle_state) {ThrottleConfig cfg; +BlockBackendPublic *blkp =blk_get_public (blk); -throttle_group_get_config (blk, &cfg); +throttle_group_get_config (&blkp->throttle_group_member, &cfg); info->bps = cfg.buckets[THROTTLE_BPS_TOTAL ].avg; info->bps_rd = cfg.buckets[THROTTLE_BPS_READ ].avg;
@@ -117,7 +118,8 @@ BlockDeviceInfo *bdrv_block_device_info(BlockBackend *blk, info->iops_size = cfg.op_size; info->has_group = true; - info->group =g_strdup (throttle_group_get_name (blk)); + info->group = +g_strdup (throttle_group_get_name (&blkp->throttle_group_member)); } info->write_threshold =bdrv_write_threshold_get (bs);
block/throttle-groups.c +144 -144
564 lines not on this page · raw message
blockdev.c +2 -2
@@ -2688,7 +2688,7 @@ void qmp_block_set_io_throttle(BlockIOThrottle *arg, Error **errp) if (throttle_enabled(&cfg)) { /* Enable I/O limits if they're not enabled yet, otherwise * just update the throttling group. */ - if (!blk_get_public(blk)->throttle_state) { + if (!blk_get_public(blk)->throttle_group_member.throttle_state) { blk_io_limits_enable(blk, arg->has_group ? arg->group : arg->has_device ? arg->device :
@@ -2698,7 +2698,7 @@ void qmp_block_set_io_throttle(BlockIOThrottle *arg, Error **errp) }/* Set the new throttling configuration */ blk_set_io_limits (blk, &cfg); - }else if (blk_get_public (blk)->throttle_state) { + }else if (blk_get_public (blk)->throttle_group_member.throttle_state) {/* If all throttling settings are set to 0, disable I/O limits */ blk_io_limits_disable (blk); }
tests/test-throttle.c +29 -24
85 lines not on this page · raw message
Signature · 1 line
2.11.0
PATCH v5 2/6 block: add aio_context field in ThrottleGroupMember
In reply to Manos Pitsidianakistimer_cb() needs to know about the current Aio context of the throttle request that is woken up. In order to make ThrottleGroupMember backend agnostic, this information is stored in an aio_context field instead of accessing it from BlockBackend.
--- include/block/throttle-groups.h | 7 ++++- block/block-backend.c | 15 ++++------ block/throttle-groups.c | 38 ++++++++++++++++--------- tests/test-throttle.c | 63 +++++++++++++++++++++-------------------- 4 files changed, 69 insertions(+), 54 deletions(-)
include/block/throttle-groups.h +6 -1
@@ -33,6 +33,7 @@*/ typedef struct ThrottleGroupMember { + AioContext *aio_context; /* throttled_reqs_lock protects the CoQueues for throttled requests. */ CoMutex throttled_reqs_lock; CoQueue throttled_reqs[2];
@@ -61,12 +62,16 @@ void throttle_group_config(ThrottleGroupMember *tgm, ThrottleConfig *cfg);void throttle_group_get_config (ThrottleGroupMember *tgm,ThrottleConfig *cfg);void throttle_group_register_tgm (ThrottleGroupMember *tgm, -const char *groupname); +const char *groupname, +AioContext *ctx);void throttle_group_unregister_tgm (ThrottleGroupMember *tgm);void throttle_group_restart_tgm (ThrottleGroupMember *tgm); void coroutine_fn throttle_group_co_io_limits_intercept(ThrottleGroupMember *tgm,unsigned int bytes,bool is_write); +void throttle_group_attach_aio_context (ThrottleGroupMember *tgm, +AioContext *new_context); +void throttle_group_detach_aio_context (ThrottleGroupMember *tgm);#endif
block/block-backend.c +6 -9
@@ -1726,18 +1726,14 @@ static AioContext *blk_aiocb_get_aio_context(BlockAIOCB *acb)void blk_set_aio_context (BlockBackend *blk,AioContext *new_context) {BlockDriverState *bs =blk_bs (blk); -ThrottleTimers *tt; +ThrottleGroupMember *tgm = &blk->public.throttle_group_member;if (bs) { -if (blk->public.throttle_group_member.throttle_state) { - tt = &blk->public.throttle_group_member.throttle_timers; -throttle_timers_detach_aio_context (tt); +if (tgm->throttle_state) { +throttle_group_detach_aio_context (tgm); +throttle_group_attach_aio_context (tgm, new_context); }bdrv_set_aio_context (bs, new_context); -if (blk->public.throttle_group_member.throttle_state) { - tt = &blk->public.throttle_group_member.throttle_timers; -throttle_timers_attach_aio_context (tt, new_context); - } } }
@@ -1970,7 +1966,8 @@ void blk_io_limits_disable(BlockBackend *blk)void blk_io_limits_enable (BlockBackend *blk,const char *group) {assert (!blk->public.throttle_group_member.throttle_state); -throttle_group_register_tgm (&blk->public.throttle_group_member, group); +throttle_group_register_tgm (&blk->public.throttle_group_member, + group,blk_get_aio_context (blk)); }void blk_io_limits_update_group (BlockBackend *blk,const char *group)
block/throttle-groups.c +24 -14
@@ -391,9 +391,6 @@ static void coroutine_fn throttle_group_restart_queue_entry(void *opaque)static void throttle_group_restart_queue (ThrottleGroupMember *tgm,bool is_write) { -BlockBackendPublic *blkp =container_of (tgm, BlockBackendPublic, - throttle_group_member); -BlockBackend *blk =blk_by_public (blkp);Coroutine *co;RestartData rd = { .tgm = tgm,
@@ -401,7 +398,7 @@ static void throttle_group_restart_queue(ThrottleGroupMember *tgm, bool is_write }; co =qemu_coroutine_create (throttle_group_restart_queue_entry, &rd); -aio_co_enter (blk_get_aio_context (blk), co); +aio_co_enter (tgm->aio_context, co); }void throttle_group_restart_tgm (ThrottleGroupMember *tgm)
@@ -449,13 +446,11 @@ void throttle_group_get_config(ThrottleGroupMember *tgm, ThrottleConfig *cfg)/* ThrottleTimers callback. This wakes up a request that was waiting * because it had been throttled. * -* @blk: the BlockBackend whose request had been throttled +* @tgm: the ThrottleGroupMember whose request had been throttled * @is_write: the type of operation (read/write) */ -static void timer_cb (BlockBackend *blk,bool is_write) +static void timer_cb (ThrottleGroupMember *tgm,bool is_write) { -BlockBackendPublic *blkp =blk_get_public (blk); -ThrottleGroupMember *tgm = &blkp->throttle_group_member;ThrottleState *ts = tgm->throttle_state;ThrottleGroup *tg =container_of (ts, ThrottleGroup, ts);
@@ -484,18 +479,18 @@ static void write_timer_cb(void *opaque)* * @tgm: the ThrottleGroupMember to insert * @groupname: the name of the group +* @ctx: the AioContext to use */ void throttle_group_register_tgm (ThrottleGroupMember *tgm, -const char *groupname) +const char *groupname, +AioContext *ctx) {int i; -BlockBackendPublic *blkp =container_of (tgm, BlockBackendPublic, - throttle_group_member); -BlockBackend *blk =blk_by_public (blkp);ThrottleState *ts =throttle_group_incref (groupname);ThrottleGroup *tg =container_of (ts, ThrottleGroup, ts); tgm->throttle_state = ts; + tgm->aio_context = ctx;qemu_mutex_lock (&tg->lock);/* If the ThrottleGroup is new set this ThrottleGroupMember as the token */
@@ -508,11 +503,11 @@ void throttle_group_register_tgm(ThrottleGroupMember *tgm,QLIST_INSERT_HEAD (&tg->head, tgm, round_robin);throttle_timers_init (&tgm->throttle_timers, -blk_get_aio_context (blk), + tgm->aio_context, tg->clock_type, read_timer_cb, write_timer_cb, - blk); + tgm);qemu_mutex_unlock (&tg->lock); }
@@ -559,6 +554,21 @@ void throttle_group_unregister_tgm(ThrottleGroupMember *tgm) tgm->throttle_state =NULL ; } +void throttle_group_attach_aio_context (ThrottleGroupMember *tgm, +AioContext *new_context) +{ +ThrottleTimers *tt = &tgm->throttle_timers; +throttle_timers_attach_aio_context (tt, new_context); + tgm->aio_context = new_context; +} + +void throttle_group_detach_aio_context (ThrottleGroupMember *tgm) +{ +ThrottleTimers *tt = &tgm->throttle_timers; +throttle_timers_detach_aio_context (tt); + tgm->aio_context =NULL ; +} +static void throttle_groups_init (void ) {qemu_mutex_init (&throttle_groups_lock);
tests/test-throttle.c +33 -30
160 lines not on this page · raw message
Signature · 1 line
2.11.0
PATCH v5 3/6 block: tidy ThrottleGroupMember initializations
In reply to Manos PitsidianakisMove the CoMutex and CoQueue inits inside throttle_group_register_tgm() which is called whenever a ThrottleGroupMember is initialized. There's no need for them to be separate.
--- block/block-backend.c | 3 --- block/throttle-groups.c | 3 +++ 2 files changed, 3 insertions(+), 3 deletions(-)
block/block-backend.c +0 -3
@@ -252,9 +252,6 @@ BlockBackend *blk_new(uint64_t perm, uint64_t shared_perm) blk->shared_perm = shared_perm;blk_set_enable_write_cache (blk, true); -qemu_co_mutex_init (&blk->public.throttle_group_member.throttled_reqs_lock); -qemu_co_queue_init (&blk->public.throttle_group_member.throttled_reqs[0 ]); -qemu_co_queue_init (&blk->public.throttle_group_member.throttled_reqs[1 ]);block_acct_init (&blk->stats);notifier_list_init (&blk->remove_bs_notifiers);
block/throttle-groups.c +3 -0
@@ -508,6 +508,9 @@ void throttle_group_register_tgm(ThrottleGroupMember *tgm, read_timer_cb, write_timer_cb, tgm); +qemu_co_mutex_init (&tgm->throttled_reqs_lock); +qemu_co_queue_init (&tgm->throttled_reqs[0 ]); +qemu_co_queue_init (&tgm->throttled_reqs[1 ]);qemu_mutex_unlock (&tg->lock); }
Signature · 1 line
2.11.0
PATCH v5 4/6 block: convert ThrottleGroup to object with QOM
In reply to Manos PitsidianakisThrottleGroup is converted to an object. This will allow the future throttle block filter drive easy creation and configuration of throttle groups in QMP and cli.
A new QAPI struct, ThrottleLimits, is introduced to provide a shared struct for all throttle configuration needs in QMP.
ThrottleGroups can be created via CLI as
-object throttle-group,id=foo,x-iops-total=100,x-..
where x-* are individual limit properties. Since we can't add non-scalar properties in -object this interface must be used instead. However, setting these properties must be disabled after initialization because certain combinations of limits are forbidden and thus configuration changes should be done in one transaction. The individual properties will go away when support for non-scalar values in CLI is implemented and thus are marked as experimental.
ThrottleGroup also has a limits property that uses the ThrottleLimits struct. It can be used to create ThrottleGroups or set the configuration in existing groups as follows:
{ "execute": "object-add",
"arguments": {
"qom-type": "throttle-group",
"id": "foo",
"props" : {
"limits": {
"iops-total": 100
}
}
}
}
{ "execute" : "qom-set",
"arguments" : {
"path" : "foo",
"property" : "limits",
"value" : {
"iops-total" : 99
}
}
}This also means a group's configuration can be fetched with qom-get.
ThrottleGroups can be anonymous which means they can't get accessed by other users ie they will always be units instead of group (Because they have one ThrottleGroupMember).
--- qapi/block-core.json | 48 +++++ include/block/throttle-groups.h | 3 + include/qemu/throttle-options.h | 59 ++++-- include/qemu/throttle.h | 3 + block/throttle-groups.c | 421 ++++++++++++++++++++++++++++++++++++---- tests/test-throttle.c | 1 + util/throttle.c | 151 ++++++++++++++ 7 files changed, 626 insertions(+), 60 deletions(-)
qapi/block-core.json +48 -0
@@ -1905,6 +1905,54 @@ '*iops_size': 'int', '*group': 'str' } } ## +# @ThrottleLimits: +# +# Limit parameters for throttling. +# Since some limit combinations are illegal, limits should always be set in one +# transaction. All fields are optional. When setting limits, if a field is +# missing the current value is not changed. +# +# @iops-total: limit total I/O operations per second +# @iops-total-max: I/O operations burst +# @iops-total-max-length: length of the iops-total-max burst period, in seconds +# It must only be set if @iops-total-max is set as well. +# @iops-read: limit read operations per second +# @iops-read-max: I/O operations read burst +# @iops-read-max-length: length of the iops-read-max burst period, in seconds +# It must only be set if @iops-read-max is set as well. +# @iops-write: limit write operations per second +# @iops-write-max: I/O operations write burst +# @iops-write-max-length: length of the iops-write-max burst period, in seconds +# It must only be set if @iops-write-max is set as well. +# @bps-total: limit total bytes per second +# @bps-total-max: total bytes burst +# @bps-total-max-length: length of the bps-total-max burst period, in seconds. +# It must only be set if @bps-total-max is set as well. +# @bps-read: limit read bytes per second +# @bps-read-max: total bytes read burst +# @bps-read-max-length: length of the bps-read-max burst period, in seconds +# It must only be set if @bps-read-max is set as well. +# @bps-write: limit write bytes per second +# @bps-write-max: total bytes write burst +# @bps-write-max-length: length of the bps-write-max burst period, in seconds +# It must only be set if @bps-write-max is set as well. +# @iops-size: when limiting by iops max size of an I/O in bytes +# +# Since: 2.11 +## +{ 'struct': 'ThrottleLimits', + 'data': { '*iops-total' : 'int', '*iops-total-max' : 'int', + '*iops-total-max-length' : 'int', '*iops-read' : 'int', + '*iops-read-max' : 'int', '*iops-read-max-length' : 'int', + '*iops-write' : 'int', '*iops-write-max' : 'int', + '*iops-write-max-length' : 'int', '*bps-total' : 'int', + '*bps-total-max' : 'int', '*bps-total-max-length' : 'int', + '*bps-read' : 'int', '*bps-read-max' : 'int', + '*bps-read-max-length' : 'int', '*bps-write' : 'int', + '*bps-write-max' : 'int', '*bps-write-max-length' : 'int', + '*iops-size' : 'int' } } + +## # @block-stream: # # Copy data from a backing file into a block device.
include/block/throttle-groups.h +3 -0
@@ -53,6 +53,9 @@ typedef struct ThrottleGroupMember { } ThrottleGroupMember; +#define TYPE_THROTTLE_GROUP "throttle-group" +#define THROTTLE_GROUP (obj) OBJECT_CHECK(ThrottleGroup, (obj), TYPE_THROTTLE_GROUP) +const char *throttle_group_get_name (ThrottleGroupMember *tgm);ThrottleState *throttle_group_incref (const char *name);
include/qemu/throttle-options.h +40 -19
121 lines not on this page · raw message
include/qemu/throttle.h +3 -0
@@ -152,5 +152,8 @@ bool throttle_schedule_timer(ThrottleState *ts, bool is_write);void throttle_account (ThrottleState *ts,bool is_write,uint64_t size); +void throttle_limits_to_config (ThrottleLimits *arg,ThrottleConfig *cfg, +Error **errp); +void throttle_config_to_limits (ThrottleConfig *cfg,ThrottleLimits *var);#endif
block/throttle-groups.c +380 -41
488 lines not on this page · raw message
tests/test-throttle.c +1 -0
@@ -662,6 +662,7 @@ int main(int argc, char **argv)qemu_init_main_loop (&error_fatal); ctx =qemu_get_aio_context ();bdrv_init (); +module_call_init (MODULE_INIT_QOM );do {}while (g_main_context_iteration (NULL , false));
util/throttle.c +151 -0
154 lines not on this page · raw message
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH v5 4/6] block: convert ThrottleGroup to object with QOM
Quoted 4 lines · Manos Pitsidianakis
* If no ThrottleGroup is found with the given name a new one is
* created.
*
- * @name: the name of the ThrottleGroup
Quoted 8 lines
+ * This function edits
throttle_groupsand must be called under the global
+ * mutex.
+ *
+ * @name: the name of the ThrottleGroup, NULL means a new anonymous group will
+ * be created.
* @ret: the ThrottleState member of the ThrottleGroup
*/
ThrottleState *throttle_group_incref(const char *name)
If we're not going to have anonymous groups in the end this patch needs changes (name == NULL is no longer allowed).
Quoted 6 lines
block/throttle-groups.c +6
-0+/* This function edits throttle_groups and must be called under the global +* mutex */ +static void throttle_group_obj_complete (UserCreatable *obj,Error **errp) +{ +ThrottleGroup *tg =THROTTLE_GROUP (obj), *iter; +ThrottleConfig *cfg = &tg->ts.cfg;
block/throttle-groups.c void throttle_group_detach_aio_context(ThrottleGroupMember *tgm) · line 703
Quoted 10 lines
block/throttle-groups.c +10
-0+ +/* set group name to object id if it exists */ +if (!tg->name && tg->parent_obj.parent) { + tg->name =object_get_canonical_path_component (OBJECT (obj)); + } + +if (tg->name) { +/* error if name is duplicate */ + QTAILQ_FOREACH(iter, &throttle_groups, list) { +if (!g_strcmp0 (tg->name, iter->name) && tg != iter) {
I'm just nitpicking here :) but if you change this and put 'tg != iter' first you'll save one unnecessary string comparison.
block/throttle-groups.c void throttle_group_detach_aio_context(ThrottleGroupMember *tgm) · line 716
Quoted 13 lines
block/throttle-groups.c +13
-0+error_setg (errp,"A group with this name already exists" ); +return ; + } + } + } + +/* unfix buckets to check validity */ +throttle_get_config (&tg->ts, cfg); +if (!throttle_is_valid (cfg, errp)) { +return ; + } +/* fix buckets again */ +throttle_config (&tg->ts, tg->clock_type, cfg);
throttle_get_config(ts, cfg) makes a copy of the existing configuration, but the cfg pointer that you are passing already points to the existing configuration, so in practice you are doing
*(ts->cfg) = *(ts->cfg);
throttle_unfix_bucket(...);and since you "unfixed" the configuration, then you need undo the whole thing by setting the config again:
*(ts->cfg) = *(ts->cfg);
throttle_fix_bucket(...);You should declare a local ThrottleConfig variable, copy the config there, and run throttle_is_valid() on that copy. The final throttle_config() call is unnecessary.
Once the patches I sent yesterday are merged we'll be able to skip the throttle_get_config() call and do throttle_is_valid(&tg->ts.cfg, errp) directly.
Quoted 45 lines
block/throttle-groups.c +45
-0+static void throttle_group_set (Object *obj,Visitor *v,const char * name, +void *opaque,Error **errp) + +{ +ThrottleGroup *tg =THROTTLE_GROUP (obj); +ThrottleConfig cfg; +ThrottleParamInfo *info = opaque; +Error *local_err =NULL ; +int64_t value; + +/* If we have finished initialization, don't accept individual property +* changes through QOM. Throttle configuration limits must be set in one +* transaction, as certain combinations are invalid. +*/ +if (tg->is_initialized) { +error_setg (&local_err,"Property cannot be set after initialization" ); + goto ret; + } + +visit_type_int64 (v, name, &value, &local_err); +if (local_err) { + goto ret; + } +if (value <0 ) { +error_setg (&local_err,"Property values cannot be negative" ); + goto ret; + } + + cfg = tg->ts.cfg; +switch (info->data_type) { +case UINT64 : + { +uint64_t *field = (void *)&cfg.buckets[info->type] + info->offset; + *field = value; + } +break ; +case DOUBLE : + { +double *field = (void *)&cfg.buckets[info->type] + info->offset; + *field = value; + } +break ; +case UNSIGNED : + { +if (value >UINT_MAX ) {
block/throttle-groups.c void throttle_group_detach_aio_context(ThrottleGroupMember *tgm) · line 785
Quoted 10 lines
block/throttle-groups.c +10
-0+error_setg (&local_err,"%s value must be in the" +"range [0, %u]" , info->name,UINT_MAX ); + goto ret; + } +unsigned *field = (void *)&cfg.buckets[info->type] + info->offset; + *field = value; + } + } + + tg->ts.cfg = cfg;
There's a bit of black magic here :) you have a user-defined enumeration (UNSIGNED, DOUBLE, UINT64) to identify C types and I'm worried about what happens if the data types of LeakyBucket change, will we be able to detect the problem?
Out of the blue I can think of the following alternative:
- There's 6 different buckets (we have BucketType listing them)
- There's 3 values we can set in each bucket (max, avg, burst_length). For those we can have an internal enumeration (probably with one additional value for iops-size).
- In the 'properties' array, for each property we know its category (and I mean: avg, max, burst-lenght, iops-size) and the bucket where they belong.
- In throttle_group_set() the switch could be something like this:
switch (info->category) {
case THROTTLE_VALUE_AVG:
cfg->buckets[info->bkt_type].avg = value;
break;
case THROTTLE_VALUE_MAX:
cfg->buckets[info->bkt_type].max = value;
break;
case THROTTLE_VALUE_BURST_LENGTH:
/* Code here to check that value <= UINT_MAX */
cfg->buckets[info->bkt_type].iops_length = value;
break;
case THROTTLE_VALUE_IOPS_SIZE:
cfg->op_size = value;
} block/throttle-groups.c void throttle_group_detach_aio_context(ThrottleGroupMember *tgm) · line 794
Quoted 2 lines
block/throttle-groups.c +2
-0+static void throttle_group_get (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp)
And the same approach here, of course.
block/throttle-groups.c void throttle_group_detach_aio_context(ThrottleGroupMember *tgm) · line 835
Quoted 11 lines
block/throttle-groups.c +11
-0+static void throttle_group_set_limits (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) + +{ +ThrottleGroup *tg =THROTTLE_GROUP (obj); +ThrottleConfig cfg; +ThrottleLimits *arg =NULL ; +Error *local_err =NULL ; + + arg =g_new0 (ThrottleLimits,1 );
Do you need to allocate ThrottleLimits in the heap?
Quoted 7 lines
block/throttle-groups.c +7
-0+static void throttle_group_get_limits (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) +{ +ThrottleGroup *tg =THROTTLE_GROUP (obj); +ThrottleConfig cfg; +ThrottleLimits *arg =NULL ;
block/throttle-groups.c void throttle_group_detach_aio_context(ThrottleGroupMember *tgm) · line 872
Quoted 10 lines
block/throttle-groups.c +10
-0+ +qemu_mutex_lock (&tg->lock); +throttle_get_config (&tg->ts, &cfg); +qemu_mutex_unlock (&tg->lock); + + arg =g_new0 (ThrottleLimits,1 ); +throttle_config_to_limits (&cfg, arg); + +visit_type_ThrottleLimits (v, name, &arg, errp); +g_free (arg);
Same question here.
Berto
Re: [Qemu-devel] [PATCH v5 4/6] block: convert ThrottleGroup to object with QOM
Quoted 29 lines · Alberto Garcia
Quoted 4 lines · Manos Pitsidianakis
* If no ThrottleGroup is found with the given name a new one is
* created.
*
- * @name: the name of the ThrottleGroupQuoted 8 lines
+ * This function edits
throttle_groupsand must be called under the global
+ * mutex.
+ *
+ * @name: the name of the ThrottleGroup, NULL means a new anonymous group will
+ * be created.
* @ret: the ThrottleState member of the ThrottleGroup
*/
ThrottleState *throttle_group_incref(const char *name)If we're not going to have anonymous groups in the end this patch needs changes (name == NULL is no longer allowed).
Quoted 11 lines
block/throttle-groups.c +11
-0+/* This function edits throttle_groups and must be called under the global +* mutex */ +static void throttle_group_obj_complete (UserCreatable *obj,Error **errp) +{ +ThrottleGroup *tg =THROTTLE_GROUP (obj), *iter; +ThrottleConfig *cfg = &tg->ts.cfg; + +/* set group name to object id if it exists */ +if (!tg->name && tg->parent_obj.parent) { + tg->name =object_get_canonical_path_component (OBJECT (obj)); + }
Quoted 8 lines
block/throttle-groups.c void throttle_group_detach_aio_context(ThrottleGroupMember *tgm) · line 703
Quoted 5 lines
block/throttle-groups.c +5
-0+ +if (tg->name) { +/* error if name is duplicate */ + QTAILQ_FOREACH(iter, &throttle_groups, list) { +if (!g_strcmp0 (tg->name, iter->name) && tg != iter) {I'm just nitpicking here :) but if you change this and put 'tg != iter' first you'll save one unnecessary string comparison.
Only in the case where tg == iter, otherwise you have one unnecessary pointer comparison for every other group.
Quoted 25 lines
Quoted 4 lines
block/throttle-groups.c +3
-0+error_setg (errp,"A group with this name already exists" ); +return ; + }block/throttle-groups.c void throttle_group_detach_aio_context(ThrottleGroupMember *tgm) · line 716
Quoted 10 lines
block/throttle-groups.c +10
-0+ } + } + +/* unfix buckets to check validity */ +throttle_get_config (&tg->ts, cfg); +if (!throttle_is_valid (cfg, errp)) { +return ; + } +/* fix buckets again */ +throttle_config (&tg->ts, tg->clock_type, cfg);
throttle_get_config(ts, cfg)makes a copy of the existing configuration, but the cfg pointer that you are passing already points to the existing configuration, so in practice you are doing*(ts->cfg) = *(ts->cfg); throttle_unfix_bucket(...);and since you "unfixed" the configuration, then you need undo the whole thing by setting the config again:
Quoted 6 lines
*(ts->cfg) = *(ts->cfg); throttle_fix_bucket(...);You should declare a local ThrottleConfig variable, copy the config there, and run
throttle_is_valid()on that copy. The finalthrottle_config()call is unnecessary.
I figured I didn't have to make an extra copy but this looks bad in retrospect
Quoted 54 lines
Once the patches I sent yesterday are merged we'll be able to skip the
throttle_get_config()call and dothrottle_is_valid(&tg->ts.cfg, errp)directly.Quoted 49 lines
block/throttle-groups.c +49
-0+static void throttle_group_set (Object *obj,Visitor *v,const char * name, +void *opaque,Error **errp) + +{ +ThrottleGroup *tg =THROTTLE_GROUP (obj); +ThrottleConfig cfg; +ThrottleParamInfo *info = opaque; +Error *local_err =NULL ; +int64_t value; + +/* If we have finished initialization, don't accept individual property +* changes through QOM. Throttle configuration limits must be set in one +* transaction, as certain combinations are invalid. +*/ +if (tg->is_initialized) { +error_setg (&local_err,"Property cannot be set after initialization" ); + goto ret; + } + +visit_type_int64 (v, name, &value, &local_err); +if (local_err) { + goto ret; + } +if (value <0 ) { +error_setg (&local_err,"Property values cannot be negative" ); + goto ret; + } + + cfg = tg->ts.cfg; +switch (info->data_type) { +case UINT64 : + { +uint64_t *field = (void *)&cfg.buckets[info->type] + info->offset; + *field = value; + } +break ; +case DOUBLE : + { +double *field = (void *)&cfg.buckets[info->type] + info->offset; + *field = value; + } +break ; +case UNSIGNED : + { +if (value >UINT_MAX ) { +error_setg (&local_err,"%s value must be in the" +"range [0, %u]" , info->name,UINT_MAX ); + goto ret; + }
Quoted 8 lines
block/throttle-groups.c void throttle_group_detach_aio_context(ThrottleGroupMember *tgm) · line 785
Quoted 6 lines
block/throttle-groups.c +6
-0+unsigned *field = (void *)&cfg.buckets[info->type] + info->offset; + *field = value; + } + } + + tg->ts.cfg = cfg;There's a bit of black magic here :)
This offset business is indeed black magic! And university makes you think the world runs on ML and Haskell...
Quoted 19 lines
you have a user-defined enumeration
(UNSIGNED, DOUBLE, UINT64) to identify C types and I'm worried about what happens if the data types of LeakyBucket change, will we be able to detect the problem?Out of the blue I can think of the following alternative:
- There's 6 different buckets (we have BucketType listing them)
- There's 3 values we can set in each bucket (max, avg,
burst_length). For those we can have an internal enumeration (probably with one additional value for iops-size).- In the 'properties' array, for each property we know its category (and I mean: avg, max, burst-lenght, iops-size) and the bucket where they belong.
- In
throttle_group_set()the switch could be something like this:
Quoted 14 lines
switch (info->category) {
case THROTTLE_VALUE_AVG:
cfg->buckets[info->bkt_type].avg = value;
break;
case THROTTLE_VALUE_MAX:
cfg->buckets[info->bkt_type].max = value;
break;
case THROTTLE_VALUE_BURST_LENGTH:
/* Code here to check that value <= UINT_MAX */
cfg->buckets[info->bkt_type].iops_length = value;
break;
case THROTTLE_VALUE_IOPS_SIZE:
cfg->op_size = value;
}I don't think that solves the type problem, since C uses coercion. For example if hypothetically a double changes to uint in the future, value will not be checked for overflow and the compiler would just convert it to uint implicitly. An academic solution would be to use a strongly typed language!
Quoted 6 lines
block/throttle-groups.c void throttle_group_detach_aio_context(ThrottleGroupMember *tgm) · line 794
Quoted 3 lines
block/throttle-groups.c +2
-0+static void throttle_group_get (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp)And the same approach here, of course.
Quoted 13 lines
block/throttle-groups.c void throttle_group_detach_aio_context(ThrottleGroupMember *tgm) · line 835
Quoted 11 lines
block/throttle-groups.c +11
-0+static void throttle_group_set_limits (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) + +{ +ThrottleGroup *tg =THROTTLE_GROUP (obj); +ThrottleConfig cfg; +ThrottleLimits *arg =NULL ; +Error *local_err =NULL ; + + arg =g_new0 (ThrottleLimits,1 );Do you need to allocate ThrottleLimits in the heap?
I thought you actually do because visit_type_ThrottleLimits() frees arg on error:
if (err && visit_is_input(v)) {
qapi_free_ThrottleLimits(*obj);
*obj = NULL;
}but I see now it doesn't actually call g_free and only sets the pointer to NULL. Is that supposed to prevent use of a stack pointer in the caller after error? I am a bit confused as to why. (This is the generated qapi-visit.c code but similar to other visitor functions)
I will change this back to
ThrottleLimits arg = { 0 };
ThrottleLimits *argp = &arg;
visit_type_ThrottleLimits(v, name, &argp, &local_err);Quoted 23 lines
Quoted 8 lines
block/throttle-groups.c +7
-0+static void throttle_group_get_limits (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) +{ +ThrottleGroup *tg =THROTTLE_GROUP (obj); +ThrottleConfig cfg; +ThrottleLimits *arg =NULL ;block/throttle-groups.c void throttle_group_detach_aio_context(ThrottleGroupMember *tgm) · line 872
Quoted 10 lines
block/throttle-groups.c +10
-0+ +qemu_mutex_lock (&tg->lock); +throttle_get_config (&tg->ts, &cfg); +qemu_mutex_unlock (&tg->lock); + + arg =g_new0 (ThrottleLimits,1 ); +throttle_config_to_limits (&cfg, arg); + +visit_type_ThrottleLimits (v, name, &arg, errp); +g_free (arg);Same question here.
Berto
Re: [Qemu-devel] [PATCH v5 4/6] block: convert ThrottleGroup to object with QOM
Quoted 10 lines · Manos Pitsidianakis
Quoted 7 lines
block/throttle-groups.c void throttle_group_detach_aio_context(ThrottleGroupMember *tgm) · line 703
Quoted 4 lines
block/throttle-groups.c +4
-0+if (tg->name) { +/* error if name is duplicate */ + QTAILQ_FOREACH(iter, &throttle_groups, list) { +if (!g_strcmp0 (tg->name, iter->name) && tg != iter) {I'm just nitpicking here :) but if you change this and put 'tg != iter' first you'll save one unnecessary string comparison.
Only in the case where tg == iter, otherwise you have one unnecessary pointer comparison for every other group.
Right, although calling g_strcmp0() may be more expensive than doing all the pointer comparisons? Anyway it probably doesn't matter much in the end.
Quoted 29 lines
Quoted 14 lines
Out of the blue I can think of the following alternative:
- There's 6 different buckets (we have BucketType listing them)
- There's 3 values we can set in each bucket (max, avg,
burst_length). For those we can have an internal enumeration (probably with one additional value for iops-size).- In the 'properties' array, for each property we know its category (and I mean: avg, max, burst-lenght, iops-size) and the bucket where they belong.
- In
throttle_group_set()the switch could be something like this:Quoted 14 lines
switch (info->category) { case THROTTLE_VALUE_AVG: cfg->buckets[info->bkt_type].avg = value; break; case THROTTLE_VALUE_MAX: cfg->buckets[info->bkt_type].max = value; break; case THROTTLE_VALUE_BURST_LENGTH: /* Code here to check that value <= UINT_MAX */ cfg->buckets[info->bkt_type].iops_length = value; break; case THROTTLE_VALUE_IOPS_SIZE: cfg->op_size = value; }
Quoted 6 lines
I don't think that solves the type problem, since C uses coercion. For example if hypothetically a double changes to uint in the future,
valuewill not be checked for overflow and the compiler would just convert it to uint implicitly. An academic solution would be to use a strongly typed language!Quoted 1 line
Indeed, but I'd rather have this:
unsigned int avg; double value = 2.5; avg = value;
than this:
unsigned int avg; double value = 2.5; *((double *)&avg) = value;
Quoted 22 lines
Quoted 5 lines
Quoted 5 lines
block/throttle-groups.c +5
-0+static void throttle_group_set_limits (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) + +{Quoted 8 lines
block/throttle-groups.c void throttle_group_detach_aio_context(ThrottleGroupMember *tgm) · line 835
Quoted 6 lines
block/throttle-groups.c +6
-0+ThrottleGroup *tg =THROTTLE_GROUP (obj); +ThrottleConfig cfg; +ThrottleLimits *arg =NULL ; +Error *local_err =NULL ; + + arg =g_new0 (ThrottleLimits,1 );Do you need to allocate ThrottleLimits in the heap?
I thought you actually do because
visit_type_ThrottleLimits()frees arg on error:if (err && visit_is_input(v)) { qapi_free_ThrottleLimits(*obj); *obj = NULL; }
Quoted 4 lines
but I see now it doesn't actually call
g_freeand only sets the pointer to NULL. Is that supposed to prevent use of a stack pointer in the caller after error? I am a bit confused as to why. (This is the generatedqapi-visit.ccode but similar to other visitor functions)
I'm not sure why it does that.
Berto
PATCH v5 5/6 block: add throttle block filter driver
In reply to Manos Pitsidianakisblock/throttle.c uses existing I/O throttle infrastructure inside a block filter driver. I/O operations are intercepted in the filter's read/write coroutines, and referred to block/throttle-groups.c
The driver can be used with the syntax
-drive driver=throttle,file.filename=foo.qcow2, \
limits.iops-total=...,throttle-group=bar
The configuration flags and their semantics are identical to the hardcoded throttling ones.
A node can be created referring to an existing group, and will overwrite its limits if any are specified, otherwise they are retained.
--- qapi/block-core.json | 22 ++- include/qemu/throttle-options.h | 1 + block/throttle.c | 314 ++++++++++++++++++++++++++++++++++++++++ block/Makefile.objs | 1 + 4 files changed, 337 insertions(+), 1 deletion(-) create mode 100644 block/throttle.c
qapi/block-core.json +21 -1
@@ -2222,6 +2222,7 @@ # Drivers that are supported in block device operations. # # @vxhs: Since 2.10 +# @throttle: Since 2.11 # # Since: 2.9 ##
@@ -2231,7 +2232,7 @@ 'host_device', 'http', 'https', 'iscsi', 'luks', 'nbd', 'nfs', 'null-aio', 'null-co', 'parallels', 'qcow', 'qcow2', 'qed', 'quorum', 'raw', 'rbd', 'replication', 'sheepdog', 'ssh', - 'vdi', 'vhdx', 'vmdk', 'vpc', 'vvfat', 'vxhs' ] } + 'throttle', 'vdi', 'vhdx', 'vmdk', 'vpc', 'vvfat', 'vxhs' ] } ## # @BlockdevOptionsFile:
@@ -3095,6 +3096,24 @@ '*tls-creds': 'str' } } ## +# @BlockdevOptionsThrottle: +# +# Driver specific block device options for the throttle driver +# +# @throttle-group: the name of the throttle-group object to use. It will be +# created if it doesn't already exist. If not specified, an +# anonymous group will be created, which cannot be +# referenced by other throttle nodes. +# @file: reference to or definition of the data source block device +# @limits: ThrottleLimits options +# Since: 2.11 +## +{ 'struct': 'BlockdevOptionsThrottle', + 'data': { '*throttle-group': 'str', + 'file' : 'BlockdevRef', + '*limits' : 'ThrottleLimits' + } } +## # @BlockdevOptions: # # Options for creating a block device. Many options are available for all
@@ -3155,6 +3174,7 @@ 'replication':'BlockdevOptionsReplication', 'sheepdog': 'BlockdevOptionsSheepdog', 'ssh': 'BlockdevOptionsSsh', + 'throttle': 'BlockdevOptionsThrottle', 'vdi': 'BlockdevOptionsGenericFormat', 'vhdx': 'BlockdevOptionsGenericFormat', 'vmdk': 'BlockdevOptionsGenericCOWFormat',
include/qemu/throttle-options.h +1 -0
@@ -29,6 +29,7 @@#define QEMU_OPT_BPS_WRITE_MAX "bps-write-max"#define QEMU_OPT_BPS_WRITE_MAX_LENGTH "bps-write-max-length"#define QEMU_OPT_IOPS_SIZE "iops-size" +#define QEMU_OPT_THROTTLE_GROUP_NAME "throttle-group"#define THROTTLE_OPT_PREFIX "throttling."#define THROTTLE_OPTS \
block/throttle.c new file +314 -0
314 lines not on this page · raw message
block/Makefile.objs +1 -0
@@ -25,6 +25,7 @@ block-obj-y += accounting.o dirty-bitmap.o block-obj-y += write-threshold.o block-obj-y += backup.o block-obj-$(CONFIG_REPLICATION) += replication.o +block-obj-y += throttle.o block-obj-y += crypto.o
Signature · 1 line
2.11.0
Re: [Qemu-devel] [PATCH v5 5/6] block: add throttle block filter driver
Quoted 7 lines · Manos Pitsidianakis
block/throttle.cuses existing I/O throttle infrastructure inside a block filter driver. I/O operations are intercepted in the filter's read/write coroutines, and referred toblock/throttle-groups.cThe driver can be used with the syntax
-drive driver=throttle,file.filename=foo.qcow2, \
limits.iops-total=...,throttle-group=bar
I had understood that we would get rid of the limits.* options in this driver, or did I get it wrong?
Other than that, the rest of the code looks perfect to me.
Berto
Re: [Qemu-devel] [PATCH v5 5/6] block: add throttle block filter driver
Quoted 9 lines · Alberto Garcia
Quoted 7 lines · Manos Pitsidianakis
block/throttle.cuses existing I/O throttle infrastructure inside a block filter driver. I/O operations are intercepted in the filter's read/write coroutines, and referred toblock/throttle-groups.cThe driver can be used with the syntax
-drive driver=throttle,file.filename=foo.qcow2, \
limits.iops-total=...,throttle-group=bar
Quoted 7 lines
I had understood that we would get rid of the limits.* options in this driver, or did I get it wrong?
Other than that, the rest of the code looks perfect to me.
Berto
I was going to send a patch after this was merged along with adding ThrottleGroups to the root container, to speed things up. Do you prefer to do this in this patch?
The root container patch probably has to go to the 'remove legacy' series since adding it here means the name collision errors introduce error paths in block/block-backend.c that go away in that series, and that'd be a waste of effort.
Re: [Qemu-devel] [PATCH v5 5/6] block: add throttle block filter driver
Quoted 10 lines · Manos Pitsidianakis
Quoted 7 lines
Quoted 3 lines
The driver can be used with the syntax
-drive driver=throttle,file.filename=foo.qcow2, \
limits.iops-total=...,throttle-group=barI had understood that we would get rid of the limits.* options in this driver, or did I get it wrong?
I was going to send a patch after this was merged along with adding ThrottleGroups to the root container, to speed things up. Do you prefer to do this in this patch?
I'm not sure what's the benefit of adding a complete infrastructure that you are going to remove immediately afterwards :-?
Quoted 4 lines
The root container patch probably has to go to the 'remove legacy' series since adding it here means the name collision errors introduce error paths in
block/block-backend.cthat go away in that series, and that'd be a waste of effort.
Ok.
Berto
PATCH v5 6/6 block: add iotest 184 for the throttle filter driver
In reply to Manos Pitsidianakis--- tests/qemu-iotests/184 | 310 +++++++++++++++++++++++++++++++++ tests/qemu-iotests/184.out | 422 +++++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/group | 1 + 3 files changed, 733 insertions(+) create mode 100755 tests/qemu-iotests/184 create mode 100644 tests/qemu-iotests/184.out
tests/qemu-iotests/184 new file +310 -0
@@ -0,0 +1,310 @@ +#!/bin/bash +# +# Test I/O throttle block filter driver interface +# +# Copyright (C) 2017 Manos Pitsidianakis +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +# creator +owner="Manos Pitsidianakis" + +seq=`basename $0` +echo "QA output created by $seq" + +here=`pwd` +status=1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter + +_supported_fmt qcow2 +_supported_proto file +_supported_os Linux + +function do_run_qemu() +{ + echo Testing: "$@" | _filter_imgfmt + $QEMU -nographic -qmp-pretty stdio -serial none "$@" + echo +} + +function run_qemu() +{ + do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qemu | _filter_qmp\ + | _filter_qemu_io | _filter_generated_node_ids +} + +_make_test_img 64M +test_throttle=$($QEMU_IMG --help|grep throttle) +[ "$test_throttle" = "" ] && _supported_fmt throttle + +echo +echo "== checking interface ==" + +run_qemu <<EOF +{ "execute": "qmp_capabilities" } +{ "execute": "blockdev-add", + "arguments": { + "driver": "$IMGFMT", + "node-name": "disk0", + "file": { + "driver": "file", + "filename": "$TEST_IMG" + } + } +} +{ "execute": "object-add", + "arguments": { + "qom-type": "throttle-group", + "id": "group0", + "props": { + "limits" : { + "iops-total": 1000 + } + } + } +} +{ "execute": "blockdev-add", + "arguments": { + "driver": "throttle", + "node-name": "throttle0", + "throttle-group": "group0", + "file": "disk0" + } +} +{ "execute": "query-named-block-nodes" } +{ "execute": "query-block" } +{ "execute": "quit" } +EOF + +echo +echo "== create anonymous group ==" + +run_qemu <<EOF +{ "execute": "qmp_capabilities" } +{ "execute": "blockdev-add", + "arguments": { + "driver": "$IMGFMT", + "node-name": "disk0", + "file": { + "driver": "file", + "filename": "$TEST_IMG" + } + } +} +{ "execute": "blockdev-add", + "arguments": { + "driver": "throttle", + "node-name": "throttle-anonymous", + "limits" : { + "iops-total" : 1000 + }, + "file": "disk0" + } +} +{ "execute": "quit" } +EOF + +echo +echo "== property changes in ThrottleGroup ==" + +run_qemu <<EOF +{ "execute": "qmp_capabilities" } +{ "execute": "object-add", + "arguments": { + "qom-type": "throttle-group", + "id": "group0", + "props" : { + "limits": { + "iops-total": 1000 + } + } + } +} +{ "execute" : "qom-get", + "arguments" : { + "path" : "group0", + "property" : "limits" + } +} +{ "execute" : "qom-set", + "arguments" : { + "path" : "group0", + "property" : "limits", + "value" : { + "iops-total" : 0 + } + } +} +{ "execute" : "qom-get", + "arguments" : { + "path" : "group0", + "property" : "limits" + } +} +{ "execute": "blockdev-add", + "arguments": { + "driver": "$IMGFMT", + "node-name": "disk0", + "file": { + "driver": "file", + "filename": "$TEST_IMG" + } + } +} +{ "execute": "blockdev-add", + "arguments": { + "driver": "throttle", + "node-name": "throttle0", + "throttle-group": "group0", + "limits" : { + "iops-total" : 128, + "iops-total-max" : 256, + "iops-total-max-length" : 60 + }, + "file": "disk0" + } +} +{ "execute" : "qom-get", + "arguments" : { + "path" : "group0", + "property" : "limits" + } +} +{ "execute": "quit" } +EOF + +echo +echo "== object creation/set errors ==" + +run_qemu <<EOF +{ "execute": "qmp_capabilities" } +{ "execute": "object-add", + "arguments": { + "qom-type": "throttle-group", + "id": "group0", + "props" : { + "limits": { + "iops-total": 1000 + } + } + } +} +{ "execute" : "qom-set", + "arguments" : { + "path" : "group0", + "property" : "x-iops-total", + "value" : 0 + } +} +{ "execute" : "qom-set", + "arguments" : { + "path" : "group0", + "property" : "limits", + "value" : { + "iops-total" : 10, + "iops-read" : 10 + } + } +} +{ "execute": "quit" } +EOF + +echo +echo "== specify both limits and group ==" + +run_qemu <<EOF +{ "execute": "qmp_capabilities" } +{ "execute": "blockdev-add", + "arguments": { + "driver": "$IMGFMT", + "node-name": "disk0", + "file": { + "driver": "file", + "filename": "$TEST_IMG" + } + } +} +{ "execute": "object-add", + "arguments": { + "qom-type": "throttle-group", + "id": "group0", + "props": { + "limits" : { + "iops-total": 1000 + } + } + } +} +{ "execute": "blockdev-add", + "arguments": { + "driver": "throttle", + "node-name": "throttle0", + "throttle-group": "group0", + "limits" : { + "iops-total" : 256, + "iops-total-max": 2048, + "iops-total-max-length": 120 + }, + "file": "disk0" + } +} +{ "execute" : "qom-get", + "arguments" : { + "path" : "group0", + "property" : "limits" + } +} +{ "execute": "quit" } +EOF + +echo +echo "== specify neither limits nor group ==" + +run_qemu <<EOF +{ "execute": "qmp_capabilities" } +{ "execute": "blockdev-add", + "arguments": { + "driver": "$IMGFMT", + "node-name": "disk0", + "file": { + "driver": "file", + "filename": "$TEST_IMG" + } + } +} +{ "execute": "blockdev-add", + "arguments": { + "driver": "throttle", + "node-name": "throttle0", + "file": "disk0" + } +} +{ "execute": "quit" } +EOF + +echo +# success, all done +echo "*** done" +rm -f $seq.full +status=0
tests/qemu-iotests/184.out new file +422 -0
422 lines not on this page · raw message
tests/qemu-iotests/group +1 -0
@@ -180,6 +180,7 @@ 181 rw auto migration 182 rw auto quick 183 rw auto migration +184 rw auto quick 185 rw auto 186 rw auto 187 rw auto
Signature · 1 line
2.11.0