From patchwork Thu Apr 28 12:57:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 8969931 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 C64329F1C1 for ; Thu, 28 Apr 2016 13:07:19 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A49DF202EB for ; Thu, 28 Apr 2016 13:07:18 +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 82E58202A1 for ; Thu, 28 Apr 2016 13:07:12 +0000 (UTC) Received: from localhost ([::1]:48829 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1avlex-0003oY-Lo for patchwork-qemu-devel@patchwork.kernel.org; Thu, 28 Apr 2016 09:07:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32789) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1avlWz-0002v4-4t for qemu-devel@nongnu.org; Thu, 28 Apr 2016 08:58:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1avlWx-0000We-DA for qemu-devel@nongnu.org; Thu, 28 Apr 2016 08:58:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53339) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1avlWs-0000Tq-Ax; Thu, 28 Apr 2016 08:58:50 -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 DCEA178225; Thu, 28 Apr 2016 12:58:49 +0000 (UTC) Received: from lemon.redhat.com (vpn1-5-154.pek2.redhat.com [10.72.5.154]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u3SCvWNH001193; Thu, 28 Apr 2016 08:58:45 -0400 From: Fam Zheng To: qemu-devel@nongnu.org Date: Thu, 28 Apr 2016 20:57:33 +0800 Message-Id: <1461848266-32119-15-git-send-email-famz@redhat.com> In-Reply-To: <1461848266-32119-1-git-send-email-famz@redhat.com> References: <1461848266-32119-1-git-send-email-famz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 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 v3 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, Jeff Cody , Markus Armbruster , Max Reitz , stefanha@redhat.com, den@openvz.org, pbonzini@redhat.com, John Snow 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 1697762..327be44 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -600,6 +600,7 @@ static int img_check(int argc, char **argv) bool quiet = false; Error *local_err = NULL; bool image_opts = false; + bool nolock = false; fmt = NULL; output = NULL; @@ -616,7 +617,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; @@ -650,6 +651,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, @@ -684,6 +688,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); @@ -804,6 +809,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; @@ -815,7 +821,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; @@ -845,6 +851,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, @@ -877,6 +886,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); @@ -1135,6 +1145,7 @@ static int img_compare(int argc, char **argv) uint64_t progress_base; Error *local_err = NULL; bool image_opts = false; + bool nolock = false; cache = BDRV_DEFAULT_CACHE; for (;;) { @@ -1144,7 +1155,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; @@ -1172,6 +1183,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, @@ -1211,6 +1225,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); @@ -1742,6 +1757,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"; @@ -1757,7 +1773,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; @@ -1846,6 +1862,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; @@ -1896,6 +1915,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); @@ -2045,6 +2065,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); @@ -2225,12 +2246,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); @@ -2247,8 +2270,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; } @@ -2301,6 +2325,7 @@ static int img_info(int argc, char **argv) ImageInfoList *list; Error *local_err = NULL; bool image_opts = false; + bool nolock = false; fmt = NULL; output = NULL; @@ -2315,7 +2340,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; @@ -2328,6 +2353,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; @@ -2368,7 +2396,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; } @@ -2515,6 +2543,8 @@ static int img_map(int argc, char **argv) int ret = 0; Error *local_err = NULL; bool image_opts = false; + bool nolock = false; + int flags; fmt = NULL; output = NULL; @@ -2528,7 +2558,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; @@ -2541,6 +2571,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; @@ -2578,7 +2611,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; } @@ -2641,6 +2675,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 */ @@ -2651,7 +2686,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; @@ -2696,6 +2731,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, @@ -2722,6 +2760,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) { @@ -2791,6 +2830,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; @@ -2805,7 +2845,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; @@ -2836,6 +2876,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; @@ -2876,6 +2919,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); @@ -3134,6 +3178,8 @@ static int img_resize(int argc, char **argv) BlockBackend *blk = NULL; QemuOpts *param; Error *local_err = NULL; + int flags; + bool nolock = false; static QemuOptsList resize_options = { .name = "resize_options", @@ -3168,7 +3214,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; @@ -3184,6 +3230,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, @@ -3236,8 +3285,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; @@ -3299,6 +3349,7 @@ static int img_amend(int argc, char **argv) BlockDriverState *bs = NULL; Error *local_err = NULL; bool image_opts = false; + bool nolock = false; cache = BDRV_DEFAULT_CACHE; for (;;) { @@ -3308,7 +3359,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; @@ -3345,6 +3396,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); @@ -3391,6 +3445,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);