O_DIRECT for block device
I have a scsi hdd configured at /dev/sdb.
open("/dev/sdb", O_DIRECT) succeeds.
A 'read' or 'write' returns -1 and errno is EINVAL.
How to read and write data to it? They do not seem to work. I have a 262144 byte buffer for data transfer.
My kernel is 2.6.9-11 and I use RedHat Enterprise Linux.
Quoted 6 lines · Karthik Sarangan
I have a scsi hdd configured at
/dev/sdb.
open("/dev/sdb", O_DIRECT)succeeds.
A 'read' or 'write' returns -1 and errno is EINVAL.How to read and write data to it? They do not seem to work. I have a 262144 byte buffer for data transfer.
make sure your buffer is aligned on a 512 byte boundary.
Quoted 2 lines · Karthik Sarangan
open("/dev/sdb", O_DIRECT)succeeds.
A 'read' or 'write' returns -1 and errno is EINVAL.
You must align your buffer to at least sector size. Seeposix_memalign(3).
Signature · 9 lines
Life's Little Instruction Book #30 "Never buy a house without a fireplace." Joel Becker Principal Software Developer Oracle E-mail: [email protected] Phone: (650) 506-8127
Quoted 9 lines · Joel Becker
Quoted 1 line · Karthik Sarangan
I tried your tip and the read works beautifully but the write returns -1 and errno = EBADF!
Did you open with
O_RDWR?Joel
Alright I didn't, though using O_DIRECT | O_RDWR the second time solved it :-) I finally got 69MBps read and 49 MBps writes on my SCSI disk.
Thanks for helping me out.