[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH v13 06/20] qemu-io: Add --unsafe-read option
From: |
Fam Zheng |
Subject: |
[Qemu-block] [PATCH v13 06/20] qemu-io: Add --unsafe-read option |
Date: |
Thu, 20 Apr 2017 15:52:23 +0800 |
Signed-off-by: Fam Zheng <address@hidden>
---
qemu-io.c | 31 +++++++++++++++++++++++--------
1 file changed, 23 insertions(+), 8 deletions(-)
diff --git a/qemu-io.c b/qemu-io.c
index 427cbae..e7e032c 100644
--- a/qemu-io.c
+++ b/qemu-io.c
@@ -53,7 +53,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 unsafe_read,
+ QDict *opts)
{
Error *local_err = NULL;
BlockDriverState *bs;
@@ -64,6 +65,9 @@ static int openfile(char *name, int flags, bool writethrough,
QDict *opts)
return 1;
}
+ if (unsafe_read) {
+ flags |= BDRV_O_UNSAFE_READ;
+ }
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 +112,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, -- allow unsafe reads when another process is writing\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 +129,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 +152,9 @@ static int open_f(BlockBackend *blk, int argc, char **argv)
int c;
QemuOpts *qopts;
QDict *opts;
+ bool unsafe_read = 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 +194,9 @@ static int open_f(BlockBackend *blk, int argc, char **argv)
return 0;
}
break;
+ case 'U':
+ unsafe_read = true;
+ break;
default:
qemu_opts_reset(&empty_opts);
return qemuio_command_usage(&open_cmd);
@@ -211,9 +220,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, unsafe_read, opts);
} else if (optind == argc) {
- return openfile(NULL, flags, writethrough, opts);
+ return openfile(NULL, flags, writethrough, unsafe_read, opts);
} else {
QDECREF(opts);
return qemuio_command_usage(&open_cmd);
@@ -257,6 +266,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, --unsafe-read allow unsafe reads when another process is writing\n"
" -h, --help display this help and exit\n"
" -V, --version output version information and exit\n"
"\n"
@@ -436,7 +446,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 +462,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 },
+ { "unsafe-read", no_argument, 0, 'U'},
{ NULL, 0, NULL, 0 }
};
int c;
@@ -462,6 +473,7 @@ int main(int argc, char **argv)
QDict *opts = NULL;
const char *format = NULL;
char *trace_file = NULL;
+ bool unsafe_read = false;
#ifdef CONFIG_POSIX
signal(SIGPIPE, SIG_IGN);
@@ -524,6 +536,9 @@ int main(int argc, char **argv)
case 'h':
usage(progname);
exit(0);
+ case 'U':
+ unsafe_read = true;
+ break;
case OPTION_OBJECT: {
QemuOpts *qopts;
qopts = qemu_opts_parse_noisily(&qemu_object_opts,
@@ -595,7 +610,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, unsafe_read, opts)) {
exit(1);
}
} else {
@@ -603,7 +618,7 @@ 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, unsafe_read,
opts)) {
exit(1);
}
}
--
2.9.3
- [Qemu-block] [PATCH v13 00/20] block: Image locking series, Fam Zheng, 2017/04/20
- [Qemu-block] [PATCH v13 01/20] block: Introduce BDRV_O_UNSAFE_READ, Fam Zheng, 2017/04/20
- [Qemu-block] [PATCH v13 02/20] block: Drop consistent read perm if opened unsafe, Fam Zheng, 2017/04/20
- [Qemu-block] [PATCH v13 03/20] block: Don't require BLK_PERM_CONSISTENT_READ when unsafe open, Fam Zheng, 2017/04/20
- [Qemu-block] [PATCH v13 04/20] qemu-img: Add --unsafe-read option to subcommands, Fam Zheng, 2017/04/20
- [Qemu-block] [PATCH v13 05/20] qemu-img: Update documentation for --unsafe-read, Fam Zheng, 2017/04/20
- [Qemu-block] [PATCH v13 06/20] qemu-io: Add --unsafe-read option,
Fam Zheng <=
- [Qemu-block] [PATCH v13 07/20] iotests: 030: Prepare for image locking, Fam Zheng, 2017/04/20
- [Qemu-block] [PATCH v13 08/20] iotests: 046: Prepare for image locking, Fam Zheng, 2017/04/20
- [Qemu-block] [PATCH v13 09/20] iotests: 055: Don't attach the target image already for drive-backup, Fam Zheng, 2017/04/20
- [Qemu-block] [PATCH v13 11/20] iotests: 087: Don't attach test image twice, Fam Zheng, 2017/04/20
- [Qemu-block] [PATCH v13 10/20] iotests: 085: Avoid image locking conflict, Fam Zheng, 2017/04/20
- [Qemu-block] [PATCH v13 12/20] iotests: 091: Quit QEMU before checking image, Fam Zheng, 2017/04/20
- [Qemu-block] [PATCH v13 13/20] iotests: 172: Use separate images for multiple devices, Fam Zheng, 2017/04/20
- [Qemu-block] [PATCH v13 14/20] tests: Use null-co:// instead of /dev/null as the dummy image, Fam Zheng, 2017/04/20
- [Qemu-block] [PATCH v13 15/20] file-posix: Add 'locking' option, Fam Zheng, 2017/04/20
- [Qemu-block] [PATCH v13 16/20] tests: Disable image lock in test-replication, Fam Zheng, 2017/04/20