Skip to contentSkip to conversation

O_DIRECT write to file by block-aligned, block-multiple buf fails?

DISCUSSION Scott McDermott 3 participants 4 messages May 15, 2003

lore
Share & tools
lore
#0 lore raw

I thought based on searching the archives that 2.4 O_DIRECT requires fs block size alignment of the buffer, and that the buffer is an exact multiple of block size. This should mean I can write aligned pages with direct IO, right?

        int
        main (void)
        {
                char *buf;
                int fd;

                buf = memalign(getpagesize(), getpagesize());
                fd = open("/tmp/testfile", O_TRUNC|O_WRONLY|O_DIRECT);
                if (write(fd, buf, getpagesize()) == -1)
                        perror("write");
        }

        $ ./test
        write: Invalid argument

        $ grep /tmp /proc/mounts
        /dev/hda5 /mnt/tmp ext3 rw 0 0

        $ sudo dumpe2fs /dev/hda5 | grep Block\ size
        dumpe2fs 1.27 (8-Mar-2002)
        Block size:               4096

        $ uname -rm
        2.4.21-pre4-ac1 i686

what silly thing am I not understanding here?

#2 lore raw

Andreas Dilger on Thu 15/05 00:04 -0600:

Quoted 10 lines · Scott McDermott
Quoted 7 lines

This should mean I can write aligned pages with direct IO, right?

write: Invalid argument

$ grep /tmp /proc/mounts
/dev/hda5 /mnt/tmp ext3 rw 0 0

ext3 does not support O_DIRECT in 2.4 yet.

should open() on an ext3-based file fail when O_DIRECT is among the flags?

#3 lore raw
In reply to Andreas Dilger
Quoted 11 lines · Andreas Dilger
Quoted 6 lines · Scott McDermott

This should mean I can write aligned pages with direct IO, right?

write: Invalid argument

$ grep /tmp /proc/mounts
/dev/hda5 /mnt/tmp ext3 rw 0 0

ext3 does not support O_DIRECT in 2.4 yet.

It does if you apply

ftp://ftp.kernel.org/pub/linux/kernel/people/andrea/kernels/v2.4/2.4.21rc2aa1/10_ext3-o_direct-2