X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=qemu-img.c;h=6fe2466032f95f43ada251f597641fae80a68bdf;hb=395aecd037dc35d110b8e1e8cc7d20c1082894b5;hp=a968c74cba3a3bb57c856eebbc11820b96565c9b;hpb=8680d6e36468f1ca00e2fe749bef50585d632401;p=qmiga%2Fqemu.git diff --git a/qemu-img.c b/qemu-img.c index a968c74cba..6fe2466032 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -33,7 +33,6 @@ #include "qapi/qobject-output-visitor.h" #include "qapi/qmp/qjson.h" #include "qapi/qmp/qdict.h" -#include "qapi/qmp/qstring.h" #include "qemu/cutils.h" #include "qemu/config-file.h" #include "qemu/option.h" @@ -83,6 +82,7 @@ enum { OPTION_MERGE = 274, OPTION_BITMAPS = 275, OPTION_FORCE = 276, + OPTION_SKIP_BROKEN = 277, }; typedef enum OutputFormat { @@ -227,23 +227,6 @@ static void QEMU_NORETURN help(void) 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 bool qemu_img_object_print_help(const char *type, QemuOpts *opts) -{ - if (user_creatable_print_help(type, opts)) { - exit(0); - } - return true; -} - /* * Is @optarg safe for accumulate_options()? * It is when multiple of them can be joined together separated by ','. @@ -567,14 +550,9 @@ static int img_create(int argc, char **argv) case 'u': flags |= BDRV_O_NO_BACKING; break; - case OPTION_OBJECT: { - QemuOpts *opts; - opts = qemu_opts_parse_noisily(&qemu_object_opts, - optarg, true); - if (!opts) { - goto fail; - } - } break; + case OPTION_OBJECT: + user_creatable_process_cmdline(optarg); + break; } } @@ -590,12 +568,6 @@ static int img_create(int argc, char **argv) } optind++; - if (qemu_opts_foreach(&qemu_object_opts, - user_creatable_add_opts_foreach, - qemu_img_object_print_help, &error_fatal)) { - goto fail; - } - /* Get image size, if specified */ if (optind < argc) { int64_t sval; @@ -627,18 +599,18 @@ fail: static void dump_json_image_check(ImageCheck *check, bool quiet) { - QString *str; + GString *str; QObject *obj; Visitor *v = qobject_output_visitor_new(&obj); visit_type_ImageCheck(v, NULL, &check, &error_abort); visit_complete(v, &obj); - str = qobject_to_json_pretty(obj); + str = qobject_to_json_pretty(obj, true); assert(str != NULL); - qprintf(quiet, "%s\n", qstring_get_str(str)); + qprintf(quiet, "%s\n", str->str); qobject_unref(obj); visit_free(v); - qobject_unref(str); + g_string_free(str, true); } static void dump_human_image_check(ImageCheck *check, bool quiet) @@ -805,14 +777,9 @@ static int img_check(int argc, char **argv) case 'U': force_share = true; break; - case OPTION_OBJECT: { - QemuOpts *opts; - opts = qemu_opts_parse_noisily(&qemu_object_opts, - optarg, true); - if (!opts) { - return 1; - } - } break; + case OPTION_OBJECT: + user_creatable_process_cmdline(optarg); + break; case OPTION_IMAGE_OPTS: image_opts = true; break; @@ -832,12 +799,6 @@ static int img_check(int argc, char **argv) return 1; } - if (qemu_opts_foreach(&qemu_object_opts, - user_creatable_add_opts_foreach, - qemu_img_object_print_help, &error_fatal)) { - return 1; - } - ret = bdrv_parse_cache_mode(cache, &flags, &writethrough); if (ret < 0) { error_report("Invalid source cache option: %s", cache); @@ -940,7 +901,8 @@ static void common_block_job_cb(void *opaque, int ret) static void run_block_job(BlockJob *job, Error **errp) { - AioContext *aio_context = blk_get_aio_context(job->blk); + uint64_t progress_current, progress_total; + AioContext *aio_context = block_job_get_aio_context(job); int ret = 0; aio_context_acquire(aio_context); @@ -948,9 +910,11 @@ static void run_block_job(BlockJob *job, Error **errp) do { float progress = 0.0f; aio_poll(aio_context, true); - if (job->job.progress.total) { - progress = (float)job->job.progress.current / - job->job.progress.total * 100.f; + + progress_get_snapshot(&job->job.progress, &progress_current, + &progress_total); + if (progress_total) { + progress = (float)progress_current / progress_total * 100.f; } qemu_progress_print(progress, 0); } while (!job_is_ready(&job->job) && !job_is_completed(&job->job)); @@ -1035,14 +999,9 @@ static int img_commit(int argc, char **argv) return 1; } break; - case OPTION_OBJECT: { - QemuOpts *opts; - opts = qemu_opts_parse_noisily(&qemu_object_opts, - optarg, true); - if (!opts) { - return 1; - } - } break; + case OPTION_OBJECT: + user_creatable_process_cmdline(optarg); + break; case OPTION_IMAGE_OPTS: image_opts = true; break; @@ -1059,12 +1018,6 @@ static int img_commit(int argc, char **argv) } filename = argv[optind++]; - if (qemu_opts_foreach(&qemu_object_opts, - user_creatable_add_opts_foreach, - qemu_img_object_print_help, &error_fatal)) { - return 1; - } - flags = BDRV_O_RDWR | BDRV_O_UNMAP; ret = bdrv_parse_cache_mode(cache, &flags, &writethrough); if (ret < 0) { @@ -1218,19 +1171,34 @@ static int is_allocated_sectors(const uint8_t *buf, int n, int *pnum, } } + if (i == n) { + /* + * The whole buf is the same. + * No reason to split it into chunks, so return now. + */ + *pnum = i; + return !is_zero; + } + tail = (sector_num + i) & (alignment - 1); if (tail) { if (is_zero && i <= tail) { - /* treat unallocated areas which only consist - * of a small tail as allocated. */ + /* + * For sure next sector after i is data, and it will rewrite this + * tail anyway due to RMW. So, let's just write data now. + */ is_zero = false; } if (!is_zero) { - /* align up end offset of allocated areas. */ + /* If possible, align up end offset of allocated areas. */ i += alignment - tail; i = MIN(i, n); } else { - /* align down end offset of zero areas. */ + /* + * For sure next sector after i is data, and it will rewrite this + * tail anyway due to RMW. Better is avoid RMW and write zeroes up + * to aligned bound. + */ i -= tail; } } @@ -1354,7 +1322,7 @@ static int check_empty_sectors(BlockBackend *blk, int64_t offset, /* * Compares two images. Exit codes: * - * 0 - Images are identical + * 0 - Images are identical or the requested help was printed * 1 - Images differ * >1 - Error occurred */ @@ -1424,15 +1392,21 @@ static int img_compare(int argc, char **argv) case 'U': force_share = true; break; - case OPTION_OBJECT: { - QemuOpts *opts; - opts = qemu_opts_parse_noisily(&qemu_object_opts, - optarg, true); - if (!opts) { - ret = 2; - goto out4; + case OPTION_OBJECT: + { + Error *local_err = NULL; + + if (!user_creatable_add_from_str(optarg, &local_err)) { + if (local_err) { + error_report_err(local_err); + exit(2); + } else { + /* Help was printed */ + exit(EXIT_SUCCESS); + } + } + break; } - } break; case OPTION_IMAGE_OPTS: image_opts = true; break; @@ -1451,13 +1425,6 @@ static int img_compare(int argc, char **argv) filename1 = argv[optind++]; filename2 = argv[optind++]; - if (qemu_opts_foreach(&qemu_object_opts, - user_creatable_add_opts_foreach, - qemu_img_object_print_help, &error_fatal)) { - ret = 2; - goto out4; - } - /* Initialize before goto out */ qemu_progress_init(progress, 2.0); @@ -1642,7 +1609,6 @@ out2: blk_unref(blk1); out3: qemu_progress_end(); -out4: return ret; } @@ -1652,14 +1618,13 @@ static void do_dirty_bitmap_merge(const char *dst_node, const char *dst_name, Error **errp) { BlockDirtyBitmapMergeSource *merge_src; - BlockDirtyBitmapMergeSourceList *list; + BlockDirtyBitmapMergeSourceList *list = NULL; merge_src = g_new0(BlockDirtyBitmapMergeSource, 1); merge_src->type = QTYPE_QDICT; merge_src->u.external.node = g_strdup(src_node); merge_src->u.external.name = g_strdup(src_name); - list = g_new0(BlockDirtyBitmapMergeSourceList, 1); - list->value = merge_src; + QAPI_LIST_PREPEND(list, merge_src); qmp_block_dirty_bitmap_merge(dst_node, dst_name, list, errp); qapi_free_BlockDirtyBitmapMergeSourceList(list); } @@ -2152,7 +2117,32 @@ static int convert_do_copy(ImgConvertState *s) return s->ret; } -static int convert_copy_bitmaps(BlockDriverState *src, BlockDriverState *dst) +/* Check that bitmaps can be copied, or output an error */ +static int convert_check_bitmaps(BlockDriverState *src, bool skip_broken) +{ + BdrvDirtyBitmap *bm; + + if (!bdrv_supports_persistent_dirty_bitmap(src)) { + error_report("Source lacks bitmap support"); + return -1; + } + FOR_EACH_DIRTY_BITMAP(src, bm) { + if (!bdrv_dirty_bitmap_get_persistence(bm)) { + continue; + } + if (!skip_broken && bdrv_dirty_bitmap_inconsistent(bm)) { + error_report("Cannot copy inconsistent bitmap '%s'", + bdrv_dirty_bitmap_name(bm)); + error_printf("Try --skip-broken-bitmaps, or " + "use 'qemu-img bitmap --remove' to delete it\n"); + return -1; + } + } + return 0; +} + +static int convert_copy_bitmaps(BlockDriverState *src, BlockDriverState *dst, + bool skip_broken) { BdrvDirtyBitmap *bm; Error *err = NULL; @@ -2164,6 +2154,10 @@ static int convert_copy_bitmaps(BlockDriverState *src, BlockDriverState *dst) continue; } name = bdrv_dirty_bitmap_name(bm); + if (skip_broken && bdrv_dirty_bitmap_inconsistent(bm)) { + warn_report("Skipping inconsistent bitmap '%s'", name); + continue; + } qmp_block_dirty_bitmap_add(dst->node_name, name, true, bdrv_dirty_bitmap_granularity(bm), true, true, @@ -2178,6 +2172,7 @@ static int convert_copy_bitmaps(BlockDriverState *src, BlockDriverState *dst) &err); if (err) { error_reportf_err(err, "Failed to populate bitmap %s: ", name); + qmp_block_dirty_bitmap_remove(dst->node_name, name, NULL); return -1; } } @@ -2200,10 +2195,11 @@ static void set_rate_limit(BlockBackend *blk, int64_t rate_limit) static int img_convert(int argc, char **argv) { - int c, bs_i, flags, src_flags = 0; + int c, bs_i, flags, src_flags = BDRV_O_NO_SHARE; const char *fmt = NULL, *out_fmt = NULL, *cache = "unsafe", *src_cache = BDRV_DEFAULT_CACHE, *out_baseimg = NULL, - *out_filename, *out_baseimg_param, *snapshot_name = NULL; + *out_filename, *out_baseimg_param, *snapshot_name = NULL, + *backing_fmt = NULL; BlockDriver *drv = NULL, *proto_drv = NULL; BlockDriverInfo bdi; BlockDriverState *out_bs; @@ -2218,6 +2214,7 @@ static int img_convert(int argc, char **argv) bool force_share = false; bool explict_min_sparse = false; bool bitmaps = false; + bool skip_broken = false; int64_t rate_limit = 0; ImgConvertState s = (ImgConvertState) { @@ -2239,9 +2236,10 @@ static int img_convert(int argc, char **argv) {"salvage", no_argument, 0, OPTION_SALVAGE}, {"target-is-zero", no_argument, 0, OPTION_TARGET_IS_ZERO}, {"bitmaps", no_argument, 0, OPTION_BITMAPS}, + {"skip-broken-bitmaps", no_argument, 0, OPTION_SKIP_BROKEN}, {0, 0, 0, 0} }; - c = getopt_long(argc, argv, ":hf:O:B:Cco:l:S:pt:T:qnm:WUr:", + c = getopt_long(argc, argv, ":hf:O:B:CcF:o:l:S:pt:T:qnm:WUr:", long_options, NULL); if (c == -1) { break; @@ -2271,6 +2269,9 @@ static int img_convert(int argc, char **argv) case 'c': s.compressed = true; break; + case 'F': + backing_fmt = optarg; + break; case 'o': if (accumulate_options(&options, optarg) < 0) { goto fail_getopt; @@ -2344,15 +2345,9 @@ static int img_convert(int argc, char **argv) goto fail_getopt; } break; - case OPTION_OBJECT: { - QemuOpts *object_opts; - object_opts = qemu_opts_parse_noisily(&qemu_object_opts, - optarg, true); - if (!object_opts) { - goto fail_getopt; - } + case OPTION_OBJECT: + user_creatable_process_cmdline(optarg); break; - } case OPTION_IMAGE_OPTS: image_opts = true; break; @@ -2373,6 +2368,9 @@ static int img_convert(int argc, char **argv) case OPTION_BITMAPS: bitmaps = true; break; + case OPTION_SKIP_BROKEN: + skip_broken = true; + break; } } @@ -2380,9 +2378,8 @@ static int img_convert(int argc, char **argv) out_fmt = "raw"; } - if (qemu_opts_foreach(&qemu_object_opts, - user_creatable_add_opts_foreach, - qemu_img_object_print_help, &error_fatal)) { + if (skip_broken && !bitmaps) { + error_report("Use of --skip-broken-bitmaps requires --bitmaps"); goto fail_getopt; } @@ -2543,7 +2540,7 @@ static int img_convert(int argc, char **argv) qemu_opt_set_number(opts, BLOCK_OPT_SIZE, s.total_sectors * BDRV_SECTOR_SIZE, &error_abort); - ret = add_old_style_options(out_fmt, opts, out_baseimg, NULL); + ret = add_old_style_options(out_fmt, opts, out_baseimg, backing_fmt); if (ret < 0) { goto out; } @@ -2571,8 +2568,10 @@ static int img_convert(int argc, char **argv) if (out_baseimg_param) { if (!qemu_opt_get(opts, BLOCK_OPT_BACKING_FMT)) { - warn_report("Deprecated use of backing file without explicit " - "backing format"); + error_report("Use of backing file requires explicit " + "backing format"); + ret = -1; + goto out; } } @@ -2615,9 +2614,8 @@ static int img_convert(int argc, char **argv) ret = -1; goto out; } - if (!bdrv_supports_persistent_dirty_bitmap(blk_bs(s.src[0]))) { - error_report("Source lacks bitmap support"); - ret = -1; + ret = convert_check_bitmaps(blk_bs(s.src[0]), skip_broken); + if (ret < 0) { goto out; } } @@ -2649,6 +2647,14 @@ static int img_convert(int argc, char **argv) goto out; } + if (flags & BDRV_O_NOCACHE) { + /* + * If we open the target with O_DIRECT, it may be necessary to + * extend its size to align to the physical sector size. + */ + flags |= BDRV_O_RESIZE; + } + if (skip_create) { s.target = img_open(tgt_image_opts, out_filename, out_fmt, flags, writethrough, s.quiet, false); @@ -2741,7 +2747,7 @@ static int img_convert(int argc, char **argv) /* Now copy the bitmaps */ if (bitmaps && ret == 0) { - ret = convert_copy_bitmaps(blk_bs(s.src[0]), out_bs); + ret = convert_copy_bitmaps(blk_bs(s.src[0]), out_bs, skip_broken); } out: @@ -2751,7 +2757,6 @@ out: qemu_progress_end(); qemu_opts_del(opts); qemu_opts_free(create_opts); - qemu_opts_del(sn_opts); qobject_unref(open_opts); blk_unref(s.target); if (s.src) { @@ -2763,6 +2768,7 @@ out: g_free(s.src_sectors); g_free(s.src_alignment); fail_getopt: + qemu_opts_del(sn_opts); g_free(options); return !!ret; @@ -2790,34 +2796,34 @@ static void dump_snapshots(BlockDriverState *bs) static void dump_json_image_info_list(ImageInfoList *list) { - QString *str; + GString *str; QObject *obj; Visitor *v = qobject_output_visitor_new(&obj); visit_type_ImageInfoList(v, NULL, &list, &error_abort); visit_complete(v, &obj); - str = qobject_to_json_pretty(obj); + str = qobject_to_json_pretty(obj, true); assert(str != NULL); - printf("%s\n", qstring_get_str(str)); + printf("%s\n", str->str); qobject_unref(obj); visit_free(v); - qobject_unref(str); + g_string_free(str, true); } static void dump_json_image_info(ImageInfo *info) { - QString *str; + GString *str; QObject *obj; Visitor *v = qobject_output_visitor_new(&obj); visit_type_ImageInfo(v, NULL, &info, &error_abort); visit_complete(v, &obj); - str = qobject_to_json_pretty(obj); + str = qobject_to_json_pretty(obj, true); assert(str != NULL); - printf("%s\n", qstring_get_str(str)); + printf("%s\n", str->str); qobject_unref(obj); visit_free(v); - qobject_unref(str); + g_string_free(str, true); } static void dump_human_image_info_list(ImageInfoList *list) @@ -2858,7 +2864,7 @@ static ImageInfoList *collect_image_info_list(bool image_opts, bool chain, bool force_share) { ImageInfoList *head = NULL; - ImageInfoList **last = &head; + ImageInfoList **tail = &head; GHashTable *filenames; Error *err = NULL; @@ -2868,7 +2874,6 @@ static ImageInfoList *collect_image_info_list(bool image_opts, BlockBackend *blk; BlockDriverState *bs; ImageInfo *info; - ImageInfoList *elem; if (g_hash_table_lookup_extended(filenames, filename, NULL, NULL)) { error_report("Backing file '%s' creates an infinite loop.", @@ -2892,10 +2897,7 @@ static ImageInfoList *collect_image_info_list(bool image_opts, goto err; } - elem = g_new0(ImageInfoList, 1); - elem->value = info; - *last = elem; - last = &elem->next; + QAPI_LIST_APPEND(tail, info); blk_unref(blk); @@ -2977,14 +2979,9 @@ static int img_info(int argc, char **argv) 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_OBJECT: + user_creatable_process_cmdline(optarg); + break; case OPTION_IMAGE_OPTS: image_opts = true; break; @@ -3004,12 +3001,6 @@ static int img_info(int argc, char **argv) return 1; } - if (qemu_opts_foreach(&qemu_object_opts, - user_creatable_add_opts_foreach, - qemu_img_object_print_help, &error_fatal)) { - return 1; - } - list = collect_image_info_list(image_opts, filename, fmt, chain, force_share); if (!list) { @@ -3058,8 +3049,9 @@ static int dump_map_entry(OutputFormat output_format, MapEntry *e, break; case OFORMAT_JSON: printf("{ \"start\": %"PRId64", \"length\": %"PRId64"," - " \"depth\": %"PRId64", \"zero\": %s, \"data\": %s", - e->start, e->length, e->depth, + " \"depth\": %"PRId64", \"present\": %s, \"zero\": %s," + " \"data\": %s", e->start, e->length, e->depth, + e->present ? "true" : "false", e->zero ? "true" : "false", e->data ? "true" : "false"); if (e->has_offset) { @@ -3125,6 +3117,7 @@ static int get_block_status(BlockDriverState *bs, int64_t offset, .offset = map, .has_offset = has_offset, .depth = depth, + .present = !!(ret & BDRV_BLOCK_ALLOCATED), .has_filename = filename, .filename = filename, }; @@ -3140,6 +3133,7 @@ static inline bool entry_mergeable(const MapEntry *curr, const MapEntry *next) if (curr->zero != next->zero || curr->data != next->data || curr->depth != next->depth || + curr->present != next->present || curr->has_filename != next->has_filename || curr->has_offset != next->has_offset) { return false; @@ -3219,14 +3213,9 @@ static int img_map(int argc, char **argv) return 1; } break; - case OPTION_OBJECT: { - QemuOpts *opts; - opts = qemu_opts_parse_noisily(&qemu_object_opts, - optarg, true); - if (!opts) { - return 1; - } - } break; + case OPTION_OBJECT: + user_creatable_process_cmdline(optarg); + break; case OPTION_IMAGE_OPTS: image_opts = true; break; @@ -3246,12 +3235,6 @@ static int img_map(int argc, char **argv) return 1; } - if (qemu_opts_foreach(&qemu_object_opts, - user_creatable_add_opts_foreach, - qemu_img_object_print_help, &error_fatal)) { - return 1; - } - blk = img_open(image_opts, filename, fmt, 0, false, false, force_share); if (!blk) { return 1; @@ -3390,14 +3373,9 @@ static int img_snapshot(int argc, char **argv) case 'U': force_share = true; break; - case OPTION_OBJECT: { - QemuOpts *opts; - opts = qemu_opts_parse_noisily(&qemu_object_opts, - optarg, true); - if (!opts) { - return 1; - } - } break; + case OPTION_OBJECT: + user_creatable_process_cmdline(optarg); + break; case OPTION_IMAGE_OPTS: image_opts = true; break; @@ -3409,12 +3387,6 @@ static int img_snapshot(int argc, char **argv) } filename = argv[optind++]; - if (qemu_opts_foreach(&qemu_object_opts, - user_creatable_add_opts_foreach, - qemu_img_object_print_help, &error_fatal)) { - return 1; - } - /* Open the image */ blk = img_open(image_opts, filename, NULL, bdrv_oflags, false, quiet, force_share); @@ -3548,14 +3520,9 @@ static int img_rebase(int argc, char **argv) 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_OBJECT: + user_creatable_process_cmdline(optarg); + break; case OPTION_IMAGE_OPTS: image_opts = true; break; @@ -3577,12 +3544,6 @@ static int img_rebase(int argc, char **argv) } filename = argv[optind++]; - if (qemu_opts_foreach(&qemu_object_opts, - user_creatable_add_opts_foreach, - qemu_img_object_print_help, &error_fatal)) { - return 1; - } - qemu_progress_init(progress, 2.0); qemu_progress_print(0, 100); @@ -3876,6 +3837,9 @@ static int img_rebase(int argc, char **argv) if (ret == -ENOSPC) { error_report("Could not change the backing file to '%s': No " "space left in the file header", out_baseimg); + } else if (ret == -EINVAL && out_baseimg && !out_basefmt) { + error_report("Could not change the backing file to '%s': backing " + "format must be specified", out_baseimg); } else if (ret < 0) { error_report("Could not change the backing file to '%s': %s", out_baseimg, strerror(-ret)); @@ -3973,14 +3937,9 @@ static int img_resize(int argc, char **argv) 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_OBJECT: + user_creatable_process_cmdline(optarg); + break; case OPTION_IMAGE_OPTS: image_opts = true; break; @@ -4002,12 +3961,6 @@ static int img_resize(int argc, char **argv) } filename = argv[optind++]; - if (qemu_opts_foreach(&qemu_object_opts, - user_creatable_add_opts_foreach, - qemu_img_object_print_help, &error_fatal)) { - return 1; - } - /* Choose grow, shrink, or absolute resize mode */ switch (size[0]) { case '+': @@ -4187,12 +4140,7 @@ static int img_amend(int argc, char **argv) quiet = true; break; case OPTION_OBJECT: - opts = qemu_opts_parse_noisily(&qemu_object_opts, - optarg, true); - if (!opts) { - ret = -1; - goto out_no_progress; - } + user_creatable_process_cmdline(optarg); break; case OPTION_IMAGE_OPTS: image_opts = true; @@ -4207,13 +4155,6 @@ static int img_amend(int argc, char **argv) error_exit("Must specify options (-o)"); } - if (qemu_opts_foreach(&qemu_object_opts, - user_creatable_add_opts_foreach, - qemu_img_object_print_help, &error_fatal)) { - ret = -1; - goto out_no_progress; - } - if (quiet) { progress = false; } @@ -4766,10 +4707,7 @@ static int img_bitmap(int argc, char **argv) merge = true; break; case OPTION_OBJECT: - opts = qemu_opts_parse_noisily(&qemu_object_opts, optarg, true); - if (!opts) { - goto out; - } + user_creatable_process_cmdline(optarg); break; case OPTION_IMAGE_OPTS: image_opts = true; @@ -4777,12 +4715,6 @@ static int img_bitmap(int argc, char **argv) } } - if (qemu_opts_foreach(&qemu_object_opts, - user_creatable_add_opts_foreach, - qemu_img_object_print_help, &error_fatal)) { - goto out; - } - if (QSIMPLEQ_EMPTY(&actions)) { error_report("Need at least one of --add, --remove, --clear, " "--enable, --disable, or --merge"); @@ -5040,10 +4972,7 @@ static int img_dd(int argc, char **argv) force_share = true; break; case OPTION_OBJECT: - if (!qemu_opts_parse_noisily(&qemu_object_opts, optarg, true)) { - ret = -1; - goto out; - } + user_creatable_process_cmdline(optarg); break; case OPTION_IMAGE_OPTS: image_opts = true; @@ -5090,13 +5019,6 @@ static int img_dd(int argc, char **argv) goto out; } - if (qemu_opts_foreach(&qemu_object_opts, - user_creatable_add_opts_foreach, - qemu_img_object_print_help, &error_fatal)) { - ret = -1; - goto out; - } - blk1 = img_open(image_opts, in.filename, fmt, 0, false, false, force_share); @@ -5237,18 +5159,18 @@ out: static void dump_json_block_measure_info(BlockMeasureInfo *info) { - QString *str; + GString *str; QObject *obj; Visitor *v = qobject_output_visitor_new(&obj); visit_type_BlockMeasureInfo(v, NULL, &info, &error_abort); visit_complete(v, &obj); - str = qobject_to_json_pretty(obj); + str = qobject_to_json_pretty(obj, true); assert(str != NULL); - printf("%s\n", qstring_get_str(str)); + printf("%s\n", str->str); qobject_unref(obj); visit_free(v); - qobject_unref(str); + g_string_free(str, true); } static int img_measure(int argc, char **argv) @@ -5317,11 +5239,7 @@ static int img_measure(int argc, char **argv) force_share = true; break; case OPTION_OBJECT: - object_opts = qemu_opts_parse_noisily(&qemu_object_opts, - optarg, true); - if (!object_opts) { - goto out; - } + user_creatable_process_cmdline(optarg); break; case OPTION_IMAGE_OPTS: image_opts = true; @@ -5351,12 +5269,6 @@ static int img_measure(int argc, char **argv) } } - if (qemu_opts_foreach(&qemu_object_opts, - user_creatable_add_opts_foreach, - qemu_img_object_print_help, &error_fatal)) { - goto out; - } - if (argc - optind > 1) { error_report("At most one filename argument is allowed."); goto out; @@ -5465,8 +5377,6 @@ int main(int argc, char **argv) { 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'}, @@ -5484,10 +5394,7 @@ int main(int argc, char **argv) module_call_init(MODULE_INIT_TRACE); qemu_init_exec_dir(argv[0]); - if (qemu_init_main_loop(&local_error)) { - error_report_err(local_error); - exit(EXIT_FAILURE); - } + qemu_init_main_loop(&error_fatal); qcrypto_init(&error_fatal); @@ -5497,7 +5404,6 @@ int main(int argc, char **argv) error_exit("Not enough arguments"); } - qemu_add_opts(&qemu_object_opts); qemu_add_opts(&qemu_source_opts); qemu_add_opts(&qemu_trace_opts); @@ -5516,8 +5422,7 @@ int main(int argc, char **argv) printf(QEMU_IMG_VERSION); return 0; case 'T': - g_free(trace_file); - trace_file = trace_opt_parse(optarg); + trace_opt_parse(optarg); break; } } @@ -5535,7 +5440,7 @@ int main(int argc, char **argv) if (!trace_init_backends()) { exit(1); } - trace_init_file(trace_file); + trace_init_file(); qemu_set_log(LOG_TRACE); /* find the command */