[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 04/32] qemu-img rebase: use empty string to rebase w
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 04/32] qemu-img rebase: use empty string to rebase without backing file |
Date: |
Wed, 24 Oct 2012 11:50:28 +0200 |
From: Alex Bligh <address@hidden>
This patch allows an empty filename to be passed as the new base image name
for qemu-img rebase to mean base the image on no backing file (i.e.
independent of any backing file). According to Eric Blake, qemu-img rebase
already supports this when '-u' is used; this adds support when -u is not
used.
Signed-off-by: Alex Bligh <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
qemu-img.c | 29 +++++++++++++++++++----------
qemu-img.texi | 4 +++-
2 files changed, 22 insertions(+), 11 deletions(-)
diff --git a/qemu-img.c b/qemu-img.c
index 849eb41..c092ccf 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -1562,13 +1562,15 @@ static int img_rebase(int argc, char **argv)
error_report("Could not open old backing file '%s'", backing_name);
goto out;
}
-
- bs_new_backing = bdrv_new("new_backing");
- ret = bdrv_open(bs_new_backing, out_baseimg, BDRV_O_FLAGS,
+ if (out_baseimg[0]) {
+ bs_new_backing = bdrv_new("new_backing");
+ ret = bdrv_open(bs_new_backing, out_baseimg, BDRV_O_FLAGS,
new_backing_drv);
- if (ret) {
- error_report("Could not open new backing file '%s'", out_baseimg);
- goto out;
+ if (ret) {
+ error_report("Could not open new backing file '%s'",
+ out_baseimg);
+ goto out;
+ }
}
}
@@ -1584,7 +1586,7 @@ static int img_rebase(int argc, char **argv)
if (!unsafe) {
uint64_t num_sectors;
uint64_t old_backing_num_sectors;
- uint64_t new_backing_num_sectors;
+ uint64_t new_backing_num_sectors = 0;
uint64_t sector;
int n;
uint8_t * buf_old;
@@ -1596,7 +1598,9 @@ static int img_rebase(int argc, char **argv)
bdrv_get_geometry(bs, &num_sectors);
bdrv_get_geometry(bs_old_backing, &old_backing_num_sectors);
- bdrv_get_geometry(bs_new_backing, &new_backing_num_sectors);
+ if (bs_new_backing) {
+ bdrv_get_geometry(bs_new_backing, &new_backing_num_sectors);
+ }
if (num_sectors != 0) {
local_progress = (float)100 /
@@ -1636,7 +1640,7 @@ static int img_rebase(int argc, char **argv)
}
}
- if (sector >= new_backing_num_sectors) {
+ if (sector >= new_backing_num_sectors || !bs_new_backing) {
memset(buf_new, 0, n * BDRV_SECTOR_SIZE);
} else {
if (sector + n > new_backing_num_sectors) {
@@ -1682,7 +1686,12 @@ static int img_rebase(int argc, char **argv)
* backing file are overwritten in the COW file now, so the visible content
* doesn't change when we switch the backing file.
*/
- ret = bdrv_change_backing_file(bs, out_baseimg, out_basefmt);
+ if (out_baseimg && *out_baseimg) {
+ ret = bdrv_change_backing_file(bs, out_baseimg, out_basefmt);
+ } else {
+ ret = bdrv_change_backing_file(bs, NULL, NULL);
+ }
+
if (ret == -ENOSPC) {
error_report("Could not change the backing file to '%s': No "
"space left in the file header", out_baseimg);
diff --git a/qemu-img.texi b/qemu-img.texi
index 8b05f2c..42ec392 100644
--- a/qemu-img.texi
+++ b/qemu-img.texi
@@ -148,7 +148,9 @@ Changes the backing file of an image. Only the formats
@code{qcow2} and
The backing file is changed to @var{backing_file} and (if the image format of
@var{filename} supports this) the backing file format is changed to
address@hidden
address@hidden If @var{backing_file} is specified as ``'' (the empty
+string), then the image is rebased onto no backing file (i.e. it will exist
+independently of any backing file).
There are two different modes in which @code{rebase} can operate:
@table @option
--
1.7.6.5
- [Qemu-devel] [PULL 00/32] Block patches, Kevin Wolf, 2012/10/24
- [Qemu-devel] [PATCH 01/32] qemu-img: Fix division by zero for zero size images, Kevin Wolf, 2012/10/24
- [Qemu-devel] [PATCH 02/32] qemu-iotests: Test qemu-img operation on zero size image, Kevin Wolf, 2012/10/24
- [Qemu-devel] [PATCH 05/32] block: make bdrv_find_backing_image compare canonical filenames, Kevin Wolf, 2012/10/24
- [Qemu-devel] [PATCH 03/32] qmp: fix __accept() in qmp.py, Kevin Wolf, 2012/10/24
- [Qemu-devel] [PATCH 07/32] qemu-iotests: add relative backing file tests for block-commit (040), Kevin Wolf, 2012/10/24
- [Qemu-devel] [PATCH 04/32] qemu-img rebase: use empty string to rebase without backing file,
Kevin Wolf <=
- [Qemu-devel] [PATCH 08/32] qemu-img: Add --backing-chain option to info command, Kevin Wolf, 2012/10/24
- [Qemu-devel] [PATCH 06/32] block: in commit, determine base image from the top image, Kevin Wolf, 2012/10/24
- [Qemu-devel] [PATCH 12/32] monitor: Allow add-fd to any specified fd set, Kevin Wolf, 2012/10/24
- [Qemu-devel] [PATCH 10/32] qemu-img: document 'info --backing-chain', Kevin Wolf, 2012/10/24
- [Qemu-devel] [PATCH 11/32] block: bdrv_create(): don't leak cco.filename on error, Kevin Wolf, 2012/10/24
- [Qemu-devel] [PATCH 14/32] monitor: Prevent removing fd from set during init, Kevin Wolf, 2012/10/24
- [Qemu-devel] [PATCH 09/32] qemu-iotests: Add 043 backing file chain infinite loop test, Kevin Wolf, 2012/10/24
- [Qemu-devel] [PATCH 17/32] block: add bdrv_query_stats, Kevin Wolf, 2012/10/24
- [Qemu-devel] [PATCH 15/32] qemu-config: Add new -add-fd command line option, Kevin Wolf, 2012/10/24
- [Qemu-devel] [PATCH 19/32] block: introduce new dirty bitmap functionality, Kevin Wolf, 2012/10/24