> From: Fam Zheng [mailto:f...@redhat.com] > Sent: Wednesday, 19 July 2017 23:53 > > On Tue, 07/18 16:19, Andrew Baumann wrote: > > > From: Eric Blake [mailto:ebl...@redhat.com] > > > Sent: Tuesday, 18 July 2017 8:07 > > > On 07/17/2017 07:33 PM, John Snow wrote: > > > > On 07/17/2017 07:30 PM, Andrew Baumann via Qemu-devel wrote: > > > >> I'm running a recent Linux build of qemu on Windows Subsystem for > Linux > > > (WSL) which doesn't appear to implement file locking: > > > >> > > > >> $ qemu-system-aarch64 ... -drive file=test.vhdx,if=none,id=hd0 - > device > > > virtio-blk-pci,drive=hd0 > > > >> qemu-system-aarch64: -drive file=test.vhdx,if=none,id=hd0: Failed to > > > unlock byte 100 > > > > > > Does WSL implement fcntl(F_SETLK) but not fcntl(F_OFD_SETLK)? > > > > Yes, this appears to be the case (there's also one report that it's broken): > > https://github.com/Microsoft/BashOnWindows/issues/1927 > > What does fcntl(F_OFD_SETLK) return? If it is -ENOTSUP, we can probably > detect > that and disable locking. Can you try the patch pasted in the end?
It returns -EINVAL. Your patch works, if I change the error code. Maybe testing for either ENOTSUP or EINVAL, and only allowing the fallback if the user didn't force locking on, would be a reasonable compromise? Cheers, Andrew > --- > > diff --git a/block/file-posix.c b/block/file-posix.c > index cfbb236f6f..0be5bbbd53 100644 > --- a/block/file-posix.c > +++ b/block/file-posix.c > @@ -493,6 +493,12 @@ static int raw_open_common(BlockDriverState *bs, > QDict *options, > } > s->fd = fd; > > + if (s->use_lock) { > + int ret0 = qemu_unlock_fd(fd, 0, 0); > + if (ret0 == -ENOTSUP) { > + s->use_lock = false; > + } > + } > s->lock_fd = -1; > if (s->use_lock) { > fd = qemu_open(filename, s->open_flags);