qemu-block
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] file-posix: Fix alignment after reopen changing O_DIRECT


From: Stefano Garzarella
Subject: Re: [PATCH] file-posix: Fix alignment after reopen changing O_DIRECT
Date: Thu, 4 Nov 2021 15:20:29 +0100

On Thu, Nov 04, 2021 at 12:31:09PM +0100, Kevin Wolf wrote:
At the end of a reopen, we already call bdrv_refresh_limits(), which
should update bs->request_alignment according to the new file
descriptor. However, raw_probe_alignment() relies on s->needs_alignment
and just uses 1 if it isn't set. We neglected to update this field, so
starting with cache=writeback and then reopening with cache=none means
that we get an incorrect bs->request_alignment == 1 and unaligned
requests fail instead of being automatically aligned.

Fix this by recalculating s->needs_alignment in raw_refresh_limits()
before calling raw_probe_alignment().

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block/file-posix.c         | 20 ++++++++++++++++----
tests/qemu-iotests/142     | 22 ++++++++++++++++++++++
tests/qemu-iotests/142.out | 15 +++++++++++++++
3 files changed, 53 insertions(+), 4 deletions(-)

diff --git a/block/file-posix.c b/block/file-posix.c
index 7a27c83060..3f14e47096 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -167,6 +167,7 @@ typedef struct BDRVRawState {
    int page_cache_inconsistent; /* errno from fdatasync failure */
    bool has_fallocate;
    bool needs_alignment;
+    bool force_alignment;
    bool drop_cache;
    bool check_cache_dropped;
    struct {
@@ -351,6 +352,17 @@ static bool dio_byte_aligned(int fd)
    return false;
}

+static int raw_needs_alignment(BlockDriverState *bs)

If you need to respin, maybe it's better to use `bool` as return type.

In both cases:
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>

Stefano




reply via email to

[Prev in Thread] Current Thread [Next in Thread]