From: "Denis V. Lunev" <den@virtuozzo.com>
To: Mike Maslenkin <mike.maslenkin@gmail.com>
Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, kwolf@redhat.com,
hreitz@redhat.com, den@openvz.org
Subject: Re: [PATCH v2 1/1] qemu-img: do not erase destination file in qemu-img dd command
Date: Sun, 1 Oct 2023 14:25:28 +0200 [thread overview]
Message-ID: <15609bb5-95d0-3d38-4c44-bcd313dc723b@virtuozzo.com> (raw)
In-Reply-To: <20230930203157.85766-1-mike.maslenkin@gmail.com>
On 9/30/23 22:31, Mike Maslenkin wrote:
> Add a check that destination file exists and do not call bdrv_create for
> this case.
>
> Currently `qemu-img dd` command destroys content of destination file.
> Effectively this means that parameters (geometry) of destination image
> file are changing. This can be undesirable behavior for user especially
> if format of destination image does not support resizing.
>
> Steps to reproduce:
> 1. Create empty disk image with some non default size.
> `qemu-img create -f qcow2 $DEST_IMG 3T`
> Remember that `qemu-img info $DEST_IMG` returns:
> virtual size: 3 TiB (3298534883328 bytes)
> disk size: 240 KiB
> cluster_size: 65536
> 2. Run `qemu-img dd -O qcow2 of=$DEST_IMG if=$SRC_IMG bs=1M count=100`
> 3. Check `qemu-img info $DEST_IMG` output:
> virtual size: 100 MiB (104857600 bytes)
> disk size: 112 MiB
> cluster_size: 65536
>
> Parameters of $DEST_IMG were changed. Actually `qemu-img dd` has created
> a new disk based on current default geometry for particular format.
> For example for "parallels" format default BAT for 256GB disk is written
> to empty file prior writing disk image data.
>
> With this patch virtual disk metadata and geometry of a destination image
> are preserved. As another visible change of `qemu-img dd` behavior is that
> if destination image is less than source it can finish with error (similar
> to "dd" utility):
> qemu-img: error while writing to output image file: Input/output error
>
> Signed-off-by: Mike Maslenkin <mike.maslenkin@gmail.com>
> ---
> diff from v1: removed additional fprintf call leaved in patch by accident
> ---
> qemu-img.c | 17 ++++++++++-------
> 1 file changed, 10 insertions(+), 7 deletions(-)
>
> diff --git a/qemu-img.c b/qemu-img.c
> index a48edb71015c..1a83c14212fb 100644
> --- a/qemu-img.c
> +++ b/qemu-img.c
> @@ -5150,13 +5150,15 @@ static int img_dd(int argc, char **argv)
> size - in.bsz * in.offset, &error_abort);
> }
>
> - ret = bdrv_create(drv, out.filename, opts, &local_err);
> - if (ret < 0) {
> - error_reportf_err(local_err,
> - "%s: error while creating output image: ",
> - out.filename);
> - ret = -1;
> - goto out;
> + if (!g_file_test(out.filename, G_FILE_TEST_EXISTS)) {
> + ret = bdrv_create(drv, out.filename, opts, &local_err);
> + if (ret < 0) {
> + error_reportf_err(local_err,
> + "%s: error while creating output image: ",
> + out.filename);
> + ret = -1;
> + goto out;
> + }
> }
>
> /* TODO, we can't honour --image-opts for the target,
may be it would be worth to follow conventional
'dd' approach, i.e. add conv=nocreat option which
will do the trick?
Den
next prev parent reply other threads:[~2023-10-01 12:26 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-30 20:31 [PATCH v2 1/1] qemu-img: do not erase destination file in qemu-img dd command Mike Maslenkin
2023-10-01 12:25 ` Denis V. Lunev [this message]
2023-10-01 17:08 ` Mike Maslenkin
2023-10-01 20:46 ` Denis V. Lunev
2023-10-31 14:33 ` Hanna Czenczek
2023-11-01 16:26 ` Eric Blake
2023-11-01 16:51 ` Daniel P. Berrangé
2023-11-01 17:03 ` Denis V. Lunev
2023-11-01 17:22 ` Daniel P. Berrangé
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=15609bb5-95d0-3d38-4c44-bcd313dc723b@virtuozzo.com \
--to=den@virtuozzo.com \
--cc=den@openvz.org \
--cc=hreitz@redhat.com \
--cc=kwolf@redhat.com \
--cc=mike.maslenkin@gmail.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).