From patchwork Thu Jul 20 06:53:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 791441 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xCl732J76z9s1h for ; Thu, 20 Jul 2017 16:56:31 +1000 (AEST) Received: from localhost ([::1]:36344 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dY5Ns-0007Vo-Ru for incoming@patchwork.ozlabs.org; Thu, 20 Jul 2017 02:56:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41456) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dY5L3-0004l9-Rl for qemu-devel@nongnu.org; Thu, 20 Jul 2017 02:53:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dY5L0-0005Y6-Pk for qemu-devel@nongnu.org; Thu, 20 Jul 2017 02:53:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55148) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dY5L0-0005Xs-Gd for qemu-devel@nongnu.org; Thu, 20 Jul 2017 02:53:30 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 63A504A71A; Thu, 20 Jul 2017 06:53:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 63A504A71A Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=famz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 63A504A71A Received: from localhost (ovpn-12-136.pek2.redhat.com [10.72.12.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8239A8206F; Thu, 20 Jul 2017 06:53:25 +0000 (UTC) Date: Thu, 20 Jul 2017 14:53:24 +0800 From: Fam Zheng To: Andrew Baumann Message-ID: <20170720065324.GH11032@lemon> References: <1263c0a6-263f-0b3b-c84a-f882df33856b@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.8.3 (2017-05-23) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 20 Jul 2017 06:53:29 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: Re: [Qemu-devel] Disable image locking for snapshot drive? X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: John Snow , "qemu-devel@nongnu.org" Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" On Tue, 07/18 16:19, Andrew Baumann wrote: > > From: Eric Blake [mailto:eblake@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? > > > We > > already have code in place for compiling when F_OFD_SETLK is not > > supported (which makes lock=auto do nothing, and issues a warning that > > F_SETLK locks may be ineffective when locks are explicitly requested), > > do we need to just expand that code into a runtime test of whether > > F_OFD_SETLK appears to be unsupported? > > That would be a nice fix, and it would avoid the need for yet another flag. On > the other hand, WSL is aiming for ABI compatibility, so they should get around > to implementing F_OFD_SETLK et al eventually. > > Even if this were fixed in QEMU or implemented in WSL, shouldn't there to be a > way to turn snapshot file locking off on a per-drive basis? A snapshot file is temporary and unlinked immediately, so applying a lock or not doesn't matter that much to deserve an option for that. 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);