From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
Jeff Cody <jcody@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>
Subject: [Qemu-devel] [PULL for-2.1 21/24] block: add QAPI command to allow live backing file change
Date: Tue, 1 Jul 2014 10:48:54 +0200 [thread overview]
Message-ID: <1404204537-5082-22-git-send-email-stefanha@redhat.com> (raw)
In-Reply-To: <1404204537-5082-1-git-send-email-stefanha@redhat.com>
From: Jeff Cody <jcody@redhat.com>
This allows a user to make a live change to the backing file recorded in
an open image.
The image file to modify can be specified 2 ways:
1) image filename
2) image node-name
Note: this does not cause the backing file itself to be reopened; it
merely changes the backing filename in the image file structure, and
in internal BDS structures.
It is the responsibility of the user to pass a filename string that
can be resolved when the image chain is reopened, and the filename
string is not validated.
A good analogy for this command is that it is a live version of
'qemu-img rebase -u', with respect to changing the backing file string.
[Jeff is offline so I respun this patch in his absence. Dropped image
filename since using node-name is preferred and this is a new command.
No need to introduce the limitations of finding images by filename.
--Stefan]
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Jeff Cody <jcody@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
blockdev.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++
qapi/block-core.json | 26 +++++++++++++++++
qmp-commands.hx | 39 ++++++++++++++++++++++++++
3 files changed, 144 insertions(+)
diff --git a/blockdev.c b/blockdev.c
index 79ce52b..57373d3 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -2367,6 +2367,85 @@ void qmp_block_job_complete(const char *device, Error **errp)
block_job_complete(job, errp);
}
+void qmp_change_backing_file(const char *device,
+ const char *image_node_name,
+ const char *backing_file,
+ Error **errp)
+{
+ BlockDriverState *bs = NULL;
+ BlockDriverState *image_bs = NULL;
+ Error *local_err = NULL;
+ bool ro;
+ int open_flags;
+ int ret;
+
+ /* find the top layer BDS of the chain */
+ bs = bdrv_find(device);
+ if (!bs) {
+ error_set(errp, QERR_DEVICE_NOT_FOUND, device);
+ return;
+ }
+
+ image_bs = bdrv_lookup_bs(NULL, image_node_name, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
+ }
+
+ if (!image_bs) {
+ error_setg(errp, "image file not found");
+ return;
+ }
+
+ if (bdrv_find_base(image_bs) == image_bs) {
+ error_setg(errp, "not allowing backing file change on an image "
+ "without a backing file");
+ return;
+ }
+
+ /* even though we are not necessarily operating on bs, we need it to
+ * determine if block ops are currently prohibited on the chain */
+ if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_CHANGE, errp)) {
+ return;
+ }
+
+ /* final sanity check */
+ if (!bdrv_chain_contains(bs, image_bs)) {
+ error_setg(errp, "'%s' and image file are not in the same chain",
+ device);
+ return;
+ }
+
+ /* if not r/w, reopen to make r/w */
+ open_flags = image_bs->open_flags;
+ ro = bdrv_is_read_only(image_bs);
+
+ if (ro) {
+ bdrv_reopen(image_bs, open_flags | BDRV_O_RDWR, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
+ }
+ }
+
+ ret = bdrv_change_backing_file(image_bs, backing_file,
+ image_bs->drv ? image_bs->drv->format_name : "");
+
+ if (ret < 0) {
+ error_setg_errno(errp, -ret, "Could not change backing file to '%s'",
+ backing_file);
+ /* don't exit here, so we can try to restore open flags if
+ * appropriate */
+ }
+
+ if (ro) {
+ bdrv_reopen(image_bs, open_flags, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err); /* will preserve prior errp */
+ }
+ }
+}
+
void qmp_blockdev_add(BlockdevOptions *options, Error **errp)
{
QmpOutputVisitor *ov = qmp_output_visitor_new();
diff --git a/qapi/block-core.json b/qapi/block-core.json
index 6a697f1..aa12527 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -680,6 +680,32 @@
'data': 'BlockdevSnapshot' }
##
+# @change-backing-file
+#
+# Change the backing file in the image file metadata. This does not
+# cause QEMU to reopen the image file to reparse the backing filename
+# (it may, however, perform a reopen to change permissions from
+# r/o -> r/w -> r/o, if needed). The new backing file string is written
+# into the image file metadata, and the QEMU internal strings are
+# updated.
+#
+# @image-node-name: The name of the block driver state node of the
+# image to modify.
+#
+# @device: The name of the device that owns image-node-name.
+#
+# @backing-file: The string to write as the backing file. This
+# string is not validated, so care should be taken
+# when specifying the string or the image chain may
+# not be able to be reopened again.
+#
+# Since: 2.1
+##
+{ 'command': 'change-backing-file',
+ 'data': { 'device': 'str', 'image-node-name': 'str',
+ 'backing-file': 'str' } }
+
+##
# @block-commit
#
# Live commit of data from overlay image nodes into backing nodes - i.e.,
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 8c5fdb5..8534948 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -1353,6 +1353,45 @@ Example:
EQMP
{
+ .name = "change-backing-file",
+ .args_type = "device:s,image-node-name:s,backing-file:s",
+ .mhandler.cmd_new = qmp_marshal_input_change_backing_file,
+ },
+
+SQMP
+change-backing-file
+-------------------
+Since: 2.1
+
+Change the backing file in the image file metadata. This does not cause
+QEMU to reopen the image file to reparse the backing filename (it may,
+however, perform a reopen to change permissions from r/o -> r/w -> r/o,
+if needed). The new backing file string is written into the image file
+metadata, and the QEMU internal strings are updated.
+
+Arguments:
+
+- "image-node-name": The name of the block driver state node of the
+ image to modify. The "device" is argument is used to
+ verify "image-node-name" is in the chain described by
+ "device".
+ (json-string, optional)
+
+- "device": The name of the device.
+ (json-string)
+
+- "backing-file": The string to write as the backing file. This string is
+ not validated, so care should be taken when specifying
+ the string or the image chain may not be able to be
+ reopened again.
+ (json-string)
+
+Returns: Nothing on success
+ If "device" does not exist or cannot be determined, DeviceNotFound
+
+EQMP
+
+ {
.name = "balloon",
.args_type = "value:M",
.mhandler.cmd_new = qmp_marshal_input_balloon,
--
1.9.3
next prev parent reply other threads:[~2014-07-01 8:50 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-01 8:48 [Qemu-devel] [PULL for-2.1 00/24] Block patches Stefan Hajnoczi
2014-07-01 8:48 ` [Qemu-devel] [PULL for-2.1 01/24] qom: add object_property_add_alias() Stefan Hajnoczi
2014-07-01 8:48 ` [Qemu-devel] [PULL for-2.1 02/24] virtio-blk: avoid qdev property definition duplication Stefan Hajnoczi
2014-07-01 8:48 ` [Qemu-devel] [PULL for-2.1 03/24] dataplane: bail out on unsupported transport Stefan Hajnoczi
2014-07-01 8:48 ` [Qemu-devel] [PULL for-2.1 04/24] virtio-blk: move x-data-plane qdev property to virtio-blk.h Stefan Hajnoczi
2014-07-01 8:48 ` [Qemu-devel] [PULL for-2.1 05/24] qdev: add qdev_alias_all_properties() Stefan Hajnoczi
2014-07-01 8:48 ` [Qemu-devel] [PULL for-2.1 06/24] virtio-blk: use aliases instead of duplicate qdev properties Stefan Hajnoczi
2014-07-01 8:48 ` [Qemu-devel] [PULL for-2.1 07/24] virtio-blk: drop virtio_blk_set_conf() Stefan Hajnoczi
2014-07-01 8:48 ` [Qemu-devel] [PULL for-2.1 08/24] virtio: fix virtio-blk child refcount in transports Stefan Hajnoczi
2014-07-01 8:48 ` [Qemu-devel] [PULL for-2.1 09/24] virtio-blk: move qdev properties into virtio-blk.c Stefan Hajnoczi
2014-07-01 8:48 ` [Qemu-devel] [PULL for-2.1 10/24] virtio-blk: replace x-iothread with iothread link property Stefan Hajnoczi
2014-07-01 8:48 ` [Qemu-devel] [PULL for-2.1 11/24] qdev: drop iothread property type Stefan Hajnoczi
2014-07-01 8:48 ` [Qemu-devel] [PULL for-2.1 12/24] virtio-blk: remove need for explicit x-data-plane=on option Stefan Hajnoczi
2014-07-01 8:48 ` [Qemu-devel] [PULL for-2.1 13/24] qemu-img create: add 'nocow' option Stefan Hajnoczi
2014-07-02 3:10 ` Eric Blake
2014-07-02 4:34 ` Chun Yan Liu
2014-07-01 8:48 ` [Qemu-devel] [PULL for-2.1 14/24] iotests: Simplify qemu-iotests-quick.sh Stefan Hajnoczi
2014-07-01 8:48 ` [Qemu-devel] [PULL for-2.1 15/24] iotests: Add qemu tests to quick group Stefan Hajnoczi
2014-07-01 8:48 ` [Qemu-devel] [PULL for-2.1 16/24] iotests: Add more " Stefan Hajnoczi
2014-07-01 8:48 ` [Qemu-devel] [PULL for-2.1 17/24] block: make 'top' argument to block-commit optional Stefan Hajnoczi
2014-07-01 8:48 ` [Qemu-devel] [PULL for-2.1 18/24] block: simplify bdrv_find_base() and bdrv_find_overlay() Stefan Hajnoczi
2014-07-01 8:48 ` [Qemu-devel] [PULL for-2.1 19/24] block/cow: Avoid use of uninitialized cow_bs in error path Stefan Hajnoczi
2014-07-01 8:48 ` [Qemu-devel] [PULL for-2.1 20/24] qapi: Change back sector-count to sectors-count in quorum QAPI events Stefan Hajnoczi
2014-07-01 8:48 ` Stefan Hajnoczi [this message]
2014-07-01 22:09 ` [Qemu-devel] [PULL for-2.1 21/24] block: add QAPI command to allow live backing file change Eric Blake
2014-07-02 13:53 ` Kevin Wolf
2014-07-01 8:48 ` [Qemu-devel] [PULL for-2.1 22/24] block: add helper function to determine if a BDS is in a chain Stefan Hajnoczi
2014-07-01 8:48 ` [Qemu-devel] [PULL for-2.1 23/24] block: extend block-commit to accept a string for the backing file Stefan Hajnoczi
2014-07-01 8:48 ` [Qemu-devel] [PULL for-2.1 24/24] block: add backing-file option to block-stream Stefan Hajnoczi
2014-07-01 20:50 ` Eric Blake
2014-07-01 22:06 ` Eric Blake
2014-07-01 13:21 ` [Qemu-devel] [PULL for-2.1 00/24] Block patches Peter Maydell
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=1404204537-5082-22-git-send-email-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=jcody@redhat.com \
--cc=peter.maydell@linaro.org \
--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).