diff mbox

[12/15] blockjob: Add 'id' parameter to 'block-job-pause'

Message ID ae2a92e1ece9587b6971713eef357072d5b7ed7b.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-pause' 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_pause' command remains unchanged.

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

Comments

Max Reitz June 20, 2016, 6:34 p.m. UTC | #1
On 09.06.2016 10:20, Alberto Garcia wrote:
> This patch allows the 'block-job-pause' 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_pause' command remains unchanged.
> 
> Signed-off-by: Alberto Garcia <berto@igalia.com>
> ---
>  blockdev.c           | 7 +++++--
>  hmp.c                | 2 +-
>  qapi/block-core.json | 9 +++++++--
>  qmp-commands.hx      | 2 +-
>  4 files changed, 14 insertions(+), 6 deletions(-)

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

Patch

diff --git a/blockdev.c b/blockdev.c
index 97041b4..591f163 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -3783,10 +3783,13 @@  out:
     aio_context_release(aio_context);
 }
 
-void qmp_block_job_pause(const char *device, Error **errp)
+void qmp_block_job_pause(bool has_id, const char *id,
+                         bool has_device, const char *device, 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 || job->user_paused) {
         return;
diff --git a/hmp.c b/hmp.c
index adeb4de..783c3af 100644
--- a/hmp.c
+++ b/hmp.c
@@ -1515,7 +1515,7 @@  void hmp_block_job_pause(Monitor *mon, const QDict *qdict)
     Error *error = NULL;
     const char *device = qdict_get_str(qdict, "device");
 
-    qmp_block_job_pause(device, &error);
+    qmp_block_job_pause(false, NULL, true, device, &error);
 
     hmp_handle_error(mon, &error);
 }
diff --git a/qapi/block-core.json b/qapi/block-core.json
index 38dd3f2..0eaf531 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -1537,14 +1537,19 @@ 
 # the operation is actually paused.  Cancelling a paused job automatically
 # resumes it.
 #
-# @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
 #
 # Returns: Nothing on success
 #          If no background operation is active on this device, DeviceNotActive
 #
 # Since: 1.3
 ##
-{ 'command': 'block-job-pause', 'data': { 'device': 'str' } }
+{ 'command': 'block-job-pause', 'data': { '*id': 'str', '*device': 'str' } }
 
 ##
 # @block-job-resume:
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 6bf8c3d..571feb6 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -1295,7 +1295,7 @@  EQMP
     },
     {
         .name       = "block-job-pause",
-        .args_type  = "device:B",
+        .args_type  = "id:s?,device:B?",
         .mhandler.cmd_new = qmp_marshal_block_job_pause,
     },
     {