From: Kevin Wolf <kwolf@redhat.com>
To: anthony@codemonkey.ws
Cc: kwolf@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 12/30] QAPI: add command for live block commit, 'block-commit'
Date: Fri, 28 Sep 2012 19:56:55 +0200 [thread overview]
Message-ID: <1348855033-17174-13-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1348855033-17174-1-git-send-email-kwolf@redhat.com>
From: Jeff Cody <jcody@redhat.com>
The command for live block commit is added, which has the following
arguments:
device: the block device to perform the commit on (mandatory)
base: the base image to commit into; optional (if not specified,
it is the underlying original image)
top: the top image of the commit - all data from inside top down
to base will be committed into base (mandatory for now; see
note, below)
speed: maximum speed, in bytes/sec
Note: Eventually this command will support merging down the active layer,
but that code is not yet complete. If the active layer is passed
in as top, then an error will be returned. Once merging down the
active layer is supported, the 'top' argument may become optional,
and default to the active layer.
The is done as a block job, so upon completion a BLOCK_JOB_COMPLETED will
be emitted.
Signed-off-by: Jeff Cody <jcody@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
QMP/qmp-events.txt | 6 +++-
blockdev.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++
qapi-schema.json | 34 ++++++++++++++++++++++++++++++
qmp-commands.hx | 6 +++++
4 files changed, 102 insertions(+), 2 deletions(-)
diff --git a/QMP/qmp-events.txt b/QMP/qmp-events.txt
index 2878058..4491020 100644
--- a/QMP/qmp-events.txt
+++ b/QMP/qmp-events.txt
@@ -50,7 +50,8 @@ Emitted when a block job has been cancelled.
Data:
-- "type": Job type ("stream" for image streaming, json-string)
+- "type": Job type (json-string; "stream" for image streaming
+ "commit" for block commit)
- "device": Device name (json-string)
- "len": Maximum progress value (json-int)
- "offset": Current progress value (json-int)
@@ -73,7 +74,8 @@ Emitted when a block job has completed.
Data:
-- "type": Job type ("stream" for image streaming, json-string)
+- "type": Job type (json-string; "stream" for image streaming
+ "commit" for block commit)
- "device": Device name (json-string)
- "len": Maximum progress value (json-int)
- "offset": Current progress value (json-int)
diff --git a/blockdev.c b/blockdev.c
index f910ac5..cea22e4 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -1131,6 +1131,64 @@ void qmp_block_stream(const char *device, bool has_base,
trace_qmp_block_stream(bs, bs->job);
}
+void qmp_block_commit(const char *device,
+ bool has_base, const char *base, const char *top,
+ bool has_speed, int64_t speed,
+ Error **errp)
+{
+ BlockDriverState *bs;
+ BlockDriverState *base_bs, *top_bs;
+ Error *local_err = NULL;
+ /* This will be part of the QMP command, if/when the
+ * BlockdevOnError change for blkmirror makes it in
+ */
+ BlockErrorAction on_error = BLOCK_ERR_REPORT;
+
+ /* drain all i/o before commits */
+ bdrv_drain_all();
+
+ bs = bdrv_find(device);
+ if (!bs) {
+ error_set(errp, QERR_DEVICE_NOT_FOUND, device);
+ return;
+ }
+ if (base && has_base) {
+ base_bs = bdrv_find_backing_image(bs, base);
+ } else {
+ base_bs = bdrv_find_base(bs);
+ }
+
+ if (base_bs == NULL) {
+ error_set(errp, QERR_BASE_NOT_FOUND, base ? base : "NULL");
+ return;
+ }
+
+ /* default top_bs is the active layer */
+ top_bs = bs;
+
+ if (top) {
+ if (strcmp(bs->filename, top) != 0) {
+ top_bs = bdrv_find_backing_image(bs, top);
+ }
+ }
+
+ if (top_bs == NULL) {
+ error_setg(errp, "Top image file %s not found", top ? top : "NULL");
+ return;
+ }
+
+ commit_start(bs, base_bs, top_bs, speed, on_error, block_job_cb, bs,
+ &local_err);
+ if (local_err != NULL) {
+ error_propagate(errp, local_err);
+ return;
+ }
+ /* Grab a reference so hotplug does not delete the BlockDriverState from
+ * underneath us.
+ */
+ drive_get_ref(drive_get_by_blockdev(bs));
+}
+
static BlockJob *find_block_job(const char *device)
{
BlockDriverState *bs;
diff --git a/qapi-schema.json b/qapi-schema.json
index 14e4419..5816545 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -1468,6 +1468,40 @@
'returns': 'str' }
##
+# @block-commit
+#
+# Live commit of data from overlay image nodes into backing nodes - i.e.,
+# writes data between 'top' and 'base' into 'base'.
+#
+# @device: the name of the device
+#
+# @base: #optional The file name of the backing image to write data into.
+# If not specified, this is the deepest backing image
+#
+# @top: The file name of the backing image within the image chain,
+# which contains the topmost data to be committed down.
+# Note, the active layer as 'top' is currently unsupported.
+#
+# If top == base, that is an error.
+#
+#
+# @speed: #optional the maximum speed, in bytes per second
+#
+# Returns: Nothing on success
+# If commit or stream is already active on this device, DeviceInUse
+# If @device does not exist, DeviceNotFound
+# If image commit is not supported by this device, NotSupported
+# If @base or @top is invalid, a generic error is returned
+# If @top is the active layer, or omitted, a generic error is returned
+# If @speed is invalid, InvalidParameter
+#
+# Since: 1.3
+#
+##
+{ 'command': 'block-commit',
+ 'data': { 'device': 'str', '*base': 'str', 'top': 'str',
+ '*speed': 'int' } }
+
# @migrate_cancel
#
# Cancel the current executing migration process.
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 6e21ddb..a55a3f5 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -792,6 +792,12 @@ EQMP
},
{
+ .name = "block-commit",
+ .args_type = "device:B,base:s?,top:s,speed:o?",
+ .mhandler.cmd_new = qmp_marshal_input_block_commit,
+ },
+
+ {
.name = "block-job-set-speed",
.args_type = "device:B,speed:o",
.mhandler.cmd_new = qmp_marshal_input_block_job_set_speed,
--
1.7.6.5
next prev parent reply other threads:[~2012-09-28 17:57 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-28 17:56 [Qemu-devel] [PULL 00/30] Block patches Kevin Wolf
2012-09-28 17:56 ` [Qemu-devel] [PATCH 01/30] block-migration: Flush requests in blk_mig_cleanup Kevin Wolf
2012-09-28 17:56 ` [Qemu-devel] [PATCH 02/30] block: after creating a live snapshot, make old image read-only Kevin Wolf
2012-09-28 17:56 ` [Qemu-devel] [PATCH 03/30] aio: Fix qemu_aio_wait() to maintain correct walking_handlers count Kevin Wolf
2012-09-28 17:56 ` [Qemu-devel] [PATCH 04/30] qemu: URI parsing library Kevin Wolf
2012-09-28 17:56 ` [Qemu-devel] [PATCH 05/30] aio: Another fix to the walking_handlers logic Kevin Wolf
2012-09-28 17:56 ` [Qemu-devel] [PATCH 06/30] configure: Add a config option for GlusterFS as block backend Kevin Wolf
2012-09-28 17:56 ` [Qemu-devel] [PATCH 07/30] block: Support GlusterFS as a QEMU " Kevin Wolf
2012-09-28 17:56 ` [Qemu-devel] [PATCH 08/30] block: add support functions for live commit, to find and delete images Kevin Wolf
2012-09-28 17:56 ` [Qemu-devel] [PATCH 09/30] block: add live block commit functionality Kevin Wolf
2012-09-28 17:56 ` [Qemu-devel] [PATCH 10/30] blockdev: rename block_stream_cb to a generic block_job_cb Kevin Wolf
2012-09-28 17:56 ` [Qemu-devel] [PATCH 11/30] block: helper function, to find the base image of a chain Kevin Wolf
2012-09-28 17:56 ` Kevin Wolf [this message]
2012-10-05 17:29 ` [Qemu-devel] [PATCH 12/30] QAPI: add command for live block commit, 'block-commit' Eric Blake
2012-10-05 18:05 ` Eric Blake
2012-10-08 14:37 ` Paolo Bonzini
2012-10-11 15:42 ` Eric Blake
2012-09-28 17:56 ` [Qemu-devel] [PATCH 13/30] qemu-iotests: add initial tests for live block commit Kevin Wolf
2012-09-28 17:56 ` [Qemu-devel] [PATCH 14/30] qerror/block: introduce QERR_BLOCK_JOB_NOT_ACTIVE Kevin Wolf
2012-09-28 17:56 ` [Qemu-devel] [PATCH 15/30] block: fix documentation of block_job_cancel_sync Kevin Wolf
2012-09-28 17:56 ` [Qemu-devel] [PATCH 16/30] block: move job APIs to separate files Kevin Wolf
2012-09-28 17:57 ` [Qemu-devel] [PATCH 17/30] block: add block_job_query Kevin Wolf
2012-09-28 17:57 ` [Qemu-devel] [PATCH 18/30] qmp: add 'busy' member to BlockJobInfo Kevin Wolf
2012-09-28 17:57 ` [Qemu-devel] [PATCH 19/30] block: add support for job pause/resume Kevin Wolf
2012-09-28 17:57 ` [Qemu-devel] [PATCH 20/30] qmp: add block-job-pause and block-job-resume Kevin Wolf
2012-09-28 17:57 ` [Qemu-devel] [PATCH 21/30] qemu-iotests: add test for pausing a streaming operation Kevin Wolf
2012-09-28 17:57 ` [Qemu-devel] [PATCH 22/30] iostatus: rename BlockErrorAction, BlockQMPEventAction Kevin Wolf
2012-09-28 17:57 ` [Qemu-devel] [PATCH 23/30] iostatus: move BlockdevOnError declaration to QAPI Kevin Wolf
2012-09-28 17:57 ` [Qemu-devel] [PATCH 24/30] iostatus: change is_read to a bool Kevin Wolf
2012-09-28 17:57 ` [Qemu-devel] [PATCH 25/30] iostatus: reorganize io error code Kevin Wolf
2012-09-28 17:57 ` [Qemu-devel] [PATCH 26/30] block: introduce block job error Kevin Wolf
2012-09-28 17:57 ` [Qemu-devel] [PATCH 27/30] stream: add on-error argument Kevin Wolf
2012-09-28 17:57 ` [Qemu-devel] [PATCH 28/30] blkdebug: process all set_state rules in the old state Kevin Wolf
2012-09-28 17:57 ` [Qemu-devel] [PATCH 29/30] qemu-iotests: map underscore to dash in QMP argument names Kevin Wolf
2012-09-28 17:57 ` [Qemu-devel] [PATCH 30/30] qemu-iotests: add tests for streaming error handling Kevin Wolf
2012-10-05 2:11 ` [Qemu-devel] [PULL 00/30] Block patches Anthony Liguori
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=1348855033-17174-13-git-send-email-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=anthony@codemonkey.ws \
--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).