[prev in list] [next in list] [prev in thread] [next in thread]
List: linux-aio
Subject: AIO O_DIRECT read bug on last block.
From: Drangon Zhou <drangon.zhou () gmail ! com>
Date: 2005-07-29 11:22:09
Message-ID: 1305ed680507290422675dbb8 () mail ! gmail ! com
[Download message RAW]
Hi,
I use linux AIO with O_DIRECT to read a file, when I read the last block,
it doesn't return the actual size, but return some size that 512 byte align.
for example, I have a file a.txt, size is 300 bytes, if I use normal read(),
it return 300, this is ok, if I use io_submit() and io_getevents(), it
return 512,
Is this a bug ??
-----------------------------
int main( int argc, char * argv[] )
{
char * buffer;
int ret;
int fd = open( "a.txt", O_RDONLY | O_DIRECT );
posix_memalign( &buffer, 4096, 4096 );
// <1> use normal disk read, this is ok
ret = read( fd, buffer, 4096 );
printf( "ret = %d\n", ret ); // ret = 300, this ok.
// <2> use AIO disk read, it seems error.
struct iocb myiocb;
struct iocb * cb = &myiocb;
memset( &myiocb, 0, sizeof(myiocb) );
cb->data = 0;
cb->key = 0;
cb->aio_lio_opcode = IO_CMD_PREAD;
cb->aio_reqprio = 0;
cb->aio_fildes = fd;
cb->u.c.buf = buffer;
cb->u.c.nbytes = 4096;
cb->u.c.offset = 0;
int num = 0;
struct io_event ie;
struct timespec ts = {0,0};
ret = io_submit( ioctx, 1, &cb );
// a foolish loop, only to see if this is really an AIO,
while( ++num ) {
ret = io_getevents( ioctx, 1, 1, &ie, &ts );
if( ret == 1 )
break;
}
printf( "ret %ld, ie.res ); // it return 512 ?? bug ?? should be 300
}
--
To unsubscribe, send a message with 'unsubscribe linux-aio' in
the body to majordomo@kvack.org. For more info on Linux AIO,
see: http://www.kvack.org/aio/
Don't email: <a href=mailto:"aart@kvack.org">aart@kvack.org</a>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic