0

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?

tshepang
  • 12,111
  • 21
  • 91
  • 136
coanor
  • 3,746
  • 4
  • 50
  • 67

1 Answers1

2

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.

Arvid
  • 10,915
  • 1
  • 32
  • 40
  • Yep. It's probably the file system. – Mike Andrews Oct 18 '12 at 12:39
  • I have test the code in CentOS, it works well, the only difference is it's `block size` is 1024. But while I change the alignment to 512 or 256, the code still works well. I'll do some more research on that issue. – coanor Oct 18 '12 at 18:03
  • It may be more a case of the type of your filesystem and your kernel version. Is it an ext4 filesystem on CentOS 6? – Mike Andrews Oct 19 '12 at 15:08
  • My origin test(the fail test) is build on Mint, it's a Ubuntu-kernel Linux release. By using `df -T`, I find it's file system is `ext4`, is direct I/O can not work on Ext4? – coanor Oct 23 '12 at 17:27