Respect the locking mode from CLI or QMP, and set the open flags accordingly.
Signed-off-by: Fam Zheng <f...@redhat.com> --- blockdev.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/blockdev.c b/blockdev.c index 1892b8e..0784c4a 100644 --- a/blockdev.c +++ b/blockdev.c @@ -356,6 +356,7 @@ static void extract_common_blockdev_options(QemuOpts *opts, int *bdrv_flags, const char *discard; Error *local_error = NULL; const char *aio; + const char *lock_mode; if (bdrv_flags) { if (!qemu_opt_get_bool(opts, "read-only", false)) { @@ -382,6 +383,18 @@ static void extract_common_blockdev_options(QemuOpts *opts, int *bdrv_flags, return; } } + + lock_mode = qemu_opt_get(opts, "lock-mode") ? : "off"; + if (!strcmp(lock_mode, "exclusive")) { + /* Default */ + } else if (!strcmp(lock_mode, "shared")) { + *bdrv_flags |= BDRV_O_SHARED_LOCK; + } else if (!strcmp(lock_mode, "off")) { + *bdrv_flags |= BDRV_O_NO_LOCK; + } else { + error_setg(errp, "invalid lock mode"); + return; + } } /* disk I/O throttling */ @@ -4304,6 +4317,11 @@ QemuOptsList qemu_common_drive_opts = { .type = QEMU_OPT_BOOL, .help = "whether to account for failed I/O operations " "in the statistics", + },{ + .name = "lock-mode", + .type = QEMU_OPT_STRING, + .help = "how to lock the image (exclusive, shared, off. " + "default: exclusive)", }, { /* end of list */ } }, @@ -4333,6 +4351,11 @@ static QemuOptsList qemu_root_bds_opts = { .name = "detect-zeroes", .type = QEMU_OPT_STRING, .help = "try to optimize zero writes (off, on, unmap)", + },{ + .name = "lock-mode", + .type = QEMU_OPT_STRING, + .help = "how to lock the image (exclusive, shared, off. " + "default: exclusive)", }, { /* end of list */ } }, -- 2.8.2