@@ -577,6 +577,11 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs,
return NULL;
}
+ if (speed < 0) {
+ error_setg(errp, QERR_INVALID_PARAMETER, "speed");
+ return NULL;
+ }
+
if (sync_mode == MIRROR_SYNC_MODE_INCREMENTAL) {
if (!sync_bitmap) {
error_setg(errp, "must provide a valid bitmap name for "
@@ -309,6 +309,12 @@ void commit_start(const char *job_id, BlockDriverState *bs,
return;
}
+ if (speed < 0) {
+ error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "speed",
+ "a non-negative rate limit");
+ return;
+ }
+
s = block_job_create(job_id, &commit_job_driver, bs, 0, BLK_PERM_ALL,
speed, BLOCK_JOB_DEFAULT, NULL, NULL, errp);
if (!s) {
@@ -1139,6 +1139,12 @@ static void mirror_start_job(const char *job_id, BlockDriverState *bs,
Error *local_err = NULL;
int ret;
+ if (speed < 0) {
+ error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "speed",
+ "a non-negative rate limit");
+ return;
+ }
+
if (granularity == 0) {
granularity = bdrv_get_default_bitmap_granularity(target);
}
@@ -237,6 +237,12 @@ void stream_start(const char *job_id, BlockDriverState *bs,
}
}
+ if (speed < 0) {
+ error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "speed",
+ "a non-negative rate limit");
+ return;
+ }
+
/* Prevent concurrent jobs trying to modify the graph structure here, we
* already have our own plans. Also don't allow resize as the image size is
* queried only at the job start and then cached. */
@@ -604,7 +604,7 @@ static void block_job_event_completed(BlockJob *job, const char *msg)
void *block_job_create(const char *job_id, const BlockJobDriver *driver,
BlockDriverState *bs, uint64_t perm,
- uint64_t shared_perm, int64_t speed, int flags,
+ uint64_t shared_perm, uint64_t speed, int flags,
BlockCompletionFunc *cb, void *opaque, Error **errp)
{
BlockBackend *blk;
@@ -641,12 +641,6 @@ void *block_job_create(const char *job_id, const BlockJobDriver *driver,
}
}
- if (speed < 0) {
- error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "speed",
- "a non-negative rate limit");
- return NULL;
- }
-
blk = blk_new(perm, shared_perm);
ret = blk_insert_bs(blk, bs, errp);
if (ret < 0) {
@@ -133,7 +133,7 @@ struct BlockJobDriver {
*/
void *block_job_create(const char *job_id, const BlockJobDriver *driver,
BlockDriverState *bs, uint64_t perm,
- uint64_t shared_perm, int64_t speed, int flags,
+ uint64_t shared_perm, uint64_t speed, int flags,
BlockCompletionFunc *cb, void *opaque, Error **errp);
/**
block_job_create() takes int64_t speed. The underlying RateLimit abstraction takes uint64_t. block_job_create() converts from int64_t to uint64_t, rejecting negative speed. Lift this check and conversion out of block_job_create() into its callers. I'm going to lift it further until it falls off the top. Signed-off-by: Markus Armbruster <armbru@redhat.com> --- block/backup.c | 5 +++++ block/commit.c | 6 ++++++ block/mirror.c | 6 ++++++ block/stream.c | 6 ++++++ blockjob.c | 8 +------- include/block/blockjob_int.h | 2 +- 6 files changed, 25 insertions(+), 8 deletions(-)