qemu-img resize: Require --shrink for shrinking all image formats
PATCH 1/1 qemu-img resize: Require --shrink for shrinking all image formats
QEMU 2.11 introduced the --shrink option for qemu-img resize to avoid accidentally shrinking images (commit 4ffca8904a3). However, for compatibility reasons, it was not enforced for raw images yet, but only a deprecation warning was printed. This warning has existed for long enough that we can now finally require --shrink for raw images, too, and error out if it's not given.
Documentation already describes the state as it is after this patch.
--- qemu-img.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-)
qemu-img.c +3 -14
@@ -4011,20 +4011,9 @@ static int img_resize(int argc, char **argv) }if (total_size < current_size && !shrink) { -warn_report ("Shrinking an image will delete all data beyond the " -"shrunken image's end. Before performing such an " -"operation, make sure there is no important data there." ); - -if (g_strcmp0 (bdrv_get_format_name (blk_bs (blk)),"raw" ) !=0 ) { -error_report ( -"Use the --shrink option to perform a shrink operation." ); - ret =-1 ; - goto out; - }else { -warn_report ("Using the --shrink option will suppress this message. " -"Note that future versions of qemu-img may refuse to " -"shrink images without this option." ); - } +error_report ("Use the --shrink option to perform a shrink operation." ); + ret =-1 ; + goto out; }/*
Signature · 1 line
2.25.4
Quoted 6 lines · Kevin Wolf
QEMU 2.11 introduced the --shrink option for qemu-img resize to avoid accidentally shrinking images (commit
4ffca8904a3). However, for compatibility reasons, it was not enforced for raw images yet, but only a deprecation warning was printed. This warning has existed for long enough that we can now finally require --shrink for raw images, too, and error out if it's not given.
Libvirt has used the --shrink flag since Aug 2018, so this is safe from our POV.
Quoted 6 lines
Documentation already describes the state as it is after this patch.
Signed-off-by Kevin Wolf <[email protected]>--- qemu-img.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-)
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Quoted 28 lines · Kevin Wolf
QEMU 2.11 introduced the --shrink option for qemu-img resize to avoid accidentally shrinking images (commit
4ffca8904a3). However, for compatibility reasons, it was not enforced for raw images yet, but only a deprecation warning was printed. This warning has existed for long enough that we can now finally require --shrink for raw images, too, and error out if it's not given.Documentation already describes the state as it is after this patch.
Signed-off-by Kevin Wolf <[email protected]>--- qemu-img.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-)qemu-img.c +0
-5@@ -4011,20 +4011,9 @@ static int img_resize(int argc, char **argv) }if (total_size < current_size && !shrink) { -warn_report ("Shrinking an image will delete all data beyond the " -"shrunken image's end. Before performing such an " -"operation, make sure there is no important data there." ); - -if (g_strcmp0 (bdrv_get_format_name (blk_bs (blk)),"raw" ) !=0 ) {
qemu-img.c static int img_resize(int argc, char **argv) · line 4014
Quoted 10 lines
qemu-img.c +1
-9-error_report ( -"Use the --shrink option to perform a shrink operation." ); - ret =-1 ; - goto out; - }else { -warn_report ("Using the --shrink option will suppress this message. " -"Note that future versions of qemu-img may refuse to " -"shrink images without this option." ); - } +error_report ("Use the --shrink option to perform a shrink operation." );
I think it would be nice to retain this bit of text:
qemu-img.c static int img_resize(int argc, char **argv) · line 4016
Quoted 3 lines
qemu-img.c +0
-3-warn_report ("Shrinking an image will delete all data beyond the " -"shrunken image's end. Before performing such an " -"operation, make sure there is no important data there." );
ie, make the raw-shrink case be the same as the non-raw-shrink case currently does.
thanks
-- PMM
Am 10.07.2020 um 14:33 hat Peter Maydell geschrieben:
Quoted 42 lines · Kevin Wolf
Quoted 28 lines
QEMU 2.11 introduced the --shrink option for qemu-img resize to avoid accidentally shrinking images (commit
4ffca8904a3). However, for compatibility reasons, it was not enforced for raw images yet, but only a deprecation warning was printed. This warning has existed for long enough that we can now finally require --shrink for raw images, too, and error out if it's not given.Documentation already describes the state as it is after this patch.
Signed-off-by Kevin Wolf <[email protected]>--- qemu-img.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-)qemu-img.c +0
-5@@ -4011,20 +4011,9 @@ static int img_resize(int argc, char **argv) }if (total_size < current_size && !shrink) { -warn_report ("Shrinking an image will delete all data beyond the " -"shrunken image's end. Before performing such an " -"operation, make sure there is no important data there." ); - -if (g_strcmp0 (bdrv_get_format_name (blk_bs (blk)),"raw" ) !=0 ) {qemu-img.c static int img_resize(int argc, char **argv) · line 4014
Quoted 10 lines
qemu-img.c +1
-9-error_report ( -"Use the --shrink option to perform a shrink operation." ); - ret =-1 ; - goto out; - }else { -warn_report ("Using the --shrink option will suppress this message. " -"Note that future versions of qemu-img may refuse to " -"shrink images without this option." ); - } +error_report ("Use the --shrink option to perform a shrink operation." );I think it would be nice to retain this bit of text:
Quoted 6 lines
qemu-img.c static int img_resize(int argc, char **argv) · line 4016
Quoted 3 lines
qemu-img.c +0
-3-warn_report ("Shrinking an image will delete all data beyond the " -"shrunken image's end. Before performing such an " -"operation, make sure there is no important data there." );ie, make the raw-shrink case be the same as the non-raw-shrink case currently does.
I had this at first, but then the whole thing looked like a warning and I wasn't sure that it would still be understood as an error. (Which is of course a preexisting problem for non-raw.)
Maybe it becomes clearer if I just swap the order and print the error first and only then the warning?
Kevin
Am 10.07.2020 um 14:41 hat Kevin Wolf geschrieben:
Quoted 50 lines
Am 10.07.2020 um 14:33 hat Peter Maydell geschrieben:
Quoted 42 lines · Kevin Wolf
Quoted 28 lines
QEMU 2.11 introduced the --shrink option for qemu-img resize to avoid accidentally shrinking images (commit
4ffca8904a3). However, for compatibility reasons, it was not enforced for raw images yet, but only a deprecation warning was printed. This warning has existed for long enough that we can now finally require --shrink for raw images, too, and error out if it's not given.Documentation already describes the state as it is after this patch.
Signed-off-by Kevin Wolf <[email protected]>--- qemu-img.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-)qemu-img.c +0
-5@@ -4011,20 +4011,9 @@ static int img_resize(int argc, char **argv) }if (total_size < current_size && !shrink) { -warn_report ("Shrinking an image will delete all data beyond the " -"shrunken image's end. Before performing such an " -"operation, make sure there is no important data there." ); - -if (g_strcmp0 (bdrv_get_format_name (blk_bs (blk)),"raw" ) !=0 ) {qemu-img.c static int img_resize(int argc, char **argv) · line 4014
Quoted 10 lines
qemu-img.c +1
-9-error_report ( -"Use the --shrink option to perform a shrink operation." ); - ret =-1 ; - goto out; - }else { -warn_report ("Using the --shrink option will suppress this message. " -"Note that future versions of qemu-img may refuse to " -"shrink images without this option." ); - } +error_report ("Use the --shrink option to perform a shrink operation." );I think it would be nice to retain this bit of text:
Quoted 6 lines
qemu-img.c static int img_resize(int argc, char **argv) · line 4016
Quoted 3 lines
qemu-img.c +0
-3-warn_report ("Shrinking an image will delete all data beyond the " -"shrunken image's end. Before performing such an " -"operation, make sure there is no important data there." );ie, make the raw-shrink case be the same as the non-raw-shrink case currently does.
Quoted 6 lines
I had this at first, but then the whole thing looked like a warning and I wasn't sure that it would still be understood as an error. (Which is of course a preexisting problem for non-raw.)
Maybe it becomes clearer if I just swap the order and print the error first and only then the warning?
I made this change and applied the patch to the block branch.
Kevin