libaio with O_DIRECT doesn't seem to work

Bug #1223400 reported by Amit
6
This bug affects 1 person
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()
{
        io_context_t ctx;
        struct iocb cb;
        struct iocb *cbs[1];
        struct io_event events[1];
        int fd;
        char *data;

        fd = open("/tmp/testfile", O_RDONLY | O_CREAT | O_DIRECT);

        ctx = 0;
        printf("Setup : %d\n", io_setup(128, &ctx));

        printf("Aligned : %d\n", posix_memalign(&data, 512, 40));
        io_prep_pread(&cb, fd, data, 40, 0);

        cbs[0] = &cb;

        printf("Submitted : %d\n", io_submit(ctx, 1, cbs));

        printf("Got Events : %d\n", io_getevents(ctx, 1, 1, events, NULL));
        printf("%ld\n", events[0].res);
        printf("%s\n", data);

        printf("Destroyed : %d\n", io_destroy(ctx));

        return 0;
}

Results:
$ ./a.out
Setup : 0
Aligned : 0
Submitted : 1
Got Events : 1
-22

Destroyed : 0

Revision history for this message
Amit (amitdev) wrote :

Looks like i was doing something stupid, the aligned size apparently needs to be a multiple of block size.

Changed in libaio (Ubuntu):
status: New → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.