From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org
Subject: [PULL 17/21] file-posix: add statx(STATX_DIOALIGN) support
Date: Wed, 7 Oct 2026 18:32:58 +0200 [thread overview]
Message-ID: <20261007163302.332250-18-kwolf@redhat.com> (raw)
In-Reply-To: <20261007163302.332250-1-kwolf@redhat.com>
From: Stefan Hajnoczi <stefanha@redhat.com>
Linux v6.1 commit 825cf206ed51 ("statx: add direct I/O alignment
information") added an interface to fetch O_DIRECT alignment values for
block devices and file systems.
Prefer STATX_DIOALIGN to older interfaces and probing, but keep them as
fallbacks in case STATX_DIOALIGN cannot provide the information.
STATX_DIOALIGN support as of Linux 6.1:
- btrfs: no
- ext4: yes
- XFS: yes
- block devices: yes
- dm-crypt: yes
This change fixes #1290 ("IO alignment probing delivers incorrect
results on Linux when used with e.g. dm-crypt") on Linux host kernel
version 6.1 or later by avoiding the problematic probing code in
raw_probe_alignment(). It would be nice to fix the probing code but I
have not been able to reproduce it. Stable/LTS distros ship Linux 6.1+,
so the number of users without STATX_DIOALIGN is becoming small.
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/1290
Cc: Eric Biggers <ebiggers@google.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-ID: <20260922154351.226540-1-stefanha@redhat.com>
Reviewed-by: Ben Chaney <bchaney@akamai.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block/file-posix.c | 56 +++++++++++++++++++++++++++++++---------------
1 file changed, 38 insertions(+), 18 deletions(-)
diff --git a/block/file-posix.c b/block/file-posix.c
index 39d6a34456c..328adb57233 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -426,28 +426,48 @@ static void raw_probe_alignment(BlockDriverState *bs, int fd, Error **errp)
bs->bl.request_alignment = 0;
s->buf_align = 0;
- /* Let's try to use the logical blocksize for the alignment. */
- if (probe_logical_blocksize(fd, &bs->bl.request_alignment) < 0) {
- bs->bl.request_alignment = 0;
- }
-#ifdef __linux__
+#if defined(__linux__) && defined(STATX_DIOALIGN)
+ struct statx stx;
+
/*
- * The XFS ioctl definitions are shipped in extra packages that might
- * not always be available. Since we just need the XFS_IOC_DIOINFO ioctl
- * here, we simply use our own definition instead:
+ * Linux 6.1 introduced an interface for both block devices and file
+ * systems. The system call returns with the STATX_DIOALIGN bit cleared
+ * when the information is unavailable.
*/
- struct xfs_dioattr {
- uint32_t d_mem;
- uint32_t d_miniosz;
- uint32_t d_maxiosz;
- } da;
- if (ioctl(fd, _IOR('X', 30, struct xfs_dioattr), &da) >= 0) {
- bs->bl.request_alignment = da.d_miniosz;
- /* The kernel returns wrong information for d_mem */
- /* s->buf_align = da.d_mem; */
+ if (statx(fd, "", AT_EMPTY_PATH, STATX_DIOALIGN, &stx) == 0 &&
+ (stx.stx_mask & STATX_DIOALIGN)) {
+ bs->bl.request_alignment = stx.stx_dio_offset_align;
+ s->buf_align = stx.stx_dio_mem_align;
+ }
+#endif /* defined(__linux__) && defined(STATX_DIOALIGN) */
+
+#ifdef __linux__
+ if (!bs->bl.request_alignment) {
+ /*
+ * The XFS ioctl definitions are shipped in extra packages that might
+ * not always be available. Since we just need the XFS_IOC_DIOINFO ioctl
+ * here, we simply use our own definition instead:
+ */
+ struct xfs_dioattr {
+ uint32_t d_mem;
+ uint32_t d_miniosz;
+ uint32_t d_maxiosz;
+ } da;
+ if (ioctl(fd, _IOR('X', 30, struct xfs_dioattr), &da) >= 0) {
+ bs->bl.request_alignment = da.d_miniosz;
+ /* The kernel returns wrong information for d_mem */
+ /* s->buf_align = da.d_mem; */
+ }
+ }
+#endif /* __linux__ */
+
+ /* Let's try to use the logical blocksize for the alignment. */
+ if (!bs->bl.request_alignment) {
+ if (probe_logical_blocksize(fd, &bs->bl.request_alignment) < 0) {
+ bs->bl.request_alignment = 0;
+ }
}
-#endif
/*
* If we could not get the sizes so far, we can only guess them. First try
--
2.56.0
next prev parent reply other threads:[~2026-10-07 16:36 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-07 16:32 [PULL 00/21] Block layer patches Kevin Wolf
2026-10-07 16:32 ` [PULL 01/21] block-common: fix BDRV_WANT_PRECISE duplicating BDRV_WANT_OFFSET_VALID Kevin Wolf
2026-10-07 16:32 ` [PULL 02/21] block/throttle-groups: fix crash when enabling I/O limits on a busy disk Kevin Wolf
2026-10-07 16:32 ` [PULL 03/21] block: fix bdrv_next() skipping monitor-owned nodes Kevin Wolf
2026-10-07 16:32 ` [PULL 04/21] block: allocate aligned write buffer for 'truncate -m full' Kevin Wolf
2026-10-07 16:32 ` [PULL 05/21] scripts/qemugdb: coroutine: Fix selected frame leak on error path Kevin Wolf
2026-10-07 16:32 ` [PULL 06/21] scripts/qemugdb: coroutine: Get rid of fallback pattern when dumping backtrace Kevin Wolf
2026-10-07 16:32 ` [PULL 07/21] scripts/qemugdb: coroutine: Only attempt to restore regs in coredump Kevin Wolf
2026-10-07 16:32 ` [PULL 08/21] scripts/qemugdb: coroutine: Don't unwind past the outermost frame Kevin Wolf
2026-10-07 16:32 ` [PULL 09/21] scripts/qemugdb: coroutine: Fix patching pt_regs in the coredump Kevin Wolf
2026-10-07 16:32 ` [PULL 10/21] scripts/qemugdb: coroutine: Fix '--detailed' description Kevin Wolf
2026-10-07 16:32 ` [PULL 11/21] scripts/qemugdb: coroutine: Handle target absence gracefully Kevin Wolf
2026-10-07 16:32 ` [PULL 12/21] scripts/qemugdb: coroutine: Speed up coroutine lookup in a coredump Kevin Wolf
2026-10-07 16:32 ` [PULL 13/21] scripts/qemugdb: coroutine: Don't touch the coredump for a plain backtrace Kevin Wolf
2026-10-07 16:32 ` [PULL 14/21] iotests: remove unused 'owner=' variable assignment Kevin Wolf
2026-10-07 16:32 ` [PULL 15/21] hw/block/fdc: account for read and write requests Kevin Wolf
2026-10-07 16:32 ` [PULL 16/21] iotests: annotate TestRunner.shared_self for mypy 2.4 Kevin Wolf
2026-10-07 16:32 ` Kevin Wolf [this message]
2026-10-07 16:32 ` [PULL 18/21] qcow2: do not clear the dirty bit when reopening a read-only node Kevin Wolf
2026-10-07 16:33 ` [PULL 19/21] block: reject a reopen of an unusable node instead of crashing Kevin Wolf
2026-10-07 16:33 ` [PULL 20/21] block: Fix corruption from broken RMW atomicity Kevin Wolf
2026-10-07 16:33 ` [PULL 21/21] block: Remove now redundant bdrv_wait_serialising_requests() calls Kevin Wolf
2026-10-09 12:29 ` [PULL 00/21] Block layer patches Richard Henderson
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=20261007163302.332250-18-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.