Question

I was trying to make a AIO practice via kernel AIO API. Here is some code:

#define _GNU_SOURCE /* syscall() not POSIX */
#define ALIGN_SIZE 4096
#define RD_WR_SIZE 1024

/* ... */

/* Make the alignment according to page size to validate open() */
posix_memalign(&buf, ALIGN_SIZE, RD_WR_SIZE);
fd = open("aio_test_file", O_RDWR | O_CREAT | O_DIRECT, 0644);
if (fd == -1) {
    perror("open");
    return -1;
}
/* ... */

But my open() calling still fail:

open: Invalid argument

I have searched that error. Some of them says that you must make the alignment in the case of direct I/O. By using the command:

$ sudo dumpe2fs /dev/sda1 | grep -i "block size"

I got the block size is 4096. But why the open() calling still fail?

Was it helpful?

Solution

From the man page:

O_DIRECT support was added under Linux in kernel version 2.4.10. Older Linux kernels simply ignore this flag. Some file systems may not implement the flag and open() will fail with EINVAL if it is used.

That would be my first guess.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top