From: Fam Zheng <famz@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>, Max Reitz <mreitz@redhat.com>,
Jeff Cody <jcody@redhat.com>,
Markus Armbruster <armbru@redhat.com>,
Eric Blake <eblake@redhat.com>, John Snow <jsnow@redhat.com>,
qemu-block@nongnu.org, berrange@redhat.com, pbonzini@redhat.com,
den@openvz.org, stefanha@redhat.com
Subject: [Qemu-devel] [PATCH v5 14/27] qemu-img: Add "-L" option to sub commands
Date: Tue, 17 May 2016 15:35:23 +0800 [thread overview]
Message-ID: <1463470536-8981-15-git-send-email-famz@redhat.com> (raw)
In-Reply-To: <1463470536-8981-1-git-send-email-famz@redhat.com>
If specified, BDRV_O_NO_LOCK flag will be set when opening the image.
Signed-off-by: Fam Zheng <famz@redhat.com>
---
qemu-img.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++------------
1 file changed, 72 insertions(+), 17 deletions(-)
diff --git a/qemu-img.c b/qemu-img.c
index 4792366..b13755b 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,
@@ -1206,6 +1220,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);
@@ -1754,6 +1769,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 +1785,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 +1874,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;
@@ -1907,6 +1926,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);
@@ -2056,6 +2076,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 +2257,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 +2281,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 +2335,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 +2350,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 +2363,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 +2405,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 +2551,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 +2566,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 +2579,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 +2618,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 +2682,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 +2693,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 +2738,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 +2766,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 +2836,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 +2851,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 +2882,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 +2924,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 +3186,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 +3222,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 +3238,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 +3292,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 +3355,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 +3365,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 +3402,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 +3450,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);
--
2.8.2
next prev parent reply other threads:[~2016-05-17 7:36 UTC|newest]
Thread overview: 71+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-17 7:35 [Qemu-devel] [PATCH v5 00/27] block: Lock images when opening Fam Zheng
2016-05-17 7:35 ` [Qemu-devel] [PATCH v5 01/27] block: Add flag bits for image locking Fam Zheng
2016-05-24 12:14 ` Max Reitz
2016-05-17 7:35 ` [Qemu-devel] [PATCH v5 02/27] qapi: Add lock-mode in blockdev-add options Fam Zheng
2016-05-24 12:15 ` Max Reitz
2016-05-17 7:35 ` [Qemu-devel] [PATCH v5 03/27] blockdev: Add and parse "lock-mode" option for image locking Fam Zheng
2016-05-24 12:17 ` Max Reitz
2016-05-17 7:35 ` [Qemu-devel] [PATCH v5 04/27] block: Introduce image file locking Fam Zheng
2016-05-24 16:01 ` Max Reitz
2016-05-17 7:35 ` [Qemu-devel] [PATCH v5 05/27] block: Add bdrv_image_locked Fam Zheng
2016-05-24 16:04 ` Max Reitz
2016-05-17 7:35 ` [Qemu-devel] [PATCH v5 06/27] block: Make bdrv_reopen_{commit, abort} private functions Fam Zheng
2016-05-24 16:09 ` Max Reitz
2016-05-27 7:42 ` Fam Zheng
2016-05-17 7:35 ` [Qemu-devel] [PATCH v5 07/27] block: Handle image locking during reopen Fam Zheng
2016-05-24 16:28 ` Max Reitz
2016-05-27 7:48 ` Fam Zheng
2016-05-27 9:57 ` Max Reitz
2016-05-27 12:36 ` Fam Zheng
2016-05-17 7:35 ` [Qemu-devel] [PATCH v5 08/27] osdep: Add qemu_lock_fd and qemu_unlock_fd Fam Zheng
2016-05-24 16:42 ` Max Reitz
2016-05-17 7:35 ` [Qemu-devel] [PATCH v5 09/27] osdep: Introduce qemu_dup Fam Zheng
2016-05-24 16:52 ` Max Reitz
2016-05-17 7:35 ` [Qemu-devel] [PATCH v5 10/27] raw-posix: Use qemu_dup Fam Zheng
2016-05-24 16:55 ` Max Reitz
2016-05-17 7:35 ` [Qemu-devel] [PATCH v5 11/27] raw-posix: Implement .bdrv_lockf Fam Zheng
2016-05-24 17:09 ` Max Reitz
2016-05-27 7:50 ` Fam Zheng
2016-05-17 7:35 ` [Qemu-devel] [PATCH v5 12/27] gluster: " Fam Zheng
2016-05-17 7:35 ` [Qemu-devel] [PATCH v5 13/27] qemu-io: Add "-L" option for BDRV_O_NO_LOCK Fam Zheng
2016-05-24 17:21 ` Max Reitz
2016-05-17 7:35 ` Fam Zheng [this message]
2016-05-24 18:06 ` [Qemu-devel] [PATCH v5 14/27] qemu-img: Add "-L" option to sub commands Max Reitz
2016-06-01 5:34 ` Fam Zheng
2016-06-02 11:30 ` Max Reitz
2016-05-17 7:35 ` [Qemu-devel] [PATCH v5 15/27] qemu-img: Update documentation of "-L" option Fam Zheng
2016-05-24 18:09 ` Max Reitz
2016-05-17 7:35 ` [Qemu-devel] [PATCH v5 16/27] qemu-nbd: Add "--no-lock/-L" option Fam Zheng
2016-05-24 18:12 ` Max Reitz
2016-05-17 7:35 ` [Qemu-devel] [PATCH v5 17/27] block: Don't lock drive-backup target image in none mode Fam Zheng
2016-05-24 18:16 ` Max Reitz
2016-05-17 7:35 ` [Qemu-devel] [PATCH v5 18/27] mirror: Disable image locking on target backing chain Fam Zheng
2016-05-24 18:20 ` Max Reitz
2016-06-03 6:32 ` Fam Zheng
2016-06-03 13:24 ` Max Reitz
2016-05-17 7:35 ` [Qemu-devel] [PATCH v5 19/27] qemu-iotests: 140: Disable image lock for qemu-io access Fam Zheng
2016-05-25 13:16 ` Max Reitz
2016-06-03 6:34 ` Fam Zheng
2016-05-17 7:35 ` [Qemu-devel] [PATCH v5 20/27] qemu-iotests: 046: Move version detection out from verify_io Fam Zheng
2016-05-25 13:23 ` Max Reitz
2016-06-03 6:43 ` Fam Zheng
2016-05-17 7:35 ` [Qemu-devel] [PATCH v5 21/27] qemu-iotests: Wait for QEMU processes before checking image in 091 Fam Zheng
2016-05-25 13:28 ` Max Reitz
2016-05-17 7:35 ` [Qemu-devel] [PATCH v5 22/27] qemu-iotests: 030: Disable image lock when checking test image Fam Zheng
2016-05-25 13:30 ` Max Reitz
2016-05-17 7:35 ` [Qemu-devel] [PATCH v5 23/27] iotests: 087: Disable image lock in cases where file is shared Fam Zheng
2016-05-25 13:41 ` Max Reitz
2016-05-25 13:41 ` Max Reitz
2016-05-17 7:35 ` [Qemu-devel] [PATCH v5 24/27] iotests: Disable image locking in 085 Fam Zheng
2016-05-25 13:52 ` Max Reitz
2016-06-03 7:18 ` Fam Zheng
2016-06-03 14:41 ` Max Reitz
2016-05-17 7:35 ` [Qemu-devel] [PATCH v5 25/27] tests: Use null-co:// instead of /dev/null Fam Zheng
2016-05-25 13:57 ` Max Reitz
2016-05-17 7:35 ` [Qemu-devel] [PATCH v5 26/27] block: Turn on image locking by default Fam Zheng
2016-05-25 13:57 ` Max Reitz
2016-05-17 7:35 ` [Qemu-devel] [PATCH v5 27/27] qemu-iotests: Add test case 153 for image locking Fam Zheng
2016-05-25 14:20 ` Max Reitz
2016-05-24 11:48 ` [Qemu-devel] [PATCH v5 00/27] block: Lock images when opening Richard W.M. Jones
2016-05-24 12:46 ` Kevin Wolf
2016-05-24 12:58 ` Richard W.M. Jones
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1463470536-8981-15-git-send-email-famz@redhat.com \
--to=famz@redhat.com \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=den@openvz.org \
--cc=eblake@redhat.com \
--cc=jcody@redhat.com \
--cc=jsnow@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).