[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH] block: posix: Always allocate the first block
From: |
Max Reitz |
Subject: |
Re: [Qemu-devel] [PATCH] block: posix: Always allocate the first block |
Date: |
Fri, 23 Aug 2019 19:53:29 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 |
On 23.08.19 18:48, Nir Soffer wrote:
> On Fri, Aug 23, 2019 at 4:58 PM Max Reitz <address@hidden
> <mailto:address@hidden>> 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
signature.asc
Description: OpenPGP digital signature
- Re: [Qemu-devel] [Qemu-block] [PATCH] block: posix: Always allocate the first block, (continued)
- Re: [Qemu-devel] [PATCH] block: posix: Always allocate the first block, Nir Soffer, 2019/08/22
- Re: [Qemu-devel] [PATCH] block: posix: Always allocate the first block, Max Reitz, 2019/08/22
- Re: [Qemu-devel] [PATCH] block: posix: Always allocate the first block, Nir Soffer, 2019/08/22
- Re: [Qemu-devel] [PATCH] block: posix: Always allocate the first block, Max Reitz, 2019/08/22
- Re: [Qemu-devel] [PATCH] block: posix: Always allocate the first block, Nir Soffer, 2019/08/22
- Re: [Qemu-devel] [PATCH] block: posix: Always allocate the first block, Max Reitz, 2019/08/23
- Re: [Qemu-devel] [PATCH] block: posix: Always allocate the first block, Nir Soffer, 2019/08/23
- Re: [Qemu-devel] [PATCH] block: posix: Always allocate the first block, Max Reitz, 2019/08/23
- Re: [Qemu-devel] [PATCH] block: posix: Always allocate the first block, Nir Soffer, 2019/08/23
- Re: [Qemu-devel] [PATCH] block: posix: Always allocate the first block,
Max Reitz <=
- Re: [Qemu-devel] [PATCH] block: posix: Always allocate the first block, Nir Soffer, 2019/08/24
Re: [Qemu-devel] [Qemu-block] [PATCH] block: posix: Always allocate the first block, Maxim Levitsky, 2019/08/25