[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 13/34] qemu-io: Add command 'reopen'
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 13/34] qemu-io: Add command 'reopen' |
Date: |
Fri, 8 May 2015 19:21:45 +0200 |
Signed-off-by: Kevin Wolf <address@hidden>
---
qemu-io-cmds.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 71 insertions(+)
diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
index 1afcfc0..ef8f3fd 100644
--- a/qemu-io-cmds.c
+++ b/qemu-io-cmds.c
@@ -1978,6 +1978,76 @@ static const cmdinfo_t map_cmd = {
.oneline = "prints the allocated areas of a file",
};
+static int reopen_f(BlockBackend *blk, int argc, char **argv);
+
+static QemuOptsList reopen_opts = {
+ .name = "reopen",
+ .merge_lists = true,
+ .head = QTAILQ_HEAD_INITIALIZER(reopen_opts.head),
+ .desc = {
+ /* no elements => accept any params */
+ { /* end of list */ }
+ },
+};
+
+static const cmdinfo_t reopen_cmd = {
+ .name = "reopen",
+ .argmin = 0,
+ .argmax = -1,
+ .cfunc = reopen_f,
+ .args = "",
+ .oneline = "reopens an image with new options",
+};
+
+static int reopen_f(BlockBackend *blk, int argc, char **argv)
+{
+ BlockDriverState *bs = blk_bs(blk);
+ QemuOpts *qopts;
+ QDict *opts;
+ int c;
+ int flags = bs->open_flags;
+
+ BlockReopenQueue *brq;
+ Error *local_err = NULL;
+
+ while ((c = getopt(argc, argv, "c:o:r")) != EOF) {
+ switch (c) {
+ case 'c':
+ if (bdrv_parse_cache_flags(optarg, &flags) < 0) {
+ error_report("Invalid cache option: %s", optarg);
+ return 0;
+ }
+ break;
+ case 'o':
+ if (!qemu_opts_parse(&reopen_opts, optarg, 0)) {
+ printf("could not parse option list -- %s\n", optarg);
+ qemu_opts_reset(&reopen_opts);
+ return 0;
+ }
+ break;
+ case 'r':
+ flags &= ~BDRV_O_RDWR;
+ break;
+ default:
+ qemu_opts_reset(&reopen_opts);
+ return qemuio_command_usage(&reopen_cmd);
+ }
+ }
+
+ qopts = qemu_opts_find(&reopen_opts, NULL);
+ opts = qopts ? qemu_opts_to_qdict(qopts, NULL) : NULL;
+ qemu_opts_reset(&reopen_opts);
+
+ brq = bdrv_reopen_queue(NULL, bs, opts, flags);
+ bdrv_reopen_multiple(brq, &local_err);
+ if (local_err) {
+ qerror_report_err(local_err);
+ error_free(local_err);
+ }
+
+ return 0;
+}
+
static int break_f(BlockBackend *blk, int argc, char **argv)
{
int ret;
@@ -2265,6 +2335,7 @@ static void __attribute((constructor))
init_qemuio_commands(void)
qemuio_add_command(&discard_cmd);
qemuio_add_command(&alloc_cmd);
qemuio_add_command(&map_cmd);
+ qemuio_add_command(&reopen_cmd);
qemuio_add_command(&break_cmd);
qemuio_add_command(&remove_break_cmd);
qemuio_add_command(&resume_cmd);
--
1.8.3.1
- Re: [Qemu-devel] [PATCH 11/34] block: Allow references for backing files, (continued)
- Re: [Qemu-devel] [PATCH 11/34] block: Allow references for backing files, Max Reitz, 2015/05/11
- Re: [Qemu-devel] [PATCH 11/34] block: Allow references for backing files, Eric Blake, 2015/05/12
- Re: [Qemu-devel] [PATCH 11/34] block: Allow references for backing files, Wen Congyang, 2015/05/21
- Re: [Qemu-devel] [PATCH 11/34] block: Allow references for backing files, Wen Congyang, 2015/05/27
- Re: [Qemu-devel] [PATCH 11/34] block: Allow references for backing files, Kevin Wolf, 2015/05/28
- Re: [Qemu-devel] [PATCH 11/34] block: Allow references for backing files, Wen Congyang, 2015/05/28
- Re: [Qemu-devel] [PATCH 11/34] block: Allow references for backing files, Wen Congyang, 2015/05/31
[Qemu-devel] [PATCH 13/34] qemu-io: Add command 'reopen',
Kevin Wolf <=
[Qemu-devel] [PATCH 12/34] block: Allow specifying driver-specific options to reopen, Kevin Wolf, 2015/05/08
[Qemu-devel] [PATCH 14/34] qcow2: Factor out qcow2_update_options(), Kevin Wolf, 2015/05/08