mirror of
https://git.proxmox.com/git/qemu
synced 2025-08-14 17:19:36 +00:00
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 <stefanha@linux.vnet.ibm.com> Acked-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
This commit is contained in:
parent
fd7f8c6537
commit
9e6636c72d
17
block.c
17
block.c
@ -4114,19 +4114,22 @@ void block_job_complete(BlockJob *job, int ret)
|
|||||||
bdrv_set_in_use(bs, 0);
|
bdrv_set_in_use(bs, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int block_job_set_speed(BlockJob *job, int64_t value)
|
void block_job_set_speed(BlockJob *job, int64_t value, Error **errp)
|
||||||
{
|
{
|
||||||
int rc;
|
Error *local_err = NULL;
|
||||||
|
|
||||||
if (!job->job_type->set_speed) {
|
if (!job->job_type->set_speed) {
|
||||||
return -ENOTSUP;
|
error_set(errp, QERR_NOT_SUPPORTED);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
rc = job->job_type->set_speed(job, value);
|
job->job_type->set_speed(job, value, &local_err);
|
||||||
if (rc == 0) {
|
if (error_is_set(&local_err)) {
|
||||||
|
error_propagate(errp, local_err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
job->speed = value;
|
job->speed = value;
|
||||||
}
|
}
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
void block_job_cancel(BlockJob *job)
|
void block_job_cancel(BlockJob *job)
|
||||||
{
|
{
|
||||||
|
@ -263,15 +263,15 @@ retry:
|
|||||||
block_job_complete(&s->common, ret);
|
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);
|
StreamBlockJob *s = container_of(job, StreamBlockJob, common);
|
||||||
|
|
||||||
if (value < 0) {
|
if (value < 0) {
|
||||||
return -EINVAL;
|
error_set(errp, QERR_INVALID_PARAMETER, "value");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
ratelimit_set_speed(&s->limit, value / BDRV_SECTOR_SIZE);
|
ratelimit_set_speed(&s->limit, value / BDRV_SECTOR_SIZE);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static BlockJobType stream_job_type = {
|
static BlockJobType stream_job_type = {
|
||||||
|
@ -79,7 +79,7 @@ typedef struct BlockJobType {
|
|||||||
const char *job_type;
|
const char *job_type;
|
||||||
|
|
||||||
/** Optional callback for job types that support setting a speed limit */
|
/** Optional callback for job types that support setting a speed limit */
|
||||||
int (*set_speed)(BlockJob *job, int64_t value);
|
void (*set_speed)(BlockJob *job, int64_t value, Error **errp);
|
||||||
} BlockJobType;
|
} BlockJobType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -375,11 +375,12 @@ void block_job_complete(BlockJob *job, int ret);
|
|||||||
* block_job_set_speed:
|
* block_job_set_speed:
|
||||||
* @job: The job to set the speed for.
|
* @job: The job to set the speed for.
|
||||||
* @speed: The new value
|
* @speed: The new value
|
||||||
|
* @errp: Error object.
|
||||||
*
|
*
|
||||||
* Set a rate-limiting parameter for the job; the actual meaning may
|
* Set a rate-limiting parameter for the job; the actual meaning may
|
||||||
* vary depending on the job type.
|
* vary depending on the job type.
|
||||||
*/
|
*/
|
||||||
int block_job_set_speed(BlockJob *job, int64_t value);
|
void block_job_set_speed(BlockJob *job, int64_t value, Error **errp);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* block_job_cancel:
|
* block_job_cancel:
|
||||||
|
@ -1145,9 +1145,7 @@ void qmp_block_job_set_speed(const char *device, int64_t value, Error **errp)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (block_job_set_speed(job, value) < 0) {
|
block_job_set_speed(job, value, errp);
|
||||||
error_set(errp, QERR_NOT_SUPPORTED);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void qmp_block_job_cancel(const char *device, Error **errp)
|
void qmp_block_job_cancel(const char *device, Error **errp)
|
||||||
|
@ -1596,6 +1596,7 @@
|
|||||||
#
|
#
|
||||||
# Returns: Nothing on success
|
# Returns: Nothing on success
|
||||||
# If the job type does not support throttling, NotSupported
|
# If the job type does not support throttling, NotSupported
|
||||||
|
# If the speed value is invalid, InvalidParameter
|
||||||
# If streaming is not active on this device, DeviceNotActive
|
# If streaming is not active on this device, DeviceNotActive
|
||||||
#
|
#
|
||||||
# Since: 1.1
|
# Since: 1.1
|
||||||
|
Loading…
Reference in New Issue
Block a user