From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51468) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bWkNk-0004dk-PV for qemu-devel@nongnu.org; Mon, 08 Aug 2016 09:14:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bWkNj-0005oi-K6 for qemu-devel@nongnu.org; Mon, 08 Aug 2016 09:14:16 -0400 From: Fam Zheng Date: Mon, 8 Aug 2016 21:13:20 +0800 Message-Id: <1470662013-19785-8-git-send-email-famz@redhat.com> In-Reply-To: <1470662013-19785-1-git-send-email-famz@redhat.com> References: <1470662013-19785-1-git-send-email-famz@redhat.com> Subject: [Qemu-devel] [PATCH v7 07/20] qemu-io: Add "-L" option for BDRV_O_NO_LOCK List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , qemu-block@nongnu.org, rjones@redhat.com, John Snow , Jeff Cody , Markus Armbruster , Max Reitz , stefanha@redhat.com, den@openvz.org, pbonzini@redhat.com, berrange@redhat.com Signed-off-by: Fam Zheng --- qemu-io.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/qemu-io.c b/qemu-io.c index db129ea..5c14eba 100644 --- a/qemu-io.c +++ b/qemu-io.c @@ -108,6 +108,7 @@ static void open_help(void) " -r, -- open file read-only\n" " -s, -- use snapshot file\n" " -n, -- disable host cache, short for -t none\n" +" -L, -- disable image locking\n" " -k, -- use kernel AIO implementation (on Linux only)\n" " -t, -- use the given cache mode for the image\n" " -d, -- use the given discard mode for the image\n" @@ -124,7 +125,7 @@ static const cmdinfo_t open_cmd = { .argmin = 1, .argmax = -1, .flags = CMD_NOFILE_OK, - .args = "[-rsnk] [-t cache] [-d discard] [-o options] [path]", + .args = "[-rsnLk] [-t cache] [-d discard] [-o options] [path]", .oneline = "open the file specified by path", .help = open_help, }; @@ -143,12 +144,13 @@ static int open_f(BlockBackend *blk, int argc, char **argv) { int flags = BDRV_O_UNMAP; int readonly = 0; + bool nolock = false; bool writethrough = true; int c; QemuOpts *qopts; QDict *opts; - while ((c = getopt(argc, argv, "snro:kt:d:")) != -1) { + while ((c = getopt(argc, argv, "snrLo:kt:d:")) != -1) { switch (c) { case 's': flags |= BDRV_O_SNAPSHOT; @@ -177,6 +179,9 @@ static int open_f(BlockBackend *blk, int argc, char **argv) return 0; } break; + case 'L': + nolock = true; + break; case 'o': if (imageOpts) { printf("--image-opts and 'open -o' are mutually exclusive\n"); @@ -198,6 +203,10 @@ static int open_f(BlockBackend *blk, int argc, char **argv) flags |= BDRV_O_RDWR; } + if (nolock) { + flags |= BDRV_O_NO_LOCK; + } + if (imageOpts && (optind == argc - 1)) { if (!qemu_opts_parse_noisily(&empty_opts, argv[optind], false)) { qemu_opts_reset(&empty_opts); @@ -436,13 +445,15 @@ static QemuOptsList file_opts = { int main(int argc, char **argv) { int readonly = 0; - const char *sopt = "hVc:d:f:rsnmkt:T:"; + const char *sopt = "hVc:d:f:rLsnmkt:T:"; + bool nolock = false; const struct option lopt[] = { { "help", no_argument, NULL, 'h' }, { "version", no_argument, NULL, 'V' }, { "cmd", required_argument, NULL, 'c' }, { "format", required_argument, NULL, 'f' }, { "read-only", no_argument, NULL, 'r' }, + { "no-lock", no_argument, NULL, 'L' }, { "snapshot", no_argument, NULL, 's' }, { "nocache", no_argument, NULL, 'n' }, { "misalign", no_argument, NULL, 'm' }, @@ -501,6 +512,9 @@ int main(int argc, char **argv) case 'r': readonly = 1; break; + case 'L': + nolock = true; + break; case 'm': qemuio_misalign = true; break; @@ -586,6 +600,10 @@ int main(int argc, char **argv) flags |= BDRV_O_RDWR; } + if (nolock) { + flags |= BDRV_O_NO_LOCK; + } + if ((argc - optind) == 1) { if (imageOpts) { QemuOpts *qopts = NULL; -- 2.7.4