#include <getopt.h>
#include <libgen.h>
+#include "qapi/error.h"
#include "qemu-io.h"
#include "qemu/error-report.h"
#include "qemu/main-loop.h"
#include "sysemu/block-backend.h"
#include "block/block_int.h"
#include "trace/control.h"
+#include "crypto/init.h"
#define CMD_NOFILE_OK 0x01
.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;
BlockDriverState *bs;
}
bs = blk_bs(qemuio_blk);
- if (bdrv_is_encrypted(bs)) {
+ if (bdrv_is_encrypted(bs) && bdrv_key_required(bs)) {
char password[256];
printf("Disk image '%s' is encrypted.\n", name);
if (qemu_read_password(password, sizeof(password)) < 0) {
}
}
+ blk_set_enable_write_cache(qemuio_blk, !writethrough);
return 0;
{
int flags = 0;
int readonly = 0;
+ bool writethrough = true;
int c;
QemuOpts *qopts;
QDict *opts;
flags |= BDRV_O_SNAPSHOT;
break;
case 'n':
- flags |= BDRV_O_NOCACHE | BDRV_O_CACHE_WB;
+ flags |= BDRV_O_NOCACHE;
+ writethrough = false;
break;
case 'r':
readonly = 1;
qemu_opts_reset(&empty_opts);
if (optind == argc - 1) {
- return openfile(argv[optind], flags, opts);
+ return openfile(argv[optind], flags, writethrough, opts);
} else if (optind == argc) {
- return openfile(NULL, flags, opts);
+ return openfile(NULL, flags, writethrough, opts);
} else {
QDECREF(opts);
return qemuio_command_usage(&open_cmd);
int c;
int opt_index = 0;
int flags = BDRV_O_UNMAP;
+ bool writethrough = true;
Error *local_error = NULL;
QDict *opts = NULL;
const char *format = NULL;
progname = basename(argv[0]);
qemu_init_exec_dir(argv[0]);
+ if (qcrypto_init(&local_error) < 0) {
+ error_reportf_err(local_error, "cannot initialize crypto: ");
+ exit(1);
+ }
+
module_call_init(MODULE_INIT_QOM);
qemu_add_opts(&qemu_object_opts);
bdrv_init();
flags |= BDRV_O_SNAPSHOT;
break;
case 'n':
- flags |= BDRV_O_NOCACHE | BDRV_O_CACHE_WB;
+ flags |= BDRV_O_NOCACHE;
+ writethrough = false;
break;
case 'd':
if (bdrv_parse_discard_flags(optarg, &flags) < 0) {
flags |= BDRV_O_NATIVE_AIO;
break;
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);
exit(1);
}
if (qemu_opts_foreach(&qemu_object_opts,
user_creatable_add_opts_foreach,
- NULL, &local_error)) {
- error_report_err(local_error);
+ NULL, NULL)) {
exit(1);
}
exit(1);
}
opts = qemu_opts_to_qdict(qopts, NULL);
- openfile(NULL, flags, opts);
+ openfile(NULL, flags, writethrough, opts);
} else {
if (format) {
opts = qdict_new();
qdict_put(opts, "driver", qstring_from_str(format));
}
- openfile(argv[optind], flags, opts);
+ openfile(argv[optind], flags, writethrough, opts);
}
}
command_loop();