[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 31/53] qemu-img: Specify backing file for commit
From: |
Stefan Hajnoczi |
Subject: |
[Qemu-devel] [PULL 31/53] qemu-img: Specify backing file for commit |
Date: |
Mon, 3 Nov 2014 11:50:34 +0000 |
From: Max Reitz <address@hidden>
Introduce a new parameter for qemu-img commit which may be used to
explicitly specify the backing file into which an image should be
committed if the backing chain has more than a single layer.
[Applied Eric Blake's qemu-img.texi documentation rewording
--Stefan]
Signed-off-by: Max Reitz <address@hidden>
Reviewed-by: Kevin Wolf <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Message-id: address@hidden
Signed-off-by: Stefan Hajnoczi <address@hidden>
---
qemu-img-cmds.hx | 4 ++--
qemu-img.c | 32 +++++++++++++++++++++++---------
qemu-img.texi | 12 +++++++++++-
3 files changed, 36 insertions(+), 12 deletions(-)
diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx
index fde33d1..04c207d 100644
--- a/qemu-img-cmds.hx
+++ b/qemu-img-cmds.hx
@@ -22,9 +22,9 @@ STEXI
ETEXI
DEF("commit", img_commit,
- "commit [-q] [-f fmt] [-t cache] [-d] [-p] filename")
+ "commit [-q] [-f fmt] [-t cache] [-b base] [-d] [-p] filename")
STEXI
address@hidden commit [-q] [-f @var{fmt}] [-t @var{cache}] [-d] [-p]
@var{filename}
address@hidden commit [-q] [-f @var{fmt}] [-t @var{cache}] [-b @var{base}] [-d]
[-p] @var{filename}
ETEXI
DEF("compare", img_compare,
diff --git a/qemu-img.c b/qemu-img.c
index 8fec160..bd5a2ae 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -759,7 +759,7 @@ static void run_block_job(BlockJob *job, Error **errp)
static int img_commit(int argc, char **argv)
{
int c, ret, flags;
- const char *filename, *fmt, *cache;
+ const char *filename, *fmt, *cache, *base;
BlockBackend *blk;
BlockDriverState *bs, *base_bs;
bool progress = false, quiet = false, drop = false;
@@ -768,8 +768,9 @@ static int img_commit(int argc, char **argv)
fmt = NULL;
cache = BDRV_DEFAULT_CACHE;
+ base = NULL;
for(;;) {
- c = getopt(argc, argv, "f:ht:dpq");
+ c = getopt(argc, argv, "f:ht:b:dpq");
if (c == -1) {
break;
}
@@ -784,6 +785,11 @@ static int img_commit(int argc, char **argv)
case 't':
cache = optarg;
break;
+ case 'b':
+ base = optarg;
+ /* -b implies -d */
+ drop = true;
+ break;
case 'd':
drop = true;
break;
@@ -822,13 +828,21 @@ static int img_commit(int argc, char **argv)
qemu_progress_init(progress, 1.f);
qemu_progress_print(0.f, 100);
- /* This is different from QMP, which by default uses the deepest file in
the
- * backing chain (i.e., the very base); however, the traditional behavior
of
- * qemu-img commit is using the immediate backing file. */
- base_bs = bs->backing_hd;
- if (!base_bs) {
- error_setg(&local_err, "Image does not have a backing file");
- goto done;
+ if (base) {
+ base_bs = bdrv_find_backing_image(bs, base);
+ if (!base_bs) {
+ error_set(&local_err, QERR_BASE_NOT_FOUND, base);
+ goto done;
+ }
+ } else {
+ /* This is different from QMP, which by default uses the deepest file
in
+ * the backing chain (i.e., the very base); however, the traditional
+ * behavior of qemu-img commit is using the immediate backing file. */
+ base_bs = bs->backing_hd;
+ if (!base_bs) {
+ error_setg(&local_err, "Image does not have a backing file");
+ goto done;
+ }
}
cbi = (CommonBlockJobCBInfo){
diff --git a/qemu-img.texi b/qemu-img.texi
index f82d1b4..078851a 100644
--- a/qemu-img.texi
+++ b/qemu-img.texi
@@ -167,7 +167,7 @@ this case. @var{backing_file} will never be modified unless
you use the
The size can also be specified using the @var{size} option with @code{-o},
it doesn't need to be specified separately in this case.
address@hidden commit [-q] [-f @var{fmt}] [-t @var{cache}] [-d] [-p]
@var{filename}
address@hidden commit [-q] [-f @var{fmt}] [-t @var{cache}] [-b @var{base}] [-d]
[-p] @var{filename}
Commit the changes recorded in @var{filename} in its base image or backing
file.
If the backing file is smaller than the snapshot, then the backing file will be
@@ -180,6 +180,16 @@ The image @var{filename} is emptied after the operation
has succeeded. If you do
not need @var{filename} afterwards and intend to drop it, you may skip emptying
@var{filename} by specifying the @code{-d} flag.
+If the backing chain of the given image file @var{filename} has more than one
+layer, the backing file into which the changes will be committed may be
+specified as @var{base} (which has to be part of @var{filename}'s backing
+chain). If @var{base} is not specified, the immediate backing file of the top
+image (which is @var{filename}) will be used. For reasons of consistency,
+explicitly specifying @var{base} will always imply @code{-d} (since emptying an
+image after committing to an indirect backing file would lead to different data
+being read from the image due to content in the intermediate backing chain
+overruling the commit target).
+
@item compare [-f @var{fmt}] [-F @var{fmt}] [-T @var{src_cache}] [-p] [-s]
[-q] @var{filename1} @var{filename2}
Check if two images have the same content. You can compare images with
--
1.9.3
- [Qemu-devel] [PULL 21/53] qcow2: Allow "full" discard, (continued)
- [Qemu-devel] [PULL 21/53] qcow2: Allow "full" discard, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 22/53] qcow2: Implement bdrv_make_empty(), Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 23/53] qcow2: Optimize bdrv_make_empty(), Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 24/53] blockjob: Introduce block_job_complete_sync(), Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 26/53] iotests: Omit length/offset test in 040 and 041, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 25/53] blockjob: Add "ready" field, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 27/53] block/mirror: Improve progress report, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 28/53] qemu-img: Implement commit like QMP, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 29/53] qemu-img: Empty image after commit, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 30/53] qemu-img: Enable progress output for commit, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 31/53] qemu-img: Specify backing file for commit,
Stefan Hajnoczi <=
- [Qemu-devel] [PULL 32/53] iotests: Add _filter_qemu_img_map, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 33/53] iotests: Add test for backing-chain commits, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 34/53] iotests: Add test for qcow2's bdrv_make_empty, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 36/53] block: Add status callback to bdrv_amend_options(), Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 35/53] block: qemu-iotest 107 supports NFS, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 37/53] qemu-img: Add progress output for amend, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 38/53] qemu-img: Fix insignificant memleak, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 39/53] block/qcow2: Implement status CB for amend, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 40/53] block/qcow2: Make get_refcount() global, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 41/53] block/qcow2: Simplify shared L2 handling in amend, Stefan Hajnoczi, 2014/11/03