qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: Max Reitz <mreitz@redhat.com>
Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org
Subject: Re: [PATCH] qcow2: Fix preallocation on block devices
Date: Thu, 7 May 2020 10:39:24 +0200	[thread overview]
Message-ID: <20200507083924.GA6019@linux.fritz.box> (raw)
In-Reply-To: <20200505141801.1096763-1-mreitz@redhat.com>

Am 05.05.2020 um 16:18 hat Max Reitz geschrieben:
> Calling bdrv_getlength() to get the pre-truncate file size will not
> really work on block devices, because they have always the same length,
> and trying to write beyond it will fail with a rather cryptic error
> message.
> 
> Instead, we should use qcow2_get_last_cluster() and bdrv_getlength()
> only as a fallback.
> 
> Before this patch:
> $ truncate -s 1G test.img
> $ sudo losetup -f --show test.img
> /dev/loop0
> $ sudo qemu-img create -f qcow2 -o preallocation=full /dev/loop0 64M
> Formatting '/dev/loop0', fmt=qcow2 size=67108864 cluster_size=65536
> preallocation=full lazy_refcounts=off refcount_bits=16
> qemu-img: /dev/loop0: Could not resize image: Failed to resize refcount
> structures: No space left on device
> 
> With this patch:
> $ sudo qemu-img create -f qcow2 -o preallocation=full /dev/loop0 64M
> Formatting '/dev/loop0', fmt=qcow2 size=67108864 cluster_size=65536
> preallocation=full lazy_refcounts=off refcount_bits=16
> qemu-img: /dev/loop0: Could not resize image: Failed to resize
> underlying file: Preallocation mode 'full' unsupported for this
> non-regular file
> 
> So as you can see, it still fails, but now the problem is missing
> support on the block device level, so we at least get a better error
> message.
> 
> Note that we cannot preallocate block devices on truncate by design,
> because we do not know what area to preallocate.  Their length is always
> the same, the truncate operation does not change it.
> 
> Signed-off-by: Max Reitz <mreitz@redhat.com>

Thanks, applied to the block branch.

Kevin



      reply	other threads:[~2020-05-07  8:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-05 14:18 [PATCH] qcow2: Fix preallocation on block devices Max Reitz
2020-05-07  8:39 ` Kevin Wolf [this message]

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=20200507083924.GA6019@linux.fritz.box \
    --to=kwolf@redhat.com \
    --cc=mreitz@redhat.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).