[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH v2 03/13] qemu-io: Add command 'reopen'
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PATCH v2 03/13] qemu-io: Add command 'reopen' |
Date: |
Fri, 4 Sep 2015 19:18:27 +0200 |
Signed-off-by: Kevin Wolf <address@hidden>
---
qemu-io-cmds.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 90 insertions(+)
diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
index 53477e1..d6572a8 100644
--- a/qemu-io-cmds.c
+++ b/qemu-io-cmds.c
@@ -1979,6 +1979,95 @@ static const cmdinfo_t map_cmd = {
.oneline = "prints the allocated areas of a file",
};
+static void reopen_help(void)
+{
+ printf(
+"\n"
+" Changes the open options of an already opened image\n"
+"\n"
+" Example:\n"
+" 'reopen -o lazy-refcounts=on' - activates lazy refcount writeback on a qcow2
image\n"
+"\n"
+" -r, -- Reopen the image read-only\n"
+" -c, -- Change the cache mode to the given value\n"
+" -o, -- Changes block driver options (cf. 'open' command)\n"
+"\n");
+}
+
+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 = "[-r] [-c cache] [-o options]",
+ .oneline = "reopens an image with new options",
+ .help = reopen_help,
+};
+
+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")) != -1) {
+ 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_noisily(&reopen_opts, optarg, 0)) {
+ 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);
+ }
+ }
+
+ if (optind != argc) {
+ 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) {
+ error_report_err(local_err);
+ }
+
+ return 0;
+}
+
static int break_f(BlockBackend *blk, int argc, char **argv)
{
int ret;
@@ -2266,6 +2355,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
- [Qemu-block] [PATCH v2 00/13] qcow2: reopen: Change driver-specific runtime options, Kevin Wolf, 2015/09/04
- [Qemu-block] [PATCH v2 02/13] qemu-io: Remove duplicate 'open' error message, Kevin Wolf, 2015/09/04
- [Qemu-block] [PATCH v2 01/13] block: Allow specifying driver-specific options to reopen, Kevin Wolf, 2015/09/04
- [Qemu-block] [PATCH v2 03/13] qemu-io: Add command 'reopen',
Kevin Wolf <=
- [Qemu-block] [PATCH v2 04/13] qcow2: Improve error message, Kevin Wolf, 2015/09/04
- [Qemu-block] [PATCH v2 06/13] qcow2: Move qcow2_update_options() call up, Kevin Wolf, 2015/09/04
- [Qemu-block] [PATCH v2 05/13] qcow2: Factor out qcow2_update_options(), Kevin Wolf, 2015/09/04
- [Qemu-block] [PATCH v2 07/13] qcow2: Move rest of option handling to qcow2_update_options(), Kevin Wolf, 2015/09/04
- [Qemu-block] [PATCH v2 08/13] qcow2: Leave s unchanged on qcow2_update_options() failure, Kevin Wolf, 2015/09/04
- [Qemu-block] [PATCH v2 09/13] qcow2: Fix memory leak in qcow2_update_options() error path, Kevin Wolf, 2015/09/04
- [Qemu-block] [PATCH v2 10/13] qcow2: Make qcow2_update_options() suitable for transactions, Kevin Wolf, 2015/09/04
- [Qemu-block] [PATCH v2 12/13] qemu-iotests: Reopen qcow2 with lazy-refcounts change, Kevin Wolf, 2015/09/04