Received: from eggs.gnu.org ([2001:4830:134:3::10]:59583) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1azxn4-00039N-DN for qemu-devel@nongnu.org; Mon, 09 May 2016 22:53:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1azxn3-00050A-1D for qemu-devel@nongnu.org; Mon, 09 May 2016 22:52:54 -0400 From: Fam Zheng Date: Tue, 10 May 2016 10:50:58 +0800 Message-Id: <1462848659-28659-27-git-send-email-famz@redhat.com> In-Reply-To: <1462848659-28659-1-git-send-email-famz@redhat.com> References: <1462848659-28659-1-git-send-email-famz@redhat.com> Subject: [Qemu-devel] [PATCH v4 26/27] block: Turn on image locking by default List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Max Reitz , Jeff Cody , Markus Armbruster , Eric Blake , qemu-block@nongnu.org, rjones@redhat.com, stefanha@redhat.com, pbonzini@redhat.com, John Snow , berrange@redhat.com, den@openvz.org Now that test cases are covered, we can turn it on. RO (shared) lock is disabled to allow existing libguestfs use cases (invoking QEMU for reading image that is exclusively locked by another QEMU). Signed-off-by: Fam Zheng --- block.c | 7 +++++++ blockdev.c | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/block.c b/block.c index 1b3aac4..a490bfe 100644 --- a/block.c +++ b/block.c @@ -972,6 +972,13 @@ static int bdrv_open_common(BlockDriverState *bs, BdrvChild *file, bs->zero_beyond_eof = true; bs->read_only = !(bs->open_flags & BDRV_O_RDWR); + if (bs->read_only) { + /* libguestfs uses us to _read_ images that are rw opened by another + * QEMU, skip locking ro images because the other QEMU may have an + * exclusive lock. */ + bs->open_flags |= BDRV_O_NO_LOCK; + } + if (use_bdrv_whitelist && !bdrv_is_whitelisted(drv, bs->read_only)) { error_setg(errp, !bs->read_only && bdrv_is_whitelisted(drv, true) diff --git a/blockdev.c b/blockdev.c index 9968568..007690b 100644 --- a/blockdev.c +++ b/blockdev.c @@ -383,7 +383,7 @@ static void extract_common_blockdev_options(QemuOpts *opts, int *bdrv_flags, } } - if (!qemu_opt_get_bool(opts, "lock-image", false)) { + if (!qemu_opt_get_bool(opts, "lock-image", true)) { *bdrv_flags |= BDRV_O_NO_LOCK; } } -- 2.8.2