qemu-io: Call blk_set_enable_write_cache() explicitly

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
This commit is contained in:
Kevin Wolf 2016-03-15 12:52:30 +01:00
parent 6effd5bfc2
commit e151fc16dd
1 changed files with 13 additions and 8 deletions

View File

@ -51,7 +51,7 @@ static const cmdinfo_t close_cmd = {
.oneline = "close the current open file", .oneline = "close the current open file",
}; };
static int openfile(char *name, int flags, QDict *opts) static int openfile(char *name, int flags, bool writethrough, QDict *opts)
{ {
Error *local_err = NULL; Error *local_err = NULL;
BlockDriverState *bs; BlockDriverState *bs;
@ -83,6 +83,7 @@ static int openfile(char *name, int flags, QDict *opts)
} }
} }
blk_set_enable_write_cache(qemuio_blk, !writethrough);
return 0; return 0;
@ -137,6 +138,7 @@ static int open_f(BlockBackend *blk, int argc, char **argv)
{ {
int flags = 0; int flags = 0;
int readonly = 0; int readonly = 0;
bool writethrough = true;
int c; int c;
QemuOpts *qopts; QemuOpts *qopts;
QDict *opts; QDict *opts;
@ -147,7 +149,8 @@ static int open_f(BlockBackend *blk, int argc, char **argv)
flags |= BDRV_O_SNAPSHOT; flags |= BDRV_O_SNAPSHOT;
break; break;
case 'n': case 'n':
flags |= BDRV_O_NOCACHE | BDRV_O_CACHE_WB; flags |= BDRV_O_NOCACHE;
writethrough = false;
break; break;
case 'r': case 'r':
readonly = 1; readonly = 1;
@ -185,9 +188,9 @@ static int open_f(BlockBackend *blk, int argc, char **argv)
qemu_opts_reset(&empty_opts); qemu_opts_reset(&empty_opts);
if (optind == argc - 1) { if (optind == argc - 1) {
return openfile(argv[optind], flags, opts); return openfile(argv[optind], flags, writethrough, opts);
} else if (optind == argc) { } else if (optind == argc) {
return openfile(NULL, flags, opts); return openfile(NULL, flags, writethrough, opts);
} else { } else {
QDECREF(opts); QDECREF(opts);
return qemuio_command_usage(&open_cmd); return qemuio_command_usage(&open_cmd);
@ -428,6 +431,7 @@ int main(int argc, char **argv)
int c; int c;
int opt_index = 0; int opt_index = 0;
int flags = BDRV_O_UNMAP; int flags = BDRV_O_UNMAP;
bool writethrough = true;
Error *local_error = NULL; Error *local_error = NULL;
QDict *opts = NULL; QDict *opts = NULL;
const char *format = NULL; const char *format = NULL;
@ -449,7 +453,8 @@ int main(int argc, char **argv)
flags |= BDRV_O_SNAPSHOT; flags |= BDRV_O_SNAPSHOT;
break; break;
case 'n': case 'n':
flags |= BDRV_O_NOCACHE | BDRV_O_CACHE_WB; flags |= BDRV_O_NOCACHE;
writethrough = false;
break; break;
case 'd': case 'd':
if (bdrv_parse_discard_flags(optarg, &flags) < 0) { if (bdrv_parse_discard_flags(optarg, &flags) < 0) {
@ -473,7 +478,7 @@ int main(int argc, char **argv)
flags |= BDRV_O_NATIVE_AIO; flags |= BDRV_O_NATIVE_AIO;
break; break;
case 't': case 't':
if (bdrv_parse_cache_flags(optarg, &flags) < 0) { if (bdrv_parse_cache_mode(optarg, &flags, &writethrough) < 0) {
error_report("Invalid cache option: %s", optarg); error_report("Invalid cache option: %s", optarg);
exit(1); exit(1);
} }
@ -555,13 +560,13 @@ int main(int argc, char **argv)
exit(1); exit(1);
} }
opts = qemu_opts_to_qdict(qopts, NULL); opts = qemu_opts_to_qdict(qopts, NULL);
openfile(NULL, flags, opts); openfile(NULL, flags, writethrough, opts);
} else { } else {
if (format) { if (format) {
opts = qdict_new(); opts = qdict_new();
qdict_put(opts, "driver", qstring_from_str(format)); qdict_put(opts, "driver", qstring_from_str(format));
} }
openfile(argv[optind], flags, opts); openfile(argv[optind], flags, writethrough, opts);
} }
} }
command_loop(); command_loop();