qemu-img: Add --target-is-zero to indicate that a target is blank
v3 cover qemu-img: Add --target-is-zero to indicate that a target is blank
qemu-img: Add --target-is-zero to indicate that a target is blank
v3:
- Merge with the rST docs.
- No more need to fix @var -> @code.
v2:
- Remove target_is_zero, preferring to set has_zero_init directly (Mark Kanda).
- Disallow --target-is-zero in the presence of a backing file (Max Reitz).
- Add relevant documentation (Max Reitz).
- @var -> @code for options in qemu-img.texi.
David Edmondson (1):
qemu-img: Add --target-is-zero to convert
docs/interop/qemu-img.rst | 8 +++++++- qemu-img-cmds.hx | 4 ++-- qemu-img.c | 25 ++++++++++++++++++++++--- 3 files changed, 31 insertions(+), 6 deletions(-)
Signature · 1 line
2.24.1
PATCH v3 1/1 qemu-img: Add --target-is-zero to convert
In many cases the target of a convert operation is a newly provisioned target that the user knows is blank (filled with zeroes). In this situation there is no requirement for qemu-img to wastefully zero out the entire device.
Add a new option, --target-is-zero, allowing the user to indicate that an existing target device is already zero filled.
--- docs/interop/qemu-img.rst | 8 +++++++- qemu-img-cmds.hx | 4 ++-- qemu-img.c | 25 ++++++++++++++++++++++--- 3 files changed, 31 insertions(+), 6 deletions(-)
docs/interop/qemu-img.rst +7 -1
@@ -214,6 +214,12 @@ Parameters to convert subcommand: will still be printed. Areas that cannot be read from the source will be treated as containing only zeroes. +.. option:: --target-is-zero + + Assume that the destination is filled with zeros. This parameter is + mutually exclusive with the use of a backing file. It is required to + also use the ``-n`` parameter to skip image creation. + Parameters to dd subcommand: .. program:: qemu-img-dd
@@ -366,7 +372,7 @@ Command description: 4 Error on reading data -.. option:: convert [--object OBJECTDEF] [--image-opts] [--target-image-opts] [-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] [-m NUM_COROUTINES] [-W] FILENAME [FILENAME2 [...]] OUTPUT_FILENAME +.. option:: convert [--object OBJECTDEF] [--image-opts] [--target-image-opts] [--target-is-zero] [-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] [-m NUM_COROUTINES] [-W] FILENAME [FILENAME2 [...]] OUTPUT_FILENAME Convert the disk image *FILENAME* or a snapshot *SNAPSHOT_PARAM* to disk image *OUTPUT_FILENAME* using format *OUTPUT_FMT*. It can
qemu-img-cmds.hx +2 -2
@@ -39,9 +39,9 @@ SRST ERST DEF("convert", img_convert, - "convert [--object objectdef] [--image-opts] [--target-image-opts] [-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] [-m num_coroutines] [-W] [--salvage] filename [filename2 [...]] output_filename") + "convert [--object objectdef] [--image-opts] [--target-image-opts] [--target-is-zero] [-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] [-m num_coroutines] [-W] [--salvage] filename [filename2 [...]] output_filename") SRST -.. option:: convert [--object OBJECTDEF] [--image-opts] [--target-image-opts] [-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] [-m NUM_COROUTINES] [-W] [--salvage] FILENAME [FILENAME2 [...]] OUTPUT_FILENAME +.. option:: convert [--object OBJECTDEF] [--image-opts] [--target-image-opts] [--target-is-zero] [-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] [-m NUM_COROUTINES] [-W] [--salvage] FILENAME [FILENAME2 [...]] OUTPUT_FILENAME ERST DEF("create", img_create,
qemu-img.c +22 -3
@@ -70,6 +70,7 @@ enum {OPTION_PREALLOCATION =265 ,OPTION_SHRINK =266 ,OPTION_SALVAGE =267 , + OPTION_TARGET_IS_ZERO = 268, }; typedef enum OutputFormat {
@@ -1984,10 +1985,9 @@ static int convert_do_copy(ImgConvertState *s)int64_t sector_num =0 ;/* Check whether we have zero initialisation or can get it efficiently */ -if (s->target_is_new && s->min_sparse && !s->target_has_backing) { +if (!s->has_zero_init && s->target_is_new && s->min_sparse && + !s->target_has_backing) { s->has_zero_init =bdrv_has_zero_init (blk_bs (s->target)); - }else { - s->has_zero_init = false; } if (!s->has_zero_init && !s->target_has_backing &&
@@ -2086,6 +2086,7 @@ static int img_convert(int argc, char **argv) {"force-share", no_argument, 0, 'U'}, {"target-image-opts", no_argument, 0, OPTION_TARGET_IMAGE_OPTS}, {"salvage", no_argument, 0, OPTION_SALVAGE}, + {"target-is-zero", no_argument, 0, OPTION_TARGET_IS_ZERO}, {0, 0, 0, 0} }; c = getopt_long(argc, argv, ":hf:O:B:Cco:l:S:pt:T:qnm:WU",
@@ -2209,6 +2210,14 @@ static int img_convert(int argc, char **argv)case OPTION_TARGET_IMAGE_OPTS : tgt_image_opts = true;break ; +case OPTION_TARGET_IS_ZERO : +/* +* The user asserting that the target is blank has the +* same effect as the target driver supporting zero +* initialisation. +*/ + s.has_zero_init = true; +break ; } }
@@ -2247,6 +2256,11 @@ static int img_convert(int argc, char **argv)warn_report ("This will become an error in future QEMU versions." ); } +if (s.has_zero_init && !skip_create) { +error_report ("--target-is-zero requires use of -n flag" ); + goto fail_getopt; + } + s.src_num = argc - optind -1 ; out_filename = s.src_num >=1 ? argv[argc -1 ] :NULL ;
@@ -2380,6 +2394,11 @@ static int img_convert(int argc, char **argv) } s.target_has_backing = (bool ) out_baseimg; +if (s.has_zero_init && s.target_has_backing) { +error_report ("Cannot use --target-is-zero with a backing file" ); + goto out; + } +if (s.src_num >1 && out_baseimg) {error_report ("Having a backing file for the target makes no sense when " "concatenating multiple input images" );
Signature · 1 line
2.24.1
Re: [PATCH v3 1/1] qemu-img: Add --target-is-zero to convert
Quoted 2 lines · David Edmondson
In many cases the target of a convert operation is a newly provisioned target that the user knows is blank (filled with zeroes). In this
'filled with zeroes' is accurate for a preallocated image, but reads awkwardly for a sparse image; it might be better to state 'reads as zero'.
Quoted 18 lines
situation there is no requirement for qemu-img to wastefully zero out the entire device.
Add a new option, --target-is-zero, allowing the user to indicate that an existing target device is already zero filled.
Signed-off-by David Edmondson <[email protected]>--- docs/interop/qemu-img.rst | 8 +++++++- qemu-img-cmds.hx | 4 ++-- qemu-img.c | 25 ++++++++++++++++++++++--- 3 files changed, 31 insertions(+), 6 deletions(-)docs/interop/qemu-img.rst +0
-0
docs/interop/qemu-img.rst Parameters to convert subcommand: · line 219
Quoted 6 lines
docs/interop/qemu-img.rst +3
-0@@ -214,6 +214,12 @@ Parameters to convert subcommand: will still be printed. Areas that cannot be read from the source will be treated as containing only zeroes. +.. option:: --target-is-zero + + Assume that the destination is filled with zeros. This parameter is
Spelled 'zeroes' just three lines earlier.
docs/interop/qemu-img.rst Parameters to convert subcommand: · line 221
Quoted 2 lines
docs/interop/qemu-img.rst +2
-0+ mutually exclusive with the use of a backing file. It is required to + also use the ``-n`` parameter to skip image creation.
I understand that it is safer to have restrictions now and lift them later, than to allow use of the option at any time and leave room for the user to shoot themselves in the foot with no way to add safety later. The argument against no backing file is somewhat understandable (technically, as long as the backing file also reads as all zeroes, then the overall image reads as all zeroes - but why have a backing file that has no content?); the argument requiring -n is a bit weaker (if I'm creating an image, I _know_ it reads as all zeroes, so the --target-is-zero argument is redundant, but it shouldn't hurt to allow it).
docs/interop/qemu-img.rst static int img_convert(int argc, char **argv) · line 2262
Quoted 10 lines
docs/interop/qemu-img.rst +5
-0+++ b/qemu-img.c@@ -2247,6 +2256,11 @@ static int img_convert(int argc, char **argv) warn_report("This will become an error in future QEMU versions."); } + if (s.has_zero_init && !skip_create) { + error_report("--target-is-zero requires use of -n flag"); + goto fail_getopt; + }
So I think we could drop this hunk with no change in behavior.
docs/interop/qemu-img.rst static int img_convert(int argc, char **argv) · line 2401
Quoted 13 lines
docs/interop/qemu-img.rst +6
-0+ s.src_num = argc - optind - 1; out_filename = s.src_num >= 1 ? argv[argc - 1] : NULL;@@ -2380,6 +2394,11 @@ static int img_convert(int argc, char **argv) } s.target_has_backing = (bool) out_baseimg; + if (s.has_zero_init && s.target_has_backing) { + error_report("Cannot use --target-is-zero with a backing file"); + goto out; + } +
while keeping this one makes sense. At any rate, typo fixes are minor, and whether or not we drop the hunk I claim is a needless restriction against redundancy,
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Re: [PATCH v3 1/1] qemu-img: Add --target-is-zero to convert
Quoted 32 lines · Eric Blake
Quoted 2 lines · David Edmondson
In many cases the target of a convert operation is a newly provisioned target that the user knows is blank (filled with zeroes). In this
'filled with zeroes' is accurate for a preallocated image, but reads awkwardly for a sparse image; it might be better to state 'reads as zero'.
Quoted 18 lines
situation there is no requirement for qemu-img to wastefully zero out the entire device.
Add a new option, --target-is-zero, allowing the user to indicate that an existing target device is already zero filled.
Signed-off-by David Edmondson <[email protected]>---
docs/interop/qemu-img.rst| 8 +++++++- qemu-img-cmds.hx | 4 ++--
qemu-img.c | 25 ++++++++++++++++++++++---3 files changed, 31 insertions(+), 6 deletions(-)docs/interop/qemu-img.rst +0
-0@@ -214,6 +214,12 @@ Parameters to convert subcommand:Quoted 5 lines
will still be printed. Areas that cannot be read from the source will be treated as containing only zeroes.
+.. option:: --target-is-zero
+
+ Assume that the destination is filled with zeros. This parameter isSpelled 'zeroes' just three lines earlier.
Quoted 4 lines
Quoted 2 lines
+ mutually exclusive with the use of a backing file. It is required to + also use the ``-n`` parameter to skip image creation.
I understand that it is safer to have restrictions now and lift them later, than to allow use of the option at any time and leave room for the user to shoot themselves in the foot with no way to add safety later. The argument against no backing file is somewhat understandable (technically, as long as the backing file also reads as all zeroes, then the overall image reads as all zeroes - but why have a backing file that has no content?); the argument requiring -n is a bit weaker (if I'm creating an image, I _know_ it reads as all zeroes, so the --target-is-zero argument is redundant, but it shouldn't hurt to allow it).
I know that it reads as all zeroes, only if this format provides zero initialization..
Quoted 12 lines
docs/interop/qemu-img.rst static int img_convert(int argc, char **argv) · line 2261
Quoted 10 lines
+++
b/qemu-img.cdocs/interop/qemu-img.rst +4
-0@@ -2247,6 +2256,11 @@ static int img_convert(int argc, char **argv) warn_report("This will become an error in future QEMU versions."); } + if (s.has_zero_init && !skip_create) { + error_report("--target-is-zero requires use of -n flag"); + goto fail_getopt; + }So I think we could drop this hunk with no change in behavior.
I think, no we can't. If we allow target-is-zero, with -n, we'd better to check that what we are creating is zero-initialized (format has zero-init), and if not we should report error.
Quoted 17 lines
docs/interop/qemu-img.rst static int img_convert(int argc, char **argv) · line 2400
Quoted 12 lines
docs/interop/qemu-img.rst +6
-0+ s.src_num = argc - optind - 1; out_filename = s.src_num >= 1 ? argv[argc - 1] : NULL;@@ -2380,6 +2394,11 @@ static int img_convert(int argc, char **argv) } s.target_has_backing = (bool) out_baseimg; + if (s.has_zero_init && s.target_has_backing) { + error_report("Cannot use --target-is-zero with a backing file"); + goto out; + } +while keeping this one makes sense. At any rate, typo fixes are minor, and whether or not we drop the hunk I claim is a needless restriction against redundancy,
Reviewed-by Eric Blake <[email protected]>
Signature · 2 lines
Best regards, Vladimir
Re: [PATCH v3 1/1] qemu-img: Add --target-is-zero to convert
Quoted 17 lines · Vladimir Sementsov-Ogievskiy
Quoted 1 line
I understand that it is safer to have restrictions now and lift them later, than to allow use of the option at any time and leave room for the user to shoot themselves in the foot with no way to add safety later. The argument against no backing file is somewhat understandable (technically, as long as the backing file also reads as all zeroes, then the overall image reads as all zeroes - but why have a backing file that has no content?); the argument requiring -n is a bit weaker (if I'm creating an image, I _know_ it reads as all zeroes, so the --target-is-zero argument is redundant, but it shouldn't hurt to allow it).
I know that it reads as all zeroes, only if this format provides zero initialization..
Quoted 12 lines
qemu-img.c static int img_convert(int argc, char **argv) · line 2261
Quoted 10 lines
+++
b/qemu-img.cqemu-img.c +4
-0@@ -2247,6 +2256,11 @@ static int img_convert(int argc, char **argv) warn_report("This will become an error in future QEMU versions."); } + if (s.has_zero_init && !skip_create) { + error_report("--target-is-zero requires use of -n flag"); + goto fail_getopt; + }So I think we could drop this hunk with no change in behavior.
Quoted 2 lines
I think, no we can't. If we allow target-is-zero, with -n, we'd better to check that what we are creating is zero-initialized (format has zero-init), and if not we should report error.
Good call. Yes, if we allow --target-is-zero without -n, we MUST insist that bdrv_has_zero_init() returns 1 (or, after my followup series, bdrv_known_zeroes() includes BDRV_ZERO_CREATE). I can work that into v2 of my series, if desired.
Quoted 20 lines
Quoted 18 lines
qemu-img.c static int img_convert(int argc, char **argv) · line 2401
Quoted 13 lines
qemu-img.c +6
-0+ s.src_num = argc - optind - 1; out_filename = s.src_num >= 1 ? argv[argc - 1] : NULL;@@ -2380,6 +2394,11 @@ static int img_convert(int argc, char **argv) } s.target_has_backing = (bool) out_baseimg; + if (s.has_zero_init && s.target_has_backing) { + error_report("Cannot use --target-is-zero with a backing file"); + goto out; + } +while keeping this one makes sense. At any rate, typo fixes are minor, and whether or not we drop the hunk I claim is a needless restriction against redundancy,
Reviewed-by Eric Blake <[email protected]>
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Re: [PATCH v3 1/1] qemu-img: Add --target-is-zero to convert
Quoted 30 lines · Eric Blake
Quoted 28 lines · Vladimir Sementsov-Ogievskiy
Quoted 10 lines
I understand that it is safer to have restrictions now and lift them later, than to allow use of the option at any time and leave room for the user to shoot themselves in the foot with no way to add safety later. The argument against no backing file is somewhat understandable (technically, as long as the backing file also reads as all zeroes, then the overall image reads as all zeroes - but why have a backing file that has no content?); the argument requiring -n is a bit weaker (if I'm creating an image, I _know_ it reads as all zeroes, so the --target-is-zero argument is redundant, but it shouldn't hurt to allow it).
I know that it reads as all zeroes, only if this format provides zero initialization..
Quoted 13 lines
Quoted 11 lines
+++
b/qemu-img.c(quoted diff) +0
-0@@ -2247,6 +2256,11 @@ static int img_convert(int argc, char **argv)
warn_report("This will become an error in future QEMU versions.");
}
+ if (s.has_zero_init && !skip_create) {
+error_report("--target-is-zero requires use of -n flag"); + gotofail_getopt;
+ }So I think we could drop this hunk with no change in behavior.
Quoted 8 lines
Quoted 4 lines
I think, no we can't. If we allow target-is-zero, with -n, we'd better to check that what we are creating is zero-initialized (format has zero-init), and if not we should report error.
Good call. Yes, if we allow --target-is-zero without -n, we MUST insist that
bdrv_has_zero_init()returns 1 (or, after my followup series,bdrv_known_zeroes()includesBDRV_ZERO_CREATE).
Why?
I could imagine a user creating a qcow2 image on some block device with preallocation where we cannot verify that the result will be zero. But they want qemu not to zero the device, so they would specify --target-is-zero.
OTOH, we can always choose to allow that behavior at a later point.
Max
Re: [PATCH v3 1/1] qemu-img: Add --target-is-zero to convert
Quoted 40 lines · Max Reitz
Quoted 30 lines · Eric Blake
Quoted 28 lines · Vladimir Sementsov-Ogievskiy
Quoted 10 lines
I understand that it is safer to have restrictions now and lift them later, than to allow use of the option at any time and leave room for the user to shoot themselves in the foot with no way to add safety later. The argument against no backing file is somewhat understandable (technically, as long as the backing file also reads as all zeroes, then the overall image reads as all zeroes - but why have a backing file that has no content?); the argument requiring -n is a bit weaker (if I'm creating an image, I _know_ it reads as all zeroes, so the --target-is-zero argument is redundant, but it shouldn't hurt to allow it).
I know that it reads as all zeroes, only if this format provides zero initialization..
Quoted 13 lines
qemu-img.c static int img_convert(int argc, char **argv) · line 2262
Quoted 11 lines
+++
b/qemu-img.cqemu-img.c +4
-0@@ -2247,6 +2256,11 @@ static int img_convert(int argc, char **argv) warn_report("This will become an error in future QEMU versions."); } + if (s.has_zero_init && !skip_create) { + error_report("--target-is-zero requires use of -n flag"); + goto fail_getopt; + }So I think we could drop this hunk with no change in behavior.
Quoted 8 lines
Quoted 4 lines
I think, no we can't. If we allow target-is-zero, with -n, we'd better to check that what we are creating is zero-initialized (format has zero-init), and if not we should report error.
Good call. Yes, if we allow --target-is-zero without -n, we MUST insist that
bdrv_has_zero_init()returns 1 (or, after my followup series,bdrv_known_zeroes()includesBDRV_ZERO_CREATE).
Quoted 6 lines
Why?
I could imagine a user creating a qcow2 image on some block device with preallocation where we cannot verify that the result will be zero. But they want qemu not to zero the device, so they would specify --target-is-zero.
If user create image, setting --target-is-zero is always valid. But if we in same operation create the image automatically, having --target-is-zero, when we know that what we are creating is not zero is misleading and should fail..
If we want to add a behavior to skip zeros unconditionally, we should call new option --skip-zeroes, to clearly specify what we want.
Quoted 5 lines
OTOH, we can always choose to allow that behavior at a later point.
Max
Signature · 2 lines
Best regards, Vladimir
Re: [PATCH v3 1/1] qemu-img: Add --target-is-zero to convert
Quoted 48 lines · Vladimir Sementsov-Ogievskiy
Quoted 40 lines · Max Reitz
Quoted 30 lines · Eric Blake
Quoted 28 lines · Vladimir Sementsov-Ogievskiy
Quoted 10 lines
I understand that it is safer to have restrictions now and lift them later, than to allow use of the option at any time and leave room for the user to shoot themselves in the foot with no way to add safety later. The argument against no backing file is somewhat understandable (technically, as long as the backing file also reads as all zeroes, then the overall image reads as all zeroes - but why have a backing file that has no content?); the argument requiring -n is a bit weaker (if I'm creating an image, I _know_ it reads as all zeroes, so the --target-is-zero argument is redundant, but it shouldn't hurt to allow it).
I know that it reads as all zeroes, only if this format provides zero initialization..
Quoted 13 lines
Quoted 11 lines
+++
b/qemu-img.c(quoted diff) +0
-0@@ -2247,6 +2256,11 @@ static int img_convert(int argc, char **argv)
warn_report("This will become an error in future QEMU versions.");
}
+ if (s.has_zero_init && !skip_create) {
+error_report("--target-is-zero requires use of -n flag"); + gotofail_getopt;
+ }So I think we could drop this hunk with no change in behavior.
Quoted 8 lines
Quoted 4 lines
I think, no we can't. If we allow target-is-zero, with -n, we'd better to check that what we are creating is zero-initialized (format has zero-init), and if not we should report error.
Good call. Yes, if we allow --target-is-zero without -n, we MUST insist that
bdrv_has_zero_init()returns 1 (or, after my followup series,bdrv_known_zeroes()includesBDRV_ZERO_CREATE).Quoted 6 lines
Why?
I could imagine a user creating a qcow2 image on some block device with preallocation where we cannot verify that the result will be zero. But they want qemu not to zero the device, so they would specify --target-is-zero.
Quoted 6 lines
If user create image, setting --target-is-zero is always valid. But if we in
same operation create the image automatically, having --target-is-zero, when
we know that what we are creating is not zero is misleading and should fail..
bdrv_has_zero_init() doesn’t return false only for images that we know are not zero. It returns true for images where we know they are. But if we don’t know, then it returns false also.
Quoted 3 lines
If we want to add a behavior to skip zeros unconditionally, we should call new
option --skip-zeroes, to clearly specify what we want.
It was my impression that this was exactly what --target-is-zero means and implies.
Max
Re: [PATCH v3 1/1] qemu-img: Add --target-is-zero to convert
Quoted 56 lines · Max Reitz
Quoted 48 lines · Vladimir Sementsov-Ogievskiy
Quoted 40 lines · Max Reitz
Quoted 30 lines · Eric Blake
Quoted 28 lines · Vladimir Sementsov-Ogievskiy
Quoted 10 lines
I understand that it is safer to have restrictions now and lift them later, than to allow use of the option at any time and leave room for the user to shoot themselves in the foot with no way to add safety later. The argument against no backing file is somewhat understandable (technically, as long as the backing file also reads as all zeroes, then the overall image reads as all zeroes - but why have a backing file that has no content?); the argument requiring -n is a bit weaker (if I'm creating an image, I _know_ it reads as all zeroes, so the --target-is-zero argument is redundant, but it shouldn't hurt to allow it).
I know that it reads as all zeroes, only if this format provides zero initialization..
Quoted 13 lines
Review static int img_convert(int argc, char **argv) · line 2262
Quoted 11 lines
+++
b/qemu-img.c(quoted diff) +4
-0@@ -2247,6 +2256,11 @@ static int img_convert(int argc, char **argv) warn_report("This will become an error in future QEMU versions."); } + if (s.has_zero_init && !skip_create) { + error_report("--target-is-zero requires use of -n flag"); + goto fail_getopt; + }So I think we could drop this hunk with no change in behavior.
Quoted 8 lines
Quoted 4 lines
I think, no we can't. If we allow target-is-zero, with -n, we'd better to check that what we are creating is zero-initialized (format has zero-init), and if not we should report error.
Good call. Yes, if we allow --target-is-zero without -n, we MUST insist that
bdrv_has_zero_init()returns 1 (or, after my followup series,bdrv_known_zeroes()includesBDRV_ZERO_CREATE).Quoted 6 lines
Why?
I could imagine a user creating a qcow2 image on some block device with preallocation where we cannot verify that the result will be zero. But they want qemu not to zero the device, so they would specify --target-is-zero.
Quoted 6 lines
If user create image, setting --target-is-zero is always valid. But if we in
same operation create the image automatically, having --target-is-zero, when
we know that what we are creating is not zero is misleading and should fail..
Quoted 3 lines
bdrv_has_zero_init()doesn’t return false only for images that we know are not zero. It returns true for images where we know they are. But if we don’t know, then it returns false also.
yes, but we don't have better check.
Quoted 8 lines
Quoted 4 lines
If we want to add a behavior to skip zeros unconditionally, we should call new
option --skip-zeroes, to clearly specify what we want.It was my impression that this was exactly what --target-is-zero means and implies.
For me it sounds strange that user has better knowledge about what Qemu creates than Qemu itself. And if it so - it should be fixed in Qemu, rather than creating user interface to hint Qemu what it does.
Signature · 2 lines
Best regards, Vladimir
Re: [PATCH v3 1/1] qemu-img: Add --target-is-zero to convert
Quoted 61 lines · Vladimir Sementsov-Ogievskiy
Quoted 60 lines · Max Reitz
Quoted 58 lines · Vladimir Sementsov-Ogievskiy
Quoted 44 lines · Max Reitz
Quoted 38 lines · Eric Blake
Quoted 30 lines · Vladimir Sementsov-Ogievskiy
Quoted 11 lines
I understand that it is safer to have restrictions now and lift them later, than to allow use of the option at any time and leave room for
the user to shoot themselves in the foot with no way to add safety later. The argument against no backing file is somewhat understandable (technically, as long as the backing file also reads as all zeroes, then the overall image reads as all zeroes - but why have a backing file that has no content?); the argument requiring -n is a bit weaker (if I'm creating an image, I _know_ it reads as all zeroes, so the --target-is-zero argument is redundant, but it shouldn't hurt to allow it).I know that it reads as all zeroes, only if this format provides zero initialization..
Quoted 14 lines
Quoted 5 lines
+++
b/qemu-img.c(quoted diff) +0
-0@@ -2247,6 +2256,11 @@ static int img_convert(int argc, char **argv)Quoted 7 lines
warn_report("This will become an error in future QEMU versions.");
}
+ if (s.has_zero_init && !skip_create) {
+error_report("--target-is-zero requires use of -n flag"); + gotofail_getopt;
+ }So I think we could drop this hunk with no change in behavior.
Quoted 5 lines
I think, no we can't. If we allow target-is-zero, with -n, we'd better
to check that what we are creating is zero-initialized (format has zero-init), and if not we should report error.Quoted 4 lines
Good call. Yes, if we allow --target-is-zero without -n, we MUST insist
thatbdrv_has_zero_init()returns 1 (or, after my followup series,bdrv_known_zeroes()includesBDRV_ZERO_CREATE).Quoted 6 lines
Why?
I could imagine a user creating a qcow2 image on some block device with preallocation where we cannot verify that the result will be zero. But they want qemu not to zero the device, so they would specify --target-is-zero.
If user create image, setting --target-is-zero is always valid. But if we in
same operation create the image automatically, having --target-is-zero, when
we know that what we are creating is not zero is misleading and should fail..
Quoted 5 lines
Quoted 3 lines
bdrv_has_zero_init()doesn’t return false only for images that we know are not zero. It returns true for images where we know they are. But if we don’t know, then it returns false also.yes, but we don't have better check.
Correct, but maybe the user knows more, hence why it may make sense for them to provide us with some information we don’t have.
Quoted 11 lines
Quoted 7 lines
Quoted 3 lines
If we want to add a behavior to skip zeros unconditionally, we should call new
option --skip-zeroes, to clearly specify what we want.It was my impression that this was exactly what --target-is-zero means and implies.
For me it sounds strange that user has better knowledge about what Qemu creates than Qemu itself. And if it so - it should be fixed in Qemu, rather than creating user interface to hint Qemu what it does.
I brought an example where qemu cannot know whether the image is zero (preallocation on a block device), but the user / management layer might know.
Max
Re: [PATCH v3 1/1] qemu-img: Add --target-is-zero to convert
Quoted 79 lines · Max Reitz
Quoted 61 lines · Vladimir Sementsov-Ogievskiy
Quoted 60 lines · Max Reitz
Quoted 58 lines · Vladimir Sementsov-Ogievskiy
Quoted 44 lines · Max Reitz
Quoted 38 lines · Eric Blake
Quoted 30 lines · Vladimir Sementsov-Ogievskiy
Quoted 11 lines
I understand that it is safer to have restrictions now and lift them later, than to allow use of the option at any time and leave room for
the user to shoot themselves in the foot with no way to add safety later. The argument against no backing file is somewhat understandable (technically, as long as the backing file also reads as all zeroes, then the overall image reads as all zeroes - but why have a backing file that has no content?); the argument requiring -n is a bit weaker (if I'm creating an image, I _know_ it reads as all zeroes, so the --target-is-zero argument is redundant, but it shouldn't hurt to allow it).I know that it reads as all zeroes, only if this format provides zero initialization..
Quoted 14 lines
Review static int img_convert(int argc, char · line 2263
Quoted 12 lines
+++
b/qemu-img.c(quoted diff) +4
-0@@ -2247,6 +2256,11 @@ static int img_convert(int argc, char **argv) warn_report("This will become an error in future QEMU versions."); } + if (s.has_zero_init && !skip_create) { + error_report("--target-is-zero requires use of -n flag"); + goto fail_getopt; + }So I think we could drop this hunk with no change in behavior.
Quoted 5 lines
I think, no we can't. If we allow target-is-zero, with -n, we'd better
to check that what we are creating is zero-initialized (format has zero-init), and if not we should report error.Quoted 4 lines
Good call. Yes, if we allow --target-is-zero without -n, we MUST insist
thatbdrv_has_zero_init()returns 1 (or, after my followup series,bdrv_known_zeroes()includesBDRV_ZERO_CREATE).Quoted 6 lines
Why?
I could imagine a user creating a qcow2 image on some block device with preallocation where we cannot verify that the result will be zero. But they want qemu not to zero the device, so they would specify --target-is-zero.
If user create image, setting --target-is-zero is always valid. But if we in
same operation create the image automatically, having --target-is-zero, when
we know that what we are creating is not zero is misleading and should fail..Quoted 5 lines
Quoted 3 lines
bdrv_has_zero_init()doesn’t return false only for images that we know are not zero. It returns true for images where we know they are. But if we don’t know, then it returns false also.yes, but we don't have better check.
Correct, but maybe the user knows more, hence why it may make sense for them to provide us with some information we don’t have.
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
If we want to add a behavior to skip zeros unconditionally, we should call new
option --skip-zeroes, to clearly specify what we want.It was my impression that this was exactly what --target-is-zero means and implies.
Quoted 8 lines
Quoted 3 lines
For me it sounds strange that user has better knowledge about what Qemu creates than Qemu itself. And if it so - it should be fixed in Qemu, rather than creating user interface to hint Qemu what it does.
I brought an example where qemu cannot know whether the image is zero (preallocation on a block device), but the user / management layer might know.
It sounds unsafe for me. User can't know how exactly Qemu do preallocation, which syscalls it calls, etc. How can user be sure, that Qemu produces all-zero image, if even Qemu doesn't sure in it?
Otherwise, we should document, how exactly (up to syscalls, their parameters, flags, the whole logic and algorithm) preallocation is done, so user can analyze it and be sure that produced image would be all-zero (when Qemu can't determine it because some specific block device, for which Qemu doesn't know that its preallocation algorithm produces all-zero, but user is sure in it)...
Signature · 2 lines
Best regards, Vladimir
Re: [PATCH v3 1/1] qemu-img: Add --target-is-zero to convert
Quoted 95 lines · Vladimir Sementsov-Ogievskiy
Quoted 94 lines · Max Reitz
Quoted 72 lines · Vladimir Sementsov-Ogievskiy
Quoted 71 lines · Max Reitz
Quoted 69 lines · Vladimir Sementsov-Ogievskiy
Quoted 52 lines · Max Reitz
Quoted 46 lines · Eric Blake
Quoted 38 lines · Vladimir Sementsov-Ogievskiy
Quoted 8 lines
I understand that it is safer to have restrictions now and lift them
later, than to allow use of the option at any time and leave room for
the user to shoot themselves in the foot with no way to add safety later. The argument against no backing file is somewhat understandable (technically, as long as the backing file also readsQuoted 8 lines
as all zeroes, then the overall image reads as all zeroes - but why
have a backing file that has no content?); the argument requiring -n
is a bit weaker (if I'm creating an image, I _know_ it reads as all
zeroes, so the --target-is-zero argument is redundant, but it shouldn't hurt to allow it).I know that it reads as all zeroes, only if this format provides zero
initialization..Quoted 16 lines
Quoted 6 lines
+++
b/qemu-img.c(quoted diff) +0
-0@@ -2247,6 +2256,11 @@ static int img_convert(int argc, char **argv)warn_report("This will become an error in future
Quoted 8 lines
QEMU
versions.");
}
+ if (s.has_zero_init && !skip_create) {
+error_report("--target-is-zero requires use of -n flag");
+ gotofail_getopt;
+ }So I think we could drop this hunk with no change in behavior.
Quoted 5 lines
I think, no we can't. If we allow target-is-zero, with -n, we'd better
to check that what we are creating is zero-initialized (format has zero-init), and if not we should report error.Quoted 4 lines
Good call. Yes, if we allow --target-is-zero without -n, we MUST insist
thatbdrv_has_zero_init()returns 1 (or, after my followup series,bdrv_known_zeroes()includesBDRV_ZERO_CREATE).Quoted 8 lines
Why?
I could imagine a user creating a qcow2 image on some block device with
preallocation where we cannot verify that the result will be zero. But
they want qemu not to zero the device, so they would specify --target-is-zero.If user create image, setting --target-is-zero is always valid. But if we in
same operation create the image automatically, having --target-is-zero,
when
we know that what we are creating is not zero is misleading and should fail..Quoted 5 lines
Quoted 3 lines
bdrv_has_zero_init()doesn’t return false only for images that we know are not zero. It returns true for images where we know they are. But if we don’t know, then it returns false also.yes, but we don't have better check.
Correct, but maybe the user knows more, hence why it may make sense for them to provide us with some information we don’t have.
Quoted 11 lines
Quoted 7 lines
Quoted 3 lines
If we want to add a behavior to skip zeros unconditionally, we should call new
option --skip-zeroes, to clearly specify what we want.It was my impression that this was exactly what --target-is-zero means and implies.
For me it sounds strange that user has better knowledge about what Qemu creates than Qemu itself. And if it so - it should be fixed in Qemu, rather than creating user interface to hint Qemu what it does.
Quoted 8 lines
Quoted 4 lines
I brought an example where qemu cannot know whether the image is zero (preallocation on a block device), but the user / management layer might know.
It sounds unsafe for me. User can't know how exactly Qemu do preallocation, which syscalls it calls, etc. How can user be sure, that Qemu produces all-zero image, if even Qemu doesn't sure in it?
For example, qcow2 images are always zero if the underlying storage is zero.
Then again, it isn’t like we need --target-is-zero without -n anyway. If users want that, they can always use qemu-img create + qemu-img convert -n --target-is-zero. So seeing that you’re uncomfortable with the idea of --target-is-zero with -n, I can’t say there is any actual reason why we’d have to allow it.
Max
Quoted 6 lines
Otherwise, we should document, how exactly (up to syscalls, their parameters, flags, the whole logic and algorithm) preallocation is done, so user can analyze it and be sure that produced image would be all-zero (when Qemu can't determine it because some specific block device, for which Qemu doesn't know that its preallocation algorithm produces all-zero, but user is sure in it)..
Re: [PATCH v3 1/1] qemu-img: Add --target-is-zero to convert
In reply to Max ReitzQuoted 12 lines · Max Reitz
Quoted 11 lines
Quoted 4 lines
I could imagine a user creating a qcow2 image on some block device with preallocation where we cannot verify that the result will be zero. But they want qemu not to zero the device, so they would specify --target-is-zero.
If user create image, setting --target-is-zero is always valid. But if we in
same operation create the image automatically, having --target-is-zero, when
we know that what we are creating is not zero is misleading and should fail..
Quoted 3 lines
bdrv_has_zero_init()doesn’t return false only for images that we know are not zero. It returns true for images where we know they are. But if we don’t know, then it returns false also.
Huh?
bdrv_has_zero_init() currently returns 1 if a driver knows that creating an image results in that image reading as 0. That means it can return 1 even for non-zero images that were not just created. Thus, that interface has both false positives (returning 1 for a non-zero image if the driver hard-codes it to 1) and false negatives (returning 0 for an image that happens to read as zero). The false negatives are less important (if we don't know if the image is already zero, then zeroing it again is a waste of time but not semantically wrong) than the false positives (but as long as you don't rely on bdrv_has_zero_init() unless you also know the image was just created, you are safely avoiding the false positives).
And that's the whole point of my series to add a qcow2 persistent bit to track whether an image has known-zero contents: qemu-img should not be calling bdrv_has_zero_init(), since it is so finicky on what it means.
Quoted 7 lines
Quoted 4 lines
If we want to add a behavior to skip zeros unconditionally, we should call new
option --skip-zeroes, to clearly specify what we want.It was my impression that this was exactly what --target-is-zero means and implies.
--target-is-zero turns into the behavior of 'skip a pre-zeroing pass'. If the destination is already zero, then copying zeroes from the source is a waste of time. If the destination is not already zero, then zeroes from the source are not copied, and the destination will not be identical to the source. We then have a choice of whether --target-is-zero is merely a way to tell qemu something that it couldn't learn otherwise but still be as safe as possible (if we can quickly prove the target has non-zero data, the user lied about it being already zero, so fail the command, so add yet another option to bypass the safety check), or whether it really is synonymous with 'only copy the non-zero portions of the source, and if the destination was not all zero the copy is not faithful but I meant for it to be that way'.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Re: [PATCH v3 1/1] qemu-img: Add --target-is-zero to convert
Quoted 32 lines · Eric Blake
Quoted 12 lines · Max Reitz
Quoted 11 lines
Quoted 4 lines
I could imagine a user creating a qcow2 image on some block device with preallocation where we cannot verify that the result will be zero. But they want qemu not to zero the device, so they would specify --target-is-zero.
If user create image, setting --target-is-zero is always valid. But if we in
same operation create the image automatically, having --target-is-zero, when
we know that what we are creating is not zero is misleading and should fail..Quoted 3 lines
bdrv_has_zero_init()doesn’t return false only for images that we know are not zero. It returns true for images where we know they are. But if we don’t know, then it returns false also.Huh?
bdrv_has_zero_init()currently returns 1 if a driver knows that creating an image results in that image reading as 0. That means it can return 1 even for non-zero images that were not just created. Thus, that interface has both false positives (returning 1 for a non-zero image if the driver hard-codes it to 1) and false negatives (returning 0 for an image that happens to read as zero). The false negatives are less important (if we don't know if the image is already zero, then zeroing it again is a waste of time but not semantically wrong) than the false positives (but as long as you don't rely onbdrv_has_zero_init()unless you also know the image was just created, you are safely avoiding the false positives).
Quoted 3 lines
And that's the whole point of my series to add a qcow2 persistent bit to track whether an image has known-zero contents: qemu-img should not be calling
bdrv_has_zero_init(), since it is so finicky on what it means.
Sorry, I was unclear. I meant “that we know are not zero immediately after creation”.
My point that it may return false even for (newly created) images that are zero stands. One could also say it returns only “yes” (is zero) or “maybe”, and not “yes” or “no”.
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
If we want to add a behavior to skip zeros unconditionally, we should call new
option --skip-zeroes, to clearly specify what we want.It was my impression that this was exactly what --target-is-zero means and implies.
Quoted 12 lines
--target-is-zero turns into the behavior of 'skip a pre-zeroing pass'. If the destination is already zero, then copying zeroes from the source is a waste of time. If the destination is not already zero, then zeroes from the source are not copied, and the destination will not be identical to the source. We then have a choice of whether --target-is-zero is merely a way to tell qemu something that it couldn't learn otherwise but still be as safe as possible (if we can quickly prove the target has non-zero data, the user lied about it being already zero, so fail the command, so add yet another option to bypass the safety check), or whether it really is synonymous with 'only copy the non-zero portions of the source, and if the destination was not all zero the copy is not faithful but I meant for it to be that way'.
If you claim that it isn’t supposed to be an unsafe override, and if we plan to take your series in some form or another, it follows that we will have to drop this patch here.
Because after your series, qemu can have some insight into existing images (either in the driver’s implementation of make_zero, or in qemu-img itself by virtue of some is_zero function). Therefore, we could do the same “safety check” and see whether our insight agrees on what the user told us.
This would make the flag completely superfluous, though, because when qemu knows the image to be zero, it does the right thing anyway.
Therefore, I see this flag to be for cases where qemu doesn’t know. And that makes it an unsafe override.
Max
Re: [PATCH v3 1/1] qemu-img: Add --target-is-zero to convert
Quoted 74 lines · Max Reitz
Quoted 32 lines · Eric Blake
Quoted 12 lines · Max Reitz
Quoted 11 lines
Quoted 4 lines
I could imagine a user creating a qcow2 image on some block device with preallocation where we cannot verify that the result will be zero. But they want qemu not to zero the device, so they would specify --target-is-zero.
If user create image, setting --target-is-zero is always valid. But if we in
same operation create the image automatically, having --target-is-zero, when
we know that what we are creating is not zero is misleading and should fail..Quoted 3 lines
bdrv_has_zero_init()doesn’t return false only for images that we know are not zero. It returns true for images where we know they are. But if we don’t know, then it returns false also.Huh?
bdrv_has_zero_init()currently returns 1 if a driver knows that creating an image results in that image reading as 0. That means it can return 1 even for non-zero images that were not just created. Thus, that interface has both false positives (returning 1 for a non-zero image if the driver hard-codes it to 1) and false negatives (returning 0 for an image that happens to read as zero). The false negatives are less important (if we don't know if the image is already zero, then zeroing it again is a waste of time but not semantically wrong) than the false positives (but as long as you don't rely onbdrv_has_zero_init()unless you also know the image was just created, you are safely avoiding the false positives).Quoted 3 lines
And that's the whole point of my series to add a qcow2 persistent bit to track whether an image has known-zero contents: qemu-img should not be calling
bdrv_has_zero_init(), since it is so finicky on what it means.Sorry, I was unclear. I meant “that we know are not zero immediately after creation”.
My point that it may return false even for (newly created) images that are zero stands. One could also say it returns only “yes” (is zero) or “maybe”, and not “yes” or “no”.
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
If we want to add a behavior to skip zeros unconditionally, we should call new
option --skip-zeroes, to clearly specify what we want.It was my impression that this was exactly what --target-is-zero means and implies.
Quoted 12 lines
--target-is-zero turns into the behavior of 'skip a pre-zeroing pass'. If the destination is already zero, then copying zeroes from the source is a waste of time. If the destination is not already zero, then zeroes from the source are not copied, and the destination will not be identical to the source. We then have a choice of whether --target-is-zero is merely a way to tell qemu something that it couldn't learn otherwise but still be as safe as possible (if we can quickly prove the target has non-zero data, the user lied about it being already zero, so fail the command, so add yet another option to bypass the safety check), or whether it really is synonymous with 'only copy the non-zero portions of the source, and if the destination was not all zero the copy is not faithful but I meant for it to be that way'.
If you claim that it isn’t supposed to be an unsafe override, and if we plan to take your series in some form or another, it follows that we will have to drop this patch here.
Because after your series, qemu can have some insight into existing images (either in the driver’s implementation of
make_zero, or in qemu-img itself by virtue of someis_zerofunction). Therefore, we could do the same “safety check” and see whether our insight agrees on what the user told us.
Quoted 6 lines
This would make the flag completely superfluous, though, because when qemu knows the image to be zero, it does the right thing anyway.
Therefore, I see this flag to be for cases where qemu doesn’t know. And that makes it an unsafe override.
IMHO, the flag just sounds wrong for images created by Qemu, and sounds OK for images provided by user (still, it can never be safe, as user may mistake).
Still, as I understand, in most of real cases, Qemu actually can determine is-zero by itself, we just didn't have this coded (Eric's series does). And may be we really don't need this arguable flag..
So, really, may be rename it to --skip-zeroes, to make obvious that it is unsafe and user is responsible for the result? Or even to --x-skip-zeroes, and drop it when all needed cases are covered by auto detection?
Signature · 2 lines
Best regards, Vladimir
Re: [PATCH v3 1/1] qemu-img: Add --target-is-zero to convert
In reply to Eric BlakeQuoted 6 lines · Eric Blake
Quoted 2 lines · David Edmondson
In many cases the target of a convert operation is a newly provisioned target that the user knows is blank (filled with zeroes). In this
'filled with zeroes' is accurate for a preallocated image, but reads awkwardly for a sparse image; it might be better to state 'reads as zero'.
Okay.
Quoted 21 lines
Quoted 21 lines
situation there is no requirement for qemu-img to wastefully zero out the entire device.
Add a new option, --target-is-zero, allowing the user to indicate that an existing target device is already zero filled.
Signed-off-by David Edmondson <[email protected]>--- docs/interop/qemu-img.rst | 8 +++++++- qemu-img-cmds.hx | 4 ++-- qemu-img.c | 25 ++++++++++++++++++++++--- 3 files changed, 31 insertions(+), 6 deletions(-)docs/interop/qemu-img.rst +0
-0@@ -214,6 +214,12 @@ Parameters to convert subcommand: will still be printed. Areas that cannot be read from the source will be treated as containing only zeroes.
Quoted 5 lines
docs/interop/qemu-img.rst Parameters to convert subcommand: · line 219
Quoted 3 lines
docs/interop/qemu-img.rst +3
-0+.. option:: --target-is-zero + + Assume that the destination is filled with zeros. This parameter isSpelled 'zeroes' just three lines earlier.
My understanding is that "zeros" is the correct plural of "zero" (and that "zeroes" relates to the use of "zero" as a verb), but perhaps that's another British English thing?
I don't care enough to fight about it.
Quoted 12 lines
docs/interop/qemu-img.rst Parameters to convert subcommand: · line 221
Quoted 2 lines
docs/interop/qemu-img.rst +2
-0+ mutually exclusive with the use of a backing file. It is required to + also use the ``-n`` parameter to skip image creation.I understand that it is safer to have restrictions now and lift them later, than to allow use of the option at any time and leave room for the user to shoot themselves in the foot with no way to add safety later. The argument against no backing file is somewhat understandable (technically, as long as the backing file also reads as all zeroes, then the overall image reads as all zeroes - but why have a backing file that has no content?); the argument requiring -n is a bit weaker (if I'm creating an image, I _know_ it reads as all zeroes, so the --target-is-zero argument is redundant, but it shouldn't hurt to allow it).
Given your patchset that improves the general behaviour of zero detection, I'm definitely inclined to leave the backing file case alone in this patch.
Convincing myself that a newly created image can only ever read as zero will take a little more time, which I'm happy to spend if it's considered significant.
Quoted 31 lines
docs/interop/qemu-img.rst static int img_convert(int argc, char **argv) · line 2262
Quoted 10 lines
docs/interop/qemu-img.rst +5
-0+++ b/qemu-img.c@@ -2247,6 +2256,11 @@ static int img_convert(int argc, char **argv) warn_report("This will become an error in future QEMU versions."); } + if (s.has_zero_init && !skip_create) { + error_report("--target-is-zero requires use of -n flag"); + goto fail_getopt; + }So I think we could drop this hunk with no change in behavior.
docs/interop/qemu-img.rst static int img_convert(int argc, char **argv) · line 2401
Quoted 13 lines
docs/interop/qemu-img.rst +6
-0+ s.src_num = argc - optind - 1; out_filename = s.src_num >= 1 ? argv[argc - 1] : NULL;@@ -2380,6 +2394,11 @@ static int img_convert(int argc, char **argv) } s.target_has_backing = (bool) out_baseimg; + if (s.has_zero_init && s.target_has_backing) { + error_report("Cannot use --target-is-zero with a backing file"); + goto out; + } +while keeping this one makes sense. At any rate, typo fixes are minor, and whether or not we drop the hunk I claim is a needless restriction against redundancy,
Quoted 1 line
Reviewed-by Eric Blake <[email protected]>
Thanks.
dme.
Signature · 1 line
Everyone I know, goes away in the end.
Re: [PATCH v3 1/1] qemu-img: Add --target-is-zero to convert
Quoted 21 lines · David Edmondson
Quoted 13 lines · Eric Blake
Quoted 2 lines · David Edmondson
In many cases the target of a convert operation is a newly provisioned target that the user knows is blank (filled with zeroes). In this
'filled with zeroes' is accurate for a preallocated image, but reads awkwardly for a sparse image; it might be better to state 'reads as zero'.
Quoted 5 lines
+++
b/docs/interop/qemu-img.rstdocs/interop/qemu-img.rst +0
-0@@ -214,6 +214,12 @@ Parameters to convert subcommand: will still be printed. Areas that cannot be read from the source will be treated as containing only zeroes.Quoted 5 lines
docs/interop/qemu-img.rst Parameters to convert subcommand: · line 219
Quoted 3 lines
docs/interop/qemu-img.rst +3
-0+.. option:: --target-is-zero + + Assume that the destination is filled with zeros. This parameter isSpelled 'zeroes' just three lines earlier.
Quoted 6 lines
My understanding is that "zeros" is the correct plural of "zero" (and that "zeroes" relates to the use of "zero" as a verb), but perhaps that's another British English thing?
I don't care enough to fight about it.
https://english.stackexchange.com/questions/3824/what-is-the-plural-form-of-zero says both zeros and zeroes are fine for the noun (with UK leaning more to zeros), but only zeroes for the verb; but also concedes that zeroes is gaining in popularity over time. I likewise won't bother tweaking your patch (I see in v4 that you left it unchanged).
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Re: [PATCH v3 1/1] qemu-img: Add --target-is-zero to convert
In reply to David EdmondsonQuoted 20 lines · David Edmondson
In many cases the target of a convert operation is a newly provisioned target that the user knows is blank (filled with zeroes). In this situation there is no requirement for qemu-img to wastefully zero out the entire device.
Add a new option, --target-is-zero, allowing the user to indicate that an existing target device is already zero filled.
Signed-off-by David Edmondson <[email protected]>--- docs/interop/qemu-img.rst | 8 +++++++- qemu-img-cmds.hx | 4 ++-- qemu-img.c | 25 ++++++++++++++++++++++--- 3 files changed, 31 insertions(+), 6 deletions(-)docs/interop/qemu-img.rst +0
-0
docs/interop/qemu-img.rst Parameters to convert subcommand: · line 220
Quoted 7 lines
docs/interop/qemu-img.rst +4
-0@@ -214,6 +214,12 @@ Parameters to convert subcommand: will still be printed. Areas that cannot be read from the source will be treated as containing only zeroes. +.. option:: --target-is-zero + + Assume that the destination is filled with zeros. This parameter is + mutually exclusive with the use of a backing file. It is required to
Should we mention, that s/backing file/backing file for destination/, to make it clean that source backing file is unrelated?
Quoted 20 lines
docs/interop/qemu-img.rst +3
-1+ also use the ``-n`` parameter to skip image creation. + Parameters to dd subcommand: .. program:: qemu-img-dd@@ -366,7 +372,7 @@ Command description: 4 Error on reading data -.. option:: convert [--object OBJECTDEF] [--image-opts] [--target-image-opts] [-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] [-m NUM_COROUTINES] [-W] FILENAME [FILENAME2 [...]] OUTPUT_FILENAME +.. option:: convert [--object OBJECTDEF] [--image-opts] [--target-image-opts] [--target-is-zero] [-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] [-m NUM_COROUTINES] [-W] FILENAME [FILENAME2 [...]] OUTPUT_FILENAME Convert the disk image *FILENAME* or a snapshot *SNAPSHOT_PARAM* to disk image *OUTPUT_FILENAME* using format *OUTPUT_FMT*. It canqemu-img-cmds.hx +0
-0@@ -39,9 +39,9 @@ SRST ERST
qemu-img-cmds.hx SRST · line 47
Quoted 10 lines
qemu-img-cmds.hx +2
-2DEF("convert", img_convert, - "convert [--object objectdef] [--image-opts] [--target-image-opts] [-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] [-m num_coroutines] [-W] [--salvage] filename [filename2 [...]] output_filename") + "convert [--object objectdef] [--image-opts] [--target-image-opts] [--target-is-zero] [-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] [-m num_coroutines] [-W] [--salvage] filename [filename2 [...]] output_filename") SRST -.. option:: convert [--object OBJECTDEF] [--image-opts] [--target-image-opts] [-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] [-m NUM_COROUTINES] [-W] [--salvage] FILENAME [FILENAME2 [...]] OUTPUT_FILENAME +.. option:: convert [--object OBJECTDEF] [--image-opts] [--target-image-opts] [--target-is-zero] [-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] [-m NUM_COROUTINES] [-W] [--salvage] FILENAME [FILENAME2 [...]] OUTPUT_FILENAME ERST DEF("create", img_create,
Side question: is there plan to get rid of this duplication, and generate everything from rst?
Quoted 61 lines
qemu-img.c +17
-3@@ -70,6 +70,7 @@ enum {OPTION_PREALLOCATION =265 ,OPTION_SHRINK =266 ,OPTION_SALVAGE =267 , + OPTION_TARGET_IS_ZERO = 268, }; typedef enum OutputFormat {@@ -1984,10 +1985,9 @@ static int convert_do_copy(ImgConvertState *s)int64_t sector_num =0 ;/* Check whether we have zero initialisation or can get it efficiently */ -if (s->target_is_new && s->min_sparse && !s->target_has_backing) { +if (!s->has_zero_init && s->target_is_new && s->min_sparse && + !s->target_has_backing) { s->has_zero_init =bdrv_has_zero_init (blk_bs (s->target)); - }else { - s->has_zero_init = false; } if (!s->has_zero_init && !s->target_has_backing &&@@ -2086,6 +2086,7 @@ static int img_convert(int argc, char **argv) {"force-share", no_argument, 0, 'U'}, {"target-image-opts", no_argument, 0, OPTION_TARGET_IMAGE_OPTS}, {"salvage", no_argument, 0, OPTION_SALVAGE}, + {"target-is-zero", no_argument, 0, OPTION_TARGET_IS_ZERO}, {0, 0, 0, 0} }; c = getopt_long(argc, argv, ":hf:O:B:Cco:l:S:pt:T:qnm:WU",@@ -2209,6 +2210,14 @@ static int img_convert(int argc, char **argv)case OPTION_TARGET_IMAGE_OPTS : tgt_image_opts = true;break ; +case OPTION_TARGET_IS_ZERO : +/* +* The user asserting that the target is blank has the +* same effect as the target driver supporting zero +* initialisation. +*/ + s.has_zero_init = true; +break ; } }@@ -2247,6 +2256,11 @@ static int img_convert(int argc, char **argv)warn_report ("This will become an error in future QEMU versions." ); } +if (s.has_zero_init && !skip_create) { +error_report ("--target-is-zero requires use of -n flag" ); + goto fail_getopt; + } + s.src_num = argc - optind -1 ; out_filename = s.src_num >=1 ? argv[argc -1 ] :NULL ;
qemu-img.c static int img_convert(int argc, char **argv) · line 2398
Quoted 5 lines
qemu-img.c +2
-0@@ -2380,6 +2394,11 @@ static int img_convert(int argc, char **argv) } s.target_has_backing = (bool ) out_baseimg; +if (s.has_zero_init && s.target_has_backing) { +error_report ("Cannot use --target-is-zero with a backing file" );
And here, probably better: "with a backing file on destination"
qemu-img.c static int img_convert(int argc, char **argv) · line 2404
Quoted 7 lines
qemu-img.c +3
-0+ goto out; + } +if (s.src_num >1 && out_baseimg) {error_report ("Having a backing file for the target makes no sense when " "concatenating multiple input images" );
With or without my suggestions:
Signature · 2 lines
Best regards, Vladimir
Re: [PATCH v3 1/1] qemu-img: Add --target-is-zero to convert
Quoted 24 lines · Vladimir Sementsov-Ogievskiy
Quoted 23 lines · David Edmondson
In many cases the target of a convert operation is a newly provisioned target that the user knows is blank (filled with zeroes). In this situation there is no requirement for qemu-img to wastefully zero out the entire device.
Add a new option, --target-is-zero, allowing the user to indicate that an existing target device is already zero filled.
Signed-off-by David Edmondson <[email protected]>--- docs/interop/qemu-img.rst | 8 +++++++- qemu-img-cmds.hx | 4 ++-- qemu-img.c | 25 ++++++++++++++++++++++--- 3 files changed, 31 insertions(+), 6 deletions(-)docs/interop/qemu-img.rst +0
-0@@ -214,6 +214,12 @@ Parameters to convert subcommand: will still be printed. Areas that cannot be read from the source will be treated as containing only zeroes.
Quoted 7 lines
docs/interop/qemu-img.rst Parameters to convert subcommand: · line 220
Quoted 4 lines
docs/interop/qemu-img.rst +4
-0+.. option:: --target-is-zero + + Assume that the destination is filled with zeros. This parameter is + mutually exclusive with the use of a backing file. It is required toShould we mention, that s/backing file/backing file for destination/, to make it clean that source backing file is unrelated?
Yes, that makes sense, similarly in the error message.
Quoted 110 lines
Quoted 20 lines
docs/interop/qemu-img.rst +3
-1+ also use the ``-n`` parameter to skip image creation. + Parameters to dd subcommand: .. program:: qemu-img-dd@@ -366,7 +372,7 @@ Command description: 4 Error on reading data -.. option:: convert [--object OBJECTDEF] [--image-opts] [--target-image-opts] [-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] [-m NUM_COROUTINES] [-W] FILENAME [FILENAME2 [...]] OUTPUT_FILENAME +.. option:: convert [--object OBJECTDEF] [--image-opts] [--target-image-opts] [--target-is-zero] [-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] [-m NUM_COROUTINES] [-W] FILENAME [FILENAME2 [...]] OUTPUT_FILENAME Convert the disk image *FILENAME* or a snapshot *SNAPSHOT_PARAM* to disk image *OUTPUT_FILENAME* using format *OUTPUT_FMT*. It canqemu-img-cmds.hx +0
-0@@ -39,9 +39,9 @@ SRST ERSTqemu-img-cmds.hx SRST · line 47
Quoted 10 lines
qemu-img-cmds.hx +2
-2DEF("convert", img_convert, - "convert [--object objectdef] [--image-opts] [--target-image-opts] [-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] [-m num_coroutines] [-W] [--salvage] filename [filename2 [...]] output_filename") + "convert [--object objectdef] [--image-opts] [--target-image-opts] [--target-is-zero] [-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] [-m num_coroutines] [-W] [--salvage] filename [filename2 [...]] output_filename") SRST -.. option:: convert [--object OBJECTDEF] [--image-opts] [--target-image-opts] [-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] [-m NUM_COROUTINES] [-W] [--salvage] FILENAME [FILENAME2 [...]] OUTPUT_FILENAME +.. option:: convert [--object OBJECTDEF] [--image-opts] [--target-image-opts] [--target-is-zero] [-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] [-m NUM_COROUTINES] [-W] [--salvage] FILENAME [FILENAME2 [...]] OUTPUT_FILENAME ERST DEF("create", img_create,Side question: is there plan to get rid of this duplication, and generate everything from rst?
Quoted 61 lines
qemu-img.c +17
-3@@ -70,6 +70,7 @@ enum {OPTION_PREALLOCATION =265 ,OPTION_SHRINK =266 ,OPTION_SALVAGE =267 , + OPTION_TARGET_IS_ZERO = 268, }; typedef enum OutputFormat {@@ -1984,10 +1985,9 @@ static int convert_do_copy(ImgConvertState *s)int64_t sector_num =0 ;/* Check whether we have zero initialisation or can get it efficiently */ -if (s->target_is_new && s->min_sparse && !s->target_has_backing) { +if (!s->has_zero_init && s->target_is_new && s->min_sparse && + !s->target_has_backing) { s->has_zero_init =bdrv_has_zero_init (blk_bs (s->target)); - }else { - s->has_zero_init = false; } if (!s->has_zero_init && !s->target_has_backing &&@@ -2086,6 +2086,7 @@ static int img_convert(int argc, char **argv) {"force-share", no_argument, 0, 'U'}, {"target-image-opts", no_argument, 0, OPTION_TARGET_IMAGE_OPTS}, {"salvage", no_argument, 0, OPTION_SALVAGE}, + {"target-is-zero", no_argument, 0, OPTION_TARGET_IS_ZERO}, {0, 0, 0, 0} }; c = getopt_long(argc, argv, ":hf:O:B:Cco:l:S:pt:T:qnm:WU",@@ -2209,6 +2210,14 @@ static int img_convert(int argc, char **argv)case OPTION_TARGET_IMAGE_OPTS : tgt_image_opts = true;break ; +case OPTION_TARGET_IS_ZERO : +/* +* The user asserting that the target is blank has the +* same effect as the target driver supporting zero +* initialisation. +*/ + s.has_zero_init = true; +break ; } }@@ -2247,6 +2256,11 @@ static int img_convert(int argc, char **argv)warn_report ("This will become an error in future QEMU versions." ); } +if (s.has_zero_init && !skip_create) { +error_report ("--target-is-zero requires use of -n flag" ); + goto fail_getopt; + } + s.src_num = argc - optind -1 ; out_filename = s.src_num >=1 ? argv[argc -1 ] :NULL ;qemu-img.c static int img_convert(int argc, char **argv) · line 2398
Quoted 5 lines
qemu-img.c +2
-0@@ -2380,6 +2394,11 @@ static int img_convert(int argc, char **argv) } s.target_has_backing = (bool ) out_baseimg; +if (s.has_zero_init && s.target_has_backing) { +error_report ("Cannot use --target-is-zero with a backing file" );And here, probably better: "with a backing file on destination"
qemu-img.c static int img_convert(int argc, char **argv) · line 2404
Quoted 7 lines
qemu-img.c +3
-0+ goto out; + } +if (s.src_num >1 && out_baseimg) {error_report ("Having a backing file for the target makes no sense when " "concatenating multiple input images" );
Quoted 7 lines
With or without my suggestions:
Reviewed-by Vladimir Sementsov-Ogievskiy <[email protected]>Signature · 2 lines
Best regards, Vladimir
dme.
Signature · 1 line
You bring light in.