Re: [PATCH v3] selftests/mm: skip hugetlb_dio tests when DIO alignment is incompatible

Li Wang
2026-03-30T11:35:57Z

> > int main(void)
> > {
> > ...
> > fd = open("/tmp", O_TMPFILE | O_RDWR | O_DIRECT, 0664);
> > if (fd < 0)
> > ksft_exit_skip("Unable to allocate file: %s\n", strerror(errno));
> >
> > if (get_dio_alignment(fd) < 0)
>
> I would suggest that you query the alignment only once, and forward it
> to the test.

Sure thing, I declare a global variable 'dio_offset_align' to get the value
only once via get_dio_alignment(fd).

(sorry for not posting in the above email)

static unsigned int dio_offset_align;

static int get_dio_alignment(int fd)
{
struct statx stx;
int ret;

ret = syscall(__NR_statx, fd, "", AT_EMPTY_PATH, STATX_DIOALIGN, &stx);
if (ret < 0)
return -1;

if (!(stx.stx_mask & STATX_DIOALIGN) || !stx.stx_dio_offset_align)
dio_offset_align = 1;
else
dio_offset_align = stx.stx_dio_offset_align;

return 0;
}

--
Regards,
Li Wang