From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Hanna Reitz <hreitz@redhat.com>,
nsoffer@redhat.com, <qemu-block@nongnu.org>,
Kevin Wolf <kwolf@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>,
Eric Biggers <ebiggers@google.com>
Subject: [PATCH v2 2/2] file-posix: add statx(STATX_DIOALIGN) support
Date: Thu, 3 Nov 2022 14:36:09 -0400 [thread overview]
Message-ID: <20221103183609.363027-3-stefanha@redhat.com> (raw)
In-Reply-To: <20221103183609.363027-1-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.
Testing shows the status of STATX_DIOALIGN support in Linux 6.1-rc3
appears to be:
- btrfs: no
- ext4: yes
- XFS: yes
- NVMe block devices: yes
- dm-crypt: yes
Cc: Eric Biggers <ebiggers@google.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
v2:
- Make sure that XFS_IOC_DIOINFO takes priority over logical blocksize [Eric Biggers]
---
block/file-posix.c | 60 ++++++++++++++++++++++++++++++----------------
1 file changed, 40 insertions(+), 20 deletions(-)
diff --git a/block/file-posix.c b/block/file-posix.c
index b9d62f52fe..b7e5a08e41 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -372,29 +372,49 @@ static void raw_probe_alignment(BlockDriverState *bs, int fd, Error **errp)
bs->bl.request_alignment = 0;
s->buf_align = 0;
+
+#if defined(__linux__) && defined(STATX_DIOALIGN)
+ struct statx stx;
+
+ /*
+ * 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.
+ */
+ 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 (probe_logical_blocksize(fd, &bs->bl.request_alignment) < 0) {
- bs->bl.request_alignment = 0;
+ if (!bs->bl.request_alignment) {
+ if (probe_logical_blocksize(fd, &bs->bl.request_alignment) < 0) {
+ bs->bl.request_alignment = 0;
+ }
}
-#ifdef __linux__
- /*
- * 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
-
/*
* If we could not get the sizes so far, we can only guess them. First try
* to detect request alignment, since it is more likely to succeed. Then
--
2.38.1
next prev parent reply other threads:[~2022-11-03 18:37 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-03 18:36 [PATCH v2 0/2] file-posix: alignment probing improvements Stefan Hajnoczi
2022-11-03 18:36 ` [PATCH v2 1/2] file-posix: fix Linux alignment probing when EIO is returned Stefan Hajnoczi
2022-11-11 11:08 ` Kevin Wolf
2022-11-03 18:36 ` Stefan Hajnoczi [this message]
2022-11-11 11:22 ` [PATCH v2 2/2] file-posix: add statx(STATX_DIOALIGN) support Kevin Wolf
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=20221103183609.363027-3-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=ebiggers@google.com \
--cc=hreitz@redhat.com \
--cc=kwolf@redhat.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).