Respect the locking mode from CLI or QMP, and set the open flags accordingly.
Signed-off-by: Fam Zheng <f...@redhat.com> Reviewed-by: Max Reitz <mre...@redhat.com> --- blockdev.c | 23 +++++++++++++++++++++++ qemu-options.hx | 1 + 2 files changed, 24 insertions(+) diff --git a/blockdev.c b/blockdev.c index 717785e..5acb286 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 */ @@ -4296,6 +4309,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 */ } }, @@ -4325,6 +4343,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 */ } }, diff --git a/qemu-options.hx b/qemu-options.hx index 6106520..731cdda 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -524,6 +524,7 @@ DEF("drive", HAS_ARG, QEMU_OPTION_drive, " [,werror=ignore|stop|report|enospc][,id=name][,aio=threads|native]\n" " [,readonly=on|off][,copy-on-read=on|off]\n" " [,discard=ignore|unmap][,detect-zeroes=on|off|unmap]\n" + " [,lock-mode=exclusive|shared|off]\n" " [[,bps=b]|[[,bps_rd=r][,bps_wr=w]]]\n" " [[,iops=i]|[[,iops_rd=r][,iops_wr=w]]]\n" " [[,bps_max=bm]|[[,bps_rd_max=rm][,bps_wr_max=wm]]]\n" -- 2.8.2