libaio with O_DIRECT doesn't seem to work
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
libaio (Ubuntu) |
Invalid
|
Undecided
|
Unassigned |
Bug Description
My system:
$ uname -a
Linux blackhole 3.2.0-53-generic #81-Ubuntu SMP Thu Aug 22 21:01:03 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
Problem: The following program which uses libaio doesn't work - No errors but no data is read. Exactly same program works if I just remove the O_DIRECT flag while opening the file.
#define _GNU_SOURCE /* syscall() is not POSIX */
#include <stdio.h> /* for perror() */
#include <unistd.h> /* for syscall() */
#include <libaio.h> /* for AIO types and constants */
#include <fcntl.h> /* O_RDWR */
#include <string.h> /* memset() */
#include <inttypes.h> /* uint64_t */
int main()
{
struct iocb cb;
struct iocb *cbs[1];
struct io_event events[1];
int fd;
char *data;
fd = open("/
ctx = 0;
cbs[0] = &cb;
printf("Got Events : %d\n", io_getevents(ctx, 1, 1, events, NULL));
return 0;
}
Results:
$ ./a.out
Setup : 0
Aligned : 0
Submitted : 1
Got Events : 1
-22
Destroyed : 0
Looks like i was doing something stupid, the aligned size apparently needs to be a multiple of block size.