From fd7f8c65377ee918479e43b38d44f54f13aa6548 Mon Sep 17 00:00:00 2001 From: Stefan Hajnoczi Date: Wed, 25 Apr 2012 16:51:00 +0100 Subject: block: use Error mechanism instead of -errno for block_job_create() The block job API uses -errno return values internally and we convert these to Error in the QMP functions. This is ugly because the Error should be created at the point where we still have all the relevant information. More importantly, it is hard to add new error cases to this case since we quickly run out of -errno values without losing information. Go ahead and use Error directly and don't convert later. Signed-off-by: Stefan Hajnoczi Acked-by: Kevin Wolf Signed-off-by: Luiz Capitulino --- block/stream.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'block') diff --git a/block/stream.c b/block/stream.c index 0efe1ad..7002dc8 100644 --- a/block/stream.c +++ b/block/stream.c @@ -280,16 +280,16 @@ static BlockJobType stream_job_type = { .set_speed = stream_set_speed, }; -int stream_start(BlockDriverState *bs, BlockDriverState *base, - const char *base_id, BlockDriverCompletionFunc *cb, - void *opaque) +void stream_start(BlockDriverState *bs, BlockDriverState *base, + const char *base_id, BlockDriverCompletionFunc *cb, + void *opaque, Error **errp) { StreamBlockJob *s; Coroutine *co; - s = block_job_create(&stream_job_type, bs, cb, opaque); + s = block_job_create(&stream_job_type, bs, cb, opaque, errp); if (!s) { - return -EBUSY; /* bs must already be in use */ + return; } s->base = base; @@ -300,5 +300,4 @@ int stream_start(BlockDriverState *bs, BlockDriverState *base, co = qemu_coroutine_create(stream_run); trace_stream_start(bs, base, s, co, opaque); qemu_coroutine_enter(co, s); - return 0; } -- cgit v1.1 From 9e6636c72d8d6f0605e23ed820c8487686882b12 Mon Sep 17 00:00:00 2001 From: Stefan Hajnoczi Date: Wed, 25 Apr 2012 16:51:01 +0100 Subject: block: use Error mechanism instead of -errno for block_job_set_speed() There are at least two different errors that can occur in block_job_set_speed(): the job might not support setting speeds or the value might be invalid. Use the Error mechanism to report the error where it occurs. Signed-off-by: Stefan Hajnoczi Acked-by: Kevin Wolf Signed-off-by: Luiz Capitulino --- block/stream.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'block') diff --git a/block/stream.c b/block/stream.c index 7002dc8..06bc70a 100644 --- a/block/stream.c +++ b/block/stream.c @@ -263,15 +263,15 @@ retry: block_job_complete(&s->common, ret); } -static int stream_set_speed(BlockJob *job, int64_t value) +static void stream_set_speed(BlockJob *job, int64_t value, Error **errp) { StreamBlockJob *s = container_of(job, StreamBlockJob, common); if (value < 0) { - return -EINVAL; + error_set(errp, QERR_INVALID_PARAMETER, "value"); + return; } ratelimit_set_speed(&s->limit, value / BDRV_SECTOR_SIZE); - return 0; } static BlockJobType stream_job_type = { -- cgit v1.1 From 882ec7ce531091bc0f3ffc6ac71943cf383f86a6 Mon Sep 17 00:00:00 2001 From: Stefan Hajnoczi Date: Wed, 25 Apr 2012 16:51:02 +0100 Subject: block: change block-job-set-speed argument from 'value' to 'speed' Signed-off-by: Stefan Hajnoczi Acked-by: Kevin Wolf Signed-off-by: Luiz Capitulino --- block/stream.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'block') diff --git a/block/stream.c b/block/stream.c index 06bc70a..b66242a 100644 --- a/block/stream.c +++ b/block/stream.c @@ -263,15 +263,15 @@ retry: block_job_complete(&s->common, ret); } -static void stream_set_speed(BlockJob *job, int64_t value, Error **errp) +static void stream_set_speed(BlockJob *job, int64_t speed, Error **errp) { StreamBlockJob *s = container_of(job, StreamBlockJob, common); - if (value < 0) { - error_set(errp, QERR_INVALID_PARAMETER, "value"); + if (speed < 0) { + error_set(errp, QERR_INVALID_PARAMETER, "speed"); return; } - ratelimit_set_speed(&s->limit, value / BDRV_SECTOR_SIZE); + ratelimit_set_speed(&s->limit, speed / BDRV_SECTOR_SIZE); } static BlockJobType stream_job_type = { -- cgit v1.1 From c83c66c3b58893a4dc056e272822beb88fe9ec7f Mon Sep 17 00:00:00 2001 From: Stefan Hajnoczi Date: Wed, 25 Apr 2012 16:51:03 +0100 Subject: block: add 'speed' optional parameter to block-stream Allow streaming operations to be started with an initial speed limit. This eliminates the window of time between starting streaming and issuing block-job-set-speed. Users should use the new optional 'speed' parameter instead so that speed limits are in effect immediately when the job starts. Signed-off-by: Stefan Hajnoczi Acked-by: Kevin Wolf Signed-off-by: Luiz Capitulino --- block/stream.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'block') diff --git a/block/stream.c b/block/stream.c index b66242a..6724af2 100644 --- a/block/stream.c +++ b/block/stream.c @@ -281,13 +281,14 @@ static BlockJobType stream_job_type = { }; void stream_start(BlockDriverState *bs, BlockDriverState *base, - const char *base_id, BlockDriverCompletionFunc *cb, + const char *base_id, int64_t speed, + BlockDriverCompletionFunc *cb, void *opaque, Error **errp) { StreamBlockJob *s; Coroutine *co; - s = block_job_create(&stream_job_type, bs, cb, opaque, errp); + s = block_job_create(&stream_job_type, bs, speed, cb, opaque, errp); if (!s) { return; } -- cgit v1.1