diff options
author | Kevin Wolf <kwolf@redhat.com> | 2016-03-18 15:36:31 +0100 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2016-03-30 12:16:03 +0200 |
commit | 19dbecdceef3f0800a96c25931d71b0b82c3a47a (patch) | |
tree | 11bb70b5e272daf0ec9a4550d0d45334d1eebc70 /qemu-io-cmds.c | |
parent | 04feb4a5073e75b8ed213b297c857fa3ccc0b538 (diff) |
qemu-io: Use bdrv_parse_cache_mode() in reopen_f()
We must forbid changing the WCE flag in bdrv_reopen() in the same patch,
as otherwise the behaviour would change so that the flag takes
precedence over the explicitly specified option.
The correct value of the WCE flag depends on the BlockBackend user (e.g.
guest device) and isn't a decision that the QMP client makes, so this
change is what we want.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Diffstat (limited to 'qemu-io-cmds.c')
-rw-r--r-- | qemu-io-cmds.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index 139f7ebcbb..932e367a17 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -2106,6 +2106,7 @@ static int reopen_f(BlockBackend *blk, int argc, char **argv) QDict *opts; int c; int flags = bs->open_flags; + bool writethrough = !blk_enable_write_cache(blk); BlockReopenQueue *brq; Error *local_err = NULL; @@ -2113,7 +2114,7 @@ static int reopen_f(BlockBackend *blk, int argc, char **argv) while ((c = getopt(argc, argv, "c:o:r")) != -1) { switch (c) { case 'c': - if (bdrv_parse_cache_flags(optarg, &flags) < 0) { + if (bdrv_parse_cache_mode(optarg, &flags, &writethrough) < 0) { error_report("Invalid cache option: %s", optarg); return 0; } @@ -2138,14 +2139,25 @@ static int reopen_f(BlockBackend *blk, int argc, char **argv) return qemuio_command_usage(&reopen_cmd); } + if (writethrough != blk_enable_write_cache(blk) && + blk_get_attached_dev(blk)) + { + error_report("Cannot change cache.writeback: Device attached"); + qemu_opts_reset(&reopen_opts); + return 0; + } + qopts = qemu_opts_find(&reopen_opts, NULL); opts = qopts ? qemu_opts_to_qdict(qopts, NULL) : NULL; qemu_opts_reset(&reopen_opts); + flags |= blk_enable_write_cache(blk) ? BDRV_O_CACHE_WB : 0; brq = bdrv_reopen_queue(NULL, bs, opts, flags); bdrv_reopen_multiple(brq, &local_err); if (local_err) { error_report_err(local_err); + } else { + blk_set_enable_write_cache(blk, !writethrough); } return 0; |