From patchwork Thu Sep 26 00:16:06 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wayne Xia X-Patchwork-Id: 278044 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 D55522C032D for ; Thu, 26 Sep 2013 10:17:27 +1000 (EST) Received: from localhost ([::1]:55485 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VOzGn-0007kU-MG for incoming@patchwork.ozlabs.org; Wed, 25 Sep 2013 20:17:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45036) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VOzG0-0007As-10 for qemu-devel@nongnu.org; Wed, 25 Sep 2013 20:16:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VOzFm-00021c-Vp for qemu-devel@nongnu.org; Wed, 25 Sep 2013 20:16:35 -0400 Received: from e28smtp03.in.ibm.com ([122.248.162.3]:38317) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VOzFm-00021K-BH for qemu-devel@nongnu.org; Wed, 25 Sep 2013 20:16:22 -0400 Received: from /spool/local by e28smtp03.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 26 Sep 2013 05:46:20 +0530 Received: from d28dlp03.in.ibm.com (9.184.220.128) by e28smtp03.in.ibm.com (192.168.1.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 26 Sep 2013 05:46:18 +0530 Received: from d28relay05.in.ibm.com (d28relay05.in.ibm.com [9.184.220.62]) by d28dlp03.in.ibm.com (Postfix) with ESMTP id 7EA7F125803F for ; Thu, 26 Sep 2013 05:46:31 +0530 (IST) Received: from d28av02.in.ibm.com (d28av02.in.ibm.com [9.184.220.64]) by d28relay05.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r8Q0GGU643384988 for ; Thu, 26 Sep 2013 05:46:16 +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 r8Q0GHvF028489 for ; Thu, 26 Sep 2013 05:46:18 +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 r8Q0GAS4028311; Thu, 26 Sep 2013 05:46:17 +0530 From: Wenchao Xia To: qemu-devel@nongnu.org Date: Thu, 26 Sep 2013 08:16:06 +0800 Message-Id: <1380154568-5339-6-git-send-email-xiawenc@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1380154568-5339-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1380154568-5339-1-git-send-email-xiawenc@linux.vnet.ibm.com> X-TM-AS-MML: No X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13092600-3864-0000-0000-00000A3EC0F4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 122.248.162.3 Cc: kwolf@redhat.com, pbonzini@redhat.com, Wenchao Xia , stefanha@gmail.com Subject: [Qemu-devel] [PATCH V3 5/7] 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.c | 30 +++++++++++++++++++++--------- 1 files changed, 21 insertions(+), 9 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 6df58ed..a784ad4 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1140,6 +1140,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 +1149,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 +1184,9 @@ static int img_convert(int argc, char **argv) case 's': snapshot_name = optarg; break; + case 'L': + sn_opts = qemu_opts_parse(&internal_snapshot_opts, optarg, 0); + break; case 'S': { int64_t sval; @@ -1254,7 +1258,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 +1271,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 +1568,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); }