blob: 66cf3ef4be02cbf9584a25a85fa1fbcdf94fe210 [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");
Markus Armbruster29f26012014-05-28 11:16:59 +020057 QDECREF(opts);
Devin Nakamura43642b32011-07-11 11:22:16 -040058 return 1;
59 }
aliguorie3aff4f2009-04-05 19:14:04 +000060
Markus Armbrusterdbb651c2014-09-08 18:50:58 +020061 qemuio_bs = bdrv_new("hda", &error_abort);
Christoph Hellwig6db95602010-04-05 16:53:57 +020062
Markus Armbrusterdbb651c2014-09-08 18:50:58 +020063 if (growable) {
64 flags |= BDRV_O_PROTOCOL;
65 }
66
67 if (bdrv_open(&qemuio_bs, name, NULL, opts, flags, NULL, &local_err) < 0) {
68 fprintf(stderr, "%s: can't open%s%s: %s\n", progname,
69 name ? " device " : "", name ?: "",
70 error_get_pretty(local_err));
71 error_free(local_err);
72 bdrv_unref(qemuio_bs);
73 qemuio_bs = NULL;
74 return 1;
Devin Nakamura43642b32011-07-11 11:22:16 -040075 }
Christoph Hellwig1db69472009-07-15 23:11:21 +020076
Devin Nakamura43642b32011-07-11 11:22:16 -040077 return 0;
aliguorie3aff4f2009-04-05 19:14:04 +000078}
79
Devin Nakamura43642b32011-07-11 11:22:16 -040080static void open_help(void)
aliguorie3aff4f2009-04-05 19:14:04 +000081{
Devin Nakamura43642b32011-07-11 11:22:16 -040082 printf(
aliguorie3aff4f2009-04-05 19:14:04 +000083"\n"
84" opens a new file in the requested mode\n"
85"\n"
86" Example:\n"
87" 'open -Cn /tmp/data' - creates/opens data file read-write and uncached\n"
88"\n"
89" Opens a file for subsequent use by all of the other qemu-io commands.\n"
aliguorie3aff4f2009-04-05 19:14:04 +000090" -r, -- open file read-only\n"
91" -s, -- use snapshot file\n"
92" -n, -- disable host cache\n"
Max Reitzb543c5c2013-10-11 14:02:10 +020093" -g, -- allow file to grow (only applies to protocols)\n"
94" -o, -- options to be given to the block driver"
aliguorie3aff4f2009-04-05 19:14:04 +000095"\n");
96}
97
Kevin Wolf734c3b82013-06-05 14:19:30 +020098static int open_f(BlockDriverState *bs, int argc, char **argv);
Blue Swirl22a2bdc2009-11-21 09:06:46 +000099
100static const cmdinfo_t open_cmd = {
Devin Nakamura43642b32011-07-11 11:22:16 -0400101 .name = "open",
102 .altname = "o",
103 .cfunc = open_f,
104 .argmin = 1,
105 .argmax = -1,
106 .flags = CMD_NOFILE_OK,
Max Reitzb543c5c2013-10-11 14:02:10 +0200107 .args = "[-Crsn] [-o options] [path]",
Devin Nakamura43642b32011-07-11 11:22:16 -0400108 .oneline = "open the file specified by path",
109 .help = open_help,
Blue Swirl22a2bdc2009-11-21 09:06:46 +0000110};
aliguorie3aff4f2009-04-05 19:14:04 +0000111
Max Reitzb543c5c2013-10-11 14:02:10 +0200112static QemuOptsList empty_opts = {
113 .name = "drive",
Markus Armbruster443422f2014-05-28 11:16:58 +0200114 .merge_lists = true,
Max Reitzb543c5c2013-10-11 14:02:10 +0200115 .head = QTAILQ_HEAD_INITIALIZER(empty_opts.head),
116 .desc = {
117 /* no elements => accept any params */
118 { /* end of list */ }
119 },
120};
121
Kevin Wolf734c3b82013-06-05 14:19:30 +0200122static int open_f(BlockDriverState *bs, int argc, char **argv)
aliguorie3aff4f2009-04-05 19:14:04 +0000123{
Devin Nakamura43642b32011-07-11 11:22:16 -0400124 int flags = 0;
125 int readonly = 0;
126 int growable = 0;
127 int c;
Max Reitzb543c5c2013-10-11 14:02:10 +0200128 QemuOpts *qopts;
Markus Armbruster443422f2014-05-28 11:16:58 +0200129 QDict *opts;
aliguorie3aff4f2009-04-05 19:14:04 +0000130
Max Reitzb543c5c2013-10-11 14:02:10 +0200131 while ((c = getopt(argc, argv, "snrgo:")) != EOF) {
Devin Nakamura43642b32011-07-11 11:22:16 -0400132 switch (c) {
133 case 's':
134 flags |= BDRV_O_SNAPSHOT;
135 break;
136 case 'n':
137 flags |= BDRV_O_NOCACHE | BDRV_O_CACHE_WB;
138 break;
139 case 'r':
140 readonly = 1;
141 break;
142 case 'g':
143 growable = 1;
144 break;
Max Reitzb543c5c2013-10-11 14:02:10 +0200145 case 'o':
Markus Armbruster443422f2014-05-28 11:16:58 +0200146 if (!qemu_opts_parse(&empty_opts, optarg, 0)) {
Max Reitzb543c5c2013-10-11 14:02:10 +0200147 printf("could not parse option list -- %s\n", optarg);
Markus Armbruster443422f2014-05-28 11:16:58 +0200148 qemu_opts_reset(&empty_opts);
Max Reitzb543c5c2013-10-11 14:02:10 +0200149 return 0;
150 }
Max Reitzb543c5c2013-10-11 14:02:10 +0200151 break;
Devin Nakamura43642b32011-07-11 11:22:16 -0400152 default:
Markus Armbruster443422f2014-05-28 11:16:58 +0200153 qemu_opts_reset(&empty_opts);
Kevin Wolfc2cdf5c2013-06-05 14:19:36 +0200154 return qemuio_command_usage(&open_cmd);
Naphtali Spreif5edb012010-01-17 16:48:13 +0200155 }
Devin Nakamura43642b32011-07-11 11:22:16 -0400156 }
aliguorie3aff4f2009-04-05 19:14:04 +0000157
Devin Nakamura43642b32011-07-11 11:22:16 -0400158 if (!readonly) {
159 flags |= BDRV_O_RDWR;
160 }
aliguorie3aff4f2009-04-05 19:14:04 +0000161
Markus Armbruster443422f2014-05-28 11:16:58 +0200162 qopts = qemu_opts_find(&empty_opts, NULL);
163 opts = qopts ? qemu_opts_to_qdict(qopts, NULL) : NULL;
164 qemu_opts_reset(&empty_opts);
165
Max Reitzfd0fee32013-12-20 19:28:20 +0100166 if (optind == argc - 1) {
167 return openfile(argv[optind], flags, growable, opts);
168 } else if (optind == argc) {
169 return openfile(NULL, flags, growable, opts);
170 } else {
Markus Armbruster29f26012014-05-28 11:16:59 +0200171 QDECREF(opts);
Kevin Wolfc2cdf5c2013-06-05 14:19:36 +0200172 return qemuio_command_usage(&open_cmd);
Devin Nakamura43642b32011-07-11 11:22:16 -0400173 }
aliguorie3aff4f2009-04-05 19:14:04 +0000174}
175
Kevin Wolfe681be72013-06-05 14:19:34 +0200176static int quit_f(BlockDriverState *bs, int argc, char **argv)
177{
178 return 1;
179}
180
181static const cmdinfo_t quit_cmd = {
182 .name = "quit",
183 .altname = "q",
184 .cfunc = quit_f,
185 .argmin = -1,
186 .argmax = -1,
187 .flags = CMD_FLAG_GLOBAL,
188 .oneline = "exit the program",
189};
190
aliguorie3aff4f2009-04-05 19:14:04 +0000191static void usage(const char *name)
192{
Devin Nakamura43642b32011-07-11 11:22:16 -0400193 printf(
Maria Kustovad208cc32014-03-18 09:59:19 +0400194"Usage: %s [-h] [-V] [-rsnm] [-c STRING] ... [file]\n"
Stefan Weil84844a22009-06-22 15:08:47 +0200195"QEMU Disk exerciser\n"
aliguorie3aff4f2009-04-05 19:14:04 +0000196"\n"
Maria Kustovad208cc32014-03-18 09:59:19 +0400197" -c, --cmd STRING execute command with its arguments\n"
198" from the given string\n"
aliguorie3aff4f2009-04-05 19:14:04 +0000199" -r, --read-only export read-only\n"
200" -s, --snapshot use snapshot file\n"
201" -n, --nocache disable host cache\n"
Christoph Hellwig1db69472009-07-15 23:11:21 +0200202" -g, --growable allow file to grow (only applies to protocols)\n"
aliguorie3aff4f2009-04-05 19:14:04 +0000203" -m, --misalign misalign allocations for O_DIRECT\n"
Christoph Hellwig5c6c3a62009-08-20 16:58:35 +0200204" -k, --native-aio use kernel AIO implementation (on Linux only)\n"
Kevin Wolf592fa072012-04-18 12:07:39 +0200205" -t, --cache=MODE use the given cache mode for the image\n"
Stefan Hajnoczid7bb72c2012-03-12 16:36:07 +0000206" -T, --trace FILE enable trace events listed in the given file\n"
aliguorie3aff4f2009-04-05 19:14:04 +0000207" -h, --help display this help and exit\n"
208" -V, --version output version information and exit\n"
Maria Kustovad208cc32014-03-18 09:59:19 +0400209"\n"
210"See '%s -c help' for information on available commands."
aliguorie3aff4f2009-04-05 19:14:04 +0000211"\n",
Maria Kustovad208cc32014-03-18 09:59:19 +0400212 name, name);
aliguorie3aff4f2009-04-05 19:14:04 +0000213}
214
Kevin Wolfd1174f12013-06-05 14:19:37 +0200215static char *get_prompt(void)
216{
217 static char prompt[FILENAME_MAX + 2 /*"> "*/ + 1 /*"\0"*/ ];
218
219 if (!prompt[0]) {
220 snprintf(prompt, sizeof(prompt), "%s> ", progname);
221 }
222
223 return prompt;
224}
225
Stefan Weild5d15072014-01-25 18:18:23 +0100226static void GCC_FMT_ATTR(2, 3) readline_printf_func(void *opaque,
227 const char *fmt, ...)
Kevin Wolfd1174f12013-06-05 14:19:37 +0200228{
Stefan Hajnoczi0cf17e12013-11-14 11:54:17 +0100229 va_list ap;
230 va_start(ap, fmt);
231 vprintf(fmt, ap);
232 va_end(ap);
233}
234
235static void readline_flush_func(void *opaque)
236{
237 fflush(stdout);
238}
239
240static void readline_func(void *opaque, const char *str, void *readline_opaque)
241{
242 char **line = readline_opaque;
243 *line = g_strdup(str);
244}
245
Stefan Hajnoczi46940202013-11-14 11:54:18 +0100246static void completion_match(const char *cmd, void *opaque)
247{
248 readline_add_completion(readline_state, cmd);
249}
250
Stefan Hajnoczi0cf17e12013-11-14 11:54:17 +0100251static void readline_completion_func(void *opaque, const char *str)
252{
Stefan Hajnoczi46940202013-11-14 11:54:18 +0100253 readline_set_completion_index(readline_state, strlen(str));
254 qemuio_complete_command(str, completion_match, NULL);
Stefan Hajnoczi0cf17e12013-11-14 11:54:17 +0100255}
256
257static char *fetchline_readline(void)
258{
259 char *line = NULL;
260
261 readline_start(readline_state, get_prompt(), 0, readline_func, &line);
262 while (!line) {
263 int ch = getchar();
264 if (ch == EOF) {
265 break;
266 }
267 readline_handle_byte(readline_state, ch);
Kevin Wolfd1174f12013-06-05 14:19:37 +0200268 }
269 return line;
270}
Kevin Wolfd1174f12013-06-05 14:19:37 +0200271
Stefan Hajnoczi0cf17e12013-11-14 11:54:17 +0100272#define MAXREADLINESZ 1024
273static char *fetchline_fgets(void)
Kevin Wolfd1174f12013-06-05 14:19:37 +0200274{
275 char *p, *line = g_malloc(MAXREADLINESZ);
276
277 if (!fgets(line, MAXREADLINESZ, stdin)) {
278 g_free(line);
279 return NULL;
280 }
281
282 p = line + strlen(line);
283 if (p != line && p[-1] == '\n') {
284 p[-1] = '\0';
285 }
286
287 return line;
288}
Stefan Hajnoczi0cf17e12013-11-14 11:54:17 +0100289
290static char *fetchline(void)
291{
292 if (readline_state) {
293 return fetchline_readline();
294 } else {
295 return fetchline_fgets();
296 }
297}
Kevin Wolfd1174f12013-06-05 14:19:37 +0200298
299static void prep_fetchline(void *opaque)
300{
301 int *fetchable = opaque;
302
303 qemu_set_fd_handler(STDIN_FILENO, NULL, NULL, NULL);
304 *fetchable= 1;
305}
306
307static void command_loop(void)
308{
309 int i, done = 0, fetchable = 0, prompted = 0;
310 char *input;
311
312 for (i = 0; !done && i < ncmdline; i++) {
Kevin Wolf3d219942013-06-05 14:19:39 +0200313 done = qemuio_command(qemuio_bs, cmdline[i]);
Kevin Wolfd1174f12013-06-05 14:19:37 +0200314 }
315 if (cmdline) {
316 g_free(cmdline);
317 return;
318 }
319
320 while (!done) {
321 if (!prompted) {
322 printf("%s", get_prompt());
323 fflush(stdout);
324 qemu_set_fd_handler(STDIN_FILENO, prep_fetchline, NULL, &fetchable);
325 prompted = 1;
326 }
327
328 main_loop_wait(false);
329
330 if (!fetchable) {
331 continue;
332 }
333
334 input = fetchline();
335 if (input == NULL) {
336 break;
337 }
Kevin Wolf3d219942013-06-05 14:19:39 +0200338 done = qemuio_command(qemuio_bs, input);
Kevin Wolfd1174f12013-06-05 14:19:37 +0200339 g_free(input);
340
341 prompted = 0;
342 fetchable = 0;
343 }
344 qemu_set_fd_handler(STDIN_FILENO, NULL, NULL, NULL);
345}
346
347static void add_user_command(char *optarg)
348{
Markus Armbruster5839e532014-08-19 10:31:08 +0200349 cmdline = g_renew(char *, cmdline, ++ncmdline);
Kevin Wolfd1174f12013-06-05 14:19:37 +0200350 cmdline[ncmdline-1] = optarg;
351}
352
Stefan Hajnoczi0cf17e12013-11-14 11:54:17 +0100353static void reenable_tty_echo(void)
354{
355 qemu_set_tty_echo(STDIN_FILENO, true);
356}
357
aliguorie3aff4f2009-04-05 19:14:04 +0000358int main(int argc, char **argv)
359{
Devin Nakamura43642b32011-07-11 11:22:16 -0400360 int readonly = 0;
361 int growable = 0;
Paolo Bonzini9e8f1832013-02-08 14:06:11 +0100362 const char *sopt = "hVc:d:rsnmgkt:T:";
Devin Nakamura43642b32011-07-11 11:22:16 -0400363 const struct option lopt[] = {
364 { "help", 0, NULL, 'h' },
365 { "version", 0, NULL, 'V' },
366 { "offset", 1, NULL, 'o' },
367 { "cmd", 1, NULL, 'c' },
368 { "read-only", 0, NULL, 'r' },
369 { "snapshot", 0, NULL, 's' },
370 { "nocache", 0, NULL, 'n' },
371 { "misalign", 0, NULL, 'm' },
372 { "growable", 0, NULL, 'g' },
373 { "native-aio", 0, NULL, 'k' },
Paolo Bonzini9e8f1832013-02-08 14:06:11 +0100374 { "discard", 1, NULL, 'd' },
Kevin Wolf592fa072012-04-18 12:07:39 +0200375 { "cache", 1, NULL, 't' },
Stefan Hajnoczid7bb72c2012-03-12 16:36:07 +0000376 { "trace", 1, NULL, 'T' },
Devin Nakamura43642b32011-07-11 11:22:16 -0400377 { NULL, 0, NULL, 0 }
378 };
379 int c;
380 int opt_index = 0;
Paolo Bonzini9e8f1832013-02-08 14:06:11 +0100381 int flags = BDRV_O_UNMAP;
Chrysostomos Nanakos2f78e492014-09-18 14:30:49 +0300382 Error *local_error = NULL;
aliguorie3aff4f2009-04-05 19:14:04 +0000383
MORITA Kazutaka526eda12013-07-23 17:30:11 +0900384#ifdef CONFIG_POSIX
385 signal(SIGPIPE, SIG_IGN);
386#endif
387
Devin Nakamura43642b32011-07-11 11:22:16 -0400388 progname = basename(argv[0]);
Fam Zheng10f5bff2014-02-10 14:48:51 +0800389 qemu_init_exec_dir(argv[0]);
aliguorie3aff4f2009-04-05 19:14:04 +0000390
Devin Nakamura43642b32011-07-11 11:22:16 -0400391 while ((c = getopt_long(argc, argv, sopt, lopt, &opt_index)) != -1) {
392 switch (c) {
393 case 's':
394 flags |= BDRV_O_SNAPSHOT;
395 break;
396 case 'n':
397 flags |= BDRV_O_NOCACHE | BDRV_O_CACHE_WB;
398 break;
Paolo Bonzini9e8f1832013-02-08 14:06:11 +0100399 case 'd':
400 if (bdrv_parse_discard_flags(optarg, &flags) < 0) {
401 error_report("Invalid discard option: %s", optarg);
402 exit(1);
403 }
404 break;
Devin Nakamura43642b32011-07-11 11:22:16 -0400405 case 'c':
406 add_user_command(optarg);
407 break;
408 case 'r':
409 readonly = 1;
410 break;
411 case 'm':
Stefan Weilf9883882014-03-05 22:23:00 +0100412 qemuio_misalign = true;
Devin Nakamura43642b32011-07-11 11:22:16 -0400413 break;
414 case 'g':
415 growable = 1;
416 break;
417 case 'k':
418 flags |= BDRV_O_NATIVE_AIO;
419 break;
Kevin Wolf592fa072012-04-18 12:07:39 +0200420 case 't':
421 if (bdrv_parse_cache_flags(optarg, &flags) < 0) {
422 error_report("Invalid cache option: %s", optarg);
423 exit(1);
424 }
425 break;
Stefan Hajnoczid7bb72c2012-03-12 16:36:07 +0000426 case 'T':
LluĂ­s Vilanova5b808272014-05-27 15:02:14 +0200427 if (!trace_init_backends(optarg, NULL)) {
Stefan Hajnoczid7bb72c2012-03-12 16:36:07 +0000428 exit(1); /* error message will have been printed */
429 }
430 break;
Devin Nakamura43642b32011-07-11 11:22:16 -0400431 case 'V':
Kevin Wolf02da3862013-06-05 14:19:40 +0200432 printf("%s version %s\n", progname, QEMU_VERSION);
Devin Nakamura43642b32011-07-11 11:22:16 -0400433 exit(0);
434 case 'h':
435 usage(progname);
436 exit(0);
437 default:
438 usage(progname);
439 exit(1);
Naphtali Spreif5edb012010-01-17 16:48:13 +0200440 }
Devin Nakamura43642b32011-07-11 11:22:16 -0400441 }
aliguorie3aff4f2009-04-05 19:14:04 +0000442
Devin Nakamura43642b32011-07-11 11:22:16 -0400443 if ((argc - optind) > 1) {
444 usage(progname);
445 exit(1);
446 }
aliguorie3aff4f2009-04-05 19:14:04 +0000447
Chrysostomos Nanakos2f78e492014-09-18 14:30:49 +0300448 if (qemu_init_main_loop(&local_error)) {
449 error_report("%s", error_get_pretty(local_error));
450 error_free(local_error);
451 exit(1);
452 }
Paolo Bonzini2592c592012-11-03 18:10:17 +0100453 bdrv_init();
Zhi Yong Wua57d1142012-02-19 22:24:59 +0800454
Devin Nakamura43642b32011-07-11 11:22:16 -0400455 /* initialize commands */
Kevin Wolfc2cdf5c2013-06-05 14:19:36 +0200456 qemuio_add_command(&quit_cmd);
457 qemuio_add_command(&open_cmd);
458 qemuio_add_command(&close_cmd);
Devin Nakamura43642b32011-07-11 11:22:16 -0400459
Stefan Hajnoczi0cf17e12013-11-14 11:54:17 +0100460 if (isatty(STDIN_FILENO)) {
461 readline_state = readline_init(readline_printf_func,
462 readline_flush_func,
463 NULL,
464 readline_completion_func);
465 qemu_set_tty_echo(STDIN_FILENO, false);
466 atexit(reenable_tty_echo);
467 }
468
Devin Nakamura43642b32011-07-11 11:22:16 -0400469 /* open the device */
470 if (!readonly) {
471 flags |= BDRV_O_RDWR;
472 }
473
474 if ((argc - optind) == 1) {
Max Reitzb543c5c2013-10-11 14:02:10 +0200475 openfile(argv[optind], flags, growable, NULL);
Devin Nakamura43642b32011-07-11 11:22:16 -0400476 }
477 command_loop();
478
479 /*
Stefan Hajnoczi922453b2011-11-30 12:23:43 +0000480 * Make sure all outstanding requests complete before the program exits.
Devin Nakamura43642b32011-07-11 11:22:16 -0400481 */
Stefan Hajnoczi922453b2011-11-30 12:23:43 +0000482 bdrv_drain_all();
Devin Nakamura43642b32011-07-11 11:22:16 -0400483
Kevin Wolf734c3b82013-06-05 14:19:30 +0200484 if (qemuio_bs) {
Fam Zheng4f6fd342013-08-23 09:14:47 +0800485 bdrv_unref(qemuio_bs);
Devin Nakamura43642b32011-07-11 11:22:16 -0400486 }
Stefan Hajnoczi0cf17e12013-11-14 11:54:17 +0100487 g_free(readline_state);
Devin Nakamura43642b32011-07-11 11:22:16 -0400488 return 0;
aliguorie3aff4f2009-04-05 19:14:04 +0000489}