[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 09/23] qemu-io: Add command 'reopen'
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 09/23] qemu-io: Add command 'reopen' |
Date: |
Fri, 11 Sep 2015 21:40:49 +0200 |
Signed-off-by: Kevin Wolf <address@hidden>
Reviewed-by: Max Reitz <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-devel] [PULL 00/23] Block layer patches, Kevin Wolf, 2015/09/11
- [Qemu-devel] [PULL 02/23] block: Drop drv parameter from bdrv_open(), Kevin Wolf, 2015/09/11
- [Qemu-devel] [PULL 05/23] block: Drop bdrv_find_whitelisted_format(), Kevin Wolf, 2015/09/11
- [Qemu-devel] [PULL 03/23] block: Drop drv parameter from bdrv_open_inherit(), Kevin Wolf, 2015/09/11
- [Qemu-devel] [PULL 01/23] block: Always pass NULL as drv for bdrv_open(), Kevin Wolf, 2015/09/11
- [Qemu-devel] [PULL 04/23] block: Drop drv parameter from bdrv_fill_options(), Kevin Wolf, 2015/09/11
- [Qemu-devel] [PULL 08/23] qemu-io: Remove duplicate 'open' error message, Kevin Wolf, 2015/09/11
- [Qemu-devel] [PULL 07/23] block: Allow specifying driver-specific options to reopen, Kevin Wolf, 2015/09/11
- [Qemu-devel] [PULL 09/23] qemu-io: Add command 'reopen',
Kevin Wolf <=
- [Qemu-devel] [PULL 10/23] qcow2: Improve error message, Kevin Wolf, 2015/09/11
- [Qemu-devel] [PULL 12/23] qcow2: Move qcow2_update_options() call up, Kevin Wolf, 2015/09/11
- [Qemu-devel] [PULL 11/23] qcow2: Factor out qcow2_update_options(), Kevin Wolf, 2015/09/11
- [Qemu-devel] [PULL 06/23] qcow2: Rename BDRVQcowState to BDRVQcow2State, Kevin Wolf, 2015/09/11
- [Qemu-devel] [PULL 15/23] qcow2: Fix memory leak in qcow2_update_options() error path, Kevin Wolf, 2015/09/11
- [Qemu-devel] [PULL 13/23] qcow2: Move rest of option handling to qcow2_update_options(), Kevin Wolf, 2015/09/11
- [Qemu-devel] [PULL 14/23] qcow2: Leave s unchanged on qcow2_update_options() failure, Kevin Wolf, 2015/09/11
- [Qemu-devel] [PULL 22/23] vmdk: Fix next_cluster_sector for compressed write, Kevin Wolf, 2015/09/11
- [Qemu-devel] [PULL 23/23] qcow2: Make qcow2_alloc_bytes() more explicit, Kevin Wolf, 2015/09/11
- [Qemu-devel] [PULL 21/23] iotests: Add test for checking large image files, Kevin Wolf, 2015/09/11