qemu-img: Add --force-share option to subcommands
This will force the opened images to allow sharing all permissions with other programs. Signed-off-by: Fam Zheng <famz@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
ffd1a5a25c
commit
335e993784
153
qemu-img.c
153
qemu-img.c
@ -28,6 +28,7 @@
|
|||||||
#include "qapi/qobject-output-visitor.h"
|
#include "qapi/qobject-output-visitor.h"
|
||||||
#include "qapi/qmp/qerror.h"
|
#include "qapi/qmp/qerror.h"
|
||||||
#include "qapi/qmp/qjson.h"
|
#include "qapi/qmp/qjson.h"
|
||||||
|
#include "qapi/qmp/qbool.h"
|
||||||
#include "qemu/cutils.h"
|
#include "qemu/cutils.h"
|
||||||
#include "qemu/config-file.h"
|
#include "qemu/config-file.h"
|
||||||
#include "qemu/option.h"
|
#include "qemu/option.h"
|
||||||
@ -283,12 +284,20 @@ static int img_open_password(BlockBackend *blk, const char *filename,
|
|||||||
|
|
||||||
static BlockBackend *img_open_opts(const char *optstr,
|
static BlockBackend *img_open_opts(const char *optstr,
|
||||||
QemuOpts *opts, int flags, bool writethrough,
|
QemuOpts *opts, int flags, bool writethrough,
|
||||||
bool quiet)
|
bool quiet, bool force_share)
|
||||||
{
|
{
|
||||||
QDict *options;
|
QDict *options;
|
||||||
Error *local_err = NULL;
|
Error *local_err = NULL;
|
||||||
BlockBackend *blk;
|
BlockBackend *blk;
|
||||||
options = qemu_opts_to_qdict(opts, NULL);
|
options = qemu_opts_to_qdict(opts, NULL);
|
||||||
|
if (force_share) {
|
||||||
|
if (qdict_haskey(options, BDRV_OPT_FORCE_SHARE)
|
||||||
|
&& !qdict_get_bool(options, BDRV_OPT_FORCE_SHARE)) {
|
||||||
|
error_report("--force-share/-U conflicts with image options");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
qdict_put(options, BDRV_OPT_FORCE_SHARE, qbool_from_bool(true));
|
||||||
|
}
|
||||||
blk = blk_new_open(NULL, NULL, options, flags, &local_err);
|
blk = blk_new_open(NULL, NULL, options, flags, &local_err);
|
||||||
if (!blk) {
|
if (!blk) {
|
||||||
error_reportf_err(local_err, "Could not open '%s': ", optstr);
|
error_reportf_err(local_err, "Could not open '%s': ", optstr);
|
||||||
@ -305,17 +314,20 @@ static BlockBackend *img_open_opts(const char *optstr,
|
|||||||
|
|
||||||
static BlockBackend *img_open_file(const char *filename,
|
static BlockBackend *img_open_file(const char *filename,
|
||||||
const char *fmt, int flags,
|
const char *fmt, int flags,
|
||||||
bool writethrough, bool quiet)
|
bool writethrough, bool quiet,
|
||||||
|
bool force_share)
|
||||||
{
|
{
|
||||||
BlockBackend *blk;
|
BlockBackend *blk;
|
||||||
Error *local_err = NULL;
|
Error *local_err = NULL;
|
||||||
QDict *options = NULL;
|
QDict *options = qdict_new();
|
||||||
|
|
||||||
if (fmt) {
|
if (fmt) {
|
||||||
options = qdict_new();
|
|
||||||
qdict_put_str(options, "driver", fmt);
|
qdict_put_str(options, "driver", fmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (force_share) {
|
||||||
|
qdict_put(options, BDRV_OPT_FORCE_SHARE, qbool_from_bool(true));
|
||||||
|
}
|
||||||
blk = blk_new_open(filename, NULL, options, flags, &local_err);
|
blk = blk_new_open(filename, NULL, options, flags, &local_err);
|
||||||
if (!blk) {
|
if (!blk) {
|
||||||
error_reportf_err(local_err, "Could not open '%s': ", filename);
|
error_reportf_err(local_err, "Could not open '%s': ", filename);
|
||||||
@ -334,7 +346,7 @@ static BlockBackend *img_open_file(const char *filename,
|
|||||||
static BlockBackend *img_open(bool image_opts,
|
static BlockBackend *img_open(bool image_opts,
|
||||||
const char *filename,
|
const char *filename,
|
||||||
const char *fmt, int flags, bool writethrough,
|
const char *fmt, int flags, bool writethrough,
|
||||||
bool quiet)
|
bool quiet, bool force_share)
|
||||||
{
|
{
|
||||||
BlockBackend *blk;
|
BlockBackend *blk;
|
||||||
if (image_opts) {
|
if (image_opts) {
|
||||||
@ -348,9 +360,11 @@ static BlockBackend *img_open(bool image_opts,
|
|||||||
if (!opts) {
|
if (!opts) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
blk = img_open_opts(filename, opts, flags, writethrough, quiet);
|
blk = img_open_opts(filename, opts, flags, writethrough, quiet,
|
||||||
|
force_share);
|
||||||
} else {
|
} else {
|
||||||
blk = img_open_file(filename, fmt, flags, writethrough, quiet);
|
blk = img_open_file(filename, fmt, flags, writethrough, quiet,
|
||||||
|
force_share);
|
||||||
}
|
}
|
||||||
return blk;
|
return blk;
|
||||||
}
|
}
|
||||||
@ -650,6 +664,7 @@ static int img_check(int argc, char **argv)
|
|||||||
ImageCheck *check;
|
ImageCheck *check;
|
||||||
bool quiet = false;
|
bool quiet = false;
|
||||||
bool image_opts = false;
|
bool image_opts = false;
|
||||||
|
bool force_share = false;
|
||||||
|
|
||||||
fmt = NULL;
|
fmt = NULL;
|
||||||
output = NULL;
|
output = NULL;
|
||||||
@ -664,9 +679,10 @@ static int img_check(int argc, char **argv)
|
|||||||
{"output", required_argument, 0, OPTION_OUTPUT},
|
{"output", required_argument, 0, OPTION_OUTPUT},
|
||||||
{"object", required_argument, 0, OPTION_OBJECT},
|
{"object", required_argument, 0, OPTION_OBJECT},
|
||||||
{"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
|
{"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
|
||||||
|
{"force-share", no_argument, 0, 'U'},
|
||||||
{0, 0, 0, 0}
|
{0, 0, 0, 0}
|
||||||
};
|
};
|
||||||
c = getopt_long(argc, argv, ":hf:r:T:q",
|
c = getopt_long(argc, argv, ":hf:r:T:qU",
|
||||||
long_options, &option_index);
|
long_options, &option_index);
|
||||||
if (c == -1) {
|
if (c == -1) {
|
||||||
break;
|
break;
|
||||||
@ -705,6 +721,9 @@ static int img_check(int argc, char **argv)
|
|||||||
case 'q':
|
case 'q':
|
||||||
quiet = true;
|
quiet = true;
|
||||||
break;
|
break;
|
||||||
|
case 'U':
|
||||||
|
force_share = true;
|
||||||
|
break;
|
||||||
case OPTION_OBJECT: {
|
case OPTION_OBJECT: {
|
||||||
QemuOpts *opts;
|
QemuOpts *opts;
|
||||||
opts = qemu_opts_parse_noisily(&qemu_object_opts,
|
opts = qemu_opts_parse_noisily(&qemu_object_opts,
|
||||||
@ -744,7 +763,8 @@ static int img_check(int argc, char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet);
|
blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet,
|
||||||
|
force_share);
|
||||||
if (!blk) {
|
if (!blk) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -947,7 +967,8 @@ static int img_commit(int argc, char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet);
|
blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet,
|
||||||
|
false);
|
||||||
if (!blk) {
|
if (!blk) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -1206,6 +1227,7 @@ static int img_compare(int argc, char **argv)
|
|||||||
int c, pnum;
|
int c, pnum;
|
||||||
uint64_t progress_base;
|
uint64_t progress_base;
|
||||||
bool image_opts = false;
|
bool image_opts = false;
|
||||||
|
bool force_share = false;
|
||||||
|
|
||||||
cache = BDRV_DEFAULT_CACHE;
|
cache = BDRV_DEFAULT_CACHE;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
@ -1213,9 +1235,10 @@ static int img_compare(int argc, char **argv)
|
|||||||
{"help", no_argument, 0, 'h'},
|
{"help", no_argument, 0, 'h'},
|
||||||
{"object", required_argument, 0, OPTION_OBJECT},
|
{"object", required_argument, 0, OPTION_OBJECT},
|
||||||
{"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
|
{"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
|
||||||
|
{"force-share", no_argument, 0, 'U'},
|
||||||
{0, 0, 0, 0}
|
{0, 0, 0, 0}
|
||||||
};
|
};
|
||||||
c = getopt_long(argc, argv, ":hf:F:T:pqs",
|
c = getopt_long(argc, argv, ":hf:F:T:pqsU",
|
||||||
long_options, NULL);
|
long_options, NULL);
|
||||||
if (c == -1) {
|
if (c == -1) {
|
||||||
break;
|
break;
|
||||||
@ -1248,6 +1271,9 @@ static int img_compare(int argc, char **argv)
|
|||||||
case 's':
|
case 's':
|
||||||
strict = true;
|
strict = true;
|
||||||
break;
|
break;
|
||||||
|
case 'U':
|
||||||
|
force_share = true;
|
||||||
|
break;
|
||||||
case OPTION_OBJECT: {
|
case OPTION_OBJECT: {
|
||||||
QemuOpts *opts;
|
QemuOpts *opts;
|
||||||
opts = qemu_opts_parse_noisily(&qemu_object_opts,
|
opts = qemu_opts_parse_noisily(&qemu_object_opts,
|
||||||
@ -1293,13 +1319,15 @@ static int img_compare(int argc, char **argv)
|
|||||||
goto out3;
|
goto out3;
|
||||||
}
|
}
|
||||||
|
|
||||||
blk1 = img_open(image_opts, filename1, fmt1, flags, writethrough, quiet);
|
blk1 = img_open(image_opts, filename1, fmt1, flags, writethrough, quiet,
|
||||||
|
force_share);
|
||||||
if (!blk1) {
|
if (!blk1) {
|
||||||
ret = 2;
|
ret = 2;
|
||||||
goto out3;
|
goto out3;
|
||||||
}
|
}
|
||||||
|
|
||||||
blk2 = img_open(image_opts, filename2, fmt2, flags, writethrough, quiet);
|
blk2 = img_open(image_opts, filename2, fmt2, flags, writethrough, quiet,
|
||||||
|
force_share);
|
||||||
if (!blk2) {
|
if (!blk2) {
|
||||||
ret = 2;
|
ret = 2;
|
||||||
goto out2;
|
goto out2;
|
||||||
@ -1902,6 +1930,7 @@ static int img_convert(int argc, char **argv)
|
|||||||
bool writethrough, src_writethrough, quiet = false, image_opts = false,
|
bool writethrough, src_writethrough, quiet = false, image_opts = false,
|
||||||
skip_create = false, progress = false;
|
skip_create = false, progress = false;
|
||||||
int64_t ret = -EINVAL;
|
int64_t ret = -EINVAL;
|
||||||
|
bool force_share = false;
|
||||||
|
|
||||||
ImgConvertState s = (ImgConvertState) {
|
ImgConvertState s = (ImgConvertState) {
|
||||||
/* Need at least 4k of zeros for sparse detection */
|
/* Need at least 4k of zeros for sparse detection */
|
||||||
@ -1916,9 +1945,10 @@ static int img_convert(int argc, char **argv)
|
|||||||
{"help", no_argument, 0, 'h'},
|
{"help", no_argument, 0, 'h'},
|
||||||
{"object", required_argument, 0, OPTION_OBJECT},
|
{"object", required_argument, 0, OPTION_OBJECT},
|
||||||
{"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
|
{"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
|
||||||
|
{"force-share", no_argument, 0, 'U'},
|
||||||
{0, 0, 0, 0}
|
{0, 0, 0, 0}
|
||||||
};
|
};
|
||||||
c = getopt_long(argc, argv, ":hf:O:B:ce6o:s:l:S:pt:T:qnm:W",
|
c = getopt_long(argc, argv, ":hf:O:B:ce6o:s:l:S:pt:T:qnm:WU",
|
||||||
long_options, NULL);
|
long_options, NULL);
|
||||||
if (c == -1) {
|
if (c == -1) {
|
||||||
break;
|
break;
|
||||||
@ -2021,6 +2051,9 @@ static int img_convert(int argc, char **argv)
|
|||||||
case 'W':
|
case 'W':
|
||||||
s.wr_in_order = false;
|
s.wr_in_order = false;
|
||||||
break;
|
break;
|
||||||
|
case 'U':
|
||||||
|
force_share = true;
|
||||||
|
break;
|
||||||
case OPTION_OBJECT: {
|
case OPTION_OBJECT: {
|
||||||
QemuOpts *object_opts;
|
QemuOpts *object_opts;
|
||||||
object_opts = qemu_opts_parse_noisily(&qemu_object_opts,
|
object_opts = qemu_opts_parse_noisily(&qemu_object_opts,
|
||||||
@ -2080,7 +2113,8 @@ static int img_convert(int argc, char **argv)
|
|||||||
|
|
||||||
for (bs_i = 0; bs_i < s.src_num; bs_i++) {
|
for (bs_i = 0; bs_i < s.src_num; bs_i++) {
|
||||||
s.src[bs_i] = img_open(image_opts, argv[optind + bs_i],
|
s.src[bs_i] = img_open(image_opts, argv[optind + bs_i],
|
||||||
fmt, src_flags, src_writethrough, quiet);
|
fmt, src_flags, src_writethrough, quiet,
|
||||||
|
force_share);
|
||||||
if (!s.src[bs_i]) {
|
if (!s.src[bs_i]) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto out;
|
goto out;
|
||||||
@ -2233,7 +2267,8 @@ static int img_convert(int argc, char **argv)
|
|||||||
* the bdrv_create() call which takes different params.
|
* the bdrv_create() call which takes different params.
|
||||||
* Not critical right now, so fix can wait...
|
* Not critical right now, so fix can wait...
|
||||||
*/
|
*/
|
||||||
s.target = img_open_file(out_filename, out_fmt, flags, writethrough, quiet);
|
s.target = img_open_file(out_filename, out_fmt, flags, writethrough, quiet,
|
||||||
|
false);
|
||||||
if (!s.target) {
|
if (!s.target) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto out;
|
goto out;
|
||||||
@ -2384,7 +2419,7 @@ static gboolean str_equal_func(gconstpointer a, gconstpointer b)
|
|||||||
static ImageInfoList *collect_image_info_list(bool image_opts,
|
static ImageInfoList *collect_image_info_list(bool image_opts,
|
||||||
const char *filename,
|
const char *filename,
|
||||||
const char *fmt,
|
const char *fmt,
|
||||||
bool chain)
|
bool chain, bool force_share)
|
||||||
{
|
{
|
||||||
ImageInfoList *head = NULL;
|
ImageInfoList *head = NULL;
|
||||||
ImageInfoList **last = &head;
|
ImageInfoList **last = &head;
|
||||||
@ -2407,7 +2442,8 @@ static ImageInfoList *collect_image_info_list(bool image_opts,
|
|||||||
g_hash_table_insert(filenames, (gpointer)filename, NULL);
|
g_hash_table_insert(filenames, (gpointer)filename, NULL);
|
||||||
|
|
||||||
blk = img_open(image_opts, filename, fmt,
|
blk = img_open(image_opts, filename, fmt,
|
||||||
BDRV_O_NO_BACKING | BDRV_O_NO_IO, false, false);
|
BDRV_O_NO_BACKING | BDRV_O_NO_IO, false, false,
|
||||||
|
force_share);
|
||||||
if (!blk) {
|
if (!blk) {
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
@ -2459,6 +2495,7 @@ static int img_info(int argc, char **argv)
|
|||||||
const char *filename, *fmt, *output;
|
const char *filename, *fmt, *output;
|
||||||
ImageInfoList *list;
|
ImageInfoList *list;
|
||||||
bool image_opts = false;
|
bool image_opts = false;
|
||||||
|
bool force_share = false;
|
||||||
|
|
||||||
fmt = NULL;
|
fmt = NULL;
|
||||||
output = NULL;
|
output = NULL;
|
||||||
@ -2471,9 +2508,10 @@ static int img_info(int argc, char **argv)
|
|||||||
{"backing-chain", no_argument, 0, OPTION_BACKING_CHAIN},
|
{"backing-chain", no_argument, 0, OPTION_BACKING_CHAIN},
|
||||||
{"object", required_argument, 0, OPTION_OBJECT},
|
{"object", required_argument, 0, OPTION_OBJECT},
|
||||||
{"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
|
{"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
|
||||||
|
{"force-share", no_argument, 0, 'U'},
|
||||||
{0, 0, 0, 0}
|
{0, 0, 0, 0}
|
||||||
};
|
};
|
||||||
c = getopt_long(argc, argv, ":f:h",
|
c = getopt_long(argc, argv, ":f:hU",
|
||||||
long_options, &option_index);
|
long_options, &option_index);
|
||||||
if (c == -1) {
|
if (c == -1) {
|
||||||
break;
|
break;
|
||||||
@ -2491,6 +2529,9 @@ static int img_info(int argc, char **argv)
|
|||||||
case 'f':
|
case 'f':
|
||||||
fmt = optarg;
|
fmt = optarg;
|
||||||
break;
|
break;
|
||||||
|
case 'U':
|
||||||
|
force_share = true;
|
||||||
|
break;
|
||||||
case OPTION_OUTPUT:
|
case OPTION_OUTPUT:
|
||||||
output = optarg;
|
output = optarg;
|
||||||
break;
|
break;
|
||||||
@ -2530,7 +2571,8 @@ static int img_info(int argc, char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
list = collect_image_info_list(image_opts, filename, fmt, chain);
|
list = collect_image_info_list(image_opts, filename, fmt, chain,
|
||||||
|
force_share);
|
||||||
if (!list) {
|
if (!list) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -2676,6 +2718,7 @@ static int img_map(int argc, char **argv)
|
|||||||
MapEntry curr = { .length = 0 }, next;
|
MapEntry curr = { .length = 0 }, next;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
bool image_opts = false;
|
bool image_opts = false;
|
||||||
|
bool force_share = false;
|
||||||
|
|
||||||
fmt = NULL;
|
fmt = NULL;
|
||||||
output = NULL;
|
output = NULL;
|
||||||
@ -2687,9 +2730,10 @@ static int img_map(int argc, char **argv)
|
|||||||
{"output", required_argument, 0, OPTION_OUTPUT},
|
{"output", required_argument, 0, OPTION_OUTPUT},
|
||||||
{"object", required_argument, 0, OPTION_OBJECT},
|
{"object", required_argument, 0, OPTION_OBJECT},
|
||||||
{"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
|
{"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
|
||||||
|
{"force-share", no_argument, 0, 'U'},
|
||||||
{0, 0, 0, 0}
|
{0, 0, 0, 0}
|
||||||
};
|
};
|
||||||
c = getopt_long(argc, argv, ":f:h",
|
c = getopt_long(argc, argv, ":f:hU",
|
||||||
long_options, &option_index);
|
long_options, &option_index);
|
||||||
if (c == -1) {
|
if (c == -1) {
|
||||||
break;
|
break;
|
||||||
@ -2707,6 +2751,9 @@ static int img_map(int argc, char **argv)
|
|||||||
case 'f':
|
case 'f':
|
||||||
fmt = optarg;
|
fmt = optarg;
|
||||||
break;
|
break;
|
||||||
|
case 'U':
|
||||||
|
force_share = true;
|
||||||
|
break;
|
||||||
case OPTION_OUTPUT:
|
case OPTION_OUTPUT:
|
||||||
output = optarg;
|
output = optarg;
|
||||||
break;
|
break;
|
||||||
@ -2743,7 +2790,7 @@ static int img_map(int argc, char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
blk = img_open(image_opts, filename, fmt, 0, false, false);
|
blk = img_open(image_opts, filename, fmt, 0, false, false, force_share);
|
||||||
if (!blk) {
|
if (!blk) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -2806,6 +2853,7 @@ static int img_snapshot(int argc, char **argv)
|
|||||||
bool quiet = false;
|
bool quiet = false;
|
||||||
Error *err = NULL;
|
Error *err = NULL;
|
||||||
bool image_opts = false;
|
bool image_opts = false;
|
||||||
|
bool force_share = false;
|
||||||
|
|
||||||
bdrv_oflags = BDRV_O_RDWR;
|
bdrv_oflags = BDRV_O_RDWR;
|
||||||
/* Parse commandline parameters */
|
/* Parse commandline parameters */
|
||||||
@ -2814,9 +2862,10 @@ static int img_snapshot(int argc, char **argv)
|
|||||||
{"help", no_argument, 0, 'h'},
|
{"help", no_argument, 0, 'h'},
|
||||||
{"object", required_argument, 0, OPTION_OBJECT},
|
{"object", required_argument, 0, OPTION_OBJECT},
|
||||||
{"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
|
{"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
|
||||||
|
{"force-share", no_argument, 0, 'U'},
|
||||||
{0, 0, 0, 0}
|
{0, 0, 0, 0}
|
||||||
};
|
};
|
||||||
c = getopt_long(argc, argv, ":la:c:d:hq",
|
c = getopt_long(argc, argv, ":la:c:d:hqU",
|
||||||
long_options, NULL);
|
long_options, NULL);
|
||||||
if (c == -1) {
|
if (c == -1) {
|
||||||
break;
|
break;
|
||||||
@ -2866,6 +2915,9 @@ static int img_snapshot(int argc, char **argv)
|
|||||||
case 'q':
|
case 'q':
|
||||||
quiet = true;
|
quiet = true;
|
||||||
break;
|
break;
|
||||||
|
case 'U':
|
||||||
|
force_share = true;
|
||||||
|
break;
|
||||||
case OPTION_OBJECT: {
|
case OPTION_OBJECT: {
|
||||||
QemuOpts *opts;
|
QemuOpts *opts;
|
||||||
opts = qemu_opts_parse_noisily(&qemu_object_opts,
|
opts = qemu_opts_parse_noisily(&qemu_object_opts,
|
||||||
@ -2892,7 +2944,8 @@ static int img_snapshot(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Open the image */
|
/* Open the image */
|
||||||
blk = img_open(image_opts, filename, NULL, bdrv_oflags, false, quiet);
|
blk = img_open(image_opts, filename, NULL, bdrv_oflags, false, quiet,
|
||||||
|
force_share);
|
||||||
if (!blk) {
|
if (!blk) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -2956,6 +3009,7 @@ static int img_rebase(int argc, char **argv)
|
|||||||
int c, flags, src_flags, ret;
|
int c, flags, src_flags, ret;
|
||||||
bool writethrough, src_writethrough;
|
bool writethrough, src_writethrough;
|
||||||
int unsafe = 0;
|
int unsafe = 0;
|
||||||
|
bool force_share = false;
|
||||||
int progress = 0;
|
int progress = 0;
|
||||||
bool quiet = false;
|
bool quiet = false;
|
||||||
Error *local_err = NULL;
|
Error *local_err = NULL;
|
||||||
@ -2972,9 +3026,10 @@ static int img_rebase(int argc, char **argv)
|
|||||||
{"help", no_argument, 0, 'h'},
|
{"help", no_argument, 0, 'h'},
|
||||||
{"object", required_argument, 0, OPTION_OBJECT},
|
{"object", required_argument, 0, OPTION_OBJECT},
|
||||||
{"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
|
{"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
|
||||||
|
{"force-share", no_argument, 0, 'U'},
|
||||||
{0, 0, 0, 0}
|
{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:qU",
|
||||||
long_options, NULL);
|
long_options, NULL);
|
||||||
if (c == -1) {
|
if (c == -1) {
|
||||||
break;
|
break;
|
||||||
@ -3024,6 +3079,9 @@ static int img_rebase(int argc, char **argv)
|
|||||||
case OPTION_IMAGE_OPTS:
|
case OPTION_IMAGE_OPTS:
|
||||||
image_opts = true;
|
image_opts = true;
|
||||||
break;
|
break;
|
||||||
|
case 'U':
|
||||||
|
force_share = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3072,7 +3130,8 @@ static int img_rebase(int argc, char **argv)
|
|||||||
* Ignore the old backing file for unsafe rebase in case we want to correct
|
* Ignore the old backing file for unsafe rebase in case we want to correct
|
||||||
* the reference to a renamed or moved backing file.
|
* the reference to a renamed or moved backing file.
|
||||||
*/
|
*/
|
||||||
blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet);
|
blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet,
|
||||||
|
false);
|
||||||
if (!blk) {
|
if (!blk) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto out;
|
goto out;
|
||||||
@ -3097,6 +3156,13 @@ static int img_rebase(int argc, char **argv)
|
|||||||
qdict_put_str(options, "driver", bs->backing_format);
|
qdict_put_str(options, "driver", bs->backing_format);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (force_share) {
|
||||||
|
if (!options) {
|
||||||
|
options = qdict_new();
|
||||||
|
}
|
||||||
|
qdict_put(options, BDRV_OPT_FORCE_SHARE,
|
||||||
|
qbool_from_bool(true));
|
||||||
|
}
|
||||||
bdrv_get_backing_filename(bs, backing_name, sizeof(backing_name));
|
bdrv_get_backing_filename(bs, backing_name, sizeof(backing_name));
|
||||||
blk_old_backing = blk_new_open(backing_name, NULL,
|
blk_old_backing = blk_new_open(backing_name, NULL,
|
||||||
options, src_flags, &local_err);
|
options, src_flags, &local_err);
|
||||||
@ -3109,11 +3175,12 @@ static int img_rebase(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (out_baseimg[0]) {
|
if (out_baseimg[0]) {
|
||||||
if (out_basefmt) {
|
|
||||||
options = qdict_new();
|
options = qdict_new();
|
||||||
|
if (out_basefmt) {
|
||||||
qdict_put_str(options, "driver", out_basefmt);
|
qdict_put_str(options, "driver", out_basefmt);
|
||||||
} else {
|
}
|
||||||
options = NULL;
|
if (force_share) {
|
||||||
|
qdict_put_bool(options, BDRV_OPT_FORCE_SHARE, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
blk_new_backing = blk_new_open(out_baseimg, NULL,
|
blk_new_backing = blk_new_open(out_baseimg, NULL,
|
||||||
@ -3419,7 +3486,8 @@ static int img_resize(int argc, char **argv)
|
|||||||
qemu_opts_del(param);
|
qemu_opts_del(param);
|
||||||
|
|
||||||
blk = img_open(image_opts, filename, fmt,
|
blk = img_open(image_opts, filename, fmt,
|
||||||
BDRV_O_RDWR | BDRV_O_RESIZE, false, quiet);
|
BDRV_O_RDWR | BDRV_O_RESIZE, false, quiet,
|
||||||
|
false);
|
||||||
if (!blk) {
|
if (!blk) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto out;
|
goto out;
|
||||||
@ -3573,7 +3641,8 @@ static int img_amend(int argc, char **argv)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet);
|
blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet,
|
||||||
|
false);
|
||||||
if (!blk) {
|
if (!blk) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto out;
|
goto out;
|
||||||
@ -3741,6 +3810,7 @@ static int img_bench(int argc, char **argv)
|
|||||||
bool writethrough = false;
|
bool writethrough = false;
|
||||||
struct timeval t1, t2;
|
struct timeval t1, t2;
|
||||||
int i;
|
int i;
|
||||||
|
bool force_share = false;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
static const struct option long_options[] = {
|
static const struct option long_options[] = {
|
||||||
@ -3749,9 +3819,10 @@ static int img_bench(int argc, char **argv)
|
|||||||
{"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
|
{"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
|
||||||
{"pattern", required_argument, 0, OPTION_PATTERN},
|
{"pattern", required_argument, 0, OPTION_PATTERN},
|
||||||
{"no-drain", no_argument, 0, OPTION_NO_DRAIN},
|
{"no-drain", no_argument, 0, OPTION_NO_DRAIN},
|
||||||
|
{"force-share", no_argument, 0, 'U'},
|
||||||
{0, 0, 0, 0}
|
{0, 0, 0, 0}
|
||||||
};
|
};
|
||||||
c = getopt_long(argc, argv, ":hc:d:f:no:qs:S:t:w", long_options, NULL);
|
c = getopt_long(argc, argv, ":hc:d:f:no:qs:S:t:wU", long_options, NULL);
|
||||||
if (c == -1) {
|
if (c == -1) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -3845,6 +3916,9 @@ static int img_bench(int argc, char **argv)
|
|||||||
flags |= BDRV_O_RDWR;
|
flags |= BDRV_O_RDWR;
|
||||||
is_write = true;
|
is_write = true;
|
||||||
break;
|
break;
|
||||||
|
case 'U':
|
||||||
|
force_share = true;
|
||||||
|
break;
|
||||||
case OPTION_PATTERN:
|
case OPTION_PATTERN:
|
||||||
{
|
{
|
||||||
unsigned long res;
|
unsigned long res;
|
||||||
@ -3892,7 +3966,8 @@ static int img_bench(int argc, char **argv)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet);
|
blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet,
|
||||||
|
force_share);
|
||||||
if (!blk) {
|
if (!blk) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto out;
|
goto out;
|
||||||
@ -4059,6 +4134,7 @@ static int img_dd(int argc, char **argv)
|
|||||||
const char *fmt = NULL;
|
const char *fmt = NULL;
|
||||||
int64_t size = 0;
|
int64_t size = 0;
|
||||||
int64_t block_count = 0, out_pos, in_pos;
|
int64_t block_count = 0, out_pos, in_pos;
|
||||||
|
bool force_share = false;
|
||||||
struct DdInfo dd = {
|
struct DdInfo dd = {
|
||||||
.flags = 0,
|
.flags = 0,
|
||||||
.count = 0,
|
.count = 0,
|
||||||
@ -4087,10 +4163,11 @@ static int img_dd(int argc, char **argv)
|
|||||||
const struct option long_options[] = {
|
const struct option long_options[] = {
|
||||||
{ "help", no_argument, 0, 'h'},
|
{ "help", no_argument, 0, 'h'},
|
||||||
{ "image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
|
{ "image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
|
||||||
|
{ "force-share", no_argument, 0, 'U'},
|
||||||
{ 0, 0, 0, 0 }
|
{ 0, 0, 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
while ((c = getopt_long(argc, argv, ":hf:O:", long_options, NULL))) {
|
while ((c = getopt_long(argc, argv, ":hf:O:U", long_options, NULL))) {
|
||||||
if (c == EOF) {
|
if (c == EOF) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -4110,6 +4187,9 @@ static int img_dd(int argc, char **argv)
|
|||||||
case 'h':
|
case 'h':
|
||||||
help();
|
help();
|
||||||
break;
|
break;
|
||||||
|
case 'U':
|
||||||
|
force_share = true;
|
||||||
|
break;
|
||||||
case OPTION_IMAGE_OPTS:
|
case OPTION_IMAGE_OPTS:
|
||||||
image_opts = true;
|
image_opts = true;
|
||||||
break;
|
break;
|
||||||
@ -4154,7 +4234,8 @@ static int img_dd(int argc, char **argv)
|
|||||||
ret = -1;
|
ret = -1;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
blk1 = img_open(image_opts, in.filename, fmt, 0, false, false);
|
blk1 = img_open(image_opts, in.filename, fmt, 0, false, false,
|
||||||
|
force_share);
|
||||||
|
|
||||||
if (!blk1) {
|
if (!blk1) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
@ -4222,7 +4303,7 @@ static int img_dd(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
blk2 = img_open(image_opts, out.filename, out_fmt, BDRV_O_RDWR,
|
blk2 = img_open(image_opts, out.filename, out_fmt, BDRV_O_RDWR,
|
||||||
false, false);
|
false, false, false);
|
||||||
|
|
||||||
if (!blk2) {
|
if (!blk2) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
|
Loading…
Reference in New Issue
Block a user