2 * Command line utility to exercise the QEMU I/O path.
4 * Copyright (C) 2009 Red Hat, Inc.
5 * Copyright (c) 2003-2005 Silicon Graphics, Inc.
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.
12 #include "sysemu/block-backend.h"
13 #include "block/block.h"
14 #include "block/block_int.h" /* for info_f() */
15 #include "block/qapi.h"
16 #include "qemu/error-report.h"
17 #include "qemu/main-loop.h"
18 #include "qemu/timer.h"
19 #include "sysemu/block-backend.h"
21 #define CMD_NOFILE_OK 0x01
25 static cmdinfo_t *cmdtab;
28 static int compare_cmdname(const void *a, const void *b)
30 return strcmp(((const cmdinfo_t *)a)->name,
31 ((const cmdinfo_t *)b)->name);
34 void qemuio_add_command(const cmdinfo_t *ci)
36 cmdtab = g_renew(cmdinfo_t, cmdtab, ++ncmds);
37 cmdtab[ncmds - 1] = *ci;
38 qsort(cmdtab, ncmds, sizeof(*cmdtab), compare_cmdname);
41 int qemuio_command_usage(const cmdinfo_t *ci)
43 printf("%s %s -- %s\n", ci->name, ci->args, ci->oneline);
47 static int init_check_command(BlockBackend *blk, const cmdinfo_t *ct)
49 if (ct->flags & CMD_FLAG_GLOBAL) {
52 if (!(ct->flags & CMD_NOFILE_OK) && !blk) {
53 fprintf(stderr, "no file open, try 'help open'\n");
59 static int command(BlockBackend *blk, const cmdinfo_t *ct, int argc,
64 if (!init_check_command(blk, ct)) {
68 if (argc - 1 < ct->argmin || (ct->argmax != -1 && argc - 1 > ct->argmax)) {
69 if (ct->argmax == -1) {
71 "bad argument count %d to %s, expected at least %d arguments\n",
72 argc-1, cmd, ct->argmin);
73 } else if (ct->argmin == ct->argmax) {
75 "bad argument count %d to %s, expected %d arguments\n",
76 argc-1, cmd, ct->argmin);
79 "bad argument count %d to %s, expected between %d and %d arguments\n",
80 argc-1, cmd, ct->argmin, ct->argmax);
85 return ct->cfunc(blk, argc, argv);
88 static const cmdinfo_t *find_command(const char *cmd)
92 for (ct = cmdtab; ct < &cmdtab[ncmds]; ct++) {
93 if (strcmp(ct->name, cmd) == 0 ||
94 (ct->altname && strcmp(ct->altname, cmd) == 0))
96 return (const cmdinfo_t *)ct;
102 /* Invoke fn() for commands with a matching prefix */
103 void qemuio_complete_command(const char *input,
104 void (*fn)(const char *cmd, void *opaque),
108 size_t input_len = strlen(input);
110 for (ct = cmdtab; ct < &cmdtab[ncmds]; ct++) {
111 if (strncmp(input, ct->name, input_len) == 0) {
112 fn(ct->name, opaque);
117 static char **breakline(char *input, int *count)
121 char **rval = g_new0(char *, 1);
123 while (rval && (p = qemu_strsep(&input, " ")) != NULL) {
128 rval = g_renew(char *, rval, (c + 1));
136 static int64_t cvtnum(const char *s)
141 ret = qemu_strtosz_suffix(s, &end, QEMU_STRTOSZ_DEFSUFFIX_B);
143 /* Detritus at the end of the string */
149 #define EXABYTES(x) ((long long)(x) << 60)
150 #define PETABYTES(x) ((long long)(x) << 50)
151 #define TERABYTES(x) ((long long)(x) << 40)
152 #define GIGABYTES(x) ((long long)(x) << 30)
153 #define MEGABYTES(x) ((long long)(x) << 20)
154 #define KILOBYTES(x) ((long long)(x) << 10)
156 #define TO_EXABYTES(x) ((x) / EXABYTES(1))
157 #define TO_PETABYTES(x) ((x) / PETABYTES(1))
158 #define TO_TERABYTES(x) ((x) / TERABYTES(1))
159 #define TO_GIGABYTES(x) ((x) / GIGABYTES(1))
160 #define TO_MEGABYTES(x) ((x) / MEGABYTES(1))
161 #define TO_KILOBYTES(x) ((x) / KILOBYTES(1))
163 static void cvtstr(double value, char *str, size_t size)
168 if (value >= EXABYTES(1)) {
170 snprintf(str, size - 4, "%.3f", TO_EXABYTES(value));
171 } else if (value >= PETABYTES(1)) {
173 snprintf(str, size - 4, "%.3f", TO_PETABYTES(value));
174 } else if (value >= TERABYTES(1)) {
176 snprintf(str, size - 4, "%.3f", TO_TERABYTES(value));
177 } else if (value >= GIGABYTES(1)) {
179 snprintf(str, size - 4, "%.3f", TO_GIGABYTES(value));
180 } else if (value >= MEGABYTES(1)) {
182 snprintf(str, size - 4, "%.3f", TO_MEGABYTES(value));
183 } else if (value >= KILOBYTES(1)) {
185 snprintf(str, size - 4, "%.3f", TO_KILOBYTES(value));
188 snprintf(str, size - 6, "%f", value);
191 trim = strstr(str, ".000");
193 strcpy(trim, suffix);
201 static struct timeval tsub(struct timeval t1, struct timeval t2)
203 t1.tv_usec -= t2.tv_usec;
204 if (t1.tv_usec < 0) {
205 t1.tv_usec += 1000000;
208 t1.tv_sec -= t2.tv_sec;
212 static double tdiv(double value, struct timeval tv)
214 return value / ((double)tv.tv_sec + ((double)tv.tv_usec / 1000000.0));
217 #define HOURS(sec) ((sec) / (60 * 60))
218 #define MINUTES(sec) (((sec) % (60 * 60)) / 60)
219 #define SECONDS(sec) ((sec) % 60)
223 TERSE_FIXED_TIME = 0x1,
224 VERBOSE_FIXED_TIME = 0x2,
227 static void timestr(struct timeval *tv, char *ts, size_t size, int format)
229 double usec = (double)tv->tv_usec / 1000000.0;
231 if (format & TERSE_FIXED_TIME) {
232 if (!HOURS(tv->tv_sec)) {
233 snprintf(ts, size, "%u:%02u.%02u",
234 (unsigned int) MINUTES(tv->tv_sec),
235 (unsigned int) SECONDS(tv->tv_sec),
236 (unsigned int) (usec * 100));
239 format |= VERBOSE_FIXED_TIME; /* fallback if hours needed */
242 if ((format & VERBOSE_FIXED_TIME) || tv->tv_sec) {
243 snprintf(ts, size, "%u:%02u:%02u.%02u",
244 (unsigned int) HOURS(tv->tv_sec),
245 (unsigned int) MINUTES(tv->tv_sec),
246 (unsigned int) SECONDS(tv->tv_sec),
247 (unsigned int) (usec * 100));
249 snprintf(ts, size, "0.%04u sec", (unsigned int) (usec * 10000));
254 * Parse the pattern argument to various sub-commands.
256 * Because the pattern is used as an argument to memset it must evaluate
257 * to an unsigned integer that fits into a single byte.
259 static int parse_pattern(const char *arg)
264 pattern = strtol(arg, &endptr, 0);
265 if (pattern < 0 || pattern > UCHAR_MAX || *endptr != '\0') {
266 printf("%s is not a valid pattern byte\n", arg);
274 * Memory allocation helpers.
276 * Make sure memory is aligned by default, or purposefully misaligned if
277 * that is specified on the command line.
280 #define MISALIGN_OFFSET 16
281 static void *qemu_io_alloc(BlockBackend *blk, size_t len, int pattern)
285 if (qemuio_misalign) {
286 len += MISALIGN_OFFSET;
288 buf = blk_blockalign(blk, len);
289 memset(buf, pattern, len);
290 if (qemuio_misalign) {
291 buf += MISALIGN_OFFSET;
296 static void qemu_io_free(void *p)
298 if (qemuio_misalign) {
299 p -= MISALIGN_OFFSET;
304 static void dump_buffer(const void *buffer, int64_t offset, int64_t len)
310 for (i = 0, p = buffer; i < len; i += 16) {
311 const uint8_t *s = p;
313 printf("%08" PRIx64 ": ", offset + i);
314 for (j = 0; j < 16 && i + j < len; j++, p++) {
318 for (j = 0; j < 16 && i + j < len; j++, s++) {
329 static void print_report(const char *op, struct timeval *t, int64_t offset,
330 int64_t count, int64_t total, int cnt, int Cflag)
332 char s1[64], s2[64], ts[64];
334 timestr(t, ts, sizeof(ts), Cflag ? VERBOSE_FIXED_TIME : 0);
336 cvtstr((double)total, s1, sizeof(s1));
337 cvtstr(tdiv((double)total, *t), s2, sizeof(s2));
338 printf("%s %"PRId64"/%"PRId64" bytes at offset %" PRId64 "\n",
339 op, total, count, offset);
340 printf("%s, %d ops; %s (%s/sec and %.4f ops/sec)\n",
341 s1, cnt, ts, s2, tdiv((double)cnt, *t));
342 } else {/* bytes,ops,time,bytes/sec,ops/sec */
343 printf("%"PRId64",%d,%s,%.3f,%.3f\n",
345 tdiv((double)total, *t),
346 tdiv((double)cnt, *t));
351 * Parse multiple length statements for vectored I/O, and construct an I/O
352 * vector matching it.
355 create_iovec(BlockBackend *blk, QEMUIOVector *qiov, char **argv, int nr_iov,
358 size_t *sizes = g_new0(size_t, nr_iov);
364 for (i = 0; i < nr_iov; i++) {
370 printf("non-numeric length argument -- %s\n", arg);
374 /* should be SIZE_T_MAX, but that doesn't exist */
376 printf("too large length argument -- %s\n", arg);
381 printf("length argument %" PRId64
382 " is not sector aligned\n", len);
390 qemu_iovec_init(qiov, nr_iov);
392 buf = p = qemu_io_alloc(blk, count, pattern);
394 for (i = 0; i < nr_iov; i++) {
395 qemu_iovec_add(qiov, p, sizes[i]);
404 static int do_read(BlockBackend *blk, char *buf, int64_t offset, int64_t count,
409 if (count >> 9 > INT_MAX) {
413 ret = blk_read(blk, offset >> 9, (uint8_t *)buf, count >> 9);
421 static int do_write(BlockBackend *blk, char *buf, int64_t offset, int64_t count,
426 if (count >> 9 > INT_MAX) {
430 ret = blk_write(blk, offset >> 9, (uint8_t *)buf, count >> 9);
438 static int do_pread(BlockBackend *blk, char *buf, int64_t offset,
439 int64_t count, int64_t *total)
441 if (count > INT_MAX) {
445 *total = blk_pread(blk, offset, (uint8_t *)buf, count);
452 static int do_pwrite(BlockBackend *blk, char *buf, int64_t offset,
453 int64_t count, int64_t *total)
455 if (count > INT_MAX) {
459 *total = blk_pwrite(blk, offset, (uint8_t *)buf, count);
475 static void coroutine_fn co_write_zeroes_entry(void *opaque)
477 CoWriteZeroes *data = opaque;
479 data->ret = blk_co_write_zeroes(data->blk, data->offset / BDRV_SECTOR_SIZE,
480 data->count / BDRV_SECTOR_SIZE, 0);
483 *data->total = data->ret;
487 *data->total = data->count;
490 static int do_co_write_zeroes(BlockBackend *blk, int64_t offset, int64_t count,
494 CoWriteZeroes data = {
502 if (count >> BDRV_SECTOR_BITS > INT_MAX) {
506 co = qemu_coroutine_create(co_write_zeroes_entry);
507 qemu_coroutine_enter(co, &data);
509 aio_poll(blk_get_aio_context(blk), true);
518 static int do_write_compressed(BlockBackend *blk, char *buf, int64_t offset,
519 int64_t count, int64_t *total)
523 if (count >> 9 > INT_MAX) {
527 ret = blk_write_compressed(blk, offset >> 9, (uint8_t *)buf, count >> 9);
535 static int do_load_vmstate(BlockBackend *blk, char *buf, int64_t offset,
536 int64_t count, int64_t *total)
538 if (count > INT_MAX) {
542 *total = blk_load_vmstate(blk, (uint8_t *)buf, offset, count);
549 static int do_save_vmstate(BlockBackend *blk, char *buf, int64_t offset,
550 int64_t count, int64_t *total)
552 if (count > INT_MAX) {
556 *total = blk_save_vmstate(blk, (uint8_t *)buf, offset, count);
563 #define NOT_DONE 0x7fffffff
564 static void aio_rw_done(void *opaque, int ret)
566 *(int *)opaque = ret;
569 static int do_aio_readv(BlockBackend *blk, QEMUIOVector *qiov,
570 int64_t offset, int *total)
572 int async_ret = NOT_DONE;
574 blk_aio_readv(blk, offset >> 9, qiov, qiov->size >> 9,
575 aio_rw_done, &async_ret);
576 while (async_ret == NOT_DONE) {
577 main_loop_wait(false);
581 return async_ret < 0 ? async_ret : 1;
584 static int do_aio_writev(BlockBackend *blk, QEMUIOVector *qiov,
585 int64_t offset, int *total)
587 int async_ret = NOT_DONE;
589 blk_aio_writev(blk, offset >> 9, qiov, qiov->size >> 9,
590 aio_rw_done, &async_ret);
591 while (async_ret == NOT_DONE) {
592 main_loop_wait(false);
596 return async_ret < 0 ? async_ret : 1;
599 struct multiwrite_async_ret {
604 static void multiwrite_cb(void *opaque, int ret)
606 struct multiwrite_async_ret *async_ret = opaque;
608 async_ret->num_done++;
610 async_ret->error = ret;
614 static int do_aio_multiwrite(BlockBackend *blk, BlockRequest* reqs,
615 int num_reqs, int *total)
618 struct multiwrite_async_ret async_ret = {
624 for (i = 0; i < num_reqs; i++) {
625 reqs[i].cb = multiwrite_cb;
626 reqs[i].opaque = &async_ret;
627 *total += reqs[i].qiov->size;
630 ret = blk_aio_multiwrite(blk, reqs, num_reqs);
635 while (async_ret.num_done < num_reqs) {
636 main_loop_wait(false);
639 return async_ret.error < 0 ? async_ret.error : 1;
642 static void read_help(void)
646 " reads a range of bytes from the given offset\n"
649 " 'read -v 512 1k' - dumps 1 kilobyte read from 512 bytes into the file\n"
651 " Reads a segment of the currently open file, optionally dumping it to the\n"
652 " standard output stream (with -v option) for subsequent inspection.\n"
653 " -b, -- read from the VM state rather than the virtual disk\n"
654 " -C, -- report statistics in a machine parsable format\n"
655 " -l, -- length for pattern verification (only with -P)\n"
656 " -p, -- use blk_pread to read the file\n"
657 " -P, -- use a pattern to verify read data\n"
658 " -q, -- quiet mode, do not show I/O statistics\n"
659 " -s, -- start offset for pattern verification (only with -P)\n"
660 " -v, -- dump buffer to standard output\n"
664 static int read_f(BlockBackend *blk, int argc, char **argv);
666 static const cmdinfo_t read_cmd = {
672 .args = "[-abCpqv] [-P pattern [-s off] [-l len]] off len",
673 .oneline = "reads a number of bytes at a specified offset",
677 static int read_f(BlockBackend *blk, int argc, char **argv)
679 struct timeval t1, t2;
680 int Cflag = 0, pflag = 0, qflag = 0, vflag = 0;
681 int Pflag = 0, sflag = 0, lflag = 0, bflag = 0;
686 /* Some compilers get confused and warn if this is not initialized. */
689 int64_t pattern_offset = 0, pattern_count = 0;
691 while ((c = getopt(argc, argv, "bCl:pP:qs:v")) != -1) {
701 pattern_count = cvtnum(optarg);
702 if (pattern_count < 0) {
703 printf("non-numeric length argument -- %s\n", optarg);
712 pattern = parse_pattern(optarg);
722 pattern_offset = cvtnum(optarg);
723 if (pattern_offset < 0) {
724 printf("non-numeric length argument -- %s\n", optarg);
732 return qemuio_command_usage(&read_cmd);
736 if (optind != argc - 2) {
737 return qemuio_command_usage(&read_cmd);
740 if (bflag && pflag) {
741 printf("-b and -p cannot be specified at the same time\n");
745 offset = cvtnum(argv[optind]);
747 printf("non-numeric length argument -- %s\n", argv[optind]);
752 count = cvtnum(argv[optind]);
754 printf("non-numeric length argument -- %s\n", argv[optind]);
756 } else if (count > SIZE_MAX) {
757 printf("length cannot exceed %" PRIu64 ", given %s\n",
758 (uint64_t) SIZE_MAX, argv[optind]);
762 if (!Pflag && (lflag || sflag)) {
763 return qemuio_command_usage(&read_cmd);
767 pattern_count = count - pattern_offset;
770 if ((pattern_count < 0) || (pattern_count + pattern_offset > count)) {
771 printf("pattern verification range exceeds end of read data\n");
776 if (offset & 0x1ff) {
777 printf("offset %" PRId64 " is not sector aligned\n",
782 printf("count %"PRId64" is not sector aligned\n",
788 buf = qemu_io_alloc(blk, count, 0xab);
790 gettimeofday(&t1, NULL);
792 cnt = do_pread(blk, buf, offset, count, &total);
794 cnt = do_load_vmstate(blk, buf, offset, count, &total);
796 cnt = do_read(blk, buf, offset, count, &total);
798 gettimeofday(&t2, NULL);
801 printf("read failed: %s\n", strerror(-cnt));
806 void *cmp_buf = g_malloc(pattern_count);
807 memset(cmp_buf, pattern, pattern_count);
808 if (memcmp(buf + pattern_offset, cmp_buf, pattern_count)) {
809 printf("Pattern verification failed at offset %"
810 PRId64 ", %"PRId64" bytes\n",
811 offset + pattern_offset, pattern_count);
821 dump_buffer(buf, offset, count);
824 /* Finally, report back -- -C gives a parsable format */
826 print_report("read", &t2, offset, count, total, cnt, Cflag);
834 static void readv_help(void)
838 " reads a range of bytes from the given offset into multiple buffers\n"
841 " 'readv -v 512 1k 1k ' - dumps 2 kilobytes read from 512 bytes into the file\n"
843 " Reads a segment of the currently open file, optionally dumping it to the\n"
844 " standard output stream (with -v option) for subsequent inspection.\n"
845 " Uses multiple iovec buffers if more than one byte range is specified.\n"
846 " -C, -- report statistics in a machine parsable format\n"
847 " -P, -- use a pattern to verify read data\n"
848 " -v, -- dump buffer to standard output\n"
849 " -q, -- quiet mode, do not show I/O statistics\n"
853 static int readv_f(BlockBackend *blk, int argc, char **argv);
855 static const cmdinfo_t readv_cmd = {
860 .args = "[-Cqv] [-P pattern ] off len [len..]",
861 .oneline = "reads a number of bytes at a specified offset",
865 static int readv_f(BlockBackend *blk, int argc, char **argv)
867 struct timeval t1, t2;
868 int Cflag = 0, qflag = 0, vflag = 0;
872 /* Some compilers get confused and warn if this is not initialized. */
879 while ((c = getopt(argc, argv, "CP:qv")) != -1) {
886 pattern = parse_pattern(optarg);
898 return qemuio_command_usage(&readv_cmd);
902 if (optind > argc - 2) {
903 return qemuio_command_usage(&readv_cmd);
907 offset = cvtnum(argv[optind]);
909 printf("non-numeric length argument -- %s\n", argv[optind]);
914 if (offset & 0x1ff) {
915 printf("offset %" PRId64 " is not sector aligned\n",
920 nr_iov = argc - optind;
921 buf = create_iovec(blk, &qiov, &argv[optind], nr_iov, 0xab);
926 gettimeofday(&t1, NULL);
927 cnt = do_aio_readv(blk, &qiov, offset, &total);
928 gettimeofday(&t2, NULL);
931 printf("readv failed: %s\n", strerror(-cnt));
936 void *cmp_buf = g_malloc(qiov.size);
937 memset(cmp_buf, pattern, qiov.size);
938 if (memcmp(buf, cmp_buf, qiov.size)) {
939 printf("Pattern verification failed at offset %"
940 PRId64 ", %zd bytes\n", offset, qiov.size);
950 dump_buffer(buf, offset, qiov.size);
953 /* Finally, report back -- -C gives a parsable format */
955 print_report("read", &t2, offset, qiov.size, total, cnt, Cflag);
958 qemu_iovec_destroy(&qiov);
963 static void write_help(void)
967 " writes a range of bytes from the given offset\n"
970 " 'write 512 1k' - writes 1 kilobyte at 512 bytes into the open file\n"
972 " Writes into a segment of the currently open file, using a buffer\n"
973 " filled with a set pattern (0xcdcdcdcd).\n"
974 " -b, -- write to the VM state rather than the virtual disk\n"
975 " -c, -- write compressed data with blk_write_compressed\n"
976 " -p, -- use blk_pwrite to write the file\n"
977 " -P, -- use different pattern to fill file\n"
978 " -C, -- report statistics in a machine parsable format\n"
979 " -q, -- quiet mode, do not show I/O statistics\n"
980 " -z, -- write zeroes using blk_co_write_zeroes\n"
984 static int write_f(BlockBackend *blk, int argc, char **argv);
986 static const cmdinfo_t write_cmd = {
992 .args = "[-bcCpqz] [-P pattern ] off len",
993 .oneline = "writes a number of bytes at a specified offset",
997 static int write_f(BlockBackend *blk, int argc, char **argv)
999 struct timeval t1, t2;
1000 int Cflag = 0, pflag = 0, qflag = 0, bflag = 0, Pflag = 0, zflag = 0;
1006 /* Some compilers get confused and warn if this is not initialized. */
1010 while ((c = getopt(argc, argv, "bcCpP:qz")) != -1) {
1026 pattern = parse_pattern(optarg);
1038 return qemuio_command_usage(&write_cmd);
1042 if (optind != argc - 2) {
1043 return qemuio_command_usage(&write_cmd);
1046 if (bflag + pflag + zflag > 1) {
1047 printf("-b, -p, or -z cannot be specified at the same time\n");
1051 if (zflag && Pflag) {
1052 printf("-z and -P cannot be specified at the same time\n");
1056 offset = cvtnum(argv[optind]);
1058 printf("non-numeric length argument -- %s\n", argv[optind]);
1063 count = cvtnum(argv[optind]);
1065 printf("non-numeric length argument -- %s\n", argv[optind]);
1067 } else if (count > SIZE_MAX) {
1068 printf("length cannot exceed %" PRIu64 ", given %s\n",
1069 (uint64_t) SIZE_MAX, argv[optind]);
1074 if (offset & 0x1ff) {
1075 printf("offset %" PRId64 " is not sector aligned\n",
1080 if (count & 0x1ff) {
1081 printf("count %"PRId64" is not sector aligned\n",
1088 buf = qemu_io_alloc(blk, count, pattern);
1091 gettimeofday(&t1, NULL);
1093 cnt = do_pwrite(blk, buf, offset, count, &total);
1095 cnt = do_save_vmstate(blk, buf, offset, count, &total);
1097 cnt = do_co_write_zeroes(blk, offset, count, &total);
1099 cnt = do_write_compressed(blk, buf, offset, count, &total);
1101 cnt = do_write(blk, buf, offset, count, &total);
1103 gettimeofday(&t2, NULL);
1106 printf("write failed: %s\n", strerror(-cnt));
1114 /* Finally, report back -- -C gives a parsable format */
1116 print_report("wrote", &t2, offset, count, total, cnt, Cflag);
1131 " writes a range of bytes from the given offset source from multiple buffers\n"
1134 " 'writev 512 1k 1k' - writes 2 kilobytes at 512 bytes into the open file\n"
1136 " Writes into a segment of the currently open file, using a buffer\n"
1137 " filled with a set pattern (0xcdcdcdcd).\n"
1138 " -P, -- use different pattern to fill file\n"
1139 " -C, -- report statistics in a machine parsable format\n"
1140 " -q, -- quiet mode, do not show I/O statistics\n"
1144 static int writev_f(BlockBackend *blk, int argc, char **argv);
1146 static const cmdinfo_t writev_cmd = {
1151 .args = "[-Cq] [-P pattern ] off len [len..]",
1152 .oneline = "writes a number of bytes at a specified offset",
1153 .help = writev_help,
1156 static int writev_f(BlockBackend *blk, int argc, char **argv)
1158 struct timeval t1, t2;
1159 int Cflag = 0, qflag = 0;
1163 /* Some compilers get confused and warn if this is not initialized. */
1169 while ((c = getopt(argc, argv, "CqP:")) != -1) {
1178 pattern = parse_pattern(optarg);
1184 return qemuio_command_usage(&writev_cmd);
1188 if (optind > argc - 2) {
1189 return qemuio_command_usage(&writev_cmd);
1192 offset = cvtnum(argv[optind]);
1194 printf("non-numeric length argument -- %s\n", argv[optind]);
1199 if (offset & 0x1ff) {
1200 printf("offset %" PRId64 " is not sector aligned\n",
1205 nr_iov = argc - optind;
1206 buf = create_iovec(blk, &qiov, &argv[optind], nr_iov, pattern);
1211 gettimeofday(&t1, NULL);
1212 cnt = do_aio_writev(blk, &qiov, offset, &total);
1213 gettimeofday(&t2, NULL);
1216 printf("writev failed: %s\n", strerror(-cnt));
1224 /* Finally, report back -- -C gives a parsable format */
1226 print_report("wrote", &t2, offset, qiov.size, total, cnt, Cflag);
1228 qemu_iovec_destroy(&qiov);
1233 static void multiwrite_help(void)
1237 " writes a range of bytes from the given offset source from multiple buffers,\n"
1238 " in a batch of requests that may be merged by qemu\n"
1241 " 'multiwrite 512 1k 1k ; 4k 1k'\n"
1242 " writes 2 kB at 512 bytes and 1 kB at 4 kB into the open file\n"
1244 " Writes into a segment of the currently open file, using a buffer\n"
1245 " filled with a set pattern (0xcdcdcdcd). The pattern byte is increased\n"
1246 " by one for each request contained in the multiwrite command.\n"
1247 " -P, -- use different pattern to fill file\n"
1248 " -C, -- report statistics in a machine parsable format\n"
1249 " -q, -- quiet mode, do not show I/O statistics\n"
1253 static int multiwrite_f(BlockBackend *blk, int argc, char **argv);
1255 static const cmdinfo_t multiwrite_cmd = {
1256 .name = "multiwrite",
1257 .cfunc = multiwrite_f,
1260 .args = "[-Cq] [-P pattern ] off len [len..] [; off len [len..]..]",
1261 .oneline = "issues multiple write requests at once",
1262 .help = multiwrite_help,
1265 static int multiwrite_f(BlockBackend *blk, int argc, char **argv)
1267 struct timeval t1, t2;
1268 int Cflag = 0, qflag = 0;
1271 int64_t offset, first_offset = 0;
1272 /* Some compilers get confused and warn if this is not initialized. */
1277 QEMUIOVector *qiovs;
1281 while ((c = getopt(argc, argv, "CqP:")) != -1) {
1290 pattern = parse_pattern(optarg);
1296 return qemuio_command_usage(&writev_cmd);
1300 if (optind > argc - 2) {
1301 return qemuio_command_usage(&writev_cmd);
1305 for (i = optind; i < argc; i++) {
1306 if (!strcmp(argv[i], ";")) {
1311 reqs = g_new0(BlockRequest, nr_reqs);
1312 buf = g_new0(char *, nr_reqs);
1313 qiovs = g_new(QEMUIOVector, nr_reqs);
1315 for (i = 0; i < nr_reqs && optind < argc; i++) {
1318 /* Read the offset of the request */
1319 offset = cvtnum(argv[optind]);
1321 printf("non-numeric offset argument -- %s\n", argv[optind]);
1326 if (offset & 0x1ff) {
1327 printf("offset %lld is not sector aligned\n",
1333 first_offset = offset;
1336 /* Read lengths for qiov entries */
1337 for (j = optind; j < argc; j++) {
1338 if (!strcmp(argv[j], ";")) {
1343 nr_iov = j - optind;
1346 buf[i] = create_iovec(blk, &qiovs[i], &argv[optind], nr_iov, pattern);
1347 if (buf[i] == NULL) {
1351 reqs[i].qiov = &qiovs[i];
1352 reqs[i].sector = offset >> 9;
1353 reqs[i].nb_sectors = reqs[i].qiov->size >> 9;
1360 /* If there were empty requests at the end, ignore them */
1363 gettimeofday(&t1, NULL);
1364 cnt = do_aio_multiwrite(blk, reqs, nr_reqs, &total);
1365 gettimeofday(&t2, NULL);
1368 printf("aio_multiwrite failed: %s\n", strerror(-cnt));
1376 /* Finally, report back -- -C gives a parsable format */
1378 print_report("wrote", &t2, first_offset, total, total, cnt, Cflag);
1380 for (i = 0; i < nr_reqs; i++) {
1381 qemu_io_free(buf[i]);
1382 if (reqs[i].qiov != NULL) {
1383 qemu_iovec_destroy(&qiovs[i]);
1401 BlockAcctCookie acct;
1406 static void aio_write_done(void *opaque, int ret)
1408 struct aio_ctx *ctx = opaque;
1411 gettimeofday(&t2, NULL);
1415 printf("aio_write failed: %s\n", strerror(-ret));
1419 block_acct_done(blk_get_stats(ctx->blk), &ctx->acct);
1425 /* Finally, report back -- -C gives a parsable format */
1426 t2 = tsub(t2, ctx->t1);
1427 print_report("wrote", &t2, ctx->offset, ctx->qiov.size,
1428 ctx->qiov.size, 1, ctx->Cflag);
1430 qemu_io_free(ctx->buf);
1431 qemu_iovec_destroy(&ctx->qiov);
1435 static void aio_read_done(void *opaque, int ret)
1437 struct aio_ctx *ctx = opaque;
1440 gettimeofday(&t2, NULL);
1443 printf("readv failed: %s\n", strerror(-ret));
1448 void *cmp_buf = g_malloc(ctx->qiov.size);
1450 memset(cmp_buf, ctx->pattern, ctx->qiov.size);
1451 if (memcmp(ctx->buf, cmp_buf, ctx->qiov.size)) {
1452 printf("Pattern verification failed at offset %"
1453 PRId64 ", %zd bytes\n", ctx->offset, ctx->qiov.size);
1458 block_acct_done(blk_get_stats(ctx->blk), &ctx->acct);
1465 dump_buffer(ctx->buf, ctx->offset, ctx->qiov.size);
1468 /* Finally, report back -- -C gives a parsable format */
1469 t2 = tsub(t2, ctx->t1);
1470 print_report("read", &t2, ctx->offset, ctx->qiov.size,
1471 ctx->qiov.size, 1, ctx->Cflag);
1473 qemu_io_free(ctx->buf);
1474 qemu_iovec_destroy(&ctx->qiov);
1478 static void aio_read_help(void)
1482 " asynchronously reads a range of bytes from the given offset\n"
1485 " 'aio_read -v 512 1k 1k ' - dumps 2 kilobytes read from 512 bytes into the file\n"
1487 " Reads a segment of the currently open file, optionally dumping it to the\n"
1488 " standard output stream (with -v option) for subsequent inspection.\n"
1489 " The read is performed asynchronously and the aio_flush command must be\n"
1490 " used to ensure all outstanding aio requests have been completed.\n"
1491 " -C, -- report statistics in a machine parsable format\n"
1492 " -P, -- use a pattern to verify read data\n"
1493 " -v, -- dump buffer to standard output\n"
1494 " -q, -- quiet mode, do not show I/O statistics\n"
1498 static int aio_read_f(BlockBackend *blk, int argc, char **argv);
1500 static const cmdinfo_t aio_read_cmd = {
1502 .cfunc = aio_read_f,
1505 .args = "[-Cqv] [-P pattern ] off len [len..]",
1506 .oneline = "asynchronously reads a number of bytes",
1507 .help = aio_read_help,
1510 static int aio_read_f(BlockBackend *blk, int argc, char **argv)
1513 struct aio_ctx *ctx = g_new0(struct aio_ctx, 1);
1516 while ((c = getopt(argc, argv, "CP:qv")) != -1) {
1523 ctx->pattern = parse_pattern(optarg);
1524 if (ctx->pattern < 0) {
1537 return qemuio_command_usage(&aio_read_cmd);
1541 if (optind > argc - 2) {
1543 return qemuio_command_usage(&aio_read_cmd);
1546 ctx->offset = cvtnum(argv[optind]);
1547 if (ctx->offset < 0) {
1548 printf("non-numeric length argument -- %s\n", argv[optind]);
1554 if (ctx->offset & 0x1ff) {
1555 printf("offset %" PRId64 " is not sector aligned\n",
1561 nr_iov = argc - optind;
1562 ctx->buf = create_iovec(blk, &ctx->qiov, &argv[optind], nr_iov, 0xab);
1563 if (ctx->buf == NULL) {
1568 gettimeofday(&ctx->t1, NULL);
1569 block_acct_start(blk_get_stats(blk), &ctx->acct, ctx->qiov.size,
1571 blk_aio_readv(blk, ctx->offset >> 9, &ctx->qiov,
1572 ctx->qiov.size >> 9, aio_read_done, ctx);
1576 static void aio_write_help(void)
1580 " asynchronously writes a range of bytes from the given offset source\n"
1581 " from multiple buffers\n"
1584 " 'aio_write 512 1k 1k' - writes 2 kilobytes at 512 bytes into the open file\n"
1586 " Writes into a segment of the currently open file, using a buffer\n"
1587 " filled with a set pattern (0xcdcdcdcd).\n"
1588 " The write is performed asynchronously and the aio_flush command must be\n"
1589 " used to ensure all outstanding aio requests have been completed.\n"
1590 " -P, -- use different pattern to fill file\n"
1591 " -C, -- report statistics in a machine parsable format\n"
1592 " -q, -- quiet mode, do not show I/O statistics\n"
1596 static int aio_write_f(BlockBackend *blk, int argc, char **argv);
1598 static const cmdinfo_t aio_write_cmd = {
1599 .name = "aio_write",
1600 .cfunc = aio_write_f,
1603 .args = "[-Cq] [-P pattern ] off len [len..]",
1604 .oneline = "asynchronously writes a number of bytes",
1605 .help = aio_write_help,
1608 static int aio_write_f(BlockBackend *blk, int argc, char **argv)
1612 struct aio_ctx *ctx = g_new0(struct aio_ctx, 1);
1615 while ((c = getopt(argc, argv, "CqP:")) != -1) {
1624 pattern = parse_pattern(optarg);
1632 return qemuio_command_usage(&aio_write_cmd);
1636 if (optind > argc - 2) {
1638 return qemuio_command_usage(&aio_write_cmd);
1641 ctx->offset = cvtnum(argv[optind]);
1642 if (ctx->offset < 0) {
1643 printf("non-numeric length argument -- %s\n", argv[optind]);
1649 if (ctx->offset & 0x1ff) {
1650 printf("offset %" PRId64 " is not sector aligned\n",
1656 nr_iov = argc - optind;
1657 ctx->buf = create_iovec(blk, &ctx->qiov, &argv[optind], nr_iov, pattern);
1658 if (ctx->buf == NULL) {
1663 gettimeofday(&ctx->t1, NULL);
1664 block_acct_start(blk_get_stats(blk), &ctx->acct, ctx->qiov.size,
1666 blk_aio_writev(blk, ctx->offset >> 9, &ctx->qiov,
1667 ctx->qiov.size >> 9, aio_write_done, ctx);
1671 static int aio_flush_f(BlockBackend *blk, int argc, char **argv)
1677 static const cmdinfo_t aio_flush_cmd = {
1678 .name = "aio_flush",
1679 .cfunc = aio_flush_f,
1680 .oneline = "completes all outstanding aio requests"
1683 static int flush_f(BlockBackend *blk, int argc, char **argv)
1689 static const cmdinfo_t flush_cmd = {
1693 .oneline = "flush all in-core file state to disk",
1696 static int truncate_f(BlockBackend *blk, int argc, char **argv)
1701 offset = cvtnum(argv[1]);
1703 printf("non-numeric truncate argument -- %s\n", argv[1]);
1707 ret = blk_truncate(blk, offset);
1709 printf("truncate: %s\n", strerror(-ret));
1716 static const cmdinfo_t truncate_cmd = {
1719 .cfunc = truncate_f,
1723 .oneline = "truncates the current file at the given offset",
1726 static int length_f(BlockBackend *blk, int argc, char **argv)
1731 size = blk_getlength(blk);
1733 printf("getlength: %s\n", strerror(-size));
1737 cvtstr(size, s1, sizeof(s1));
1743 static const cmdinfo_t length_cmd = {
1747 .oneline = "gets the length of the current file",
1751 static int info_f(BlockBackend *blk, int argc, char **argv)
1753 BlockDriverState *bs = blk_bs(blk);
1754 BlockDriverInfo bdi;
1755 ImageInfoSpecific *spec_info;
1756 char s1[64], s2[64];
1759 if (bs->drv && bs->drv->format_name) {
1760 printf("format name: %s\n", bs->drv->format_name);
1762 if (bs->drv && bs->drv->protocol_name) {
1763 printf("format name: %s\n", bs->drv->protocol_name);
1766 ret = bdrv_get_info(bs, &bdi);
1771 cvtstr(bdi.cluster_size, s1, sizeof(s1));
1772 cvtstr(bdi.vm_state_offset, s2, sizeof(s2));
1774 printf("cluster size: %s\n", s1);
1775 printf("vm state offset: %s\n", s2);
1777 spec_info = bdrv_get_specific_info(bs);
1779 printf("Format specific information:\n");
1780 bdrv_image_info_specific_dump(fprintf, stdout, spec_info);
1781 qapi_free_ImageInfoSpecific(spec_info);
1789 static const cmdinfo_t info_cmd = {
1793 .oneline = "prints information about the current file",
1796 static void discard_help(void)
1800 " discards a range of bytes from the given offset\n"
1803 " 'discard 512 1k' - discards 1 kilobyte from 512 bytes into the file\n"
1805 " Discards a segment of the currently open file.\n"
1806 " -C, -- report statistics in a machine parsable format\n"
1807 " -q, -- quiet mode, do not show I/O statistics\n"
1811 static int discard_f(BlockBackend *blk, int argc, char **argv);
1813 static const cmdinfo_t discard_cmd = {
1819 .args = "[-Cq] off len",
1820 .oneline = "discards a number of bytes at a specified offset",
1821 .help = discard_help,
1824 static int discard_f(BlockBackend *blk, int argc, char **argv)
1826 struct timeval t1, t2;
1827 int Cflag = 0, qflag = 0;
1829 int64_t offset, count;
1831 while ((c = getopt(argc, argv, "Cq")) != -1) {
1840 return qemuio_command_usage(&discard_cmd);
1844 if (optind != argc - 2) {
1845 return qemuio_command_usage(&discard_cmd);
1848 offset = cvtnum(argv[optind]);
1850 printf("non-numeric length argument -- %s\n", argv[optind]);
1855 count = cvtnum(argv[optind]);
1857 printf("non-numeric length argument -- %s\n", argv[optind]);
1859 } else if (count >> BDRV_SECTOR_BITS > INT_MAX) {
1860 printf("length cannot exceed %"PRIu64", given %s\n",
1861 (uint64_t)INT_MAX << BDRV_SECTOR_BITS,
1866 gettimeofday(&t1, NULL);
1867 ret = blk_discard(blk, offset >> BDRV_SECTOR_BITS,
1868 count >> BDRV_SECTOR_BITS);
1869 gettimeofday(&t2, NULL);
1872 printf("discard failed: %s\n", strerror(-ret));
1876 /* Finally, report back -- -C gives a parsable format */
1879 print_report("discard", &t2, offset, count, count, 1, Cflag);
1886 static int alloc_f(BlockBackend *blk, int argc, char **argv)
1888 BlockDriverState *bs = blk_bs(blk);
1889 int64_t offset, sector_num, nb_sectors, remaining;
1894 offset = cvtnum(argv[1]);
1896 printf("non-numeric offset argument -- %s\n", argv[1]);
1898 } else if (offset & 0x1ff) {
1899 printf("offset %" PRId64 " is not sector aligned\n",
1905 nb_sectors = cvtnum(argv[2]);
1906 if (nb_sectors < 0) {
1907 printf("non-numeric length argument -- %s\n", argv[2]);
1909 } else if (nb_sectors > INT_MAX) {
1910 printf("length argument cannot exceed %d, given %s\n",
1918 remaining = nb_sectors;
1920 sector_num = offset >> 9;
1922 ret = bdrv_is_allocated(bs, sector_num, remaining, &num);
1924 printf("is_allocated failed: %s\n", strerror(-ret));
1933 nb_sectors -= remaining;
1938 cvtstr(offset, s1, sizeof(s1));
1940 printf("%"PRId64"/%"PRId64" sectors allocated at offset %s\n",
1941 sum_alloc, nb_sectors, s1);
1945 static const cmdinfo_t alloc_cmd = {
1951 .args = "off [sectors]",
1952 .oneline = "checks if a sector is present in the file",
1956 static int map_is_allocated(BlockDriverState *bs, int64_t sector_num,
1957 int64_t nb_sectors, int64_t *pnum)
1959 int num, num_checked;
1962 num_checked = MIN(nb_sectors, INT_MAX);
1963 ret = bdrv_is_allocated(bs, sector_num, num_checked, &num);
1971 while (nb_sectors > 0 && ret == firstret) {
1975 num_checked = MIN(nb_sectors, INT_MAX);
1976 ret = bdrv_is_allocated(bs, sector_num, num_checked, &num);
1977 if (ret == firstret && num) {
1987 static int map_f(BlockBackend *blk, int argc, char **argv)
1990 int64_t nb_sectors, total_sectors;
1997 total_sectors = blk_nb_sectors(blk);
1998 if (total_sectors < 0) {
1999 error_report("Failed to query image length: %s",
2000 strerror(-total_sectors));
2004 nb_sectors = total_sectors;
2007 ret = map_is_allocated(blk_bs(blk), offset, nb_sectors, &num);
2009 error_report("Failed to get allocation status: %s", strerror(-ret));
2012 error_report("Unexpected end of image");
2016 retstr = ret ? " allocated" : "not allocated";
2017 cvtstr(offset << 9ULL, s1, sizeof(s1));
2018 printf("[% 24" PRId64 "] % 8" PRId64 "/% 8" PRId64 " sectors %s "
2019 "at offset %s (%d)\n",
2020 offset << 9ULL, num, nb_sectors, retstr, s1, ret);
2024 } while (offset < total_sectors);
2029 static const cmdinfo_t map_cmd = {
2035 .oneline = "prints the allocated areas of a file",
2038 static void reopen_help(void)
2042 " Changes the open options of an already opened image\n"
2045 " 'reopen -o lazy-refcounts=on' - activates lazy refcount writeback on a qcow2 image\n"
2047 " -r, -- Reopen the image read-only\n"
2048 " -c, -- Change the cache mode to the given value\n"
2049 " -o, -- Changes block driver options (cf. 'open' command)\n"
2053 static int reopen_f(BlockBackend *blk, int argc, char **argv);
2055 static QemuOptsList reopen_opts = {
2057 .merge_lists = true,
2058 .head = QTAILQ_HEAD_INITIALIZER(reopen_opts.head),
2060 /* no elements => accept any params */
2061 { /* end of list */ }
2065 static const cmdinfo_t reopen_cmd = {
2070 .args = "[-r] [-c cache] [-o options]",
2071 .oneline = "reopens an image with new options",
2072 .help = reopen_help,
2075 static int reopen_f(BlockBackend *blk, int argc, char **argv)
2077 BlockDriverState *bs = blk_bs(blk);
2081 int flags = bs->open_flags;
2083 BlockReopenQueue *brq;
2084 Error *local_err = NULL;
2086 while ((c = getopt(argc, argv, "c:o:r")) != -1) {
2089 if (bdrv_parse_cache_flags(optarg, &flags) < 0) {
2090 error_report("Invalid cache option: %s", optarg);
2095 if (!qemu_opts_parse_noisily(&reopen_opts, optarg, 0)) {
2096 qemu_opts_reset(&reopen_opts);
2101 flags &= ~BDRV_O_RDWR;
2104 qemu_opts_reset(&reopen_opts);
2105 return qemuio_command_usage(&reopen_cmd);
2109 if (optind != argc) {
2110 qemu_opts_reset(&reopen_opts);
2111 return qemuio_command_usage(&reopen_cmd);
2114 qopts = qemu_opts_find(&reopen_opts, NULL);
2115 opts = qopts ? qemu_opts_to_qdict(qopts, NULL) : NULL;
2116 qemu_opts_reset(&reopen_opts);
2118 brq = bdrv_reopen_queue(NULL, bs, opts, flags);
2119 bdrv_reopen_multiple(brq, &local_err);
2121 error_report_err(local_err);
2127 static int break_f(BlockBackend *blk, int argc, char **argv)
2131 ret = bdrv_debug_breakpoint(blk_bs(blk), argv[1], argv[2]);
2133 printf("Could not set breakpoint: %s\n", strerror(-ret));
2139 static int remove_break_f(BlockBackend *blk, int argc, char **argv)
2143 ret = bdrv_debug_remove_breakpoint(blk_bs(blk), argv[1]);
2145 printf("Could not remove breakpoint %s: %s\n", argv[1], strerror(-ret));
2151 static const cmdinfo_t break_cmd = {
2156 .args = "event tag",
2157 .oneline = "sets a breakpoint on event and tags the stopped "
2161 static const cmdinfo_t remove_break_cmd = {
2162 .name = "remove_break",
2165 .cfunc = remove_break_f,
2167 .oneline = "remove a breakpoint by tag",
2170 static int resume_f(BlockBackend *blk, int argc, char **argv)
2174 ret = bdrv_debug_resume(blk_bs(blk), argv[1]);
2176 printf("Could not resume request: %s\n", strerror(-ret));
2182 static const cmdinfo_t resume_cmd = {
2188 .oneline = "resumes the request tagged as tag",
2191 static int wait_break_f(BlockBackend *blk, int argc, char **argv)
2193 while (!bdrv_debug_is_suspended(blk_bs(blk), argv[1])) {
2194 aio_poll(blk_get_aio_context(blk), true);
2200 static const cmdinfo_t wait_break_cmd = {
2201 .name = "wait_break",
2204 .cfunc = wait_break_f,
2206 .oneline = "waits for the suspension of a request",
2209 static int abort_f(BlockBackend *blk, int argc, char **argv)
2214 static const cmdinfo_t abort_cmd = {
2217 .flags = CMD_NOFILE_OK,
2218 .oneline = "simulate a program crash using abort(3)",
2221 static void sigraise_help(void)
2225 " raises the given signal\n"
2228 " 'sigraise %i' - raises SIGTERM\n"
2230 " Invokes raise(signal), where \"signal\" is the mandatory integer argument\n"
2231 " given to sigraise.\n"
2235 static int sigraise_f(BlockBackend *blk, int argc, char **argv);
2237 static const cmdinfo_t sigraise_cmd = {
2239 .cfunc = sigraise_f,
2242 .flags = CMD_NOFILE_OK,
2244 .oneline = "raises a signal",
2245 .help = sigraise_help,
2248 static int sigraise_f(BlockBackend *blk, int argc, char **argv)
2250 int64_t sig = cvtnum(argv[1]);
2252 printf("non-numeric signal number argument -- %s\n", argv[1]);
2254 } else if (sig > NSIG) {
2255 printf("signal argument '%s' is too large to be a valid signal\n",
2260 /* Using raise() to kill this process does not necessarily flush all open
2261 * streams. At least stdout and stderr (although the latter should be
2262 * non-buffered anyway) should be flushed, though. */
2270 static void sleep_cb(void *opaque)
2272 bool *expired = opaque;
2276 static int sleep_f(BlockBackend *blk, int argc, char **argv)
2280 struct QEMUTimer *timer;
2281 bool expired = false;
2283 ms = strtol(argv[1], &endptr, 0);
2284 if (ms < 0 || *endptr != '\0') {
2285 printf("%s is not a valid number\n", argv[1]);
2289 timer = timer_new_ns(QEMU_CLOCK_HOST, sleep_cb, &expired);
2290 timer_mod(timer, qemu_clock_get_ns(QEMU_CLOCK_HOST) + SCALE_MS * ms);
2293 main_loop_wait(false);
2301 static const cmdinfo_t sleep_cmd = {
2306 .flags = CMD_NOFILE_OK,
2307 .oneline = "waits for the given value in milliseconds",
2310 static void help_oneline(const char *cmd, const cmdinfo_t *ct)
2315 printf("%s ", ct->name);
2317 printf("(or %s) ", ct->altname);
2322 printf("%s ", ct->args);
2324 printf("-- %s\n", ct->oneline);
2327 static void help_onecmd(const char *cmd, const cmdinfo_t *ct)
2329 help_oneline(cmd, ct);
2335 static void help_all(void)
2337 const cmdinfo_t *ct;
2339 for (ct = cmdtab; ct < &cmdtab[ncmds]; ct++) {
2340 help_oneline(ct->name, ct);
2342 printf("\nUse 'help commandname' for extended help.\n");
2345 static int help_f(BlockBackend *blk, int argc, char **argv)
2347 const cmdinfo_t *ct;
2354 ct = find_command(argv[1]);
2356 printf("command %s not found\n", argv[1]);
2360 help_onecmd(argv[1], ct);
2364 static const cmdinfo_t help_cmd = {
2370 .flags = CMD_FLAG_GLOBAL,
2371 .args = "[command]",
2372 .oneline = "help for one or all commands",
2375 bool qemuio_command(BlockBackend *blk, const char *cmd)
2378 const cmdinfo_t *ct;
2383 input = g_strdup(cmd);
2384 v = breakline(input, &c);
2386 ct = find_command(v[0]);
2388 done = command(blk, ct, c, v);
2390 fprintf(stderr, "command \"%s\" not found\n", v[0]);
2399 static void __attribute((constructor)) init_qemuio_commands(void)
2401 /* initialize commands */
2402 qemuio_add_command(&help_cmd);
2403 qemuio_add_command(&read_cmd);
2404 qemuio_add_command(&readv_cmd);
2405 qemuio_add_command(&write_cmd);
2406 qemuio_add_command(&writev_cmd);
2407 qemuio_add_command(&multiwrite_cmd);
2408 qemuio_add_command(&aio_read_cmd);
2409 qemuio_add_command(&aio_write_cmd);
2410 qemuio_add_command(&aio_flush_cmd);
2411 qemuio_add_command(&flush_cmd);
2412 qemuio_add_command(&truncate_cmd);
2413 qemuio_add_command(&length_cmd);
2414 qemuio_add_command(&info_cmd);
2415 qemuio_add_command(&discard_cmd);
2416 qemuio_add_command(&alloc_cmd);
2417 qemuio_add_command(&map_cmd);
2418 qemuio_add_command(&reopen_cmd);
2419 qemuio_add_command(&break_cmd);
2420 qemuio_add_command(&remove_break_cmd);
2421 qemuio_add_command(&resume_cmd);
2422 qemuio_add_command(&wait_break_cmd);
2423 qemuio_add_command(&abort_cmd);
2424 qemuio_add_command(&sleep_cmd);
2425 qemuio_add_command(&sigraise_cmd);