diff mbox

[v4,26/27] block: Turn on image locking by default

Message ID 1462848659-28659-27-git-send-email-famz@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Fam Zheng May 10, 2016, 2:50 a.m. UTC
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 <famz@redhat.com>
---
 block.c    | 7 +++++++
 blockdev.c | 2 +-
 2 files changed, 8 insertions(+), 1 deletion(-)
diff mbox

Patch

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;
         }
     }