From patchwork Mon Oct 15 17:29:34 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Bligh X-Patchwork-Id: 191615 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 1C1C02C00BE for ; Tue, 16 Oct 2012 04:39:23 +1100 (EST) Received: from localhost ([::1]:46567 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TNodN-0001vt-Ti for incoming@patchwork.ozlabs.org; Mon, 15 Oct 2012 13:39:21 -0400 Received: from eggs.gnu.org ([208.118.235.92]:42107) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TNodD-0001uG-9r for qemu-devel@nongnu.org; Mon, 15 Oct 2012 13:39:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TNodA-0006L6-M4 for qemu-devel@nongnu.org; Mon, 15 Oct 2012 13:39:11 -0400 Received: from mail.avalus.com ([89.16.176.221]:58485) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TNodA-0006Kb-Cb for qemu-devel@nongnu.org; Mon, 15 Oct 2012 13:39:08 -0400 Received: by mail.avalus.com (Postfix) with ESMTPSA id 7E90CC56179; Mon, 15 Oct 2012 18:29:36 +0100 (BST) Date: Mon, 15 Oct 2012 18:29:34 +0100 From: Alex Bligh To: qemu-devel@nongnu.org Message-ID: X-Mailer: Mulberry/4.0.8 (Mac OS X) MIME-Version: 1.0 Content-Disposition: inline X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 89.16.176.221 Cc: Alex Bligh Subject: [Qemu-devel] [PATCH] qemu-img rebase: allow backing file to be specified as '-' X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: Alex Bligh List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This patch allows qemu-img rebase to rebase an image to have no backing file, as opposed to merely allowing it to rebase to an existing backing file. Patch below, or pull from git at: https://github.com/abligh/qemu.git Commit visible at: https://github.com/abligh/qemu/commit/4d5b3b431d8dd276f4c564d8a82c6d25cb111381 Signed-off-by: Alex Bligh --- qemu-img.c | 26 ++++++++++++++++---------- qemu-img.texi | 4 +++- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index f17f187..770e221 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1558,13 +1558,14 @@ 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 (strcmp("-", out_baseimg)) { + 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; + } } } @@ -1580,7 +1581,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; @@ -1592,7 +1593,8 @@ 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); local_progress = (float)100 / (num_sectors / MIN(num_sectors, IO_BUF_SIZE / 512)); @@ -1629,7 +1631,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) { @@ -1675,7 +1677,11 @@ 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 (bs_new_backing) + 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..7c29f23 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 -@var{backing_fmt}. +@var{backing_fmt}. If @var{backing_file} is specified as ``-'', 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