@@ -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)
@@ -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;
}
}
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(-)