From patchwork Wed Dec 4 09:10:57 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wayne Xia X-Patchwork-Id: 296457 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 07FE92C00B6 for ; Wed, 4 Dec 2013 20:13:39 +1100 (EST) Received: from localhost ([::1]:47124 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vo8WX-00049I-3n for incoming@patchwork.ozlabs.org; Wed, 04 Dec 2013 04:13:37 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36388) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vo8Sl-000862-U0 for qemu-devel@nongnu.org; Wed, 04 Dec 2013 04:09:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vo8SY-0001tR-RU for qemu-devel@nongnu.org; Wed, 04 Dec 2013 04:09:43 -0500 Received: from e28smtp06.in.ibm.com ([122.248.162.6]:43814) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vo8SY-0001tA-56 for qemu-devel@nongnu.org; Wed, 04 Dec 2013 04:09:30 -0500 Received: from /spool/local by e28smtp06.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 4 Dec 2013 14:39:28 +0530 Received: from d28dlp03.in.ibm.com (9.184.220.128) by e28smtp06.in.ibm.com (192.168.1.136) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 4 Dec 2013 14:39:26 +0530 Received: from d28relay02.in.ibm.com (d28relay02.in.ibm.com [9.184.220.59]) by d28dlp03.in.ibm.com (Postfix) with ESMTP id B877A1258054 for ; Wed, 4 Dec 2013 14:40:29 +0530 (IST) Received: from d28av02.in.ibm.com (d28av02.in.ibm.com [9.184.220.64]) by d28relay02.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id rB499Id450266256 for ; Wed, 4 Dec 2013 14:39:19 +0530 Received: from d28av02.in.ibm.com (localhost [127.0.0.1]) by d28av02.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id rB499MdK017468 for ; Wed, 4 Dec 2013 14:39:22 +0530 Received: from RH64wenchao ([9.181.129.59]) by d28av02.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id rB499Eun016935; Wed, 4 Dec 2013 14:39:21 +0530 From: Wenchao Xia To: qemu-devel@nongnu.org Date: Wed, 4 Dec 2013 17:10:57 +0800 Message-Id: <1386148259-10962-5-git-send-email-xiawenc@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1386148259-10962-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1386148259-10962-1-git-send-email-xiawenc@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13120409-9574-0000-0000-00000AE04DAD X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 122.248.162.6 Cc: kwolf@redhat.com, jcody@redhat.com, stefanha@redhat.com, pbonzini@redhat.com, Wenchao Xia Subject: [Qemu-devel] [PATCH V7 4/6] qemu-img: add -l for snapshot in convert X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list 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 Now qemu-img convert have similar options as qemu-nbd for internal snapshot. Signed-off-by: Wenchao Xia --- qemu-img-cmds.hx | 4 ++-- qemu-img.c | 44 +++++++++++++++++++++++++++++++++++--------- qemu-img.texi | 12 ++++++++---- 3 files changed, 45 insertions(+), 15 deletions(-) diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx index da1d965..d029609 100644 --- a/qemu-img-cmds.hx +++ b/qemu-img-cmds.hx @@ -34,9 +34,9 @@ STEXI ETEXI DEF("convert", img_convert, - "convert [-c] [-p] [-q] [-n] [-f fmt] [-t cache] [-O output_fmt] [-o options] [-s snapshot_name] [-S sparse_size] filename [filename2 [...]] output_filename") + "convert [-c] [-p] [-q] [-n] [-f fmt] [-t cache] [-O output_fmt] [-o options] [-s snapshot_id_or_name] [-l snapshot_param] [-S sparse_size] filename [filename2 [...]] output_filename") STEXI -@item convert [-c] [-p] [-q] [-n] [-f @var{fmt}] [-t @var{cache}] [-O @var{output_fmt}] [-o @var{options}] [-s @var{snapshot_name}] [-S @var{sparse_size}] @var{filename} [@var{filename2} [...]] @var{output_filename} +@item convert [-c] [-p] [-q] [-n] [-f @var{fmt}] [-t @var{cache}] [-O @var{output_fmt}] [-o @var{options}] [-s @var{snapshot_id_or_name}] [-l @var{snapshot_param}] [-S @var{sparse_size}] @var{filename} [@var{filename2} [...]] @var{output_filename} ETEXI DEF("info", img_info, diff --git a/qemu-img.c b/qemu-img.c index a73beb5..ee940c2 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -93,6 +93,11 @@ static void help(void) " 'options' is a comma separated list of format specific options in a\n" " name=value format. Use -o ? for an overview of the options supported by the\n" " used format\n" + " 'snapshot_param' is param used for internal snapshot, format\n" + " is 'snapshot.id=[ID],snapshot.name=[NAME]', or\n" + " '[ID_OR_NAME]'\n" + " 'snapshot_id_or_name' is deprecated, use 'snapshot_param'\n" + " instead\n" " '-c' indicates that target image must be compressed (qcow format only)\n" " '-u' enables unsafe rebasing. It is assumed that old and new backing file\n" " match exactly. The image doesn't need a working backing file before\n" @@ -1140,6 +1145,7 @@ static int img_convert(int argc, char **argv) int min_sparse = 8; /* Need at least 4k of zeros for sparse detection */ bool quiet = false; Error *local_err = NULL; + QemuOpts *sn_opts = NULL; fmt = NULL; out_fmt = "raw"; @@ -1148,7 +1154,7 @@ static int img_convert(int argc, char **argv) compress = 0; skip_create = 0; for(;;) { - c = getopt(argc, argv, "f:O:B:s:hce6o:pS:t:qn"); + c = getopt(argc, argv, "f:O:B:s:hce6o:pS:t:qnl:"); if (c == -1) { break; } @@ -1183,6 +1189,18 @@ static int img_convert(int argc, char **argv) case 's': snapshot_name = optarg; break; + case 'l': + if (strstart(optarg, SNAPSHOT_OPT_BASE, NULL)) { + sn_opts = qemu_opts_parse(&internal_snapshot_opts, optarg, 0); + if (!sn_opts) { + error_report("Failed in parsing snapshot param '%s'", + optarg); + return 1; + } + } else { + snapshot_name = optarg; + } + break; case 'S': { int64_t sval; @@ -1254,7 +1272,12 @@ static int img_convert(int argc, char **argv) total_sectors += bs_sectors; } - if (snapshot_name != NULL) { + if (sn_opts) { + ret = bdrv_snapshot_load_tmp(bs[0], + qemu_opt_get(sn_opts, SNAPSHOT_OPT_ID), + qemu_opt_get(sn_opts, SNAPSHOT_OPT_NAME), + &local_err); + } else if (snapshot_name != NULL) { if (bs_n > 1) { error_report("No support for concatenating multiple snapshot"); ret = -1; @@ -1262,13 +1285,13 @@ static int img_convert(int argc, char **argv) } bdrv_snapshot_load_tmp_by_id_or_name(bs[0], snapshot_name, &local_err); - if (error_is_set(&local_err)) { - error_report("Failed to load snapshot: %s", - error_get_pretty(local_err)); - error_free(local_err); - ret = -1; - goto out; - } + } + if (error_is_set(&local_err)) { + error_report("Failed to load snapshot: %s", + error_get_pretty(local_err)); + error_free(local_err); + ret = -1; + goto out; } /* Find driver and parse its options */ @@ -1559,6 +1582,9 @@ out: free_option_parameters(create_options); free_option_parameters(param); qemu_vfree(buf); + if (sn_opts) { + qemu_opts_del(sn_opts); + } if (out_bs) { bdrv_unref(out_bs); } diff --git a/qemu-img.texi b/qemu-img.texi index 768054e..fbdbfa7 100644 --- a/qemu-img.texi +++ b/qemu-img.texi @@ -46,7 +46,11 @@ is the destination disk image filename is a comma separated list of format specific options in a name=value format. Use @code{-o ?} for an overview of the options supported by the used format or see the format descriptions below for details. - +@item snapshot_param +is param used for internal snapshot, format is +'snapshot.id=[ID],snapshot.name=[NAME]' or '[ID_OR_NAME]' +@item snapshot_id_or_name +is deprecated, use snapshot_param instead @item -c indicates that target image must be compressed (qcow format only) @@ -179,10 +183,10 @@ Error on reading data @end table -@item convert [-c] [-p] [-n] [-f @var{fmt}] [-t @var{cache}] [-O @var{output_fmt}] [-o @var{options}] [-s @var{snapshot_name}] [-S @var{sparse_size}] @var{filename} [@var{filename2} [...]] @var{output_filename} +@item convert [-c] [-p] [-n] [-f @var{fmt}] [-t @var{cache}] [-O @var{output_fmt}] [-o @var{options}] [-s @var{snapshot_id_or_name}] [-l @var{snapshot_param}] [-S @var{sparse_size}] @var{filename} [@var{filename2} [...]] @var{output_filename} -Convert the disk image @var{filename} or a snapshot @var{snapshot_name} to disk image @var{output_filename} -using format @var{output_fmt}. It can be optionally compressed (@code{-c} +Convert the disk image @var{filename} or a snapshot @var{snapshot_param}(@var{snapshot_id_or_name} is deprecated) +to disk image @var{output_filename} using format @var{output_fmt}. It can be optionally compressed (@code{-c} option) or use any format specific options like encryption (@code{-o} option). Only the formats @code{qcow} and @code{qcow2} support compression. The