From patchwork Tue Mar 2 11:14:31 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 46630 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id BCAA0B7C06 for ; Tue, 2 Mar 2010 22:24:24 +1100 (EST) Received: from localhost ([127.0.0.1]:57051 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NmQBP-0006BW-GM for incoming@patchwork.ozlabs.org; Tue, 02 Mar 2010 06:22:35 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NmQ4P-000253-Ed for qemu-devel@nongnu.org; Tue, 02 Mar 2010 06:15:22 -0500 Received: from [199.232.76.173] (port=44054 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NmQ4O-00023G-BG for qemu-devel@nongnu.org; Tue, 02 Mar 2010 06:15:20 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NmQ4L-0002d7-H6 for qemu-devel@nongnu.org; Tue, 02 Mar 2010 06:15:20 -0500 Received: from mx1.redhat.com ([209.132.183.28]:13359) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NmQ4L-0002d1-5f for qemu-devel@nongnu.org; Tue, 02 Mar 2010 06:15:17 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o22BFFw9031113 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 2 Mar 2010 06:15:15 -0500 Received: from localhost.localdomain (dhcp-5-175.str.redhat.com [10.32.5.175]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o22BFDiY028807; Tue, 2 Mar 2010 06:15:14 -0500 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Tue, 2 Mar 2010 12:14:31 +0100 Message-Id: <1267528471-7011-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: kwolf@redhat.com Subject: [Qemu-devel] [PATCH] qemu-img rebase: Add -f option X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Allow the user to specify the format of the image to rebase. Signed-off-by: Kevin Wolf Acked-by: Juan Quintela --- qemu-img.c | 20 ++++++++++++++++---- 1 files changed, 16 insertions(+), 4 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 258dc62..7fc980a 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1081,24 +1081,28 @@ static int img_snapshot(int argc, char **argv) static int img_rebase(int argc, char **argv) { BlockDriverState *bs, *bs_old_backing, *bs_new_backing; - BlockDriver *old_backing_drv, *new_backing_drv; + BlockDriver *drv, *old_backing_drv, *new_backing_drv; char *filename; - const char *out_basefmt, *out_baseimg; + const char *fmt, *out_basefmt, *out_baseimg; int c, flags, ret; int unsafe = 0; /* Parse commandline parameters */ + fmt = NULL; out_baseimg = NULL; out_basefmt = NULL; for(;;) { - c = getopt(argc, argv, "uhF:b:"); + c = getopt(argc, argv, "uhf:F:b:"); if (c == -1) break; switch(c) { case 'h': help(); return 0; + case 'f': + fmt = optarg; + break; case 'F': out_basefmt = optarg; break; @@ -1125,8 +1129,16 @@ static int img_rebase(int argc, char **argv) if (!bs) error("Not enough memory"); + drv = NULL; + if (fmt) { + drv = bdrv_find_format(fmt); + if (drv == NULL) { + error("Invalid format name: '%s'", fmt); + } + } + flags = BRDV_O_FLAGS | BDRV_O_RDWR | (unsafe ? BDRV_O_NO_BACKING : 0); - if (bdrv_open2(bs, filename, flags, NULL) < 0) { + if (bdrv_open2(bs, filename, flags, drv) < 0) { error("Could not open '%s'", filename); }