On 3/30/26 12:10, Li Wang wrote:
>>> Why can't we simply open the file once and pass the fd to
>>> run_dio_using_hugetlb()?
>>>
>>> fd = open("/tmp", O_TMPFILE | O_RDWR | O_DIRECT, 0664);
>>> if (fd < 0)
>>> ksft_exit_skip("Unable to allocate file: %s\n", strerror(errno));
>>> dio_align = get_dio_alignment(fd);
>>> if (dio_align <= 0)
>>> ksft_exit_skip("Unable to obtain DIO alignment: %s\n", strerror(errno));
>>
>> Yes, apparently this is a good suggestion. Thanks!
>
> And, to make the test elegant, I'm going to add check_dio_alignment()
> dedicated
> to alignment checking. Then we don't need to pass too many args.
>
> Tell me your thoughts if you don't like this:
>
> static int get_dio_alignment(int fd)
> {...}
>
> static bool check_dio_alignment(unsigned int start_off, unsigned int
> end_off)
> {...}
>
> static void run_test(int fd, unsigned int start_off, unsigned int end_off)
> {
> if (!check_dio_alignment(start_off, end_off))
> return;
>
> run_dio_using_hugetlb(fd, start_off, end_off);
> }
>
> 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.
--
Cheers,
David