]> git.proxmox.com Git - qemu.git/commitdiff
block: use Error mechanism instead of -errno for block_job_set_speed()
authorStefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Wed, 25 Apr 2012 15:51:01 +0000 (16:51 +0100)
committerLuiz Capitulino <lcapitulino@redhat.com>
Fri, 27 Apr 2012 14:44:50 +0000 (11:44 -0300)
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>
block.c
block/stream.c
block_int.h
blockdev.c
qapi-schema.json

diff --git a/block.c b/block.c
index 2b72a0f3b066479cf1d09ba3261a3dc0b7a7f25f..dc02736d7e9f3d89bf8af83072587faf79e43c9f 100644 (file)
--- a/block.c
+++ b/block.c
@@ -4114,18 +4114,21 @@ void block_job_complete(BlockJob *job, int ret)
     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) {
-        return -ENOTSUP;
+        error_set(errp, QERR_NOT_SUPPORTED);
+        return;
     }
-    rc = job->job_type->set_speed(job, value);
-    if (rc == 0) {
-        job->speed = value;
+    job->job_type->set_speed(job, value, &local_err);
+    if (error_is_set(&local_err)) {
+        error_propagate(errp, local_err);
+        return;
     }
-    return rc;
+
+    job->speed = value;
 }
 
 void block_job_cancel(BlockJob *job)
index 7002dc85734cccedf9fd682f168a02cc750d749b..06bc70a9b4deda4866703c70642bea265c05c8bc 100644 (file)
@@ -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 = {
index e70a33e0c2a24eb1bc5025a7c78361fcce747216..e042676be3610eec735acd21c39822c2919264d3 100644 (file)
@@ -79,7 +79,7 @@ typedef struct BlockJobType {
     const char *job_type;
 
     /** 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;
 
 /**
@@ -375,11 +375,12 @@ void block_job_complete(BlockJob *job, int ret);
  * block_job_set_speed:
  * @job: The job to set the speed for.
  * @speed: The new value
+ * @errp: Error object.
  *
  * Set a rate-limiting parameter for the job; the actual meaning may
  * 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:
index a41147749a028067d549c9f6b300f2e007237d37..70733308c9893d6ea721fc35ec95608bd1523ae5 100644 (file)
@@ -1145,9 +1145,7 @@ void qmp_block_job_set_speed(const char *device, int64_t value, Error **errp)
         return;
     }
 
-    if (block_job_set_speed(job, value) < 0) {
-        error_set(errp, QERR_NOT_SUPPORTED);
-    }
+    block_job_set_speed(job, value, errp);
 }
 
 void qmp_block_job_cancel(const char *device, Error **errp)
index 64998959db2e360cfccb2039c9e5bdec22033f18..49f1e16bd706376a63a61ed4e02d91addf39d1a5 100644 (file)
 #
 # Returns: Nothing on success
 #          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
 #
 # Since: 1.1