[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v6 03/22] blockdev: Add and parse "lock-mode" option
From: |
Fam Zheng |
Subject: |
[Qemu-devel] [PATCH v6 03/22] blockdev: Add and parse "lock-mode" option for image locking |
Date: |
Fri, 3 Jun 2016 16:48:57 +0800 |
Respect the locking mode from CLI or QMP, and set the open flags
accordingly.
Signed-off-by: Fam Zheng <address@hidden>
Reviewed-by: Max Reitz <address@hidden>
---
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
- Re: [Qemu-devel] [PATCH v6 02/22] qapi: Add lock-mode in blockdev-add options, (continued)
[Qemu-devel] [PATCH v6 04/22] block: Introduce image file locking, Fam Zheng, 2016/06/03
[Qemu-devel] [PATCH v6 03/22] blockdev: Add and parse "lock-mode" option for image locking,
Fam Zheng <=
[Qemu-devel] [PATCH v6 01/22] block: Add flag bits for image locking, Fam Zheng, 2016/06/03
[Qemu-devel] [PATCH v6 05/22] osdep: Add qemu_lock_fd and qemu_unlock_fd, Fam Zheng, 2016/06/03
[Qemu-devel] [PATCH v6 07/22] raw-posix: Use qemu_dup, Fam Zheng, 2016/06/03
[Qemu-devel] [PATCH v6 09/22] qemu-io: Add "-L" option for BDRV_O_NO_LOCK, Fam Zheng, 2016/06/03