[Linux-cluster] directio problem

Daniel McNeil daniel at osdl.org
Tue Nov 2 16:30:24 UTC 2004


On Mon, 2004-11-01 at 21:30, 孙俊伟 wrote:
> Hi,all
> 	When the GFS's version was 6.0,its documents said that GFS supported directio。
> But now is 6.1pre2 or 6.1pre3 with Linux kernel 2.6.8.1 or 2.6.9, does it support too?
> I've tried some tests, the result showed negative. My test program has the lines as follow:
> 
> #define _GNU_SOURCE 1 //for the tag O_DIRECT.
> fd=open(argv[1], O_RDONLY|O_DIRECT);
> if(fd<0) {
> 		perror("open");
> 		return -1;
> 	}
> readed=read(fd, buf, block_size);
> if(readed<=0) {
> 			perror("read");
> 			break;
> 		}
> close(fd);
> 
> the result is "1. fd=3,valid. 2.read return: Invalid argument"
> I've run the same program on ext3 and gfs filesystem, the result is the same.
> 
> So what's the problem, the kernel 2.6 does not support, or some kernel config problem? 
> 
> Another problem: 
> Do I need to (or must) update GFS from 6.1pre2 with 2.6.8.1 to 6.1pre3 with 2.6.9?
> I see the cvs log "Lock_dlm and lock_gulm are broken ..."
> 
> Thanks for any reply! Best regards!
> 

Direct IO requires the buffer address be aligned and the size
of the i/o needs to be a multiple of 512.

This worked for me on GFS (and ext3).

#define _GNU_SOURCE 1 //for the tag O_DIRECT.
#include <fcntl.h>
#include <malloc.h>
 
main(int argc, char **argv)
{
        int fd;
        int readed;
        char *buf;
        int block_size = 4096;
 
        buf = memalign(512, 4096);
        fd=open(argv[1], O_RDONLY|O_DIRECT);
        if(fd<0) {
                perror("open");
                return -1;
        }
        readed=read(fd, buf, block_size);
        if(readed<=0) {
                        perror("read");
        }
        close(fd);
}







More information about the Linux-cluster mailing list