From: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
Marcelo Tosatti <mtosatti@redhat.com>,
Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>,
Luiz Capitulino <lcapitulino@redhat.com>
Subject: [Qemu-devel] [PATCH v3 7/9] qmp: add block_job_cancel command
Date: Tue, 13 Dec 2011 13:52:29 +0000 [thread overview]
Message-ID: <1323784351-25531-8-git-send-email-stefanha@linux.vnet.ibm.com> (raw)
In-Reply-To: <1323784351-25531-1-git-send-email-stefanha@linux.vnet.ibm.com>
Add block_job_cancel, which stops an active block streaming operation.
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
---
blockdev.c | 19 ++++++++++++++++++-
hmp-commands.hx | 14 ++++++++++++++
hmp.c | 13 +++++++++++++
hmp.h | 1 +
monitor.c | 3 +++
monitor.h | 1 +
qapi-schema.json | 36 ++++++++++++++++++++++++++++++++++++
qmp-commands.hx | 18 ++++++++++++++++++
trace-events | 1 +
9 files changed, 105 insertions(+), 1 deletions(-)
diff --git a/blockdev.c b/blockdev.c
index b101ba1..b276b2f 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -919,7 +919,11 @@ static void block_stream_cb(void *opaque, int ret)
qdict_put(dict, "error", qstring_from_str(strerror(-ret)));
}
- monitor_protocol_event(QEVENT_BLOCK_JOB_COMPLETED, obj);
+ if (block_job_is_cancelled(bs->job)) {
+ monitor_protocol_event(QEVENT_BLOCK_JOB_CANCELLED, obj);
+ } else {
+ monitor_protocol_event(QEVENT_BLOCK_JOB_COMPLETED, obj);
+ }
qobject_decref(obj);
}
@@ -980,3 +984,16 @@ void qmp_block_job_set_speed(const char *device, int64_t value, Error **errp)
error_set(errp, QERR_NOT_SUPPORTED);
}
}
+
+void qmp_block_job_cancel(const char *device, Error **errp)
+{
+ BlockJob *job = find_block_job(device);
+
+ if (!job) {
+ error_set(errp, QERR_DEVICE_NOT_ACTIVE, device);
+ return;
+ }
+
+ trace_qmp_block_job_cancel(job);
+ block_job_cancel(job);
+}
diff --git a/hmp-commands.hx b/hmp-commands.hx
index 788ec97..cc91055 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -99,6 +99,20 @@ Set maximum speed for a background block operation.
ETEXI
{
+ .name = "block_job_cancel",
+ .args_type = "device:B",
+ .params = "device",
+ .help = "stop an active block streaming operation",
+ .mhandler.cmd = hmp_block_job_cancel,
+ },
+
+STEXI
+@item block_job_cancel
+@findex block_job_cancel
+Stop an active block streaming operation.
+ETEXI
+
+ {
.name = "eject",
.args_type = "force:-f,device:B",
.params = "[-f] device",
diff --git a/hmp.c b/hmp.c
index f3edf7c..66d9d0f 100644
--- a/hmp.c
+++ b/hmp.c
@@ -559,3 +559,16 @@ void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict)
error_free(error);
}
}
+
+void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
+{
+ Error *error = NULL;
+ const char *device = qdict_get_str(qdict, "device");
+
+ qmp_block_job_cancel(device, &error);
+
+ if (error) {
+ monitor_printf(mon, "%s\n", error_get_pretty(error));
+ error_free(error);
+ }
+}
diff --git a/hmp.h b/hmp.h
index 4c1458e..30d9051 100644
--- a/hmp.h
+++ b/hmp.h
@@ -39,5 +39,6 @@ void hmp_system_powerdown(Monitor *mon, const QDict *qdict);
void hmp_cpu(Monitor *mon, const QDict *qdict);
void hmp_block_stream(Monitor *mon, const QDict *qdict);
void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict);
+void hmp_block_job_cancel(Monitor *mon, const QDict *qdict);
#endif
diff --git a/monitor.c b/monitor.c
index a33218c..5bf29f2 100644
--- a/monitor.c
+++ b/monitor.c
@@ -482,6 +482,9 @@ void monitor_protocol_event(MonitorEvent event, QObject *data)
case QEVENT_BLOCK_JOB_COMPLETED:
event_name = "BLOCK_JOB_COMPLETED";
break;
+ case QEVENT_BLOCK_JOB_CANCELLED:
+ event_name = "BLOCK_JOB_CANCELLED";
+ break;
default:
abort();
break;
diff --git a/monitor.h b/monitor.h
index d9b07dc..2e7f38a 100644
--- a/monitor.h
+++ b/monitor.h
@@ -36,6 +36,7 @@ typedef enum MonitorEvent {
QEVENT_SPICE_INITIALIZED,
QEVENT_SPICE_DISCONNECTED,
QEVENT_BLOCK_JOB_COMPLETED,
+ QEVENT_BLOCK_JOB_CANCELLED,
QEVENT_MAX,
} MonitorEvent;
diff --git a/qapi-schema.json b/qapi-schema.json
index f6a8252..270d05e 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -943,6 +943,10 @@
# - speed: rate limit, bytes per second (json-int)
# - error: error message (json-string, only on error)
#
+# If the operation was cancelled using block_job_cancel then the
+# BLOCK_JOB_CANCELLED event is raised with the same fields as
+# BLOCK_JOB_COMPLETED.
+#
# The completion event is raised both on success and on failure. On
# success offset is equal to len. On failure offset and len can be
# used to indicate at which point the operation failed.
@@ -977,3 +981,35 @@
##
{ 'command': 'block_job_set_speed',
'data': { 'device': 'str', 'value': 'int' } }
+
+##
+# @block_job_cancel:
+#
+# Stop an active block streaming operation.
+#
+# This command returns immediately after marking the active block streaming
+# operation for cancellation. It is an error to call this command if no
+# operation is in progress.
+#
+# The operation will cancel as soon as possible and emit the
+# BLOCK_JOB_CANCELLED event. Before that happens the job is still visible when
+# enumerated using query-block-jobs.
+#
+# The image file retains its backing file unless the streaming operation happens
+# to complete just as it is being cancelled.
+#
+# A new block streaming operation can be started at a later time to finish
+# copying all data from the backing file.
+#
+# Arguments:
+#
+# - device: device name
+#
+# Errors:
+#
+# DeviceNotActive: streaming is not active on this device
+# DeviceInUse: cancellation already in progress
+#
+# Since: 1.1
+##
+{ 'command': 'block_job_cancel', 'data': { 'device': 'str' } }
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 5541ca0..a57d079 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -719,6 +719,24 @@ Example:
EQMP
{
+ .name = "block_job_cancel",
+ .args_type = "device:B",
+ .mhandler.cmd_new = qmp_marshal_input_block_job_cancel,
+ },
+
+SQMP
+block_job_cancel
+----------------
+See qapi-schema.json for documentation.
+
+Examples:
+
+-> { "execute": "block_job_cancel", "arguments": { "device": "virtio0" } }
+<- { "return": {} }
+
+EQMP
+
+ {
.name = "blockdev-snapshot-sync",
.args_type = "device:B,snapshot-file:s?,format:s?",
.params = "device [new-image-file] [format]",
diff --git a/trace-events b/trace-events
index 6c1eec2..cbca6d5 100644
--- a/trace-events
+++ b/trace-events
@@ -74,6 +74,7 @@ stream_one_iteration(void *s, int64_t sector_num, int nb_sectors, int is_allocat
stream_start(void *bs, void *base, void *s, void *co, void *opaque) "bs %p base %p s %p co %p opaque %p"
# blockdev.c
+qmp_block_job_cancel(void *job) "job %p"
block_stream_cb(void *bs, void *job, int ret) "bs %p job %p ret %d"
qmp_block_stream(void *bs, void *job) "bs %p job %p"
--
1.7.7.3
next prev parent reply other threads:[~2011-12-13 13:55 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-13 13:52 [Qemu-devel] [PATCH v3 0/9] block: generic image streaming Stefan Hajnoczi
2011-12-13 13:52 ` [Qemu-devel] [PATCH v3 1/9] coroutine: add co_sleep_ns() coroutine sleep function Stefan Hajnoczi
2011-12-13 13:52 ` [Qemu-devel] [PATCH v3 2/9] block: add BlockJob interface for long-running operations Stefan Hajnoczi
2011-12-14 13:51 ` Kevin Wolf
2011-12-15 8:50 ` Stefan Hajnoczi
2011-12-15 10:40 ` Marcelo Tosatti
2011-12-16 8:09 ` Stefan Hajnoczi
2011-12-13 13:52 ` [Qemu-devel] [PATCH v3 3/9] block: add image streaming block job Stefan Hajnoczi
2011-12-13 14:14 ` Marcelo Tosatti
2011-12-13 15:18 ` Stefan Hajnoczi
2011-12-14 13:59 ` Kevin Wolf
2011-12-13 13:52 ` [Qemu-devel] [PATCH v3 4/9] block: rate-limit streaming operations Stefan Hajnoczi
2011-12-13 13:52 ` [Qemu-devel] [PATCH v3 5/9] qmp: add block_stream command Stefan Hajnoczi
2012-01-04 12:59 ` Luiz Capitulino
2012-01-04 13:11 ` Luiz Capitulino
2012-01-05 13:48 ` Stefan Hajnoczi
2012-01-05 14:16 ` [Qemu-devel] QMP: Supporting off tree APIs Luiz Capitulino
2012-01-05 15:35 ` [Qemu-devel] [libvirt] " Eric Blake
2012-01-05 15:56 ` Anthony Liguori
2012-01-05 20:26 ` Luiz Capitulino
2012-01-06 11:06 ` Stefan Hajnoczi
2012-01-06 12:45 ` Luiz Capitulino
2012-01-06 15:08 ` Anthony Liguori
2012-01-06 19:42 ` Luiz Capitulino
2012-01-10 19:18 ` Anthony Liguori
2012-01-10 20:55 ` Luiz Capitulino
2012-01-10 21:02 ` Anthony Liguori
2012-01-11 1:41 ` Luiz Capitulino
2012-01-05 14:20 ` [Qemu-devel] [PATCH v3 5/9] qmp: add block_stream command Stefan Hajnoczi
2011-12-13 13:52 ` [Qemu-devel] [PATCH v3 6/9] qmp: add block_job_set_speed command Stefan Hajnoczi
2011-12-13 13:52 ` Stefan Hajnoczi [this message]
2011-12-13 13:52 ` [Qemu-devel] [PATCH v3 8/9] qmp: add query-block-jobs Stefan Hajnoczi
2011-12-14 14:54 ` Kevin Wolf
2011-12-15 8:27 ` Stefan Hajnoczi
2011-12-15 10:34 ` Kevin Wolf
2011-12-15 11:30 ` Luiz Capitulino
2011-12-15 12:00 ` Stefan Hajnoczi
2011-12-15 12:09 ` Luiz Capitulino
2011-12-15 12:37 ` Kevin Wolf
2011-12-15 12:51 ` Stefan Hajnoczi
2012-01-04 13:17 ` Luiz Capitulino
2011-12-13 13:52 ` [Qemu-devel] [PATCH v3 9/9] test: add image streaming test cases Stefan Hajnoczi
2011-12-13 14:12 ` [Qemu-devel] [PATCH v3 0/9] block: generic image streaming Yibin Shen
2011-12-13 15:18 ` Stefan Hajnoczi
2011-12-14 1:42 ` Yibin Shen
2011-12-14 10:50 ` Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1323784351-25531-8-git-send-email-stefanha@linux.vnet.ibm.com \
--to=stefanha@linux.vnet.ibm.com \
--cc=kwolf@redhat.com \
--cc=lcapitulino@redhat.com \
--cc=mtosatti@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).