From: Fam Zheng <famz@redhat.com>
To: qemu-devel@nongnu.org
Cc: eblake@redhat.com, Kevin Wolf <kwolf@redhat.com>,
Max Reitz <mreitz@redhat.com>,
qemu-block@nongnu.org
Subject: [Qemu-devel] [PATCH v15 07/21] qemu-io: Add --force-share option
Date: Wed, 26 Apr 2017 11:33:59 +0800 [thread overview]
Message-ID: <20170426033413.17192-8-famz@redhat.com> (raw)
In-Reply-To: <20170426033413.17192-1-famz@redhat.com>
Add --force-share/-U to program options and -U to open subcommand.
Signed-off-by: Fam Zheng <famz@redhat.com>
---
qemu-io.c | 42 ++++++++++++++++++++++++++++++++++--------
1 file changed, 34 insertions(+), 8 deletions(-)
diff --git a/qemu-io.c b/qemu-io.c
index 427cbae..cf4b876 100644
--- a/qemu-io.c
+++ b/qemu-io.c
@@ -20,6 +20,7 @@
#include "qemu/readline.h"
#include "qemu/log.h"
#include "qapi/qmp/qstring.h"
+#include "qapi/qmp/qbool.h"
#include "qom/object_interfaces.h"
#include "sysemu/block-backend.h"
#include "block/block_int.h"
@@ -53,7 +54,8 @@ static const cmdinfo_t close_cmd = {
.oneline = "close the current open file",
};
-static int openfile(char *name, int flags, bool writethrough, QDict *opts)
+static int openfile(char *name, int flags, bool writethrough, bool force_share,
+ QDict *opts)
{
Error *local_err = NULL;
BlockDriverState *bs;
@@ -64,6 +66,18 @@ static int openfile(char *name, int flags, bool writethrough, QDict *opts)
return 1;
}
+ if (force_share) {
+ if (!opts) {
+ opts = qdict_new();
+ }
+ if (qdict_haskey(opts, BDRV_OPT_FORCE_SHARE)
+ && !qdict_get_bool(opts, BDRV_OPT_FORCE_SHARE)) {
+ error_report("-U conflicts with image options");
+ QDECREF(opts);
+ return 1;
+ }
+ qdict_put(opts, BDRV_OPT_FORCE_SHARE, qbool_from_bool(true));
+ }
qemuio_blk = blk_new_open(name, NULL, opts, flags, &local_err);
if (!qemuio_blk) {
error_reportf_err(local_err, "can't open%s%s: ",
@@ -108,6 +122,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"
+" -U, -- force shared permissions\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 +139,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 = "[-rsnkU] [-t cache] [-d discard] [-o options] [path]",
.oneline = "open the file specified by path",
.help = open_help,
};
@@ -147,8 +162,9 @@ static int open_f(BlockBackend *blk, int argc, char **argv)
int c;
QemuOpts *qopts;
QDict *opts;
+ bool force_share = false;
- while ((c = getopt(argc, argv, "snro:kt:d:")) != -1) {
+ while ((c = getopt(argc, argv, "snro:kt:d:U")) != -1) {
switch (c) {
case 's':
flags |= BDRV_O_SNAPSHOT;
@@ -188,6 +204,9 @@ static int open_f(BlockBackend *blk, int argc, char **argv)
return 0;
}
break;
+ case 'U':
+ force_share = true;
+ break;
default:
qemu_opts_reset(&empty_opts);
return qemuio_command_usage(&open_cmd);
@@ -211,9 +230,9 @@ static int open_f(BlockBackend *blk, int argc, char **argv)
qemu_opts_reset(&empty_opts);
if (optind == argc - 1) {
- return openfile(argv[optind], flags, writethrough, opts);
+ return openfile(argv[optind], flags, writethrough, force_share, opts);
} else if (optind == argc) {
- return openfile(NULL, flags, writethrough, opts);
+ return openfile(NULL, flags, writethrough, force_share, opts);
} else {
QDECREF(opts);
return qemuio_command_usage(&open_cmd);
@@ -257,6 +276,7 @@ static void usage(const char *name)
" -T, --trace [[enable=]<pattern>][,events=<file>][,file=<file>]\n"
" specify tracing options\n"
" see qemu-img(1) man page for full description\n"
+" -U, --force-share force shared permissions\n"
" -h, --help display this help and exit\n"
" -V, --version output version information and exit\n"
"\n"
@@ -436,7 +456,7 @@ 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:rsnmkt:T:U";
const struct option lopt[] = {
{ "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, 'V' },
@@ -452,6 +472,7 @@ int main(int argc, char **argv)
{ "trace", required_argument, NULL, 'T' },
{ "object", required_argument, NULL, OPTION_OBJECT },
{ "image-opts", no_argument, NULL, OPTION_IMAGE_OPTS },
+ { "force-share", no_argument, 0, 'U'},
{ NULL, 0, NULL, 0 }
};
int c;
@@ -462,6 +483,7 @@ int main(int argc, char **argv)
QDict *opts = NULL;
const char *format = NULL;
char *trace_file = NULL;
+ bool force_share = false;
#ifdef CONFIG_POSIX
signal(SIGPIPE, SIG_IGN);
@@ -524,6 +546,9 @@ int main(int argc, char **argv)
case 'h':
usage(progname);
exit(0);
+ case 'U':
+ force_share = true;
+ break;
case OPTION_OBJECT: {
QemuOpts *qopts;
qopts = qemu_opts_parse_noisily(&qemu_object_opts,
@@ -595,7 +620,7 @@ int main(int argc, char **argv)
exit(1);
}
opts = qemu_opts_to_qdict(qopts, NULL);
- if (openfile(NULL, flags, writethrough, opts)) {
+ if (openfile(NULL, flags, writethrough, force_share, opts)) {
exit(1);
}
} else {
@@ -603,7 +628,8 @@ int main(int argc, char **argv)
opts = qdict_new();
qdict_put(opts, "driver", qstring_from_str(format));
}
- if (openfile(argv[optind], flags, writethrough, opts)) {
+ if (openfile(argv[optind], flags, writethrough,
+ force_share, opts)) {
exit(1);
}
}
--
2.9.3
next prev parent reply other threads:[~2017-04-26 3:34 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-26 3:33 [Qemu-devel] [PATCH v15 00/21] block: Image locking series Fam Zheng
2017-04-26 3:33 ` [Qemu-devel] [PATCH v15 01/21] block: Make bdrv_perm_names public Fam Zheng
2017-04-26 3:33 ` [Qemu-devel] [PATCH v15 02/21] block: Define BLK_PERM_MAX Fam Zheng
2017-04-26 9:36 ` Kevin Wolf
2017-04-27 2:03 ` Fam Zheng
2017-04-26 3:33 ` [Qemu-devel] [PATCH v15 03/21] block: Add, parse and store "force-share" option Fam Zheng
2017-04-26 3:33 ` [Qemu-devel] [PATCH v15 04/21] block: Respect "force-share" in perm propagating Fam Zheng
2017-04-26 3:33 ` [Qemu-devel] [PATCH v15 05/21] qemu-img: Add --force-share option to subcommands Fam Zheng
2017-04-26 3:33 ` [Qemu-devel] [PATCH v15 06/21] qemu-img: Update documentation for -U Fam Zheng
2017-04-26 3:33 ` Fam Zheng [this message]
2017-04-26 3:34 ` [Qemu-devel] [PATCH v15 08/21] iotests: 030: Prepare for image locking Fam Zheng
2017-04-26 3:34 ` [Qemu-devel] [PATCH v15 09/21] iotests: 046: " Fam Zheng
2017-04-26 3:34 ` [Qemu-devel] [PATCH v15 10/21] iotests: 055: Don't attach the target image already for drive-backup Fam Zheng
2017-04-26 3:34 ` [Qemu-devel] [PATCH v15 11/21] iotests: 085: Avoid image locking conflict Fam Zheng
2017-04-26 12:30 ` Kevin Wolf
2017-04-27 7:16 ` Fam Zheng
2017-04-26 3:34 ` [Qemu-devel] [PATCH v15 12/21] iotests: 087: Don't attach test image twice Fam Zheng
2017-04-26 3:34 ` [Qemu-devel] [PATCH v15 13/21] iotests: 091: Quit QEMU before checking image Fam Zheng
2017-04-26 12:34 ` Kevin Wolf
2017-04-27 7:04 ` Fam Zheng
2017-04-26 3:34 ` [Qemu-devel] [PATCH v15 14/21] iotests: 172: Use separate images for multiple devices Fam Zheng
2017-04-26 3:34 ` [Qemu-devel] [PATCH v15 15/21] tests: Use null-co:// instead of /dev/null as the dummy image Fam Zheng
2017-04-26 3:34 ` [Qemu-devel] [PATCH v15 16/21] file-posix: Add 'locking' option Fam Zheng
2017-04-26 12:41 ` Kevin Wolf
2017-04-27 2:29 ` Fam Zheng
2017-04-26 3:34 ` [Qemu-devel] [PATCH v15 17/21] tests: Disable image lock in test-replication Fam Zheng
2017-04-26 3:34 ` [Qemu-devel] [PATCH v15 18/21] block: Reuse bs as backing hd for drive-backup sync=none Fam Zheng
2017-04-26 12:52 ` Kevin Wolf
2017-04-26 13:15 ` Fam Zheng
2017-04-26 14:34 ` Kevin Wolf
2017-04-27 1:50 ` Fam Zheng
2017-04-26 3:34 ` [Qemu-devel] [PATCH v15 19/21] osdep: Add qemu_lock_fd and qemu_unlock_fd Fam Zheng
2017-04-26 12:57 ` Kevin Wolf
2017-04-26 13:20 ` Fam Zheng
2017-04-26 14:24 ` Kevin Wolf
2017-04-26 14:29 ` Daniel P. Berrange
2017-04-27 1:40 ` Fam Zheng
2017-04-26 3:34 ` [Qemu-devel] [PATCH v15 20/21] file-posix: Add image locking to perm operations Fam Zheng
2017-04-26 14:22 ` Kevin Wolf
2017-04-27 6:43 ` Fam Zheng
2017-04-28 13:45 ` Kevin Wolf
2017-04-28 15:30 ` Fam Zheng
2017-04-28 18:27 ` Kevin Wolf
2017-04-26 3:34 ` [Qemu-devel] [PATCH v15 21/21] qemu-iotests: Add test case 153 for image locking Fam Zheng
2017-04-26 12:53 ` Fam Zheng
2017-04-26 14:49 ` Kevin Wolf
2017-04-27 1:32 ` Fam Zheng
2017-04-27 9:05 ` Kevin Wolf
2017-04-27 10:34 ` Fam Zheng
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170426033413.17192-8-famz@redhat.com \
--to=famz@redhat.com \
--cc=eblake@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).