From patchwork Tue May 10 02:50:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 9053571 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id AC50E9F6FA for ; Tue, 10 May 2016 02:58:11 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9D15A2012D for ; Tue, 10 May 2016 02:58:10 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4BEC02009C for ; Tue, 10 May 2016 02:58:09 +0000 (UTC) Received: from localhost ([::1]:44135 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1azxs8-0004xB-FU for patchwork-qemu-devel@patchwork.kernel.org; Mon, 09 May 2016 22:58:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59272) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1azxmT-0001xG-Nm for qemu-devel@nongnu.org; Mon, 09 May 2016 22:52:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1azxmR-0004oz-ER for qemu-devel@nongnu.org; Mon, 09 May 2016 22:52:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38050) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1azxmC-0004gf-8k; Mon, 09 May 2016 22:52:00 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B93DF6265D; Tue, 10 May 2016 02:51:59 +0000 (UTC) Received: from ad.usersys.redhat.com (dhcp-15-133.nay.redhat.com [10.66.15.133]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u4A2ovV1023061; Mon, 9 May 2016 22:51:56 -0400 From: Fam Zheng To: qemu-devel@nongnu.org Date: Tue, 10 May 2016 10:50:46 +0800 Message-Id: <1462848659-28659-15-git-send-email-famz@redhat.com> In-Reply-To: <1462848659-28659-1-git-send-email-famz@redhat.com> References: <1462848659-28659-1-git-send-email-famz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 10 May 2016 02:51:59 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 14/27] qemu-img: Add "-L" option to sub commands X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-block@nongnu.org, rjones@redhat.com, John Snow , Jeff Cody , Markus Armbruster , Max Reitz , stefanha@redhat.com, den@openvz.org, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If specified, BDRV_O_NO_LOCK flag will be set when opening the image. Signed-off-by: Fam Zheng --- qemu-img.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 72 insertions(+), 17 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 46f2a6d..28e350c 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -598,6 +598,7 @@ static int img_check(int argc, char **argv) ImageCheck *check; bool quiet = false; bool image_opts = false; + bool nolock = false; fmt = NULL; output = NULL; @@ -614,7 +615,7 @@ static int img_check(int argc, char **argv) {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, {0, 0, 0, 0} }; - c = getopt_long(argc, argv, "hf:r:T:q", + c = getopt_long(argc, argv, "hf:r:T:qL", long_options, &option_index); if (c == -1) { break; @@ -648,6 +649,9 @@ static int img_check(int argc, char **argv) case 'q': quiet = true; break; + case 'L': + nolock = true; + break; case OPTION_OBJECT: { QemuOpts *opts; opts = qemu_opts_parse_noisily(&qemu_object_opts, @@ -681,6 +685,7 @@ static int img_check(int argc, char **argv) return 1; } + flags |= nolock ? BDRV_O_NO_LOCK : 0; ret = bdrv_parse_cache_mode(cache, &flags, &writethrough); if (ret < 0) { error_report("Invalid source cache option: %s", cache); @@ -801,6 +806,7 @@ static int img_commit(int argc, char **argv) Error *local_err = NULL; CommonBlockJobCBInfo cbi; bool image_opts = false; + bool nolock = false; fmt = NULL; cache = BDRV_DEFAULT_CACHE; @@ -812,7 +818,7 @@ static int img_commit(int argc, char **argv) {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, {0, 0, 0, 0} }; - c = getopt_long(argc, argv, "f:ht:b:dpq", + c = getopt_long(argc, argv, "f:ht:b:dpqL", long_options, NULL); if (c == -1) { break; @@ -842,6 +848,9 @@ static int img_commit(int argc, char **argv) case 'q': quiet = true; break; + case 'L': + nolock = true; + break; case OPTION_OBJECT: { QemuOpts *opts; opts = qemu_opts_parse_noisily(&qemu_object_opts, @@ -873,6 +882,7 @@ static int img_commit(int argc, char **argv) } flags = BDRV_O_RDWR | BDRV_O_UNMAP; + flags |= nolock ? BDRV_O_NO_LOCK : 0; ret = bdrv_parse_cache_mode(cache, &flags, &writethrough); if (ret < 0) { error_report("Invalid cache option: %s", cache); @@ -1130,6 +1140,7 @@ static int img_compare(int argc, char **argv) int c, pnum; uint64_t progress_base; bool image_opts = false; + bool nolock = false; cache = BDRV_DEFAULT_CACHE; for (;;) { @@ -1139,7 +1150,7 @@ static int img_compare(int argc, char **argv) {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, {0, 0, 0, 0} }; - c = getopt_long(argc, argv, "hf:F:T:pqs", + c = getopt_long(argc, argv, "hf:F:T:pqsL", long_options, NULL); if (c == -1) { break; @@ -1167,6 +1178,9 @@ static int img_compare(int argc, char **argv) case 's': strict = true; break; + case 'L': + nolock = true; + break; case OPTION_OBJECT: { QemuOpts *opts; opts = qemu_opts_parse_noisily(&qemu_object_opts, @@ -1205,6 +1219,7 @@ static int img_compare(int argc, char **argv) qemu_progress_init(progress, 2.0); flags = 0; + flags |= nolock ? BDRV_O_NO_LOCK : 0; ret = bdrv_parse_cache_mode(cache, &flags, &writethrough); if (ret < 0) { error_report("Invalid source cache option: %s", cache); @@ -1736,6 +1751,7 @@ static int img_convert(int argc, char **argv) QemuOpts *sn_opts = NULL; ImgConvertState state; bool image_opts = false; + bool nolock = false; fmt = NULL; out_fmt = "raw"; @@ -1751,7 +1767,7 @@ static int img_convert(int argc, char **argv) {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, {0, 0, 0, 0} }; - c = getopt_long(argc, argv, "hf:O:B:ce6o:s:l:S:pt:T:qn", + c = getopt_long(argc, argv, "hf:O:B:ce6o:s:l:S:pt:T:qnL", long_options, NULL); if (c == -1) { break; @@ -1840,6 +1856,9 @@ static int img_convert(int argc, char **argv) case 'q': quiet = true; break; + case 'L': + nolock = true; + break; case 'n': skip_create = 1; break; @@ -1889,6 +1908,7 @@ static int img_convert(int argc, char **argv) } src_flags = 0; + src_flags |= nolock ? BDRV_O_NO_LOCK : 0; ret = bdrv_parse_cache_mode(src_cache, &src_flags, &src_writethrough); if (ret < 0) { error_report("Invalid source cache option: %s", src_cache); @@ -2038,6 +2058,7 @@ static int img_convert(int argc, char **argv) } flags = min_sparse ? (BDRV_O_RDWR | BDRV_O_UNMAP) : BDRV_O_RDWR; + flags |= nolock ? BDRV_O_NO_LOCK : 0; ret = bdrv_parse_cache_mode(cache, &flags, &writethrough); if (ret < 0) { error_report("Invalid cache option: %s", cache); @@ -2218,12 +2239,14 @@ static gboolean str_equal_func(gconstpointer a, gconstpointer b) static ImageInfoList *collect_image_info_list(bool image_opts, const char *filename, const char *fmt, - bool chain) + bool chain, + bool nolock) { ImageInfoList *head = NULL; ImageInfoList **last = &head; GHashTable *filenames; Error *err = NULL; + int flags; filenames = g_hash_table_new_full(g_str_hash, str_equal_func, NULL, NULL); @@ -2240,8 +2263,9 @@ static ImageInfoList *collect_image_info_list(bool image_opts, } g_hash_table_insert(filenames, (gpointer)filename, NULL); - blk = img_open(image_opts, filename, fmt, - BDRV_O_NO_BACKING | BDRV_O_NO_IO, false, false); + flags = BDRV_O_NO_BACKING | BDRV_O_NO_IO; + flags |= nolock ? BDRV_O_NO_LOCK : 0; + blk = img_open(image_opts, filename, fmt, flags, false, false); if (!blk) { goto err; } @@ -2293,6 +2317,7 @@ static int img_info(int argc, char **argv) const char *filename, *fmt, *output; ImageInfoList *list; bool image_opts = false; + bool nolock = false; fmt = NULL; output = NULL; @@ -2307,7 +2332,7 @@ static int img_info(int argc, char **argv) {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, {0, 0, 0, 0} }; - c = getopt_long(argc, argv, "f:h", + c = getopt_long(argc, argv, "f:hL", long_options, &option_index); if (c == -1) { break; @@ -2320,6 +2345,9 @@ static int img_info(int argc, char **argv) case 'f': fmt = optarg; break; + case 'L': + nolock = true; + break; case OPTION_OUTPUT: output = optarg; break; @@ -2359,7 +2387,7 @@ static int img_info(int argc, char **argv) return 1; } - list = collect_image_info_list(image_opts, filename, fmt, chain); + list = collect_image_info_list(image_opts, filename, fmt, chain, nolock); if (!list) { return 1; } @@ -2505,6 +2533,8 @@ static int img_map(int argc, char **argv) MapEntry curr = { .length = 0 }, next; int ret = 0; bool image_opts = false; + bool nolock = false; + int flags; fmt = NULL; output = NULL; @@ -2518,7 +2548,7 @@ static int img_map(int argc, char **argv) {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, {0, 0, 0, 0} }; - c = getopt_long(argc, argv, "f:h", + c = getopt_long(argc, argv, "f:hL", long_options, &option_index); if (c == -1) { break; @@ -2531,6 +2561,9 @@ static int img_map(int argc, char **argv) case 'f': fmt = optarg; break; + case 'L': + nolock = true; + break; case OPTION_OUTPUT: output = optarg; break; @@ -2567,7 +2600,8 @@ static int img_map(int argc, char **argv) return 1; } - blk = img_open(image_opts, filename, fmt, 0, false, false); + flags = nolock ? BDRV_O_NO_LOCK : 0; + blk = img_open(image_opts, filename, fmt, flags, false, false); if (!blk) { return 1; } @@ -2630,6 +2664,7 @@ static int img_snapshot(int argc, char **argv) bool quiet = false; Error *err = NULL; bool image_opts = false; + bool nolock = false; bdrv_oflags = BDRV_O_RDWR; /* Parse commandline parameters */ @@ -2640,7 +2675,7 @@ static int img_snapshot(int argc, char **argv) {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, {0, 0, 0, 0} }; - c = getopt_long(argc, argv, "la:c:d:hq", + c = getopt_long(argc, argv, "la:c:d:hqL", long_options, NULL); if (c == -1) { break; @@ -2685,6 +2720,9 @@ static int img_snapshot(int argc, char **argv) case 'q': quiet = true; break; + case 'L': + nolock = true; + break; case OPTION_OBJECT: { QemuOpts *opts; opts = qemu_opts_parse_noisily(&qemu_object_opts, @@ -2710,6 +2748,7 @@ static int img_snapshot(int argc, char **argv) return 1; } + bdrv_oflags |= nolock ? BDRV_O_NO_LOCK : 0; /* Open the image */ blk = img_open(image_opts, filename, NULL, bdrv_oflags, false, quiet); if (!blk) { @@ -2779,6 +2818,7 @@ static int img_rebase(int argc, char **argv) bool quiet = false; Error *local_err = NULL; bool image_opts = false; + bool nolock = false; /* Parse commandline parameters */ fmt = NULL; @@ -2793,7 +2833,7 @@ static int img_rebase(int argc, char **argv) {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, {0, 0, 0, 0} }; - c = getopt_long(argc, argv, "hf:F:b:upt:T:q", + c = getopt_long(argc, argv, "hf:F:b:upt:T:qL", long_options, NULL); if (c == -1) { break; @@ -2824,6 +2864,9 @@ static int img_rebase(int argc, char **argv) case 'T': src_cache = optarg; break; + case 'L': + nolock = true; + break; case 'q': quiet = true; break; @@ -2863,6 +2906,7 @@ static int img_rebase(int argc, char **argv) qemu_progress_print(0, 100); flags = BDRV_O_RDWR | (unsafe ? BDRV_O_NO_BACKING : 0); + flags |= nolock ? BDRV_O_NO_LOCK : 0; ret = bdrv_parse_cache_mode(cache, &flags, &writethrough); if (ret < 0) { error_report("Invalid cache option: %s", cache); @@ -3120,6 +3164,8 @@ static int img_resize(int argc, char **argv) bool quiet = false; BlockBackend *blk = NULL; QemuOpts *param; + int flags; + bool nolock = false; static QemuOptsList resize_options = { .name = "resize_options", @@ -3154,7 +3200,7 @@ static int img_resize(int argc, char **argv) {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, {0, 0, 0, 0} }; - c = getopt_long(argc, argv, "f:hq", + c = getopt_long(argc, argv, "f:hqL", long_options, NULL); if (c == -1) { break; @@ -3170,6 +3216,9 @@ static int img_resize(int argc, char **argv) case 'q': quiet = true; break; + case 'L': + nolock = true; + break; case OPTION_OBJECT: { QemuOpts *opts; opts = qemu_opts_parse_noisily(&qemu_object_opts, @@ -3221,8 +3270,9 @@ static int img_resize(int argc, char **argv) n = qemu_opt_get_size(param, BLOCK_OPT_SIZE, 0); qemu_opts_del(param); - blk = img_open(image_opts, filename, fmt, - BDRV_O_RDWR, false, quiet); + flags = BDRV_O_RDWR; + flags |= nolock ? BDRV_O_NO_LOCK : 0; + blk = img_open(image_opts, filename, fmt, flags, false, quiet); if (!blk) { ret = -1; goto out; @@ -3283,6 +3333,7 @@ static int img_amend(int argc, char **argv) BlockBackend *blk = NULL; BlockDriverState *bs = NULL; bool image_opts = false; + bool nolock = false; cache = BDRV_DEFAULT_CACHE; for (;;) { @@ -3292,7 +3343,7 @@ static int img_amend(int argc, char **argv) {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, {0, 0, 0, 0} }; - c = getopt_long(argc, argv, "ho:f:t:pq", + c = getopt_long(argc, argv, "ho:f:t:pqL", long_options, NULL); if (c == -1) { break; @@ -3329,6 +3380,9 @@ static int img_amend(int argc, char **argv) case 'q': quiet = true; break; + case 'L': + nolock = true; + break; case OPTION_OBJECT: opts = qemu_opts_parse_noisily(&qemu_object_opts, optarg, true); @@ -3374,6 +3428,7 @@ static int img_amend(int argc, char **argv) } flags = BDRV_O_RDWR; + flags |= nolock ? BDRV_O_NO_LOCK : 0; ret = bdrv_parse_cache_mode(cache, &flags, &writethrough); if (ret < 0) { error_report("Invalid cache option: %s", cache);