diff mbox

[11/15] blockjob: Add 'id' parameter to 'block-job-cancel'

Message ID 1599dd098b60851f684d39890f9cb5d892c83e79.1465459496.git.berto@igalia.com
State New
Headers show

Commit Message

Alberto Garcia June 9, 2016, 8:20 a.m. UTC
This patch allows the 'block-job-cancel' command to identify the
job by either its ID or its device name. The latter becomes now
optional since the ID alone is enough to identify the job.

The HMP 'block_job_cancel' command remains unchanged.

Signed-off-by: Alberto Garcia <berto@igalia.com>
---
 blockdev.c           |  7 +++++--
 hmp.c                |  2 +-
 qapi/block-core.json | 10 ++++++++--
 qmp-commands.hx      |  2 +-
 4 files changed, 15 insertions(+), 6 deletions(-)

Comments

Max Reitz June 20, 2016, 6:32 p.m. UTC | #1
On 09.06.2016 10:20, Alberto Garcia wrote:
> This patch allows the 'block-job-cancel' command to identify the
> job by either its ID or its device name. The latter becomes now
> optional since the ID alone is enough to identify the job.
> 
> The HMP 'block_job_cancel' command remains unchanged.
> 
> Signed-off-by: Alberto Garcia <berto@igalia.com>
> ---
>  blockdev.c           |  7 +++++--
>  hmp.c                |  2 +-
>  qapi/block-core.json | 10 ++++++++--
>  qmp-commands.hx      |  2 +-
>  4 files changed, 15 insertions(+), 6 deletions(-)

Reviewed-by: Max Reitz <mreitz@redhat.com>
diff mbox

Patch

diff --git a/blockdev.c b/blockdev.c
index 5aaa429..97041b4 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -3754,11 +3754,14 @@  void qmp_block_job_set_speed(bool has_id, const char *id, bool has_device,
     aio_context_release(aio_context);
 }
 
-void qmp_block_job_cancel(const char *device,
+void qmp_block_job_cancel(bool has_id, const char *id,
+                          bool has_device, const char *device,
                           bool has_force, bool force, Error **errp)
 {
     AioContext *aio_context;
-    BlockJob *job = find_block_job(NULL, device, &aio_context, errp);
+    BlockJob *job = find_block_job(has_id ? id : NULL,
+                                   has_device ? device : NULL,
+                                   &aio_context, errp);
 
     if (!job) {
         return;
diff --git a/hmp.c b/hmp.c
index 0bf5558..adeb4de 100644
--- a/hmp.c
+++ b/hmp.c
@@ -1505,7 +1505,7 @@  void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
     const char *device = qdict_get_str(qdict, "device");
     bool force = qdict_get_try_bool(qdict, "force", false);
 
-    qmp_block_job_cancel(device, true, force, &error);
+    qmp_block_job_cancel(false, NULL, true, device, true, force, &error);
 
     hmp_handle_error(mon, &error);
 }
diff --git a/qapi/block-core.json b/qapi/block-core.json
index 64038cc..38dd3f2 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -1505,7 +1505,12 @@ 
 # operation can be started at a later time to finish copying all data from the
 # backing file.
 #
-# @device: the device name
+# The job must be identified with the @id or @device parameters, but
+# only one of them must be set.
+#
+# @id: #optional the job identifier (Since 2.7)
+#
+# @device: #optional the device name
 #
 # @force: #optional whether to allow cancellation of a paused job (default
 #         false).  Since 1.3.
@@ -1515,7 +1520,8 @@ 
 #
 # Since: 1.1
 ##
-{ 'command': 'block-job-cancel', 'data': { 'device': 'str', '*force': 'bool' } }
+{ 'command': 'block-job-cancel',
+  'data': { '*id': 'str', '*device': 'str', '*force': 'bool' } }
 
 ##
 # @block-job-pause:
diff --git a/qmp-commands.hx b/qmp-commands.hx
index bbbab53..6bf8c3d 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -1290,7 +1290,7 @@  EQMP
 
     {
         .name       = "block-job-cancel",
-        .args_type  = "device:B,force:b?",
+        .args_type  = "id:s?,device:B?,force:b?",
         .mhandler.cmd_new = qmp_marshal_block_job_cancel,
     },
     {