Skip to content

Commit 1899bf4

Browse files
ebblakeXanClic
authored andcommitted
qemu-img: Add -F shorthand to convert
Although we have long supported 'qemu-img convert -o backing_file=foo,backing_fmt=bar', the fact that we have a shortcut -B for backing_file but none for backing_fmt has made it more likely that users accidentally run into: qemu-img: warning: Deprecated use of backing file without explicit backing format when using -B instead of -o. For similarity with other qemu-img commands, such as create and compare, add '-F $fmt' as the shorthand for '-o backing_fmt=$fmt'. Update iotest 122 for coverage of both spellings. Signed-off-by: Eric Blake <[email protected]> Message-Id: <[email protected]> Reviewed-by: Vladimir Sementsov-Ogievskiy <[email protected]> Reviewed-by: Maxim Levitsky <[email protected]> Signed-off-by: Hanna Reitz <[email protected]>
1 parent 8fba395 commit 1899bf4

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

docs/tools/qemu-img.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ Command description:
415415
4
416416
Error on reading data
417417

418-
.. option:: convert [--object OBJECTDEF] [--image-opts] [--target-image-opts] [--target-is-zero] [--bitmaps [--skip-broken-bitmaps]] [-U] [-C] [-c] [-p] [-q] [-n] [-f FMT] [-t CACHE] [-T SRC_CACHE] [-O OUTPUT_FMT] [-B BACKING_FILE] [-o OPTIONS] [-l SNAPSHOT_PARAM] [-S SPARSE_SIZE] [-r RATE_LIMIT] [-m NUM_COROUTINES] [-W] FILENAME [FILENAME2 [...]] OUTPUT_FILENAME
418+
.. option:: convert [--object OBJECTDEF] [--image-opts] [--target-image-opts] [--target-is-zero] [--bitmaps [--skip-broken-bitmaps]] [-U] [-C] [-c] [-p] [-q] [-n] [-f FMT] [-t CACHE] [-T SRC_CACHE] [-O OUTPUT_FMT] [-B BACKING_FILE [-F backing_fmt]] [-o OPTIONS] [-l SNAPSHOT_PARAM] [-S SPARSE_SIZE] [-r RATE_LIMIT] [-m NUM_COROUTINES] [-W] FILENAME [FILENAME2 [...]] OUTPUT_FILENAME
419419

420420
Convert the disk image *FILENAME* or a snapshot *SNAPSHOT_PARAM*
421421
to disk image *OUTPUT_FILENAME* using format *OUTPUT_FMT*. It can
@@ -439,7 +439,7 @@ Command description:
439439
You can use the *BACKING_FILE* option to force the output image to be
440440
created as a copy on write image of the specified base image; the
441441
*BACKING_FILE* should have the same content as the input's base image,
442-
however the path, image format, etc may differ.
442+
however the path, image format (as given by *BACKING_FMT*), etc may differ.
443443

444444
If a relative path name is given, the backing file is looked up relative to
445445
the directory containing *OUTPUT_FILENAME*.

qemu-img-cmds.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ SRST
4646
ERST
4747

4848
DEF("convert", img_convert,
49-
"convert [--object objectdef] [--image-opts] [--target-image-opts] [--target-is-zero] [--bitmaps] [-U] [-C] [-c] [-p] [-q] [-n] [-f fmt] [-t cache] [-T src_cache] [-O output_fmt] [-B backing_file] [-o options] [-l snapshot_param] [-S sparse_size] [-r rate_limit] [-m num_coroutines] [-W] [--salvage] filename [filename2 [...]] output_filename")
49+
"convert [--object objectdef] [--image-opts] [--target-image-opts] [--target-is-zero] [--bitmaps] [-U] [-C] [-c] [-p] [-q] [-n] [-f fmt] [-t cache] [-T src_cache] [-O output_fmt] [-B backing_file [-F backing_fmt]] [-o options] [-l snapshot_param] [-S sparse_size] [-r rate_limit] [-m num_coroutines] [-W] [--salvage] filename [filename2 [...]] output_filename")
5050
SRST
5151
.. option:: convert [--object OBJECTDEF] [--image-opts] [--target-image-opts] [--target-is-zero] [--bitmaps] [-U] [-C] [-c] [-p] [-q] [-n] [-f FMT] [-t CACHE] [-T SRC_CACHE] [-O OUTPUT_FMT] [-B BACKING_FILE] [-o OPTIONS] [-l SNAPSHOT_PARAM] [-S SPARSE_SIZE] [-r RATE_LIMIT] [-m NUM_COROUTINES] [-W] [--salvage] FILENAME [FILENAME2 [...]] OUTPUT_FILENAME
5252
ERST

qemu-img.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2183,7 +2183,8 @@ static int img_convert(int argc, char **argv)
21832183
int c, bs_i, flags, src_flags = BDRV_O_NO_SHARE;
21842184
const char *fmt = NULL, *out_fmt = NULL, *cache = "unsafe",
21852185
*src_cache = BDRV_DEFAULT_CACHE, *out_baseimg = NULL,
2186-
*out_filename, *out_baseimg_param, *snapshot_name = NULL;
2186+
*out_filename, *out_baseimg_param, *snapshot_name = NULL,
2187+
*backing_fmt = NULL;
21872188
BlockDriver *drv = NULL, *proto_drv = NULL;
21882189
BlockDriverInfo bdi;
21892190
BlockDriverState *out_bs;
@@ -2223,7 +2224,7 @@ static int img_convert(int argc, char **argv)
22232224
{"skip-broken-bitmaps", no_argument, 0, OPTION_SKIP_BROKEN},
22242225
{0, 0, 0, 0}
22252226
};
2226-
c = getopt_long(argc, argv, ":hf:O:B:Cco:l:S:pt:T:qnm:WUr:",
2227+
c = getopt_long(argc, argv, ":hf:O:B:CcF:o:l:S:pt:T:qnm:WUr:",
22272228
long_options, NULL);
22282229
if (c == -1) {
22292230
break;
@@ -2253,6 +2254,9 @@ static int img_convert(int argc, char **argv)
22532254
case 'c':
22542255
s.compressed = true;
22552256
break;
2257+
case 'F':
2258+
backing_fmt = optarg;
2259+
break;
22562260
case 'o':
22572261
if (accumulate_options(&options, optarg) < 0) {
22582262
goto fail_getopt;
@@ -2521,7 +2525,7 @@ static int img_convert(int argc, char **argv)
25212525

25222526
qemu_opt_set_number(opts, BLOCK_OPT_SIZE,
25232527
s.total_sectors * BDRV_SECTOR_SIZE, &error_abort);
2524-
ret = add_old_style_options(out_fmt, opts, out_baseimg, NULL);
2528+
ret = add_old_style_options(out_fmt, opts, out_baseimg, backing_fmt);
25252529
if (ret < 0) {
25262530
goto out;
25272531
}

tests/qemu-iotests/122

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ echo
6767
_make_test_img -b "$TEST_IMG".base -F $IMGFMT
6868

6969
$QEMU_IO -c "write -P 0 0 3M" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
70-
$QEMU_IMG convert -O $IMGFMT -B "$TEST_IMG".base -o backing_fmt=$IMGFMT \
70+
$QEMU_IMG convert -O $IMGFMT -B "$TEST_IMG".base -F $IMGFMT \
7171
"$TEST_IMG" "$TEST_IMG".orig
7272
$QEMU_IO -c "read -P 0 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
7373
$QEMU_IMG convert -O $IMGFMT -c -B "$TEST_IMG".base -o backing_fmt=$IMGFMT \

0 commit comments

Comments
 (0)