* [LTP] [PATCH] ioctl_loop05: Account for backing file STATX_DIOALIGN
@ 2026-12-05 13:37 Wake Liu via ltp
2026-12-05 19:37 ` [LTP] " linuxtestproject.agent
0 siblings, 1 reply; 2+ messages in thread
From: Wake Liu via ltp @ 2026-12-05 13:37 UTC (permalink / raw)
To: ltp; +Cc: Wake Liu
Since Linux commit f4774e92aab8 ("loop: take the file system minimum
dio alignment into account"), the loop driver queries STATX_DIOALIGN on
the backing file in loop_update_dio_alignment() and requires both the
loop logical block size and lo_offset to satisfy stx_dio_offset_align
before LOOP_SET_DIRECT_IO can be enabled.
When the temporary directory resides on a filesystem whose block size
exceeds the underlying block device's logical block size (for example,
a 16KB f2fs filesystem over a 4KB dm block device), querying only
BLKSSZGET yields 4096 while stx_dio_offset_align is 16384. Setting
LOOP_SET_BLOCK_SIZE to 4096 then causes LOOP_SET_DIRECT_IO to fail
with EINVAL.
Query STATX_DIOALIGN on the backing file via statx() and use the larger
of BLKSSZGET and stx_dio_offset_align when configuring the loop block
size and offset test cases. If LOOP_SET_BLOCK_SIZE fails with EINVAL,
report TCONF instead of proceeding with an unconfigured block size.
Signed-off-by: Wake Liu <wakel@google.com>
---
.../kernel/syscalls/ioctl/ioctl_loop05.c | 39 +++++++++++++++----
1 file changed, 31 insertions(+), 8 deletions(-)
diff --git a/testcases/kernel/syscalls/ioctl/ioctl_loop05.c b/testcases/kernel/syscalls/ioctl/ioctl_loop05.c
index 11952af0a..9ff013d7f 100644
--- a/testcases/kernel/syscalls/ioctl/ioctl_loop05.c
+++ b/testcases/kernel/syscalls/ioctl/ioctl_loop05.c
@@ -24,13 +24,16 @@
* success with non-zero offset.
*/
+#define _GNU_SOURCE
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <sys/mount.h>
-#include "lapi/loop.h"
#include "tst_test.h"
+#include "lapi/fcntl.h"
+#include "lapi/loop.h"
+#include "lapi/stat.h"
#define DIO_MESSAGE "In dio mode"
#define NON_DIO_MESSAGE "In non dio mode"
@@ -101,6 +104,7 @@ static void verify_ioctl_loop(void)
static void setup(void)
{
char bd_path[100];
+ struct ltp_statx stx;
dev_num = tst_find_free_loopdev(dev_path, sizeof(dev_path));
if (dev_num < 0)
@@ -117,11 +121,11 @@ static void setup(void)
tst_brk(TCONF, "LOOP_SET_DIRECT_IO is not supported");
/*
- * from __loop_update_dio():
- * We support direct I/O only if lo_offset is aligned with the
- * logical I/O size of backing device, and the logical block
- * size of loop is bigger than the backing device's and the loop
- * needn't transform transfer.
+ * From loop_update_dio_alignment() / lo_can_use_dio():
+ * Direct I/O requires the loop logical block size and lo_offset to
+ * be at least and aligned with the backing file's minimum DIO
+ * alignment (STATX_DIOALIGN when reported by the filesystem, or the
+ * backing block device's logical block size otherwise).
*/
backing_file_path = tst_tmpdir_genpath("test.img");
tst_find_backing_dev(backing_file_path, bd_path, sizeof(bd_path));
@@ -129,8 +133,27 @@ static void setup(void)
SAFE_IOCTL(block_devfd, BLKSSZGET, &logical_block_size);
tst_res(TINFO, "backing dev(%s) logical_block_size is %d", bd_path, logical_block_size);
SAFE_CLOSE(block_devfd);
- if (logical_block_size > 512)
- TST_RETRY_FUNC(ioctl(dev_fd, LOOP_SET_BLOCK_SIZE, logical_block_size), TST_RETVAL_EQ0);
+
+ memset(&stx, 0, sizeof(stx));
+ if (!statx(AT_FDCWD, "test.img", 0, STATX_DIOALIGN, &stx.buff) &&
+ (stx.data.stx_mask & STATX_DIOALIGN) &&
+ stx.data.stx_dio_mem_align && stx.data.stx_dio_offset_align) {
+ tst_res(TINFO, "backing file stx_dio_offset_align is %u",
+ stx.data.stx_dio_offset_align);
+ if (logical_block_size < 0 ||
+ stx.data.stx_dio_offset_align > (uint32_t)logical_block_size)
+ logical_block_size = stx.data.stx_dio_offset_align;
+ }
+
+ if (logical_block_size > 512 &&
+ TST_RETRY_FUNC(ioctl(dev_fd, LOOP_SET_BLOCK_SIZE, logical_block_size),
+ TST_RETVAL_EQ0)) {
+ if (errno == EINVAL)
+ tst_brk(TCONF, "LOOP_SET_BLOCK_SIZE(%d) not supported",
+ logical_block_size);
+ tst_brk(TBROK | TERRNO, "LOOP_SET_BLOCK_SIZE(%d) failed",
+ logical_block_size);
+ }
}
static void cleanup(void)
--
2.56.1.915.g69d5ec7298-goog
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-05 19:38 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-05 13:37 [LTP] [PATCH] ioctl_loop05: Account for backing file STATX_DIOALIGN Wake Liu via ltp
2026-12-05 19:37 ` [LTP] " linuxtestproject.agent
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.