Re: [Qemu-devel] [PATCH V2] Add -f option to qemu-nbd

2011-11-22 Thread Paolo Bonzini
On 11/23/2011 07:51 AM, Chun Yan Liu wrote: According to above code logic, if lock in an early place is not accepted, then removing CLEAR_SOCK in nbd_init phase can also solve problem. In fact, if cleanup work done well, I think that ioctl is not needed. Any comments? I think you're right. In

Re: [Qemu-devel] [PATCH V2] Add -f option to qemu-nbd

2011-11-22 Thread Chun Yan Liu
I've had a look at nbd driver code and viewed the trace log, and get clear about why the previously mentioned problem happens: 1st time: qemu-nbd -c /dev/nbd0 disk.img nbd_init: send these ioctl(s) in order, SET_BLKSIZE, SET_SIZE, CLEAR_SOCK, SET_SOCK nbd_clinet: NBD_DO_IT (it will then handl

Re: [Qemu-devel] [PATCH V2] Add -f option to qemu-nbd

2011-11-18 Thread Paolo Bonzini
On 11/18/2011 02:25 AM, Chun Yan Liu wrote: Yes. I have tested using same device twice as described in my previous mail. Without lock: If issuing "qemu-nbd -c /dev/nbd0 disk.img" and "qemu-nbd -c /dev/nbd0 disk1.img" almost at the same time, both can pass nbd_init() and get to nbd_client(), the

Re: [Qemu-devel] [PATCH V2] Add -f option to qemu-nbd

2011-11-17 Thread Chun Yan Liu
Yes. I have tested using same device twice as described in my previous mail. Without lock: If issuing "qemu-nbd -c /dev/nbd0 disk.img" and "qemu-nbd -c /dev/nbd0 disk1.img" almost at the same time, both can pass nbd_init() and get to nbd_client(), then the latter one will fail and exit, but t

Re: [Qemu-devel] [PATCH V2] Add -f option to qemu-nbd

2011-11-17 Thread Stefan Hajnoczi
On Thu, Nov 17, 2011 at 1:41 PM, Paolo Bonzini wrote: > On 11/17/2011 12:36 PM, Chunyan Liu wrote: >> >> Adding lock to the nbd device before connecting disk image to that device >> to >> handling race conditions. > > This removes the possibility for other programs to lock.  Have you checked > wha

Re: [Qemu-devel] [PATCH V2] Add -f option to qemu-nbd

2011-11-17 Thread Paolo Bonzini
On 11/17/2011 12:36 PM, Chunyan Liu wrote: Adding lock to the nbd device before connecting disk image to that device to handling race conditions. This removes the possibility for other programs to lock. Have you checked what happens if you use the same device twice and whether you can piggy

[Qemu-devel] [PATCH V2] Add -f option to qemu-nbd

2011-11-17 Thread Chunyan Liu
Adding -f option to qemu-nbd to support finding a free nbd device and connect disk image to that device. Usage of this option is similar to "losetup -f". #qemu-nbd -f show the first free nbd device found at the very moment. #qemu-nbd -f disk.img find a free nbd device and connect disk.img to that d