* THE SOFTWARE.
*/
#include "qemu/osdep.h"
+#include "qemu-version.h"
+#include "qapi/error.h"
#include "qapi-visit.h"
#include "qapi/qmp-output-visitor.h"
#include "qapi/qmp/qerror.h"
#include "qapi/qmp/qjson.h"
-#include "qemu-common.h"
+#include "qemu/cutils.h"
+#include "qemu/config-file.h"
#include "qemu/option.h"
#include "qemu/error-report.h"
+#include "qemu/log.h"
+#include "qom/object_interfaces.h"
#include "sysemu/sysemu.h"
#include "sysemu/block-backend.h"
#include "block/block_int.h"
#include "block/blockjob.h"
#include "block/qapi.h"
+#include "crypto/init.h"
+#include "trace/control.h"
#include <getopt.h>
#define QEMU_IMG_VERSION "qemu-img version " QEMU_VERSION QEMU_PKGVERSION \
enum {
OPTION_OUTPUT = 256,
OPTION_BACKING_CHAIN = 257,
+ OPTION_OBJECT = 258,
+ OPTION_IMAGE_OPTS = 259,
+ OPTION_PATTERN = 260,
+ OPTION_FLUSH_INTERVAL = 261,
+ OPTION_NO_DRAIN = 262,
};
typedef enum OutputFormat {
OFORMAT_HUMAN,
} OutputFormat;
-/* Default to cache=writeback as data integrity is not important for qemu-tcg. */
-#define BDRV_O_FLAGS BDRV_O_CACHE_WB
+/* Default to cache=writeback as data integrity is not important for qemu-img */
#define BDRV_DEFAULT_CACHE "writeback"
static void format_print(void *opaque, const char *name)
{
const char *help_msg =
QEMU_IMG_VERSION
- "usage: qemu-img command [command options]\n"
+ "usage: qemu-img [standard options] command [command options]\n"
"QEMU disk image utility\n"
"\n"
+ " '-h', '--help' display this help and exit\n"
+ " '-V', '--version' output version information and exit\n"
+ " '-T', '--trace' [[enable=]<pattern>][,events=<file>][,file=<file>]\n"
+ " specify tracing options\n"
+ "\n"
"Command syntax:\n"
#define DEF(option, callback, arg_string) \
" " arg_string "\n"
"\n"
"Command parameters:\n"
" 'filename' is a disk image filename\n"
+ " 'objectdef' is a QEMU user creatable object definition. See the qemu(1)\n"
+ " manual page for a description of the object properties. The most common\n"
+ " object type is a 'secret', which is used to supply passwords and/or\n"
+ " encryption keys.\n"
" 'fmt' is the disk image format. It is guessed automatically in most cases\n"
" 'cache' is the cache mode used to write the output disk image, the valid\n"
" options are: 'none', 'writeback' (default, except for convert), 'writethrough',\n"
exit(EXIT_SUCCESS);
}
+static QemuOptsList qemu_object_opts = {
+ .name = "object",
+ .implied_opt_name = "qom-type",
+ .head = QTAILQ_HEAD_INITIALIZER(qemu_object_opts.head),
+ .desc = {
+ { }
+ },
+};
+
+static QemuOptsList qemu_source_opts = {
+ .name = "source",
+ .implied_opt_name = "file",
+ .head = QTAILQ_HEAD_INITIALIZER(qemu_source_opts.head),
+ .desc = {
+ { }
+ },
+};
+
static int GCC_FMT_ATTR(2, 3) qprintf(bool quiet, const char *fmt, ...)
{
int ret = 0;
return 0;
}
-static BlockBackend *img_open(const char *id, const char *filename,
- const char *fmt, int flags,
- bool require_io, bool quiet)
+
+static int img_open_password(BlockBackend *blk, const char *filename,
+ int flags, bool quiet)
{
- BlockBackend *blk;
BlockDriverState *bs;
char password[256];
+
+ bs = blk_bs(blk);
+ if (bdrv_is_encrypted(bs) && bdrv_key_required(bs) &&
+ !(flags & BDRV_O_NO_IO)) {
+ qprintf(quiet, "Disk image '%s' is encrypted.\n", filename);
+ if (qemu_read_password(password, sizeof(password)) < 0) {
+ error_report("No password given");
+ return -1;
+ }
+ if (bdrv_set_key(bs, password) < 0) {
+ error_report("invalid password");
+ return -1;
+ }
+ }
+ return 0;
+}
+
+
+static BlockBackend *img_open_opts(const char *optstr,
+ QemuOpts *opts, int flags, bool writethrough,
+ bool quiet)
+{
+ QDict *options;
+ Error *local_err = NULL;
+ BlockBackend *blk;
+ options = qemu_opts_to_qdict(opts, NULL);
+ blk = blk_new_open(NULL, NULL, options, flags, &local_err);
+ if (!blk) {
+ error_reportf_err(local_err, "Could not open '%s': ", optstr);
+ return NULL;
+ }
+ blk_set_enable_write_cache(blk, !writethrough);
+
+ if (img_open_password(blk, optstr, flags, quiet) < 0) {
+ blk_unref(blk);
+ return NULL;
+ }
+ return blk;
+}
+
+static BlockBackend *img_open_file(const char *filename,
+ const char *fmt, int flags,
+ bool writethrough, bool quiet)
+{
+ BlockBackend *blk;
Error *local_err = NULL;
QDict *options = NULL;
qdict_put(options, "driver", qstring_from_str(fmt));
}
- blk = blk_new_open(id, filename, NULL, options, flags, &local_err);
+ blk = blk_new_open(filename, NULL, options, flags, &local_err);
if (!blk) {
error_reportf_err(local_err, "Could not open '%s': ", filename);
- goto fail;
+ return NULL;
}
+ blk_set_enable_write_cache(blk, !writethrough);
- bs = blk_bs(blk);
- if (bdrv_is_encrypted(bs) && require_io) {
- qprintf(quiet, "Disk image '%s' is encrypted.\n", filename);
- if (qemu_read_password(password, sizeof(password)) < 0) {
- error_report("No password given");
- goto fail;
- }
- if (bdrv_set_key(bs, password) < 0) {
- error_report("invalid password");
- goto fail;
- }
+ if (img_open_password(blk, filename, flags, quiet) < 0) {
+ blk_unref(blk);
+ return NULL;
+ }
+ return blk;
+}
+
+
+static BlockBackend *img_open(bool image_opts,
+ const char *filename,
+ const char *fmt, int flags, bool writethrough,
+ bool quiet)
+{
+ BlockBackend *blk;
+ if (image_opts) {
+ QemuOpts *opts;
+ if (fmt) {
+ error_report("--image-opts and --format are mutually exclusive");
+ return NULL;
+ }
+ opts = qemu_opts_parse_noisily(qemu_find_opts("source"),
+ filename, true);
+ if (!opts) {
+ return NULL;
+ }
+ blk = img_open_opts(filename, opts, flags, writethrough, quiet);
+ } else {
+ blk = img_open_file(filename, fmt, flags, writethrough, quiet);
}
return blk;
-fail:
- blk_unref(blk);
- return NULL;
}
+
static int add_old_style_options(const char *fmt, QemuOpts *opts,
const char *base_filename,
const char *base_fmt)
bool quiet = false;
for(;;) {
- c = getopt(argc, argv, "F:b:f:he6o:q");
+ static const struct option long_options[] = {
+ {"help", no_argument, 0, 'h'},
+ {"object", required_argument, 0, OPTION_OBJECT},
+ {0, 0, 0, 0}
+ };
+ c = getopt_long(argc, argv, "F:b:f:he6o:q",
+ long_options, NULL);
if (c == -1) {
break;
}
case 'q':
quiet = true;
break;
+ case OPTION_OBJECT: {
+ QemuOpts *opts;
+ opts = qemu_opts_parse_noisily(&qemu_object_opts,
+ optarg, true);
+ if (!opts) {
+ goto fail;
+ }
+ } break;
}
}
}
optind++;
+ if (qemu_opts_foreach(&qemu_object_opts,
+ user_creatable_add_opts_foreach,
+ NULL, NULL)) {
+ goto fail;
+ }
+
/* Get image size, if specified */
if (optind < argc) {
int64_t sval;
}
bdrv_img_create(filename, fmt, base_filename, base_fmt,
- options, img_size, BDRV_O_FLAGS, &local_err, quiet);
+ options, img_size, 0, &local_err, quiet);
if (local_err) {
error_reportf_err(local_err, "%s: ", filename);
goto fail;
BlockBackend *blk;
BlockDriverState *bs;
int fix = 0;
- int flags = BDRV_O_FLAGS | BDRV_O_CHECK;
+ int flags = BDRV_O_CHECK;
+ bool writethrough;
ImageCheck *check;
bool quiet = false;
+ bool image_opts = false;
fmt = NULL;
output = NULL;
cache = BDRV_DEFAULT_CACHE;
+
for(;;) {
int option_index = 0;
static const struct option long_options[] = {
{"format", required_argument, 0, 'f'},
{"repair", required_argument, 0, 'r'},
{"output", required_argument, 0, OPTION_OUTPUT},
+ {"object", required_argument, 0, OPTION_OBJECT},
+ {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
{0, 0, 0, 0}
};
c = getopt_long(argc, argv, "hf:r:T:q",
case 'q':
quiet = true;
break;
+ case OPTION_OBJECT: {
+ QemuOpts *opts;
+ opts = qemu_opts_parse_noisily(&qemu_object_opts,
+ optarg, true);
+ if (!opts) {
+ return 1;
+ }
+ } break;
+ case OPTION_IMAGE_OPTS:
+ image_opts = true;
+ break;
}
}
if (optind != argc - 1) {
return 1;
}
- ret = bdrv_parse_cache_flags(cache, &flags);
+ if (qemu_opts_foreach(&qemu_object_opts,
+ user_creatable_add_opts_foreach,
+ NULL, NULL)) {
+ return 1;
+ }
+
+ ret = bdrv_parse_cache_mode(cache, &flags, &writethrough);
if (ret < 0) {
error_report("Invalid source cache option: %s", cache);
return 1;
}
- blk = img_open("image", filename, fmt, flags, true, quiet);
+ blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet);
if (!blk) {
return 1;
}
static void run_block_job(BlockJob *job, Error **errp)
{
- AioContext *aio_context = bdrv_get_aio_context(job->bs);
+ AioContext *aio_context = blk_get_aio_context(job->blk);
do {
aio_poll(aio_context, true);
BlockBackend *blk;
BlockDriverState *bs, *base_bs;
bool progress = false, quiet = false, drop = false;
+ bool writethrough;
Error *local_err = NULL;
CommonBlockJobCBInfo cbi;
+ bool image_opts = false;
fmt = NULL;
cache = BDRV_DEFAULT_CACHE;
base = NULL;
for(;;) {
- c = getopt(argc, argv, "f:ht:b:dpq");
+ static const struct option long_options[] = {
+ {"help", no_argument, 0, 'h'},
+ {"object", required_argument, 0, OPTION_OBJECT},
+ {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
+ {0, 0, 0, 0}
+ };
+ c = getopt_long(argc, argv, "f:ht:b:dpq",
+ long_options, NULL);
if (c == -1) {
break;
}
case 'q':
quiet = true;
break;
+ case OPTION_OBJECT: {
+ QemuOpts *opts;
+ opts = qemu_opts_parse_noisily(&qemu_object_opts,
+ optarg, true);
+ if (!opts) {
+ return 1;
+ }
+ } break;
+ case OPTION_IMAGE_OPTS:
+ image_opts = true;
+ break;
}
}
}
filename = argv[optind++];
+ if (qemu_opts_foreach(&qemu_object_opts,
+ user_creatable_add_opts_foreach,
+ NULL, NULL)) {
+ return 1;
+ }
+
flags = BDRV_O_RDWR | BDRV_O_UNMAP;
- ret = bdrv_parse_cache_flags(cache, &flags);
+ ret = bdrv_parse_cache_mode(cache, &flags, &writethrough);
if (ret < 0) {
error_report("Invalid cache option: %s", cache);
return 1;
}
- blk = img_open("image", filename, fmt, flags, true, quiet);
+ blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet);
if (!blk) {
return 1;
}
uint8_t *buffer, bool quiet)
{
int pnum, ret = 0;
- ret = blk_read(blk, sect_num, buffer, sect_count);
+ ret = blk_pread(blk, sect_num << BDRV_SECTOR_BITS, buffer,
+ sect_count << BDRV_SECTOR_BITS);
if (ret < 0) {
error_report("Error while reading offset %" PRId64 " of %s: %s",
sectors_to_bytes(sect_num), filename, strerror(-ret));
int ret = 0; /* return value - 0 Ident, 1 Different, >1 Error */
bool progress = false, quiet = false, strict = false;
int flags;
+ bool writethrough;
int64_t total_sectors;
int64_t sector_num = 0;
int64_t nb_sectors;
int c, pnum;
uint64_t progress_base;
+ bool image_opts = false;
cache = BDRV_DEFAULT_CACHE;
for (;;) {
- c = getopt(argc, argv, "hf:F:T:pqs");
+ static const struct option long_options[] = {
+ {"help", no_argument, 0, 'h'},
+ {"object", required_argument, 0, OPTION_OBJECT},
+ {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
+ {0, 0, 0, 0}
+ };
+ c = getopt_long(argc, argv, "hf:F:T:pqs",
+ long_options, NULL);
if (c == -1) {
break;
}
case 's':
strict = true;
break;
+ case OPTION_OBJECT: {
+ QemuOpts *opts;
+ opts = qemu_opts_parse_noisily(&qemu_object_opts,
+ optarg, true);
+ if (!opts) {
+ ret = 2;
+ goto out4;
+ }
+ } break;
+ case OPTION_IMAGE_OPTS:
+ image_opts = true;
+ break;
}
}
filename1 = argv[optind++];
filename2 = argv[optind++];
+ if (qemu_opts_foreach(&qemu_object_opts,
+ user_creatable_add_opts_foreach,
+ NULL, NULL)) {
+ ret = 2;
+ goto out4;
+ }
+
/* Initialize before goto out */
qemu_progress_init(progress, 2.0);
- flags = BDRV_O_FLAGS;
- ret = bdrv_parse_cache_flags(cache, &flags);
+ flags = 0;
+ ret = bdrv_parse_cache_mode(cache, &flags, &writethrough);
if (ret < 0) {
error_report("Invalid source cache option: %s", cache);
ret = 2;
goto out3;
}
- blk1 = img_open("image_1", filename1, fmt1, flags, true, quiet);
+ blk1 = img_open(image_opts, filename1, fmt1, flags, writethrough, quiet);
if (!blk1) {
ret = 2;
goto out3;
}
- bs1 = blk_bs(blk1);
- blk2 = img_open("image_2", filename2, fmt2, flags, true, quiet);
+ blk2 = img_open(image_opts, filename2, fmt2, flags, writethrough, quiet);
if (!blk2) {
ret = 2;
goto out2;
}
+ bs1 = blk_bs(blk1);
bs2 = blk_bs(blk2);
buf1 = blk_blockalign(blk1, IO_BUF_SIZE);
nb_sectors = MIN(pnum1, pnum2);
} else if (allocated1 == allocated2) {
if (allocated1) {
- ret = blk_read(blk1, sector_num, buf1, nb_sectors);
+ ret = blk_pread(blk1, sector_num << BDRV_SECTOR_BITS, buf1,
+ nb_sectors << BDRV_SECTOR_BITS);
if (ret < 0) {
error_report("Error while reading offset %" PRId64 " of %s:"
" %s", sectors_to_bytes(sector_num), filename1,
ret = 4;
goto out;
}
- ret = blk_read(blk2, sector_num, buf2, nb_sectors);
+ ret = blk_pread(blk2, sector_num << BDRV_SECTOR_BITS, buf2,
+ nb_sectors << BDRV_SECTOR_BITS);
if (ret < 0) {
error_report("Error while reading offset %" PRId64
" of %s: %s", sectors_to_bytes(sector_num),
blk_unref(blk1);
out3:
qemu_progress_end();
+out4:
return ret;
}
} else if (!s->target_has_backing) {
/* Without a target backing file we must copy over the contents of
* the backing file as well. */
- /* TODO Check block status of the backing file chain to avoid
+ /* Check block status of the backing file chain to avoid
* needlessly reading zeroes and limiting the iteration to the
* buffer size */
- s->status = BLK_DATA;
+ ret = bdrv_get_block_status_above(blk_bs(s->src[s->src_cur]), NULL,
+ sector_num - s->src_cur_offset,
+ n, &n, &file);
+ if (ret < 0) {
+ return ret;
+ }
+
+ if (ret & BDRV_BLOCK_ZERO) {
+ s->status = BLK_ZERO;
+ } else {
+ s->status = BLK_DATA;
+ }
} else {
s->status = BLK_BACKING_FILE;
}
int n;
int ret;
- if (s->status == BLK_ZERO || s->status == BLK_BACKING_FILE) {
- return 0;
- }
-
assert(nb_sectors <= s->buf_sectors);
while (nb_sectors > 0) {
BlockBackend *blk;
bs_sectors = s->src_sectors[s->src_cur];
n = MIN(nb_sectors, bs_sectors - (sector_num - s->src_cur_offset));
- ret = blk_read(blk, sector_num - s->src_cur_offset, buf, n);
+ ret = blk_pread(blk,
+ (sector_num - s->src_cur_offset) << BDRV_SECTOR_BITS,
+ buf, n << BDRV_SECTOR_BITS);
if (ret < 0) {
return ret;
}
if (!s->min_sparse ||
is_allocated_sectors_min(buf, n, &n, s->min_sparse))
{
- ret = blk_write(s->target, sector_num, buf, n);
+ ret = blk_pwrite(s->target, sector_num << BDRV_SECTOR_BITS,
+ buf, n << BDRV_SECTOR_BITS, 0);
if (ret < 0) {
return ret;
}
if (s->has_zero_init) {
break;
}
- ret = blk_write_zeroes(s->target, sector_num, n, 0);
+ ret = blk_pwrite_zeroes(s->target, sector_num << BDRV_SECTOR_BITS,
+ n << BDRV_SECTOR_BITS, 0);
if (ret < 0) {
return ret;
}
ret = n;
goto fail;
}
- if (s->status == BLK_DATA) {
+ if (s->status == BLK_DATA || (!s->min_sparse && s->status == BLK_ZERO))
+ {
s->allocated_sectors += n;
}
sector_num += n;
ret = n;
goto fail;
}
- if (s->status == BLK_DATA) {
+ if (s->status == BLK_DATA || (!s->min_sparse && s->status == BLK_ZERO))
+ {
allocated_done += n;
qemu_progress_print(100.0 * allocated_done / s->allocated_sectors,
0);
}
- ret = convert_read(s, sector_num, n, buf);
- if (ret < 0) {
- error_report("error while reading sector %" PRId64
- ": %s", sector_num, strerror(-ret));
- goto fail;
+ if (s->status == BLK_DATA) {
+ ret = convert_read(s, sector_num, n, buf);
+ if (ret < 0) {
+ error_report("error while reading sector %" PRId64
+ ": %s", sector_num, strerror(-ret));
+ goto fail;
+ }
+ } else if (!s->min_sparse && s->status == BLK_ZERO) {
+ n = MIN(n, s->buf_sectors);
+ memset(buf, 0, n * BDRV_SECTOR_SIZE);
+ s->status = BLK_DATA;
}
ret = convert_write(s, sector_num, n, buf);
int c, bs_n, bs_i, compress, cluster_sectors, skip_create;
int64_t ret = 0;
int progress = 0, flags, src_flags;
+ bool writethrough, src_writethrough;
const char *fmt, *out_fmt, *cache, *src_cache, *out_baseimg, *out_filename;
BlockDriver *drv, *proto_drv;
BlockBackend **blk = NULL, *out_blk = NULL;
Error *local_err = NULL;
QemuOpts *sn_opts = NULL;
ImgConvertState state;
+ bool image_opts = false;
fmt = NULL;
out_fmt = "raw";
compress = 0;
skip_create = 0;
for(;;) {
- c = getopt(argc, argv, "hf:O:B:ce6o:s:l:S:pt:T:qn");
+ static const struct option long_options[] = {
+ {"help", no_argument, 0, 'h'},
+ {"object", required_argument, 0, OPTION_OBJECT},
+ {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
+ {0, 0, 0, 0}
+ };
+ c = getopt_long(argc, argv, "hf:O:B:ce6o:s:l:S:pt:T:qn",
+ long_options, NULL);
if (c == -1) {
break;
}
case 'n':
skip_create = 1;
break;
+ case OPTION_OBJECT:
+ opts = qemu_opts_parse_noisily(&qemu_object_opts,
+ optarg, true);
+ if (!opts) {
+ goto fail_getopt;
+ }
+ break;
+ case OPTION_IMAGE_OPTS:
+ image_opts = true;
+ break;
}
}
+ if (qemu_opts_foreach(&qemu_object_opts,
+ user_creatable_add_opts_foreach,
+ NULL, NULL)) {
+ goto fail_getopt;
+ }
+
/* Initialize before goto out */
if (quiet) {
progress = 0;
}
qemu_progress_init(progress, 1.0);
-
bs_n = argc - optind - 1;
out_filename = bs_n >= 1 ? argv[argc - 1] : NULL;
goto out;
}
- src_flags = BDRV_O_FLAGS;
- ret = bdrv_parse_cache_flags(src_cache, &src_flags);
+ src_flags = 0;
+ ret = bdrv_parse_cache_mode(src_cache, &src_flags, &src_writethrough);
if (ret < 0) {
error_report("Invalid source cache option: %s", src_cache);
goto out;
total_sectors = 0;
for (bs_i = 0; bs_i < bs_n; bs_i++) {
- char *id = bs_n > 1 ? g_strdup_printf("source_%d", bs_i)
- : g_strdup("source");
- blk[bs_i] = img_open(id, argv[optind + bs_i], fmt, src_flags,
- true, quiet);
- g_free(id);
+ blk[bs_i] = img_open(image_opts, argv[optind + bs_i],
+ fmt, src_flags, src_writethrough, quiet);
if (!blk[bs_i]) {
ret = -1;
goto out;
}
flags = min_sparse ? (BDRV_O_RDWR | BDRV_O_UNMAP) : BDRV_O_RDWR;
- ret = bdrv_parse_cache_flags(cache, &flags);
+ ret = bdrv_parse_cache_mode(cache, &flags, &writethrough);
if (ret < 0) {
error_report("Invalid cache option: %s", cache);
goto out;
}
- out_blk = img_open("target", out_filename, out_fmt, flags, true, quiet);
+ /* XXX we should allow --image-opts to trigger use of
+ * img_open() here, but then we have trouble with
+ * the bdrv_create() call which takes different params.
+ * Not critical right now, so fix can wait...
+ */
+ out_blk = img_open_file(out_filename, out_fmt, flags, writethrough, quiet);
if (!out_blk) {
ret = -1;
goto out;
* image file. If there was an error a message will have been printed to
* stderr.
*/
-static ImageInfoList *collect_image_info_list(const char *filename,
+static ImageInfoList *collect_image_info_list(bool image_opts,
+ const char *filename,
const char *fmt,
bool chain)
{
}
g_hash_table_insert(filenames, (gpointer)filename, NULL);
- blk = img_open("image", filename, fmt,
- BDRV_O_FLAGS | BDRV_O_NO_BACKING, false, false);
+ blk = img_open(image_opts, filename, fmt,
+ BDRV_O_NO_BACKING | BDRV_O_NO_IO, false, false);
if (!blk) {
goto err;
}
bool chain = false;
const char *filename, *fmt, *output;
ImageInfoList *list;
+ bool image_opts = false;
fmt = NULL;
output = NULL;
{"format", required_argument, 0, 'f'},
{"output", required_argument, 0, OPTION_OUTPUT},
{"backing-chain", no_argument, 0, OPTION_BACKING_CHAIN},
+ {"object", required_argument, 0, OPTION_OBJECT},
+ {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
{0, 0, 0, 0}
};
c = getopt_long(argc, argv, "f:h",
case OPTION_BACKING_CHAIN:
chain = true;
break;
+ case OPTION_OBJECT: {
+ QemuOpts *opts;
+ opts = qemu_opts_parse_noisily(&qemu_object_opts,
+ optarg, true);
+ if (!opts) {
+ return 1;
+ }
+ } break;
+ case OPTION_IMAGE_OPTS:
+ image_opts = true;
+ break;
}
}
if (optind != argc - 1) {
return 1;
}
- list = collect_image_info_list(filename, fmt, chain);
+ if (qemu_opts_foreach(&qemu_object_opts,
+ user_creatable_add_opts_foreach,
+ NULL, NULL)) {
+ return 1;
+ }
+
+ list = collect_image_info_list(image_opts, filename, fmt, chain);
if (!list) {
return 1;
}
int64_t ret;
int depth;
BlockDriverState *file;
+ bool has_offset;
/* As an optimization, we could cache the current range of unallocated
* clusters in each file of the chain, and avoid querying the same
depth++;
}
- e->start = sector_num * BDRV_SECTOR_SIZE;
- e->length = nb_sectors * BDRV_SECTOR_SIZE;
- e->data = !!(ret & BDRV_BLOCK_DATA);
- e->zero = !!(ret & BDRV_BLOCK_ZERO);
- e->offset = ret & BDRV_BLOCK_OFFSET_MASK;
- e->has_offset = !!(ret & BDRV_BLOCK_OFFSET_VALID);
- e->depth = depth;
- if (file && e->has_offset) {
- e->has_filename = true;
- e->filename = file->filename;
- }
+ has_offset = !!(ret & BDRV_BLOCK_OFFSET_VALID);
+
+ *e = (MapEntry) {
+ .start = sector_num * BDRV_SECTOR_SIZE,
+ .length = nb_sectors * BDRV_SECTOR_SIZE,
+ .data = !!(ret & BDRV_BLOCK_DATA),
+ .zero = !!(ret & BDRV_BLOCK_ZERO),
+ .offset = ret & BDRV_BLOCK_OFFSET_MASK,
+ .has_offset = has_offset,
+ .depth = depth,
+ .has_filename = file && has_offset,
+ .filename = file && has_offset ? file->filename : NULL,
+ };
+
return 0;
}
int64_t length;
MapEntry curr = { .length = 0 }, next;
int ret = 0;
+ bool image_opts = false;
fmt = NULL;
output = NULL;
{"help", no_argument, 0, 'h'},
{"format", required_argument, 0, 'f'},
{"output", required_argument, 0, OPTION_OUTPUT},
+ {"object", required_argument, 0, OPTION_OBJECT},
+ {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
{0, 0, 0, 0}
};
c = getopt_long(argc, argv, "f:h",
case OPTION_OUTPUT:
output = optarg;
break;
+ case OPTION_OBJECT: {
+ QemuOpts *opts;
+ opts = qemu_opts_parse_noisily(&qemu_object_opts,
+ optarg, true);
+ if (!opts) {
+ return 1;
+ }
+ } break;
+ case OPTION_IMAGE_OPTS:
+ image_opts = true;
+ break;
}
}
if (optind != argc - 1) {
return 1;
}
- blk = img_open("image", filename, fmt, BDRV_O_FLAGS, true, false);
+ if (qemu_opts_foreach(&qemu_object_opts,
+ user_creatable_add_opts_foreach,
+ NULL, NULL)) {
+ return 1;
+ }
+
+ blk = img_open(image_opts, filename, fmt, 0, false, false);
if (!blk) {
return 1;
}
qemu_timeval tv;
bool quiet = false;
Error *err = NULL;
+ bool image_opts = false;
- bdrv_oflags = BDRV_O_FLAGS | BDRV_O_RDWR;
+ bdrv_oflags = BDRV_O_RDWR;
/* Parse commandline parameters */
for(;;) {
- c = getopt(argc, argv, "la:c:d:hq");
+ static const struct option long_options[] = {
+ {"help", no_argument, 0, 'h'},
+ {"object", required_argument, 0, OPTION_OBJECT},
+ {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
+ {0, 0, 0, 0}
+ };
+ c = getopt_long(argc, argv, "la:c:d:hq",
+ long_options, NULL);
if (c == -1) {
break;
}
case 'q':
quiet = true;
break;
+ case OPTION_OBJECT: {
+ QemuOpts *opts;
+ opts = qemu_opts_parse_noisily(&qemu_object_opts,
+ optarg, true);
+ if (!opts) {
+ return 1;
+ }
+ } break;
+ case OPTION_IMAGE_OPTS:
+ image_opts = true;
+ break;
}
}
}
filename = argv[optind++];
+ if (qemu_opts_foreach(&qemu_object_opts,
+ user_creatable_add_opts_foreach,
+ NULL, NULL)) {
+ return 1;
+ }
+
/* Open the image */
- blk = img_open("image", filename, NULL, bdrv_oflags, true, quiet);
+ blk = img_open(image_opts, filename, NULL, bdrv_oflags, false, quiet);
if (!blk) {
return 1;
}
static int img_rebase(int argc, char **argv)
{
BlockBackend *blk = NULL, *blk_old_backing = NULL, *blk_new_backing = NULL;
+ uint8_t *buf_old = NULL;
+ uint8_t *buf_new = NULL;
BlockDriverState *bs = NULL;
char *filename;
const char *fmt, *cache, *src_cache, *out_basefmt, *out_baseimg;
int c, flags, src_flags, ret;
+ bool writethrough, src_writethrough;
int unsafe = 0;
int progress = 0;
bool quiet = false;
Error *local_err = NULL;
+ bool image_opts = false;
/* Parse commandline parameters */
fmt = NULL;
out_baseimg = NULL;
out_basefmt = NULL;
for(;;) {
- c = getopt(argc, argv, "hf:F:b:upt:T:q");
+ static const struct option long_options[] = {
+ {"help", no_argument, 0, 'h'},
+ {"object", required_argument, 0, OPTION_OBJECT},
+ {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
+ {0, 0, 0, 0}
+ };
+ c = getopt_long(argc, argv, "hf:F:b:upt:T:q",
+ long_options, NULL);
if (c == -1) {
break;
}
case 'q':
quiet = true;
break;
+ case OPTION_OBJECT: {
+ QemuOpts *opts;
+ opts = qemu_opts_parse_noisily(&qemu_object_opts,
+ optarg, true);
+ if (!opts) {
+ return 1;
+ }
+ } break;
+ case OPTION_IMAGE_OPTS:
+ image_opts = true;
+ break;
}
}
}
filename = argv[optind++];
+ if (qemu_opts_foreach(&qemu_object_opts,
+ user_creatable_add_opts_foreach,
+ NULL, NULL)) {
+ return 1;
+ }
+
qemu_progress_init(progress, 2.0);
qemu_progress_print(0, 100);
flags = BDRV_O_RDWR | (unsafe ? BDRV_O_NO_BACKING : 0);
- ret = bdrv_parse_cache_flags(cache, &flags);
+ ret = bdrv_parse_cache_mode(cache, &flags, &writethrough);
if (ret < 0) {
error_report("Invalid cache option: %s", cache);
goto out;
}
- src_flags = BDRV_O_FLAGS;
- ret = bdrv_parse_cache_flags(src_cache, &src_flags);
+ src_flags = 0;
+ ret = bdrv_parse_cache_mode(src_cache, &src_flags, &src_writethrough);
if (ret < 0) {
error_report("Invalid source cache option: %s", src_cache);
goto out;
}
+ /* The source files are opened read-only, don't care about WCE */
+ assert((src_flags & BDRV_O_RDWR) == 0);
+ (void) src_writethrough;
+
/*
* Open the images.
*
* Ignore the old backing file for unsafe rebase in case we want to correct
* the reference to a renamed or moved backing file.
*/
- blk = img_open("image", filename, fmt, flags, true, quiet);
+ blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet);
if (!blk) {
ret = -1;
goto out;
}
bdrv_get_backing_filename(bs, backing_name, sizeof(backing_name));
- blk_old_backing = blk_new_open("old_backing", backing_name, NULL,
+ blk_old_backing = blk_new_open(backing_name, NULL,
options, src_flags, &local_err);
if (!blk_old_backing) {
error_reportf_err(local_err,
options = NULL;
}
- blk_new_backing = blk_new_open("new_backing", out_baseimg, NULL,
+ blk_new_backing = blk_new_open(out_baseimg, NULL,
options, src_flags, &local_err);
if (!blk_new_backing) {
error_reportf_err(local_err,
int64_t new_backing_num_sectors = 0;
uint64_t sector;
int n;
- uint8_t * buf_old;
- uint8_t * buf_new;
float local_progress = 0;
buf_old = blk_blockalign(blk, IO_BUF_SIZE);
n = old_backing_num_sectors - sector;
}
- ret = blk_read(blk_old_backing, sector, buf_old, n);
+ ret = blk_pread(blk_old_backing, sector << BDRV_SECTOR_BITS,
+ buf_old, n << BDRV_SECTOR_BITS);
if (ret < 0) {
error_report("error while reading from old backing file");
goto out;
n = new_backing_num_sectors - sector;
}
- ret = blk_read(blk_new_backing, sector, buf_new, n);
+ ret = blk_pread(blk_new_backing, sector << BDRV_SECTOR_BITS,
+ buf_new, n << BDRV_SECTOR_BITS);
if (ret < 0) {
error_report("error while reading from new backing file");
goto out;
if (compare_sectors(buf_old + written * 512,
buf_new + written * 512, n - written, &pnum))
{
- ret = blk_write(blk, sector + written,
- buf_old + written * 512, pnum);
+ ret = blk_pwrite(blk,
+ (sector + written) << BDRV_SECTOR_BITS,
+ buf_old + written * 512,
+ pnum << BDRV_SECTOR_BITS, 0);
if (ret < 0) {
error_report("Error while writing to COW image: %s",
strerror(-ret));
}
qemu_progress_print(local_progress, 100);
}
-
- qemu_vfree(buf_old);
- qemu_vfree(buf_new);
}
/*
blk_unref(blk_old_backing);
blk_unref(blk_new_backing);
}
+ qemu_vfree(buf_old);
+ qemu_vfree(buf_new);
blk_unref(blk);
if (ret) {
bool quiet = false;
BlockBackend *blk = NULL;
QemuOpts *param;
+
static QemuOptsList resize_options = {
.name = "resize_options",
.head = QTAILQ_HEAD_INITIALIZER(resize_options.head),
}
},
};
+ bool image_opts = false;
/* Remove size from argv manually so that negative numbers are not treated
* as options by getopt. */
/* Parse getopt arguments */
fmt = NULL;
for(;;) {
- c = getopt(argc, argv, "f:hq");
+ static const struct option long_options[] = {
+ {"help", no_argument, 0, 'h'},
+ {"object", required_argument, 0, OPTION_OBJECT},
+ {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
+ {0, 0, 0, 0}
+ };
+ c = getopt_long(argc, argv, "f:hq",
+ long_options, NULL);
if (c == -1) {
break;
}
case 'q':
quiet = true;
break;
+ case OPTION_OBJECT: {
+ QemuOpts *opts;
+ opts = qemu_opts_parse_noisily(&qemu_object_opts,
+ optarg, true);
+ if (!opts) {
+ return 1;
+ }
+ } break;
+ case OPTION_IMAGE_OPTS:
+ image_opts = true;
+ break;
}
}
if (optind != argc - 1) {
}
filename = argv[optind++];
+ if (qemu_opts_foreach(&qemu_object_opts,
+ user_creatable_add_opts_foreach,
+ NULL, NULL)) {
+ return 1;
+ }
+
/* Choose grow, shrink, or absolute resize mode */
switch (size[0]) {
case '+':
n = qemu_opt_get_size(param, BLOCK_OPT_SIZE, 0);
qemu_opts_del(param);
- blk = img_open("image", filename, fmt, BDRV_O_FLAGS | BDRV_O_RDWR,
- true, quiet);
+ blk = img_open(image_opts, filename, fmt,
+ BDRV_O_RDWR, false, quiet);
if (!blk) {
ret = -1;
goto out;
QemuOpts *opts = NULL;
const char *fmt = NULL, *filename, *cache;
int flags;
+ bool writethrough;
bool quiet = false, progress = false;
BlockBackend *blk = NULL;
BlockDriverState *bs = NULL;
+ bool image_opts = false;
cache = BDRV_DEFAULT_CACHE;
for (;;) {
- c = getopt(argc, argv, "ho:f:t:pq");
+ static const struct option long_options[] = {
+ {"help", no_argument, 0, 'h'},
+ {"object", required_argument, 0, OPTION_OBJECT},
+ {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
+ {0, 0, 0, 0}
+ };
+ c = getopt_long(argc, argv, "ho:f:t:pq",
+ long_options, NULL);
if (c == -1) {
break;
}
case 'q':
quiet = true;
break;
+ case OPTION_OBJECT:
+ opts = qemu_opts_parse_noisily(&qemu_object_opts,
+ optarg, true);
+ if (!opts) {
+ ret = -1;
+ goto out_no_progress;
+ }
+ break;
+ case OPTION_IMAGE_OPTS:
+ image_opts = true;
+ break;
}
}
error_exit("Must specify options (-o)");
}
+ if (qemu_opts_foreach(&qemu_object_opts,
+ user_creatable_add_opts_foreach,
+ NULL, NULL)) {
+ ret = -1;
+ goto out_no_progress;
+ }
+
if (quiet) {
progress = false;
}
goto out;
}
- flags = BDRV_O_FLAGS | BDRV_O_RDWR;
- ret = bdrv_parse_cache_flags(cache, &flags);
+ flags = BDRV_O_RDWR;
+ ret = bdrv_parse_cache_mode(cache, &flags, &writethrough);
if (ret < 0) {
error_report("Invalid cache option: %s", cache);
goto out;
}
- blk = img_open("image", filename, fmt, flags, true, quiet);
+ blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet);
if (!blk) {
ret = -1;
goto out;
return 0;
}
+typedef struct BenchData {
+ BlockBackend *blk;
+ uint64_t image_size;
+ bool write;
+ int bufsize;
+ int step;
+ int nrreq;
+ int n;
+ int flush_interval;
+ bool drain_on_flush;
+ uint8_t *buf;
+ QEMUIOVector *qiov;
+
+ int in_flight;
+ bool in_flush;
+ uint64_t offset;
+} BenchData;
+
+static void bench_undrained_flush_cb(void *opaque, int ret)
+{
+ if (ret < 0) {
+ error_report("Failed flush request: %s\n", strerror(-ret));
+ exit(EXIT_FAILURE);
+ }
+}
+
+static void bench_cb(void *opaque, int ret)
+{
+ BenchData *b = opaque;
+ BlockAIOCB *acb;
+
+ if (ret < 0) {
+ error_report("Failed request: %s\n", strerror(-ret));
+ exit(EXIT_FAILURE);
+ }
+
+ if (b->in_flush) {
+ /* Just finished a flush with drained queue: Start next requests */
+ assert(b->in_flight == 0);
+ b->in_flush = false;
+ } else if (b->in_flight > 0) {
+ int remaining = b->n - b->in_flight;
+
+ b->n--;
+ b->in_flight--;
+
+ /* Time for flush? Drain queue if requested, then flush */
+ if (b->flush_interval && remaining % b->flush_interval == 0) {
+ if (!b->in_flight || !b->drain_on_flush) {
+ BlockCompletionFunc *cb;
+
+ if (b->drain_on_flush) {
+ b->in_flush = true;
+ cb = bench_cb;
+ } else {
+ cb = bench_undrained_flush_cb;
+ }
+
+ acb = blk_aio_flush(b->blk, cb, b);
+ if (!acb) {
+ error_report("Failed to issue flush request");
+ exit(EXIT_FAILURE);
+ }
+ }
+ if (b->drain_on_flush) {
+ return;
+ }
+ }
+ }
+
+ while (b->n > b->in_flight && b->in_flight < b->nrreq) {
+ if (b->write) {
+ acb = blk_aio_pwritev(b->blk, b->offset, b->qiov, 0,
+ bench_cb, b);
+ } else {
+ acb = blk_aio_preadv(b->blk, b->offset, b->qiov, 0,
+ bench_cb, b);
+ }
+ if (!acb) {
+ error_report("Failed to issue request");
+ exit(EXIT_FAILURE);
+ }
+ b->in_flight++;
+ b->offset += b->step;
+ b->offset %= b->image_size;
+ }
+}
+
+static int img_bench(int argc, char **argv)
+{
+ int c, ret = 0;
+ const char *fmt = NULL, *filename;
+ bool quiet = false;
+ bool image_opts = false;
+ bool is_write = false;
+ int count = 75000;
+ int depth = 64;
+ int64_t offset = 0;
+ size_t bufsize = 4096;
+ int pattern = 0;
+ size_t step = 0;
+ int flush_interval = 0;
+ bool drain_on_flush = true;
+ int64_t image_size;
+ BlockBackend *blk = NULL;
+ BenchData data = {};
+ int flags = 0;
+ bool writethrough = false;
+ struct timeval t1, t2;
+ int i;
+
+ for (;;) {
+ static const struct option long_options[] = {
+ {"help", no_argument, 0, 'h'},
+ {"flush-interval", required_argument, 0, OPTION_FLUSH_INTERVAL},
+ {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
+ {"pattern", required_argument, 0, OPTION_PATTERN},
+ {"no-drain", no_argument, 0, OPTION_NO_DRAIN},
+ {0, 0, 0, 0}
+ };
+ c = getopt_long(argc, argv, "hc:d:f:no:qs:S:t:w", long_options, NULL);
+ if (c == -1) {
+ break;
+ }
+
+ switch (c) {
+ case 'h':
+ case '?':
+ help();
+ break;
+ case 'c':
+ {
+ char *end;
+ errno = 0;
+ count = strtoul(optarg, &end, 0);
+ if (errno || *end || count > INT_MAX) {
+ error_report("Invalid request count specified");
+ return 1;
+ }
+ break;
+ }
+ case 'd':
+ {
+ char *end;
+ errno = 0;
+ depth = strtoul(optarg, &end, 0);
+ if (errno || *end || depth > INT_MAX) {
+ error_report("Invalid queue depth specified");
+ return 1;
+ }
+ break;
+ }
+ case 'f':
+ fmt = optarg;
+ break;
+ case 'n':
+ flags |= BDRV_O_NATIVE_AIO;
+ break;
+ case 'o':
+ {
+ char *end;
+ errno = 0;
+ offset = qemu_strtosz_suffix(optarg, &end,
+ QEMU_STRTOSZ_DEFSUFFIX_B);
+ if (offset < 0|| *end) {
+ error_report("Invalid offset specified");
+ return 1;
+ }
+ break;
+ }
+ break;
+ case 'q':
+ quiet = true;
+ break;
+ case 's':
+ {
+ int64_t sval;
+ char *end;
+
+ sval = qemu_strtosz_suffix(optarg, &end, QEMU_STRTOSZ_DEFSUFFIX_B);
+ if (sval < 0 || sval > INT_MAX || *end) {
+ error_report("Invalid buffer size specified");
+ return 1;
+ }
+
+ bufsize = sval;
+ break;
+ }
+ case 'S':
+ {
+ int64_t sval;
+ char *end;
+
+ sval = qemu_strtosz_suffix(optarg, &end, QEMU_STRTOSZ_DEFSUFFIX_B);
+ if (sval < 0 || sval > INT_MAX || *end) {
+ error_report("Invalid step size specified");
+ return 1;
+ }
+
+ step = sval;
+ break;
+ }
+ case 't':
+ ret = bdrv_parse_cache_mode(optarg, &flags, &writethrough);
+ if (ret < 0) {
+ error_report("Invalid cache mode");
+ ret = -1;
+ goto out;
+ }
+ break;
+ case 'w':
+ flags |= BDRV_O_RDWR;
+ is_write = true;
+ break;
+ case OPTION_PATTERN:
+ {
+ char *end;
+ errno = 0;
+ pattern = strtoul(optarg, &end, 0);
+ if (errno || *end || pattern > 0xff) {
+ error_report("Invalid pattern byte specified");
+ return 1;
+ }
+ break;
+ }
+ case OPTION_FLUSH_INTERVAL:
+ {
+ char *end;
+ errno = 0;
+ flush_interval = strtoul(optarg, &end, 0);
+ if (errno || *end || flush_interval > INT_MAX) {
+ error_report("Invalid flush interval specified");
+ return 1;
+ }
+ break;
+ }
+ case OPTION_NO_DRAIN:
+ drain_on_flush = false;
+ break;
+ case OPTION_IMAGE_OPTS:
+ image_opts = true;
+ break;
+ }
+ }
+
+ if (optind != argc - 1) {
+ error_exit("Expecting one image file name");
+ }
+ filename = argv[argc - 1];
+
+ if (!is_write && flush_interval) {
+ error_report("--flush-interval is only available in write tests");
+ ret = -1;
+ goto out;
+ }
+ if (flush_interval && flush_interval < depth) {
+ error_report("Flush interval can't be smaller than depth");
+ ret = -1;
+ goto out;
+ }
+
+ blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet);
+ if (!blk) {
+ ret = -1;
+ goto out;
+ }
+
+ image_size = blk_getlength(blk);
+ if (image_size < 0) {
+ ret = image_size;
+ goto out;
+ }
+
+ data = (BenchData) {
+ .blk = blk,
+ .image_size = image_size,
+ .bufsize = bufsize,
+ .step = step ?: bufsize,
+ .nrreq = depth,
+ .n = count,
+ .offset = offset,
+ .write = is_write,
+ .flush_interval = flush_interval,
+ .drain_on_flush = drain_on_flush,
+ };
+ printf("Sending %d %s requests, %d bytes each, %d in parallel "
+ "(starting at offset %" PRId64 ", step size %d)\n",
+ data.n, data.write ? "write" : "read", data.bufsize, data.nrreq,
+ data.offset, data.step);
+ if (flush_interval) {
+ printf("Sending flush every %d requests\n", flush_interval);
+ }
+
+ data.buf = blk_blockalign(blk, data.nrreq * data.bufsize);
+ memset(data.buf, pattern, data.nrreq * data.bufsize);
+
+ data.qiov = g_new(QEMUIOVector, data.nrreq);
+ for (i = 0; i < data.nrreq; i++) {
+ qemu_iovec_init(&data.qiov[i], 1);
+ qemu_iovec_add(&data.qiov[i],
+ data.buf + i * data.bufsize, data.bufsize);
+ }
+
+ gettimeofday(&t1, NULL);
+ bench_cb(&data, 0);
+
+ while (data.n > 0) {
+ main_loop_wait(false);
+ }
+ gettimeofday(&t2, NULL);
+
+ printf("Run completed in %3.3f seconds.\n",
+ (t2.tv_sec - t1.tv_sec)
+ + ((double)(t2.tv_usec - t1.tv_usec) / 1000000));
+
+out:
+ qemu_vfree(data.buf);
+ blk_unref(blk);
+
+ if (ret) {
+ return 1;
+ }
+ return 0;
+}
+
+
static const img_cmd_t img_cmds[] = {
#define DEF(option, callback, arg_string) \
{ option, callback },
const img_cmd_t *cmd;
const char *cmdname;
Error *local_error = NULL;
+ char *trace_file = NULL;
int c;
static const struct option long_options[] = {
{"help", no_argument, 0, 'h'},
- {"version", no_argument, 0, 'v'},
+ {"version", no_argument, 0, 'V'},
+ {"trace", required_argument, NULL, 'T'},
{0, 0, 0, 0}
};
exit(EXIT_FAILURE);
}
+ qcrypto_init(&error_fatal);
+
module_call_init(MODULE_INIT_QOM);
bdrv_init();
if (argc < 2) {
error_exit("Not enough arguments");
}
- cmdname = argv[1];
- /* find the command */
- for (cmd = img_cmds; cmd->name != NULL; cmd++) {
- if (!strcmp(cmdname, cmd->name)) {
- return cmd->handler(argc - 1, argv + 1);
+ qemu_add_opts(&qemu_object_opts);
+ qemu_add_opts(&qemu_source_opts);
+ qemu_add_opts(&qemu_trace_opts);
+
+ while ((c = getopt_long(argc, argv, "+hVT:", long_options, NULL)) != -1) {
+ switch (c) {
+ case 'h':
+ help();
+ return 0;
+ case 'V':
+ printf(QEMU_IMG_VERSION);
+ return 0;
+ case 'T':
+ g_free(trace_file);
+ trace_file = trace_opt_parse(optarg);
+ break;
}
}
- c = getopt_long(argc, argv, "h", long_options, NULL);
+ cmdname = argv[optind];
- if (c == 'h') {
- help();
- }
- if (c == 'v') {
- printf(QEMU_IMG_VERSION);
+ /* reset getopt_long scanning */
+ argc -= optind;
+ if (argc < 1) {
return 0;
}
+ argv += optind;
+ optind = 1;
+
+ if (!trace_init_backends()) {
+ exit(1);
+ }
+ trace_init_file(trace_file);
+ qemu_set_log(LOG_TRACE);
+
+ /* find the command */
+ for (cmd = img_cmds; cmd->name != NULL; cmd++) {
+ if (!strcmp(cmdname, cmd->name)) {
+ return cmd->handler(argc, argv);
+ }
+ }
/* not found */
error_exit("Command not found: %s", cmdname);