#include "qemu/option.h"
#include "qemu/config-file.h"
#include "qemu/readline.h"
+#include "sysemu/block-backend.h"
#include "block/block_int.h"
#include "trace/control.h"
static char *progname;
+static BlockBackend *qemuio_blk;
static BlockDriverState *qemuio_bs;
/* qemu-io commands passed using -c */
static int close_f(BlockDriverState *bs, int argc, char **argv)
{
- bdrv_unref(bs);
+ blk_unref(qemuio_blk);
qemuio_bs = NULL;
+ qemuio_blk = NULL;
return 0;
}
if (qemuio_bs) {
fprintf(stderr, "file open already, try 'help close'\n");
+ QDECREF(opts);
return 1;
}
+ qemuio_blk = blk_new_with_bs("hda", &error_abort);
+ qemuio_bs = blk_bs(qemuio_blk);
+
if (growable) {
- if (bdrv_open(&qemuio_bs, name, NULL, opts, flags | BDRV_O_PROTOCOL,
- NULL, &local_err))
- {
- fprintf(stderr, "%s: can't open device %s: %s\n", progname, name,
- error_get_pretty(local_err));
- error_free(local_err);
- return 1;
- }
- } else {
- qemuio_bs = bdrv_new("hda", &error_abort);
-
- if (bdrv_open(&qemuio_bs, name, NULL, opts, flags, NULL, &local_err)
- < 0)
- {
- fprintf(stderr, "%s: can't open device %s: %s\n", progname, name,
- error_get_pretty(local_err));
- error_free(local_err);
- bdrv_unref(qemuio_bs);
- qemuio_bs = NULL;
- return 1;
- }
+ flags |= BDRV_O_PROTOCOL;
+ }
+
+ if (bdrv_open(&qemuio_bs, name, NULL, opts, flags, NULL, &local_err) < 0) {
+ fprintf(stderr, "%s: can't open%s%s: %s\n", progname,
+ name ? " device " : "", name ?: "",
+ error_get_pretty(local_err));
+ error_free(local_err);
+ blk_unref(qemuio_blk);
+ qemuio_bs = NULL;
+ qemuio_blk = NULL;
+ return 1;
}
return 0;
static QemuOptsList empty_opts = {
.name = "drive",
+ .merge_lists = true,
.head = QTAILQ_HEAD_INITIALIZER(empty_opts.head),
.desc = {
/* no elements => accept any params */
int growable = 0;
int c;
QemuOpts *qopts;
- QDict *opts = NULL;
+ QDict *opts;
while ((c = getopt(argc, argv, "snrgo:")) != EOF) {
switch (c) {
growable = 1;
break;
case 'o':
- qopts = qemu_opts_parse(&empty_opts, optarg, 0);
- if (qopts == NULL) {
+ if (!qemu_opts_parse(&empty_opts, optarg, 0)) {
printf("could not parse option list -- %s\n", optarg);
+ qemu_opts_reset(&empty_opts);
return 0;
}
- opts = qemu_opts_to_qdict(qopts, opts);
- qemu_opts_del(qopts);
break;
default:
+ qemu_opts_reset(&empty_opts);
return qemuio_command_usage(&open_cmd);
}
}
flags |= BDRV_O_RDWR;
}
+ qopts = qemu_opts_find(&empty_opts, NULL);
+ opts = qopts ? qemu_opts_to_qdict(qopts, NULL) : NULL;
+ qemu_opts_reset(&empty_opts);
+
if (optind == argc - 1) {
return openfile(argv[optind], flags, growable, opts);
} else if (optind == argc) {
return openfile(NULL, flags, growable, opts);
} else {
+ QDECREF(opts);
return qemuio_command_usage(&open_cmd);
}
}
static void add_user_command(char *optarg)
{
- cmdline = g_realloc(cmdline, ++ncmdline * sizeof(char *));
+ cmdline = g_renew(char *, cmdline, ++ncmdline);
cmdline[ncmdline-1] = optarg;
}
int c;
int opt_index = 0;
int flags = BDRV_O_UNMAP;
+ Error *local_error = NULL;
#ifdef CONFIG_POSIX
signal(SIGPIPE, SIG_IGN);
}
break;
case 'T':
- if (!trace_backend_init(optarg, NULL)) {
+ if (!trace_init_backends(optarg, NULL)) {
exit(1); /* error message will have been printed */
}
break;
exit(1);
}
- qemu_init_main_loop();
+ if (qemu_init_main_loop(&local_error)) {
+ error_report("%s", error_get_pretty(local_error));
+ error_free(local_error);
+ exit(1);
+ }
bdrv_init();
/* initialize commands */
*/
bdrv_drain_all();
- if (qemuio_bs) {
- bdrv_unref(qemuio_bs);
- }
+ blk_unref(qemuio_blk);
g_free(readline_state);
return 0;
}