From patchwork Fri Jun 3 08:49:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 9152319 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 38C4760221 for ; Fri, 3 Jun 2016 09:09:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 292DF282EE for ; Fri, 3 Jun 2016 09:09:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1DCE828309; Fri, 3 Jun 2016 09:09:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 47928282EE for ; Fri, 3 Jun 2016 09:09:45 +0000 (UTC) Received: from localhost ([::1]:53514 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8l6t-0000Fg-MI for patchwork-qemu-devel@patchwork.kernel.org; Fri, 03 Jun 2016 05:09:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55136) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8ko4-0007EF-VF for qemu-devel@nongnu.org; Fri, 03 Jun 2016 04:50:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b8ko3-0001zg-7I for qemu-devel@nongnu.org; Fri, 03 Jun 2016 04:50:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38823) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8knv-0001wI-Lm; Fri, 03 Jun 2016 04:50:07 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (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 21A93800AF; Fri, 3 Jun 2016 08:50:07 +0000 (UTC) Received: from ad.usersys.redhat.com (dhcp-15-133.nay.redhat.com [10.66.15.133]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u538nKXu023508; Fri, 3 Jun 2016 04:50:02 -0400 From: Fam Zheng To: qemu-devel@nongnu.org Date: Fri, 3 Jun 2016 16:49:04 +0800 Message-Id: <1464943756-14143-11-git-send-email-famz@redhat.com> In-Reply-To: <1464943756-14143-1-git-send-email-famz@redhat.com> References: <1464943756-14143-1-git-send-email-famz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 03 Jun 2016 08:50:07 +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 v6 10/22] 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-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 | 91 +++++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 72 insertions(+), 19 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 4b56ad3..88a12b5 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); @@ -1131,6 +1141,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 (;;) { @@ -1140,7 +1151,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; @@ -1168,6 +1179,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,7 +1219,7 @@ static int img_compare(int argc, char **argv) /* Initialize before goto out */ 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); @@ -1754,6 +1768,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"; @@ -1769,7 +1784,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; @@ -1858,6 +1873,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; @@ -1906,7 +1924,7 @@ static int img_convert(int argc, char **argv) goto out; } - 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); @@ -2056,6 +2074,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); @@ -2236,12 +2255,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); @@ -2258,8 +2279,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; } @@ -2311,6 +2333,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; @@ -2325,7 +2348,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; @@ -2338,6 +2361,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; @@ -2377,7 +2403,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; } @@ -2523,6 +2549,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; @@ -2536,7 +2564,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; @@ -2549,6 +2577,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; @@ -2585,7 +2616,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; } @@ -2648,6 +2680,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 */ @@ -2658,7 +2691,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; @@ -2703,6 +2736,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, @@ -2728,6 +2764,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) { @@ -2797,6 +2834,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; @@ -2811,7 +2849,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; @@ -2842,6 +2880,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; @@ -2881,6 +2922,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); @@ -3142,6 +3184,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", @@ -3176,7 +3220,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; @@ -3192,6 +3236,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, @@ -3243,8 +3290,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; @@ -3305,6 +3353,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 (;;) { @@ -3314,7 +3363,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; @@ -3351,6 +3400,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); @@ -3396,6 +3448,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);