From: Max Reitz <mreitz@redhat.com>
To: Nir Soffer <nsoffer@redhat.com>
Cc: Kevin Wolf <kwolf@redhat.com>, qemu-block <qemu-block@nongnu.org>,
Nir Soffer <nirsof@gmail.com>,
QEMU Developers <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH] block: posix: Always allocate the first block
Date: Fri, 23 Aug 2019 19:53:29 +0200 [thread overview]
Message-ID: <5a6cabf2-a284-9f63-da0e-96af26f8e0cd@redhat.com> (raw)
In-Reply-To: <CAMRbyytObKSo+spkrQsTurybGJEndDTWP4UJgieP0nVw=CLmag@mail.gmail.com>
[-- Attachment #1.1: Type: text/plain, Size: 1872 bytes --]
On 23.08.19 18:48, Nir Soffer wrote:
> On Fri, Aug 23, 2019 at 4:58 PM Max Reitz <mreitz@redhat.com
> <mailto:mreitz@redhat.com>> wrote:
[...]
> If you have a format layer that truncates the image to a fixed size and
> does not write anything into the first block itself (say because it uses
> a footer), then (with O_DIRECT) allocate_first_block() will fail
> (silently, because while it does return an error value, it is never
> checked and there is no comment that explains why we don’t check it)
>
>
> The motivation is that this is an optimization for the special case of using
> empty image, so it does not worth failing image creation.
> I will add a comment about that.
Thanks!
[...]
> Thanks for the example.
>
> I will need time to play with blockdev and understand the flows when image
> are created. Do you think is would be useful to fix now only image creation
> via qemu-img, and handle blockdev later?
Well, it isn’t about blockdev, it’s simply about the fact that this
function doesn’t work for O_DIRECT files. I showed how to reproduce the
issue without blockdev (namely block_resize). Sure, that is an edge
case, but it is a completely valid case.
Also, it seems to me the fix is rather simple. Just something like:
static int allocate_first_block(int fd, int64_t max_size)
{
int write_size = MIN(max_size, MAX_BLOCKSIZE);
void *buf;
ssize_t n;
/* Round down to power of two */
assert(write_size > 0);
write_size = 1 << (31 - clz32(write_size));
buf = qemu_memalign(MAX(getpagesize(), write_size), write_size);
memset(buf, 0, write_size);
do {
n = pwrite(fd, buf, write_size, 0);
} while (n < 0 && errno == EINTR);
qemu_vfree(buf);
return n < 0 ? -errno : 0;
}
Wouldn’t that work?
Max
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2019-08-23 17:54 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-16 21:21 [Qemu-devel] [PATCH] block: posix: Always allocate the first block Nir Soffer
2019-08-16 21:57 ` [Qemu-devel] [Qemu-block] " John Snow
2019-08-16 22:45 ` Nir Soffer
2019-08-16 23:00 ` John Snow
2019-08-22 11:30 ` [Qemu-devel] " Nir Soffer
2019-08-22 14:28 ` Max Reitz
2019-08-22 16:39 ` Nir Soffer
2019-08-22 18:11 ` Max Reitz
2019-08-22 19:01 ` Nir Soffer
2019-08-23 13:58 ` Max Reitz
2019-08-23 16:30 ` Nir Soffer
2019-08-23 17:41 ` Max Reitz
2019-08-23 16:48 ` Nir Soffer
2019-08-23 17:53 ` Max Reitz [this message]
2019-08-24 22:57 ` Nir Soffer
2019-08-25 7:44 ` [Qemu-devel] [Qemu-block] " Maxim Levitsky
2019-08-25 19:51 ` Nir Soffer
2019-08-25 22:17 ` Maxim Levitsky
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=5a6cabf2-a284-9f63-da0e-96af26f8e0cd@redhat.com \
--to=mreitz@redhat.com \
--cc=kwolf@redhat.com \
--cc=nirsof@gmail.com \
--cc=nsoffer@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).