From: jake wires Subject: Re: a problem from blktap? Date: Tue, 7 Jul 2009 09:49:08 -0700 Message-ID: <9f1df9e20907070949w1d2918ebmeab40a7d86a7fd8f@mail.gmail.com> References: <200907071719004656785@126.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0849475092==" Return-path: In-Reply-To: <200907071719004656785@126.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: =?GB2312?B?t7+6o7fl?= Cc: xen-devel , fanghaifeng List-Id: xen-devel@lists.xenproject.org --===============0849475092== Content-Type: multipart/alternative; boundary=0016361e8448bc6603046e206660 --0016361e8448bc6603046e206660 Content-Type: text/plain; charset=GB2312 Content-Transfer-Encoding: quoted-printable hi, when you use O_DIRECT, buffers passed to read/write calls must be sector-aligned. posix_memalign() will give you what you want. jake 2009/7/7 =B7=BF=BA=A3=B7=E5 > hi all, > > currently, i am debuging the code derived from block-sync.c, the detail a= s > follow: > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > > struct socket_message_header *msg_hdr; > > struct socketmsg_sync_read * msg_body; > > > > int msglen, size; > > char * msgbuf =3D msg; > > int ret =3D 0; > > uint64_t offset; > > > > char * iobuf =3D NULL; > > > > msg_hdr =3D (struct socket_message_header *)msgbuf; > > msg_body =3D (struct socketmsg_sync_read *)(msgbuf + sizeof(struc= t socket_message_header)); > > msglen =3D msg_hdr->len; > > > size =3D msg_body->nb_sectors * msg_body-sector_size; > > offset =3D msg_body->sector * (uint64_t)msg_body->sector_size; > > > > MY_DPRINTF("READ: nb_sectors =3D %d, sector_size =3D %d, start_se= ctor =3D %llu", > > msg_body->nb_sectors, > > msg_body->sector_size, > > msg_body->sector); > > > > //iobuf =3D calloc(size, sizeof(char)); > > iobuf =3D malloc(size); > > if (!iobuf) > > goto failure; > > MY_DPRINTF("IO Buffer memory calloc is ok!"); > > > > ret =3D lseek(image_fd, offset, SEEK_SET); > > if (ret !=3D (off_t)-1) { > > > > MY_DPRINTF("after lseek, the position is at %lu", (unsign= ed long) ret); > > MY_DPRINTF("image_fd =3D %d, iobuf =3D %p, size =3D %d", = image_fd, iobuf, size); > > > > ret =3D readn(image_fd, (void*)iobuf, (size_t)size); > > if (ret < 0) { > > MY_DPRINTF("readn(%s) is error!", strerror(errno)= ); > > goto failure; > > } > > else > > { > > MY_DPRINTF("readn() is end, and has read = [%d] data!", ret); > > } > > } else > > { > > MY_DPRINTF("lseek is error(%s)", strerror(errno)); > > goto failure; > > } > > MY_DPRINTF("Seek and Read image is ok!"); > > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D > the debuging output, which cut from /var/log/message, are as follow: > > > Jul 7 16:45:07 domain0 remote-blktapctrl[3963]: [hook_new_tapdisk(712)] = loop for select(4)............ > > Jul 7 16:45:11 domain0 remote-blktapctrl[3963]: [hook_new_tapdisk(715)] = select() is end, and ret =3D 1 > > Jul 7 16:45:11 domain0 remote-blktapctrl[3963]: [hook_new_tapdisk(720)] = enter hook_read_message(). > > Jul 7 16:45:11 domain0 remote-blktapctrl[3963]: [hook_read_message(632)]= read() is end, and msglen=3D32 > > Jul 7 16:45:11 domain0 remote-blktapctrl[3963]: [hook_read_message(651)]= receive SOCK_MSG_READ message. > > Jul 7 16:45:11 domain0 remote-blktapctrl[3963]: [hook_do_read(502)] READ= : nb_sectors =3D 2, sector_size =3D 512, start_sector =3D 2 > > Jul 7 16:45:11 domain0 remote-blktapctrl[3963]: [hook_do_read(508)] IO B= uffer memory calloc is ok! > > Jul 7 16:45:11 domain0 remote-blktapctrl[3963]: [hook_do_read(513)] afte= r lseek, the position is at 1024 > > Jul 7 16:45:11 domain0 remote-blktapctrl[3963]: [hook_do_read(514)] imag= e_fd =3D 6, iobuf =3D 0x804f388, size =3D 1024 > > Jul 7 16:45:11 domain0 remote-blktapctrl[3963]: [readn(66)] call readn(f= d[6], ptr[0x804f388], n[1024]) > > Jul 7 16:45:11 domain0 remote-blktapctrl[3963]: [readn(70)] call read(fd= [6], ptr[0x804f388], nleft[1024]) > > Jul 7 16:45:11 domain0 remote-blktapctrl[3963]: [readn(73)] read is erro= r (Invalid argument) > > Jul 7 16:45:11 domain0 remote-blktapctrl[3963]: [readn(74)] nread =3D -1= , nleft =3D 1024, n =3D 1024 > > Jul 7 16:45:11 domain0 remote-blktapctrl[3963]: [hook_do_read(518)] read= n(Invalid argument) is error! > > Jul 7 16:45:11 domain0 remote-blktapctrl[3963]: [hook_read_message(653)]= hook_do_read() is end, and ret =3D -1 > > Jul 7 16:45:11 domain0 remote-blktapctrl[3963]: [hook_read_message(670)]= do with message is error! > > Jul 7 16:45:11 domain0 remote-blktapctrl[3963]: [hook_new_tapdisk(722)] = out of hook_read_message(). > > Jul 7 16:45:11 domain0 remote-blktapctrl[3963]: [hook_new_tapdisk(712)] = loop for select(5)............ > > Jul 7 16:45:21 domain0 remote-blktapctrl[3963]: [hook_new_tapdisk(715)] = select() is end, and ret =3D 0 > > among the list above, you can find the error message about the "readn" > function. to resovle this problem, i have try some methods, BUT all is > failure. > > varify the mode of opening the file, that is O_RDWR | O_DIRECT | > O_LARGEFILE > > So, who can help me to do with this problem? > > read is error (Invalid argument) ? > > > thanks a lot! > > > 2009-07-07 > ------------------------------ > =B7=BF=BA=A3=B7=E5 > > _______________________________________________ > Xen-devel mailing list > Xen-devel@lists.xensource.com > http://lists.xensource.com/xen-devel > > --0016361e8448bc6603046e206660 Content-Type: text/html; charset=GB2312 Content-Transfer-Encoding: quoted-printable hi,

when you use O_DIRECT, buffers passed to read/write calls must b= e sector-aligned.  posix_memalign() will give you what you want.
jake

2009/7/7 =B7=BF=BA=A3=B7=E5 <fhf25@12= 6.com>
hi all,
 
currently, i am debuging the code derived from block-sync.c, the detai= l as=20 follow:
 
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
        struct socket_mes= sage_header *msg_hdr;        &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;  
        struct socketmsg_= sync_read * msg_body;       &n= bsp;            = ;            &n= bsp;            = ;            &n= bsp;            = ;            &n= bsp;            = ;            &n= bsp;   
           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;       
        int msglen, = size;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;       
        char * msgbu= f =3D msg;         &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;       
        int ret =3D&= nbsp;0;           &n= bsp;            = ;            &n= bsp;            = ;            &n= bsp;            = ;            &n= bsp;            = ;            &n= bsp;            = ;            &n= bsp;
        uint64_t offset;&= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;       
           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;       
        char * iobuf=  =3D NULL;         &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;       
           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;       
        msg_hdr =3D = (struct socket_message_header *)msgbuf;    &n= bsp;            = ;            &n= bsp;            = ;            &n= bsp;            = ;            &n= bsp;            = ;        
        msg_body =3D = ;(struct socketmsg_sync_read *)(msgbuf + sizeof(struct&= nbsp;socket_message_header));       &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;  
        msglen =3D m= sg_hdr->len;          =             &nb= sp;            =             &nb= sp;            =             &nb= sp;            =             &nb= sp;            =             &nb= sp;    
           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;       
        size   =  =3D msg_body->nb_sectors * msg_body-sector_size;
        offset  =3D&= nbsp;msg_body->sector * (uint64_t)msg_body->sector_size;&nb= sp;            =             
           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;       
        MY_DPRINTF("READ:=  nb_sectors =3D %d, sector_size =3D %d, = start_sector =3D %llu",      &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;      
           &nbs= p;    msg_body->nb_sectors,    &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;   
           &nbs= p;    msg_body->sector_size,    =             &nb= sp;            =             &nb= sp;            =             &nb= sp;            =             &nb= sp;            =             &nb= sp;  
           &nbs= p;    msg_body->sector);    &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;     
           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;       
        //iobuf =3D = calloc(size, sizeof(char));       &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;    
        iobuf =3D ma= lloc(size);          &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;    
        if (!iobuf) =             &nb= sp;            =             &nb= sp;            =             &nb= sp;            =             &nb= sp;            =             &nb= sp;            =             
           &nbs= p;    goto failure;     &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;          
        MY_DPRINTF("IO&nb= sp;Buffer memory calloc is ok!");   = ;            &n= bsp;            = ;            &n= bsp;            = ;            &n= bsp;            = ;            &n= bsp;            = ; 
           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;       
        ret =3D lsee= k(image_fd, offset, SEEK_SET);      = ;            &n= bsp;            = ;            &n= bsp;            = ;            &n= bsp;            = ;            &n= bsp;            = ;   
        if (ret !=3D=  (off_t)-1) {        &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;    
           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;       
           &nbs= p;    MY_DPRINTF("after lseek, the = position is at %lu", (unsigned long) ret= );            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;       
           &nbs= p;    MY_DPRINTF("image_fd =3D %d, = iobuf =3D %p, size =3D %d", image_fd,&nb= sp;iobuf, size);         =             &nb= sp;            =             &nb= sp;            =         
           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;       
           &nbs= p;    ret =3D readn(image_fd, (void*)iob= uf, (size_t)size);        &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;       
           &nbs= p;    if (ret < 0) {  =             &nb= sp;            =             &nb= sp;            =             &nb= sp;            =             &nb= sp;            =             &nb= sp;            =
           &nbs= p;            M= Y_DPRINTF("readn(%s) is error!", strerror(errno));=             &nb= sp;            =             &nb= sp;            =             &nb= sp;            =        
           &nbs= p;            g= oto failure;         &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;          
           &nbs= p;    }        =             &nb= sp;            =             &nb= sp;            =             &nb= sp;            =             &nb= sp;            =             &nb= sp;            =        
           &nbs= p;    else       &nb= sp;            =             &nb= sp;            =             &nb= sp;            =             &nb= sp;            =             &nb= sp;            =             &nb= sp;    
           &nbs= p;            {=             &nb= sp;            =             &nb= sp;            =             &nb= sp;            =             &nb= sp;            =             &nb= sp;            =        
           &nbs= p;            &= nbsp;       MY_DPRINTF("readn()&nbs= p;is end, and has read [%d] data!", = ;ret);           &nb= sp;            =             &nb= sp;            =             &nb= sp;    
           &nbs= p;            }=             &nb= sp;            =             &nb= sp;            =             &nb= sp;            =             &nb= sp;            =             &nb= sp;            =        
        } else  = ;            &n= bsp;            = ;            &n= bsp;            = ;            &n= bsp;            = ;            &n= bsp;            = ;            &n= bsp;            = ;            &n= bsp;   
        {   &nb= sp;            =             &nb= sp;            =             &nb= sp;            =             &nb= sp;            =             &nb= sp;            =             &nb= sp;            =        
           &nbs= p;    MY_DPRINTF("lseek is error(%s)&quo= t;, strerror(errno));        &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;       
           &nbs= p;    goto failure;     &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;          
        }   &nb= sp;            =             &nb= sp;            =             &nb= sp;            =             &nb= sp;            =             &nb= sp;            =             &nb= sp;            =        
        MY_DPRINTF("Seek&= nbsp;and Read image is ok!");   &nb= sp;            =             &nb= sp;         
 
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
the debuging output, which cut from /var/log/message, are as follow:
 
Jul  7 16:45:07 domain0 remote-blktapctrl[396= 3]: [hook_new_tapdisk(712)] loop for select(4).........= ...            =             &nb= sp;            =             &nb= sp;    
Jul  7 16:45:11 domain0 remote-blktapctrl[396= 3]: [hook_new_tapdisk(715)] select() is end, and&n= bsp;ret =3D 1        &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;         
Jul  7 16:45:11 domain0 remote-blktapctrl[396= 3]: [hook_new_tapdisk(720)] enter hook_read_message(). =             &nb= sp;            =             &nb= sp;            =        
Jul  7 16:45:11 domain0 remote-blktapctrl[396= 3]: [hook_read_message(632)] read() is end, and&nb= sp;msglen=3D32          &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;       
Jul  7 16:45:11 domain0 remote-blktapctrl[396= 3]: [hook_read_message(651)] receive SOCK_MSG_READ mess= age.            = ;            &n= bsp;            = ;            &n= bsp;   
Jul  7 16:45:11 domain0 remote-blktapctrl[396= 3]: [hook_do_read(502)] READ: nb_sectors =3D 2,&nb= sp;sector_size =3D 512, start_sector =3D 2 &n= bsp;            = ;            &n= bsp;    
Jul  7 16:45:11 domain0 remote-blktapctrl[396= 3]: [hook_do_read(508)] IO Buffer memory calloc&nb= sp;is ok!          &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;          
Jul  7 16:45:11 domain0 remote-blktapctrl[396= 3]: [hook_do_read(513)] after lseek, the position&= nbsp;is at 1024        &n= bsp;            = ;            &n= bsp;            = ;      
Jul  7 16:45:11 domain0 remote-blktapctrl[396= 3]: [hook_do_read(514)] image_fd =3D 6, iobuf = ;=3D 0x804f388, size =3D 1024    &n= bsp;            = ;            &n= bsp;            = ;  
Jul  7 16:45:11 domain0 remote-blktapctrl[396= 3]: [readn(66)] call readn(fd[6], ptr[0x804f388], = n[1024])           &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;     
Jul  7 16:45:11 domain0 remote-blktapctrl[396= 3]: [readn(70)] call read(fd[6], ptr[0x804f388], n= left[1024])          &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;  
Jul  7 16:45:11 domain0 remote-blktapctrl[396= 3]: [readn(73)] read is error (Invalid argume= nt)            =             &nb= sp;            =             &nb= sp;            =   
Jul  7 16:45:11 domain0 remote-blktapctrl[396= 3]: [readn(74)] nread =3D -1, nleft =3D = 1024, n =3D 1024       &n= bsp;            = ;            &n= bsp;            = ;            &n= bsp;    
Jul  7 16:45:11 domain0 remote-blktapctrl[396= 3]: [hook_do_read(518)] readn(Invalid argument) is = ;error!           &n= bsp;            = ;            &n= bsp;            = ;      
Jul  7 16:45:11 domain0 remote-blktapctrl[396= 3]: [hook_read_message(653)] hook_do_read() is end,&nbs= p;and ret =3D -1       &n= bsp;            = ;            &n= bsp;            = ;   
Jul  7 16:45:11 domain0 remote-blktapctrl[396= 3]: [hook_read_message(670)] do with message is&nb= sp;error!           =             &nb= sp;            =             &nb= sp;         
Jul  7 16:45:11 domain0 remote-blktapctrl[396= 3]: [hook_new_tapdisk(722)] out of hook_read_message().=             &nb= sp;            =             &nb= sp;            =        
Jul  7 16:45:11 domain0 remote-blktapctrl[396= 3]: [hook_new_tapdisk(712)] loop for select(5).........= ...            =             &nb= sp;            =             &nb= sp;    
Jul  7 16:45:21 domain0 remote-blktapctrl[396= 3]: [hook_new_tapdisk(715)] select() is end, and&n= bsp;ret =3D 0     
 
among the list above, you can find the error message about the "r= eadn"=20 function. to resovle this problem, i have try some methods, BUT all is=20 failure.
 
varify the mode of opening the file, that is O_RDWR | O_DIRECT |=20 O_LARGEFILE
 
So, who can help me to do with this problem?
 
read is error (Invalid argument) ?
 
 
thanks a lot!
 
 
200= 9-07-07=20

=B7=BF=BA=A3= =B7=E5=20

_______________________________________________
Xen-devel mailing list
Xen-deve= l@lists.xensource.com
http://l= ists.xensource.com/xen-devel


--0016361e8448bc6603046e206660-- --===============0849475092== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --===============0849475092==--