blob: ef3fef6e5f42347ece2b8389f9995030712493f8 [file] [log] [blame]
aliguorie3aff4f2009-04-05 19:14:04 +00001/*
2 * Command line utility to exercise the QEMU I/O path.
3 *
4 * Copyright (C) 2009 Red Hat, Inc.
5 * Copyright (c) 2003-2005 Silicon Graphics, Inc.
6 *
7 * This work is licensed under the terms of the GNU GPL, version 2 or later.
8 * See the COPYING file in the top-level directory.
9 */
Stefan Weilc32d7662009-08-31 22:16:16 +020010#include <sys/time.h>
aliguorie3aff4f2009-04-05 19:14:04 +000011#include <sys/types.h>
12#include <stdarg.h>
13#include <stdio.h>
14#include <getopt.h>
Stefan Weilc32d7662009-08-31 22:16:16 +020015#include <libgen.h>
aliguorie3aff4f2009-04-05 19:14:04 +000016
Kevin Wolf3d219942013-06-05 14:19:39 +020017#include "qemu-io.h"
Paolo Bonzini1de7afc2012-12-17 18:20:00 +010018#include "qemu/main-loop.h"
Max Reitzb543c5c2013-10-11 14:02:10 +020019#include "qemu/option.h"
20#include "qemu/config-file.h"
Stefan Hajnoczi0cf17e12013-11-14 11:54:17 +010021#include "qemu/readline.h"
Paolo Bonzini737e1502012-12-17 18:19:44 +010022#include "block/block_int.h"
Stefan Hajnoczid7bb72c2012-03-12 16:36:07 +000023#include "trace/control.h"
aliguorie3aff4f2009-04-05 19:14:04 +000024
Devin Nakamura43642b32011-07-11 11:22:16 -040025#define CMD_NOFILE_OK 0x01
aliguorie3aff4f2009-04-05 19:14:04 +000026
Stefan Weilf9883882014-03-05 22:23:00 +010027static char *progname;
aliguorie3aff4f2009-04-05 19:14:04 +000028
Stefan Weilf9883882014-03-05 22:23:00 +010029static BlockDriverState *qemuio_bs;
Kevin Wolf191c2892010-09-16 13:18:08 +020030
Kevin Wolfd1174f12013-06-05 14:19:37 +020031/* qemu-io commands passed using -c */
32static int ncmdline;
33static char **cmdline;
34
Stefan Hajnoczi0cf17e12013-11-14 11:54:17 +010035static ReadLineState *readline_state;
36
Kevin Wolf734c3b82013-06-05 14:19:30 +020037static int close_f(BlockDriverState *bs, int argc, char **argv)
aliguorie3aff4f2009-04-05 19:14:04 +000038{
Fam Zheng4f6fd342013-08-23 09:14:47 +080039 bdrv_unref(bs);
Kevin Wolf734c3b82013-06-05 14:19:30 +020040 qemuio_bs = NULL;
Devin Nakamura43642b32011-07-11 11:22:16 -040041 return 0;
aliguorie3aff4f2009-04-05 19:14:04 +000042}
43
44static const cmdinfo_t close_cmd = {
Devin Nakamura43642b32011-07-11 11:22:16 -040045 .name = "close",
46 .altname = "c",
47 .cfunc = close_f,
48 .oneline = "close the current open file",
aliguorie3aff4f2009-04-05 19:14:04 +000049};
50
Max Reitzb543c5c2013-10-11 14:02:10 +020051static int openfile(char *name, int flags, int growable, QDict *opts)
aliguorie3aff4f2009-04-05 19:14:04 +000052{
Max Reitz34b5d2c2013-09-05 14:45:29 +020053 Error *local_err = NULL;
54
Kevin Wolf734c3b82013-06-05 14:19:30 +020055 if (qemuio_bs) {
Devin Nakamura43642b32011-07-11 11:22:16 -040056 fprintf(stderr, "file open already, try 'help close'\n");
57 return 1;
58 }
aliguorie3aff4f2009-04-05 19:14:04 +000059
Devin Nakamura43642b32011-07-11 11:22:16 -040060 if (growable) {
Max Reitz2e401342014-02-18 18:33:07 +010061 if (bdrv_open(&qemuio_bs, name, NULL, opts, flags | BDRV_O_PROTOCOL,
62 NULL, &local_err))
63 {
Max Reitz34b5d2c2013-09-05 14:45:29 +020064 fprintf(stderr, "%s: can't open device %s: %s\n", progname, name,
65 error_get_pretty(local_err));
66 error_free(local_err);
Devin Nakamura43642b32011-07-11 11:22:16 -040067 return 1;
68 }
69 } else {
Kevin Wolf98522f62014-04-17 13:16:01 +020070 qemuio_bs = bdrv_new("hda", &error_abort);
Christoph Hellwig6db95602010-04-05 16:53:57 +020071
Max Reitzddf56362014-02-18 18:33:06 +010072 if (bdrv_open(&qemuio_bs, name, NULL, opts, flags, NULL, &local_err)
73 < 0)
74 {
Max Reitz34b5d2c2013-09-05 14:45:29 +020075 fprintf(stderr, "%s: can't open device %s: %s\n", progname, name,
76 error_get_pretty(local_err));
77 error_free(local_err);
Fam Zheng4f6fd342013-08-23 09:14:47 +080078 bdrv_unref(qemuio_bs);
Kevin Wolf734c3b82013-06-05 14:19:30 +020079 qemuio_bs = NULL;
Devin Nakamura43642b32011-07-11 11:22:16 -040080 return 1;
81 }
82 }
Christoph Hellwig1db69472009-07-15 23:11:21 +020083
Devin Nakamura43642b32011-07-11 11:22:16 -040084 return 0;
aliguorie3aff4f2009-04-05 19:14:04 +000085}
86
Devin Nakamura43642b32011-07-11 11:22:16 -040087static void open_help(void)
aliguorie3aff4f2009-04-05 19:14:04 +000088{
Devin Nakamura43642b32011-07-11 11:22:16 -040089 printf(
aliguorie3aff4f2009-04-05 19:14:04 +000090"\n"
91" opens a new file in the requested mode\n"
92"\n"
93" Example:\n"
94" 'open -Cn /tmp/data' - creates/opens data file read-write and uncached\n"
95"\n"
96" Opens a file for subsequent use by all of the other qemu-io commands.\n"
aliguorie3aff4f2009-04-05 19:14:04 +000097" -r, -- open file read-only\n"
98" -s, -- use snapshot file\n"
99" -n, -- disable host cache\n"
Max Reitzb543c5c2013-10-11 14:02:10 +0200100" -g, -- allow file to grow (only applies to protocols)\n"
101" -o, -- options to be given to the block driver"
aliguorie3aff4f2009-04-05 19:14:04 +0000102"\n");
103}
104
Kevin Wolf734c3b82013-06-05 14:19:30 +0200105static int open_f(BlockDriverState *bs, int argc, char **argv);
Blue Swirl22a2bdc2009-11-21 09:06:46 +0000106
107static const cmdinfo_t open_cmd = {
Devin Nakamura43642b32011-07-11 11:22:16 -0400108 .name = "open",
109 .altname = "o",
110 .cfunc = open_f,
111 .argmin = 1,
112 .argmax = -1,
113 .flags = CMD_NOFILE_OK,
Max Reitzb543c5c2013-10-11 14:02:10 +0200114 .args = "[-Crsn] [-o options] [path]",
Devin Nakamura43642b32011-07-11 11:22:16 -0400115 .oneline = "open the file specified by path",
116 .help = open_help,
Blue Swirl22a2bdc2009-11-21 09:06:46 +0000117};
aliguorie3aff4f2009-04-05 19:14:04 +0000118
Max Reitzb543c5c2013-10-11 14:02:10 +0200119static QemuOptsList empty_opts = {
120 .name = "drive",
Markus Armbruster443422f2014-05-28 11:16:58 +0200121 .merge_lists = true,
Max Reitzb543c5c2013-10-11 14:02:10 +0200122 .head = QTAILQ_HEAD_INITIALIZER(empty_opts.head),
123 .desc = {
124 /* no elements => accept any params */
125 { /* end of list */ }
126 },
127};
128
Kevin Wolf734c3b82013-06-05 14:19:30 +0200129static int open_f(BlockDriverState *bs, int argc, char **argv)
aliguorie3aff4f2009-04-05 19:14:04 +0000130{
Devin Nakamura43642b32011-07-11 11:22:16 -0400131 int flags = 0;
132 int readonly = 0;
133 int growable = 0;
134 int c;
Max Reitzb543c5c2013-10-11 14:02:10 +0200135 QemuOpts *qopts;
Markus Armbruster443422f2014-05-28 11:16:58 +0200136 QDict *opts;
aliguorie3aff4f2009-04-05 19:14:04 +0000137
Max Reitzb543c5c2013-10-11 14:02:10 +0200138 while ((c = getopt(argc, argv, "snrgo:")) != EOF) {
Devin Nakamura43642b32011-07-11 11:22:16 -0400139 switch (c) {
140 case 's':
141 flags |= BDRV_O_SNAPSHOT;
142 break;
143 case 'n':
144 flags |= BDRV_O_NOCACHE | BDRV_O_CACHE_WB;
145 break;
146 case 'r':
147 readonly = 1;
148 break;
149 case 'g':
150 growable = 1;
151 break;
Max Reitzb543c5c2013-10-11 14:02:10 +0200152 case 'o':
Markus Armbruster443422f2014-05-28 11:16:58 +0200153 if (!qemu_opts_parse(&empty_opts, optarg, 0)) {
Max Reitzb543c5c2013-10-11 14:02:10 +0200154 printf("could not parse option list -- %s\n", optarg);
Markus Armbruster443422f2014-05-28 11:16:58 +0200155 qemu_opts_reset(&empty_opts);
Max Reitzb543c5c2013-10-11 14:02:10 +0200156 return 0;
157 }
Max Reitzb543c5c2013-10-11 14:02:10 +0200158 break;
Devin Nakamura43642b32011-07-11 11:22:16 -0400159 default:
Markus Armbruster443422f2014-05-28 11:16:58 +0200160 qemu_opts_reset(&empty_opts);
Kevin Wolfc2cdf5c2013-06-05 14:19:36 +0200161 return qemuio_command_usage(&open_cmd);
Naphtali Spreif5edb012010-01-17 16:48:13 +0200162 }
Devin Nakamura43642b32011-07-11 11:22:16 -0400163 }
aliguorie3aff4f2009-04-05 19:14:04 +0000164
Devin Nakamura43642b32011-07-11 11:22:16 -0400165 if (!readonly) {
166 flags |= BDRV_O_RDWR;
167 }
aliguorie3aff4f2009-04-05 19:14:04 +0000168
Markus Armbruster443422f2014-05-28 11:16:58 +0200169 qopts = qemu_opts_find(&empty_opts, NULL);
170 opts = qopts ? qemu_opts_to_qdict(qopts, NULL) : NULL;
171 qemu_opts_reset(&empty_opts);
172
Max Reitzfd0fee32013-12-20 19:28:20 +0100173 if (optind == argc - 1) {
174 return openfile(argv[optind], flags, growable, opts);
175 } else if (optind == argc) {
176 return openfile(NULL, flags, growable, opts);
177 } else {
Kevin Wolfc2cdf5c2013-06-05 14:19:36 +0200178 return qemuio_command_usage(&open_cmd);
Devin Nakamura43642b32011-07-11 11:22:16 -0400179 }
aliguorie3aff4f2009-04-05 19:14:04 +0000180}
181
Kevin Wolfe681be72013-06-05 14:19:34 +0200182static int quit_f(BlockDriverState *bs, int argc, char **argv)
183{
184 return 1;
185}
186
187static const cmdinfo_t quit_cmd = {
188 .name = "quit",
189 .altname = "q",
190 .cfunc = quit_f,
191 .argmin = -1,
192 .argmax = -1,
193 .flags = CMD_FLAG_GLOBAL,
194 .oneline = "exit the program",
195};
196
aliguorie3aff4f2009-04-05 19:14:04 +0000197static void usage(const char *name)
198{
Devin Nakamura43642b32011-07-11 11:22:16 -0400199 printf(
Maria Kustovad208cc32014-03-18 09:59:19 +0400200"Usage: %s [-h] [-V] [-rsnm] [-c STRING] ... [file]\n"
Stefan Weil84844a22009-06-22 15:08:47 +0200201"QEMU Disk exerciser\n"
aliguorie3aff4f2009-04-05 19:14:04 +0000202"\n"
Maria Kustovad208cc32014-03-18 09:59:19 +0400203" -c, --cmd STRING execute command with its arguments\n"
204" from the given string\n"
aliguorie3aff4f2009-04-05 19:14:04 +0000205" -r, --read-only export read-only\n"
206" -s, --snapshot use snapshot file\n"
207" -n, --nocache disable host cache\n"
Christoph Hellwig1db69472009-07-15 23:11:21 +0200208" -g, --growable allow file to grow (only applies to protocols)\n"
aliguorie3aff4f2009-04-05 19:14:04 +0000209" -m, --misalign misalign allocations for O_DIRECT\n"
Christoph Hellwig5c6c3a62009-08-20 16:58:35 +0200210" -k, --native-aio use kernel AIO implementation (on Linux only)\n"
Kevin Wolf592fa072012-04-18 12:07:39 +0200211" -t, --cache=MODE use the given cache mode for the image\n"
Stefan Hajnoczid7bb72c2012-03-12 16:36:07 +0000212" -T, --trace FILE enable trace events listed in the given file\n"
aliguorie3aff4f2009-04-05 19:14:04 +0000213" -h, --help display this help and exit\n"
214" -V, --version output version information and exit\n"
Maria Kustovad208cc32014-03-18 09:59:19 +0400215"\n"
216"See '%s -c help' for information on available commands."
aliguorie3aff4f2009-04-05 19:14:04 +0000217"\n",
Maria Kustovad208cc32014-03-18 09:59:19 +0400218 name, name);
aliguorie3aff4f2009-04-05 19:14:04 +0000219}
220
Kevin Wolfd1174f12013-06-05 14:19:37 +0200221static char *get_prompt(void)
222{
223 static char prompt[FILENAME_MAX + 2 /*"> "*/ + 1 /*"\0"*/ ];
224
225 if (!prompt[0]) {
226 snprintf(prompt, sizeof(prompt), "%s> ", progname);
227 }
228
229 return prompt;
230}
231
Stefan Weild5d15072014-01-25 18:18:23 +0100232static void GCC_FMT_ATTR(2, 3) readline_printf_func(void *opaque,
233 const char *fmt, ...)
Kevin Wolfd1174f12013-06-05 14:19:37 +0200234{
Stefan Hajnoczi0cf17e12013-11-14 11:54:17 +0100235 va_list ap;
236 va_start(ap, fmt);
237 vprintf(fmt, ap);
238 va_end(ap);
239}
240
241static void readline_flush_func(void *opaque)
242{
243 fflush(stdout);
244}
245
246static void readline_func(void *opaque, const char *str, void *readline_opaque)
247{
248 char **line = readline_opaque;
249 *line = g_strdup(str);
250}
251
Stefan Hajnoczi46940202013-11-14 11:54:18 +0100252static void completion_match(const char *cmd, void *opaque)
253{
254 readline_add_completion(readline_state, cmd);
255}
256
Stefan Hajnoczi0cf17e12013-11-14 11:54:17 +0100257static void readline_completion_func(void *opaque, const char *str)
258{
Stefan Hajnoczi46940202013-11-14 11:54:18 +0100259 readline_set_completion_index(readline_state, strlen(str));
260 qemuio_complete_command(str, completion_match, NULL);
Stefan Hajnoczi0cf17e12013-11-14 11:54:17 +0100261}
262
263static char *fetchline_readline(void)
264{
265 char *line = NULL;
266
267 readline_start(readline_state, get_prompt(), 0, readline_func, &line);
268 while (!line) {
269 int ch = getchar();
270 if (ch == EOF) {
271 break;
272 }
273 readline_handle_byte(readline_state, ch);
Kevin Wolfd1174f12013-06-05 14:19:37 +0200274 }
275 return line;
276}
Kevin Wolfd1174f12013-06-05 14:19:37 +0200277
Stefan Hajnoczi0cf17e12013-11-14 11:54:17 +0100278#define MAXREADLINESZ 1024
279static char *fetchline_fgets(void)
Kevin Wolfd1174f12013-06-05 14:19:37 +0200280{
281 char *p, *line = g_malloc(MAXREADLINESZ);
282
283 if (!fgets(line, MAXREADLINESZ, stdin)) {
284 g_free(line);
285 return NULL;
286 }
287
288 p = line + strlen(line);
289 if (p != line && p[-1] == '\n') {
290 p[-1] = '\0';
291 }
292
293 return line;
294}
Stefan Hajnoczi0cf17e12013-11-14 11:54:17 +0100295
296static char *fetchline(void)
297{
298 if (readline_state) {
299 return fetchline_readline();
300 } else {
301 return fetchline_fgets();
302 }
303}
Kevin Wolfd1174f12013-06-05 14:19:37 +0200304
305static void prep_fetchline(void *opaque)
306{
307 int *fetchable = opaque;
308
309 qemu_set_fd_handler(STDIN_FILENO, NULL, NULL, NULL);
310 *fetchable= 1;
311}
312
313static void command_loop(void)
314{
315 int i, done = 0, fetchable = 0, prompted = 0;
316 char *input;
317
318 for (i = 0; !done && i < ncmdline; i++) {
Kevin Wolf3d219942013-06-05 14:19:39 +0200319 done = qemuio_command(qemuio_bs, cmdline[i]);
Kevin Wolfd1174f12013-06-05 14:19:37 +0200320 }
321 if (cmdline) {
322 g_free(cmdline);
323 return;
324 }
325
326 while (!done) {
327 if (!prompted) {
328 printf("%s", get_prompt());
329 fflush(stdout);
330 qemu_set_fd_handler(STDIN_FILENO, prep_fetchline, NULL, &fetchable);
331 prompted = 1;
332 }
333
334 main_loop_wait(false);
335
336 if (!fetchable) {
337 continue;
338 }
339
340 input = fetchline();
341 if (input == NULL) {
342 break;
343 }
Kevin Wolf3d219942013-06-05 14:19:39 +0200344 done = qemuio_command(qemuio_bs, input);
Kevin Wolfd1174f12013-06-05 14:19:37 +0200345 g_free(input);
346
347 prompted = 0;
348 fetchable = 0;
349 }
350 qemu_set_fd_handler(STDIN_FILENO, NULL, NULL, NULL);
351}
352
353static void add_user_command(char *optarg)
354{
355 cmdline = g_realloc(cmdline, ++ncmdline * sizeof(char *));
356 cmdline[ncmdline-1] = optarg;
357}
358
Stefan Hajnoczi0cf17e12013-11-14 11:54:17 +0100359static void reenable_tty_echo(void)
360{
361 qemu_set_tty_echo(STDIN_FILENO, true);
362}
363
aliguorie3aff4f2009-04-05 19:14:04 +0000364int main(int argc, char **argv)
365{
Devin Nakamura43642b32011-07-11 11:22:16 -0400366 int readonly = 0;
367 int growable = 0;
Paolo Bonzini9e8f1832013-02-08 14:06:11 +0100368 const char *sopt = "hVc:d:rsnmgkt:T:";
Devin Nakamura43642b32011-07-11 11:22:16 -0400369 const struct option lopt[] = {
370 { "help", 0, NULL, 'h' },
371 { "version", 0, NULL, 'V' },
372 { "offset", 1, NULL, 'o' },
373 { "cmd", 1, NULL, 'c' },
374 { "read-only", 0, NULL, 'r' },
375 { "snapshot", 0, NULL, 's' },
376 { "nocache", 0, NULL, 'n' },
377 { "misalign", 0, NULL, 'm' },
378 { "growable", 0, NULL, 'g' },
379 { "native-aio", 0, NULL, 'k' },
Paolo Bonzini9e8f1832013-02-08 14:06:11 +0100380 { "discard", 1, NULL, 'd' },
Kevin Wolf592fa072012-04-18 12:07:39 +0200381 { "cache", 1, NULL, 't' },
Stefan Hajnoczid7bb72c2012-03-12 16:36:07 +0000382 { "trace", 1, NULL, 'T' },
Devin Nakamura43642b32011-07-11 11:22:16 -0400383 { NULL, 0, NULL, 0 }
384 };
385 int c;
386 int opt_index = 0;
Paolo Bonzini9e8f1832013-02-08 14:06:11 +0100387 int flags = BDRV_O_UNMAP;
aliguorie3aff4f2009-04-05 19:14:04 +0000388
MORITA Kazutaka526eda12013-07-23 17:30:11 +0900389#ifdef CONFIG_POSIX
390 signal(SIGPIPE, SIG_IGN);
391#endif
392
Devin Nakamura43642b32011-07-11 11:22:16 -0400393 progname = basename(argv[0]);
Fam Zheng10f5bff2014-02-10 14:48:51 +0800394 qemu_init_exec_dir(argv[0]);
aliguorie3aff4f2009-04-05 19:14:04 +0000395
Devin Nakamura43642b32011-07-11 11:22:16 -0400396 while ((c = getopt_long(argc, argv, sopt, lopt, &opt_index)) != -1) {
397 switch (c) {
398 case 's':
399 flags |= BDRV_O_SNAPSHOT;
400 break;
401 case 'n':
402 flags |= BDRV_O_NOCACHE | BDRV_O_CACHE_WB;
403 break;
Paolo Bonzini9e8f1832013-02-08 14:06:11 +0100404 case 'd':
405 if (bdrv_parse_discard_flags(optarg, &flags) < 0) {
406 error_report("Invalid discard option: %s", optarg);
407 exit(1);
408 }
409 break;
Devin Nakamura43642b32011-07-11 11:22:16 -0400410 case 'c':
411 add_user_command(optarg);
412 break;
413 case 'r':
414 readonly = 1;
415 break;
416 case 'm':
Stefan Weilf9883882014-03-05 22:23:00 +0100417 qemuio_misalign = true;
Devin Nakamura43642b32011-07-11 11:22:16 -0400418 break;
419 case 'g':
420 growable = 1;
421 break;
422 case 'k':
423 flags |= BDRV_O_NATIVE_AIO;
424 break;
Kevin Wolf592fa072012-04-18 12:07:39 +0200425 case 't':
426 if (bdrv_parse_cache_flags(optarg, &flags) < 0) {
427 error_report("Invalid cache option: %s", optarg);
428 exit(1);
429 }
430 break;
Stefan Hajnoczid7bb72c2012-03-12 16:36:07 +0000431 case 'T':
432 if (!trace_backend_init(optarg, NULL)) {
433 exit(1); /* error message will have been printed */
434 }
435 break;
Devin Nakamura43642b32011-07-11 11:22:16 -0400436 case 'V':
Kevin Wolf02da3862013-06-05 14:19:40 +0200437 printf("%s version %s\n", progname, QEMU_VERSION);
Devin Nakamura43642b32011-07-11 11:22:16 -0400438 exit(0);
439 case 'h':
440 usage(progname);
441 exit(0);
442 default:
443 usage(progname);
444 exit(1);
Naphtali Spreif5edb012010-01-17 16:48:13 +0200445 }
Devin Nakamura43642b32011-07-11 11:22:16 -0400446 }
aliguorie3aff4f2009-04-05 19:14:04 +0000447
Devin Nakamura43642b32011-07-11 11:22:16 -0400448 if ((argc - optind) > 1) {
449 usage(progname);
450 exit(1);
451 }
aliguorie3aff4f2009-04-05 19:14:04 +0000452
Zhi Yong Wua57d1142012-02-19 22:24:59 +0800453 qemu_init_main_loop();
Paolo Bonzini2592c592012-11-03 18:10:17 +0100454 bdrv_init();
Zhi Yong Wua57d1142012-02-19 22:24:59 +0800455
Devin Nakamura43642b32011-07-11 11:22:16 -0400456 /* initialize commands */
Kevin Wolfc2cdf5c2013-06-05 14:19:36 +0200457 qemuio_add_command(&quit_cmd);
458 qemuio_add_command(&open_cmd);
459 qemuio_add_command(&close_cmd);
Devin Nakamura43642b32011-07-11 11:22:16 -0400460
Stefan Hajnoczi0cf17e12013-11-14 11:54:17 +0100461 if (isatty(STDIN_FILENO)) {
462 readline_state = readline_init(readline_printf_func,
463 readline_flush_func,
464 NULL,
465 readline_completion_func);
466 qemu_set_tty_echo(STDIN_FILENO, false);
467 atexit(reenable_tty_echo);
468 }
469
Devin Nakamura43642b32011-07-11 11:22:16 -0400470 /* open the device */
471 if (!readonly) {
472 flags |= BDRV_O_RDWR;
473 }
474
475 if ((argc - optind) == 1) {
Max Reitzb543c5c2013-10-11 14:02:10 +0200476 openfile(argv[optind], flags, growable, NULL);
Devin Nakamura43642b32011-07-11 11:22:16 -0400477 }
478 command_loop();
479
480 /*
Stefan Hajnoczi922453b2011-11-30 12:23:43 +0000481 * Make sure all outstanding requests complete before the program exits.
Devin Nakamura43642b32011-07-11 11:22:16 -0400482 */
Stefan Hajnoczi922453b2011-11-30 12:23:43 +0000483 bdrv_drain_all();
Devin Nakamura43642b32011-07-11 11:22:16 -0400484
Kevin Wolf734c3b82013-06-05 14:19:30 +0200485 if (qemuio_bs) {
Fam Zheng4f6fd342013-08-23 09:14:47 +0800486 bdrv_unref(qemuio_bs);
Devin Nakamura43642b32011-07-11 11:22:16 -0400487 }
Stefan Hajnoczi0cf17e12013-11-14 11:54:17 +0100488 g_free(readline_state);
Devin Nakamura43642b32011-07-11 11:22:16 -0400489 return 0;
aliguorie3aff4f2009-04-05 19:14:04 +0000490}