Received: from eggs.gnu.org ([2001:4830:134:3::10]:54898) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8knc-0006iD-4O for qemu-devel@nongnu.org; Fri, 03 Jun 2016 04:49:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b8kna-0001qH-14 for qemu-devel@nongnu.org; Fri, 03 Jun 2016 04:49:47 -0400 From: Fam Zheng Date: Fri, 3 Jun 2016 16:48:57 +0800 Message-Id: <1464943756-14143-4-git-send-email-famz@redhat.com> In-Reply-To: <1464943756-14143-1-git-send-email-famz@redhat.com> References: <1464943756-14143-1-git-send-email-famz@redhat.com> Subject: [Qemu-devel] [PATCH v6 03/22] blockdev: Add and parse "lock-mode" option for image locking 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 Respect the locking mode from CLI or QMP, and set the open flags accordingly. Signed-off-by: Fam Zheng Reviewed-by: Max Reitz --- 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