@@ -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);
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 | 91 +++++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 72 insertions(+), 19 deletions(-)