Lines Matching +full:- +full:- +full:disable +full:- +full:rbd
4 * Copyright (c) 2003-2008 Fabrice Bellard
28 #include "qemu/help-texts.h"
29 #include "qemu/qemu-progress.h"
30 #include "qemu-version.h"
32 #include "qapi/qapi-commands-block-core.h"
33 #include "qapi/qapi-visit-block-core.h"
34 #include "qapi/qobject-output-visitor.h"
38 #include "qemu/config-file.h"
40 #include "qemu/error-report.h"
42 #include "qemu/main-loop.h"
48 #include "system/block-backend.h"
51 #include "block/dirty-bitmap.h"
56 #include "block/throttle-groups.h"
58 #define QEMU_IMG_VERSION "qemu-img version " QEMU_FULL_VERSION \
96 /* Default to cache=writeback as data integrity is not important for qemu-img */
102 error_printf("Try '%s --help' for more information\n", argv0); in tryhelp()
119 * Print --help output for a command and exit.
120 * @syntax and @description are multi-line with trailing EOL
124 * and with 5 chars for argument description (like -h arg below).
136 " -h, --help\n" in cmd_help()
139 "qemu-img", ccmd->name, syntax, ccmd->description, arguments); in cmd_help()
150 error_exit(argv0, "--output expects 'human' or 'json', not '%s'", arg); in parse_output_format()
173 for (i = len; i > 0 && list[i - 1] == ','; i--) { in is_valid_option_list()
175 if ((len - i) % 2) { in is_valid_option_list()
188 return -1; in accumulate_options()
236 if (!drv->create_opts) { in print_block_option_help()
241 create_opts = qemu_opts_append(create_opts, drv->create_opts); in print_block_option_help()
249 if (!proto_drv->create_opts) { in print_block_option_help()
251 proto_drv->format_name); in print_block_option_help()
255 create_opts = qemu_opts_append(create_opts, proto_drv->create_opts); in print_block_option_help()
287 error_report("--force-share/-U conflicts with image options"); in img_open_opts()
339 if (g_str_has_suffix(name, "key-secret")) { in img_add_key_secrets()
356 error_report("--image-opts and --format are mutually exclusive"); in img_open()
388 return -1; in add_old_style_options()
395 return -1; in add_old_style_options()
409 if (err < 0 && err != -ERANGE) { in cvtnum_full()
413 if (err == -ERANGE || res > max || res < min) { in cvtnum_full()
416 return -ERANGE; in cvtnum_full()
429 int64_t img_size = -1; in img_create()
445 {"backing-format", required_argument, 0, 'B'}, /* was -F in 10.0 */ in img_create()
446 {"backing-unsafe", no_argument, 0, 'u'}, in img_create()
453 if (c == -1) { in img_create()
458 cmd_help(ccmd, "[-f FMT] [-o FMT_OPTS]\n" in img_create()
459 " [-b BACKING_FILE [-B BACKING_FMT]] [-u]\n" in img_create()
460 " [-q] [--object OBJDEF] FILE [SIZE]\n" in img_create()
462 " -f, --format FMT\n" in img_create()
464 " -o, --options FMT_OPTS\n" in img_create()
465 " format-specific options (specify '-o help' for help)\n" in img_create()
466 " -b, --backing BACKING_FILE\n" in img_create()
468 " -B, --backing-format BACKING_FMT (was -F in <= 10.0)\n" in img_create()
470 " -u, --backing-unsafe\n" in img_create()
472 " -q, --quiet\n" in img_create()
474 " --object OBJDEF\n" in img_create()
475 " defines QEMU user-creatable object\n" in img_create()
560 qprintf(quiet, "%s\n", str->str); in dump_json_image_check()
568 if (!(check->corruptions || check->leaks || check->check_errors)) { in dump_human_image_check()
571 if (check->corruptions) { in dump_human_image_check()
575 check->corruptions); in dump_human_image_check()
578 if (check->leaks) { in dump_human_image_check()
582 check->leaks); in dump_human_image_check()
585 if (check->check_errors) { in dump_human_image_check()
589 check->check_errors); in dump_human_image_check()
593 if (check->total_clusters != 0 && check->allocated_clusters != 0) { in dump_human_image_check()
596 check->allocated_clusters, check->total_clusters, in dump_human_image_check()
597 check->allocated_clusters * 100.0 / check->total_clusters, in dump_human_image_check()
598 check->fragmented_clusters * 100.0 / check->allocated_clusters, in dump_human_image_check()
599 check->compressed_clusters * 100.0 / in dump_human_image_check()
600 check->allocated_clusters); in dump_human_image_check()
603 if (check->image_end_offset) { in dump_human_image_check()
605 "Image end offset: %" PRId64 "\n", check->image_end_offset); in dump_human_image_check()
623 check->filename = g_strdup(filename); in collect_image_check()
624 check->format = g_strdup(bdrv_get_format_name(bs)); in collect_image_check()
625 check->check_errors = result.check_errors; in collect_image_check()
626 check->corruptions = result.corruptions; in collect_image_check()
627 check->has_corruptions = result.corruptions != 0; in collect_image_check()
628 check->leaks = result.leaks; in collect_image_check()
629 check->has_leaks = result.leaks != 0; in collect_image_check()
630 check->corruptions_fixed = result.corruptions_fixed; in collect_image_check()
631 check->has_corruptions_fixed = result.corruptions_fixed != 0; in collect_image_check()
632 check->leaks_fixed = result.leaks_fixed; in collect_image_check()
633 check->has_leaks_fixed = result.leaks_fixed != 0; in collect_image_check()
634 check->image_end_offset = result.image_end_offset; in collect_image_check()
635 check->has_image_end_offset = result.image_end_offset != 0; in collect_image_check()
636 check->total_clusters = result.bfi.total_clusters; in collect_image_check()
637 check->has_total_clusters = result.bfi.total_clusters != 0; in collect_image_check()
638 check->allocated_clusters = result.bfi.allocated_clusters; in collect_image_check()
639 check->has_allocated_clusters = result.bfi.allocated_clusters != 0; in collect_image_check()
640 check->fragmented_clusters = result.bfi.fragmented_clusters; in collect_image_check()
641 check->has_fragmented_clusters = result.bfi.fragmented_clusters != 0; in collect_image_check()
642 check->compressed_clusters = result.bfi.compressed_clusters; in collect_image_check()
643 check->has_compressed_clusters = result.bfi.compressed_clusters != 0; in collect_image_check()
651 * 0 - Check completed, image is good
652 * 1 - Check not completed because of internal errors
653 * 2 - Check completed, image is corrupted
654 * 3 - Check completed, image has leaked clusters, but is good otherwise
655 * 63 - Checks are not supported by the image format
680 {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, in img_check()
683 {"force-share", no_argument, 0, 'U'}, in img_check()
691 if (c == -1) { in img_check()
696 cmd_help(ccmd, "[-f FMT | --image-opts] [-T CACHE_MODE] [-r leaks|all]\n" in img_check()
697 " [-U] [--output human|json] [-q] [--object OBJDEF] FILE\n" in img_check()
699 " -f, --format FMT\n" in img_check()
701 " --image-opts\n" in img_check()
703 " (incompatible with -f|--format)\n" in img_check()
704 " -T, --cache CACHE_MODE\n" /* why not -t ? */ in img_check()
706 " -r, --repair leaks|all\n" in img_check()
708 " opened in read-write mode, incompatible with -U|--force-share)\n" in img_check()
709 " -U, --force-share\n" in img_check()
711 " --output human|json\n" in img_check()
713 " -q, --quiet\n" in img_check()
715 " --object OBJDEF\n" in img_check()
716 " defines QEMU user-creatable object\n" in img_check()
719 " with --image-opts, to operate on\n" in img_check()
740 "--repair (-r) expects 'leaks' or 'all', not '%s'", in img_check()
760 if (optind != argc - 1) { in img_check()
781 if (ret == -ENOTSUP) { in img_check()
787 if (check->corruptions_fixed || check->leaks_fixed) { in img_check()
791 leaks_fixed = check->leaks_fixed; in img_check()
792 has_leaks_fixed = check->has_leaks_fixed; in img_check()
793 corruptions_fixed = check->corruptions_fixed; in img_check()
794 has_corruptions_fixed = check->has_corruptions_fixed; in img_check()
802 check->leaks_fixed, in img_check()
803 check->corruptions_fixed); in img_check()
810 check->leaks_fixed = leaks_fixed; in img_check()
811 check->has_leaks_fixed = has_leaks_fixed; in img_check()
812 check->corruptions_fixed = corruptions_fixed; in img_check()
813 check->has_corruptions_fixed = has_corruptions_fixed; in img_check()
827 if (ret || check->check_errors) { in img_check()
829 error_report("Check failed: %s", strerror(-ret)); in img_check()
837 if (check->corruptions) { in img_check()
839 } else if (check->leaks) { in img_check()
861 error_setg_errno(cbi->errp, -ret, "Block job failed"); in common_block_job_cb()
872 job_ref_locked(&job->job); in run_block_job()
878 progress_get_snapshot(&job->job.progress, &progress_current, in run_block_job()
885 } while (!job_is_ready_locked(&job->job) && in run_block_job()
886 !job_is_completed_locked(&job->job)); in run_block_job()
888 if (!job_is_completed_locked(&job->job)) { in run_block_job()
889 ret = job_complete_sync_locked(&job->job, errp); in run_block_job()
891 ret = job->job.ret; in run_block_job()
893 job_unref_locked(&job->job); in run_block_job()
923 {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, in img_commit()
927 {"rate-limit", required_argument, 0, 'r'}, in img_commit()
935 if (c == -1) { in img_commit()
940 cmd_help(ccmd, "[-f FMT | --image-opts] [-t CACHE_MODE] [-b BASE_IMG]\n" in img_commit()
941 " [-d] [-r RATE] [-q] [--object OBJDEF] FILE\n" in img_commit()
943 " -f, --format FMT\n" in img_commit()
945 " --image-opts\n" in img_commit()
947 " (incompatible with -f|--format)\n" in img_commit()
948 " -t, --cache CACHE_MODE image cache mode (default: " BDRV_DEFAULT_CACHE ")\n" in img_commit()
949 " -d, --drop\n" in img_commit()
951 " -b, --base BASE_IMG\n" in img_commit()
953 " (default: immediate backing file; implies --drop)\n" in img_commit()
954 " -r, --rate-limit RATE\n" in img_commit()
956 " -p, --progress\n" in img_commit()
958 " -q, --quiet\n" in img_commit()
960 " --object OBJDEF\n" in img_commit()
961 " defines QEMU user-creatable object\n" in img_commit()
964 " with --image-opts, to operate on\n" in img_commit()
981 /* -b implies -d */ in img_commit()
1009 if (optind != argc - 1) { in img_commit()
1044 * behavior of qemu-img commit is using the immediate backing file. */ in img_commit()
1091 if (ret == -ENOTSUP) { in img_commit()
1113 error_setg_errno(&local_err, -ret, "Error while closing the image"); in img_commit()
1127 * Returns -1 if 'buf' contains only zeroes, otherwise the byte index
1129 * non-zero byte. This function is robust to a buffer that is not
1130 * sector-aligned.
1142 if (i < n && !buffer_is_zero(buf + i, n - end)) { in find_nonzero()
1145 return -1; in find_nonzero()
1150 * a non-NUL byte.
1185 tail = (sector_num + i) & (alignment - 1); in is_allocated_sectors()
1196 i += alignment - tail; in is_allocated_sectors()
1204 i -= tail; in is_allocated_sectors()
1233 n -= *pnum; in is_allocated_sectors_min()
1241 n -= *pnum; in is_allocated_sectors_min()
1258 * Returns 0 if the first chunk of each buffer matches, non-zero otherwise.
1278 int64_t len = MIN(bytes - i, chsize); in compare_buffers()
1295 * Intended for use by 'qemu-img compare': Returns 0 in case sectors are
1296 * filled with 0, 1 if sectors contain non-zero data (this is a comparison
1317 offset, filename, strerror(-ret)); in check_empty_sectors()
1333 * 0 - Images are identical or the requested help was printed
1334 * 1 - Images differ
1335 * >1 - Error occurred
1346 int ret = 0; /* return value - 0 Ident, 1 Different, >1 Error */ in img_compare()
1362 {"a-format", required_argument, 0, 'f'}, in img_compare()
1363 {"b-format", required_argument, 0, 'F'}, in img_compare()
1364 {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, in img_compare()
1367 {"force-share", no_argument, 0, 'U'}, in img_compare()
1375 if (c == -1) { in img_compare()
1381 "[[-f FMT] [-F FMT] | --image-opts] [-s] [-T CACHE]\n" in img_compare()
1382 " [-U] [-p] [-q] [--object OBJDEF] FILE1 FILE2\n" in img_compare()
1384 " -f, --a-format FMT\n" in img_compare()
1386 " -F, --b-format FMT\n" in img_compare()
1388 " --image-opts\n" in img_compare()
1390 " (incompatible with -f|--a-format and -F|--b-format)\n" in img_compare()
1391 " -s, --strict\n" in img_compare()
1393 " -T, --cache CACHE_MODE\n" in img_compare()
1395 " -U, --force-share\n" in img_compare()
1397 " -p, --progress\n" in img_compare()
1399 " -q, --quiet\n" in img_compare()
1401 " --object OBJDEF\n" in img_compare()
1402 " defines QEMU user-creatable object\n" in img_compare()
1405 " with --image-opts, to compare\n" in img_compare()
1446 if (optind != argc - 2) { in img_compare()
1484 filename1, strerror(-total_size1)); in img_compare()
1491 filename2, strerror(-total_size2)); in img_compare()
1510 total_size1 - offset, &pnum1, NULL, in img_compare()
1520 total_size2 - offset, &pnum2, NULL, in img_compare()
1551 offset, filename1, strerror(-ret)); in img_compare()
1559 offset, filename2, strerror(-ret)); in img_compare()
1603 progress_base - offset, &chunk, in img_compare()
1648 merge_src->type = QTYPE_QDICT; in do_dirty_bitmap_merge()
1649 merge_src->u.external.node = g_strdup(src_node); in do_dirty_bitmap_merge()
1650 merge_src->u.external.name = g_strdup(src_name); in do_dirty_bitmap_merge()
1704 while (sector_num - *src_cur_offset >= s->src_sectors[*src_cur]) { in convert_select_part()
1705 *src_cur_offset += s->src_sectors[*src_cur]; in convert_select_part()
1707 assert(*src_cur < s->src_num); in convert_select_part()
1720 assert(s->total_sectors > sector_num); in convert_iteration_sectors()
1721 n = MIN(s->total_sectors - sector_num, BDRV_REQUEST_MAX_SECTORS); in convert_iteration_sectors()
1723 if (s->target_backing_sectors >= 0) { in convert_iteration_sectors()
1724 if (sector_num >= s->target_backing_sectors) { in convert_iteration_sectors()
1726 } else if (sector_num + n > s->target_backing_sectors) { in convert_iteration_sectors()
1729 n = s->target_backing_sectors - sector_num; in convert_iteration_sectors()
1733 if (s->sector_next_status <= sector_num) { in convert_iteration_sectors()
1734 uint64_t offset = (sector_num - src_cur_offset) * BDRV_SECTOR_SIZE; in convert_iteration_sectors()
1737 BlockDriverState *src_bs = blk_bs(s->src[src_cur]); in convert_iteration_sectors()
1740 if (s->target_has_backing) { in convert_iteration_sectors()
1753 if (s->salvage) { in convert_iteration_sectors()
1755 if (!s->quiet) { in convert_iteration_sectors()
1758 strerror(-ret)); in convert_iteration_sectors()
1769 "%" PRIu64 ": %s", offset, strerror(-ret)); in convert_iteration_sectors()
1778 * Avoid that s->sector_next_status becomes unaligned to the source in convert_iteration_sectors()
1782 tail = (sector_num - src_cur_offset + n) % s->src_alignment[src_cur]; in convert_iteration_sectors()
1784 n -= tail; in convert_iteration_sectors()
1788 s->status = post_backing_zero ? BLK_BACKING_FILE : BLK_ZERO; in convert_iteration_sectors()
1790 s->status = BLK_DATA; in convert_iteration_sectors()
1792 s->status = s->target_has_backing ? BLK_BACKING_FILE : BLK_DATA; in convert_iteration_sectors()
1795 s->sector_next_status = sector_num + n; in convert_iteration_sectors()
1798 n = MIN(n, s->sector_next_status - sector_num); in convert_iteration_sectors()
1799 if (s->status == BLK_DATA) { in convert_iteration_sectors()
1800 n = MIN(n, s->buf_sectors); in convert_iteration_sectors()
1806 if (s->compressed) { in convert_iteration_sectors()
1807 if (n < s->cluster_sectors) { in convert_iteration_sectors()
1808 n = MIN(s->cluster_sectors, s->total_sectors - sector_num); in convert_iteration_sectors()
1809 s->status = BLK_DATA; in convert_iteration_sectors()
1811 n = QEMU_ALIGN_DOWN(n, s->cluster_sectors); in convert_iteration_sectors()
1824 assert(nb_sectors <= s->buf_sectors); in convert_co_read()
1835 blk = s->src[src_cur]; in convert_co_read()
1836 bs_sectors = s->src_sectors[src_cur]; in convert_co_read()
1838 offset = (sector_num - src_cur_offset) << BDRV_SECTOR_BITS; in convert_co_read()
1840 n = MIN(nb_sectors, bs_sectors - (sector_num - src_cur_offset)); in convert_co_read()
1847 if (s->salvage) { in convert_co_read()
1852 if (!s->quiet) { in convert_co_read()
1854 ": %s", offset, strerror(-ret)); in convert_co_read()
1864 nb_sectors -= n; in convert_co_read()
1880 BdrvRequestFlags flags = s->compressed ? BDRV_REQ_WRITE_COMPRESSED : 0; in convert_co_write()
1887 assert(s->target_has_backing); in convert_co_write()
1891 /* If we're told to keep the target fully allocated (-S 0) or there in convert_co_write()
1892 * is real non-zero data, we must write it. Otherwise we can treat in convert_co_write()
1897 if (!s->min_sparse || in convert_co_write()
1898 (!s->compressed && in convert_co_write()
1899 is_allocated_sectors_min(buf, n, &n, s->min_sparse, in convert_co_write()
1900 sector_num, s->alignment)) || in convert_co_write()
1901 (s->compressed && in convert_co_write()
1904 ret = blk_co_pwrite(s->target, sector_num << BDRV_SECTOR_BITS, in convert_co_write()
1911 /* fall-through */ in convert_co_write()
1914 if (s->has_zero_init) { in convert_co_write()
1915 assert(!s->target_has_backing); in convert_co_write()
1918 ret = blk_co_pwrite_zeroes(s->target, in convert_co_write()
1929 nb_sectors -= n; in convert_co_write()
1948 offset = (sector_num - src_cur_offset) << BDRV_SECTOR_BITS; in convert_co_copy_range()
1949 blk = s->src[src_cur]; in convert_co_copy_range()
1950 bs_sectors = s->src_sectors[src_cur]; in convert_co_copy_range()
1952 n = MIN(nb_sectors, bs_sectors - (sector_num - src_cur_offset)); in convert_co_copy_range()
1954 ret = blk_co_copy_range(blk, offset, s->target, in convert_co_copy_range()
1962 nb_sectors -= n; in convert_co_copy_range()
1972 int index = -1; in convert_co_do_copy()
1974 for (i = 0; i < s->num_coroutines; i++) { in convert_co_do_copy()
1975 if (s->co[i] == qemu_coroutine_self()) { in convert_co_do_copy()
1982 s->running_coroutines++; in convert_co_do_copy()
1983 buf = blk_blockalign(s->target, s->buf_sectors * BDRV_SECTOR_SIZE); in convert_co_do_copy()
1991 qemu_co_mutex_lock(&s->lock); in convert_co_do_copy()
1992 if (s->ret != -EINPROGRESS || s->sector_num >= s->total_sectors) { in convert_co_do_copy()
1993 qemu_co_mutex_unlock(&s->lock); in convert_co_do_copy()
1997 n = convert_iteration_sectors(s, s->sector_num); in convert_co_do_copy()
2000 qemu_co_mutex_unlock(&s->lock); in convert_co_do_copy()
2001 s->ret = n; in convert_co_do_copy()
2005 sector_num = s->sector_num; in convert_co_do_copy()
2006 status = s->status; in convert_co_do_copy()
2007 if (!s->min_sparse && s->status == BLK_ZERO) { in convert_co_do_copy()
2008 n = MIN(n, s->buf_sectors); in convert_co_do_copy()
2012 s->sector_num += n; in convert_co_do_copy()
2013 qemu_co_mutex_unlock(&s->lock); in convert_co_do_copy()
2015 if (status == BLK_DATA || (!s->min_sparse && status == BLK_ZERO)) { in convert_co_do_copy()
2016 s->allocated_done += n; in convert_co_do_copy()
2017 qemu_progress_print(100.0 * s->allocated_done / in convert_co_do_copy()
2018 s->allocated_sectors, 0); in convert_co_do_copy()
2022 copy_range = s->copy_range && s->status == BLK_DATA; in convert_co_do_copy()
2027 sector_num * BDRV_SECTOR_SIZE, strerror(-ret)); in convert_co_do_copy()
2028 s->ret = ret; in convert_co_do_copy()
2030 } else if (!s->min_sparse && status == BLK_ZERO) { in convert_co_do_copy()
2035 if (s->wr_in_order) { in convert_co_do_copy()
2037 while (s->wr_offs != sector_num && s->ret == -EINPROGRESS) { in convert_co_do_copy()
2038 s->wait_sector_num[index] = sector_num; in convert_co_do_copy()
2041 s->wait_sector_num[index] = -1; in convert_co_do_copy()
2044 if (s->ret == -EINPROGRESS) { in convert_co_do_copy()
2050 s->copy_range = false; in convert_co_do_copy()
2058 sector_num * BDRV_SECTOR_SIZE, strerror(-ret)); in convert_co_do_copy()
2059 s->ret = ret; in convert_co_do_copy()
2063 if (s->wr_in_order) { in convert_co_do_copy()
2066 s->wr_offs = sector_num + n; in convert_co_do_copy()
2067 for (i = 0; i < s->num_coroutines; i++) { in convert_co_do_copy()
2068 if (s->co[i] && s->wait_sector_num[i] == s->wr_offs) { in convert_co_do_copy()
2070 * A -> B -> A cannot occur because A has in convert_co_do_copy()
2071 * s->wait_sector_num[i] == -1 during A -> B. Therefore in convert_co_do_copy()
2074 qemu_coroutine_enter(s->co[i]); in convert_co_do_copy()
2082 s->co[index] = NULL; in convert_co_do_copy()
2083 s->running_coroutines--; in convert_co_do_copy()
2084 if (!s->running_coroutines && s->ret == -EINPROGRESS) { in convert_co_do_copy()
2086 s->ret = 0; in convert_co_do_copy()
2096 if (!s->has_zero_init && s->target_is_new && s->min_sparse && in convert_do_copy()
2097 !s->target_has_backing) { in convert_do_copy()
2099 s->has_zero_init = bdrv_has_zero_init(blk_bs(s->target)); in convert_do_copy()
2105 if (s->compressed) { in convert_do_copy()
2106 if (s->cluster_sectors <= 0 || s->cluster_sectors > s->buf_sectors) { in convert_do_copy()
2108 return -EINVAL; in convert_do_copy()
2110 s->buf_sectors = s->cluster_sectors; in convert_do_copy()
2113 while (sector_num < s->total_sectors) { in convert_do_copy()
2120 if (s->status == BLK_DATA || (!s->min_sparse && s->status == BLK_ZERO)) in convert_do_copy()
2122 s->allocated_sectors += n; in convert_do_copy()
2128 s->sector_next_status = 0; in convert_do_copy()
2129 s->ret = -EINPROGRESS; in convert_do_copy()
2131 qemu_co_mutex_init(&s->lock); in convert_do_copy()
2132 for (i = 0; i < s->num_coroutines; i++) { in convert_do_copy()
2133 s->co[i] = qemu_coroutine_create(convert_co_do_copy, s); in convert_do_copy()
2134 s->wait_sector_num[i] = -1; in convert_do_copy()
2135 qemu_coroutine_enter(s->co[i]); in convert_do_copy()
2138 while (s->running_coroutines) { in convert_do_copy()
2142 if (s->compressed && !s->ret) { in convert_do_copy()
2144 ret = blk_pwrite_compressed(s->target, 0, 0, NULL); in convert_do_copy()
2150 return s->ret; in convert_do_copy()
2160 return -1; in convert_check_bitmaps()
2169 error_printf("Try --skip-broken-bitmaps, or " in convert_check_bitmaps()
2170 "use 'qemu-img bitmap --remove' to delete it\n"); in convert_check_bitmaps()
2171 return -1; in convert_check_bitmaps()
2194 qmp_block_dirty_bitmap_add(dst->node_name, name, in convert_copy_bitmaps()
2201 return -1; in convert_copy_bitmaps()
2204 do_dirty_bitmap_merge(dst->node_name, name, src->node_name, name, in convert_copy_bitmaps()
2208 qmp_block_dirty_bitmap_remove(dst->node_name, name, NULL); in convert_copy_bitmaps()
2209 return -1; in convert_copy_bitmaps()
2246 int64_t ret = -EINVAL; in img_convert()
2265 {"source-format", required_argument, 0, 'f'}, in img_convert()
2267 * XXX: historic --image-opts acts on source file only, in img_convert()
2269 * and have separate --source-image-opts for source, in img_convert()
2272 {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, in img_convert()
2273 {"source-cache", required_argument, 0, 'T'}, in img_convert()
2276 {"skip-broken-bitmaps", no_argument, 0, OPTION_SKIP_BROKEN}, in img_convert()
2278 {"target-format", required_argument, 0, 'O'}, in img_convert()
2279 {"target-image-opts", no_argument, 0, OPTION_TARGET_IMAGE_OPTS}, in img_convert()
2280 {"target-format-options", required_argument, 0, 'o'}, in img_convert()
2281 {"target-cache", required_argument, 0, 't'}, in img_convert()
2283 {"backing-format", required_argument, 0, 'F'}, in img_convert()
2284 {"sparse-size", required_argument, 0, 'S'}, in img_convert()
2285 {"no-create", no_argument, 0, 'n'}, in img_convert()
2286 {"target-is-zero", no_argument, 0, OPTION_TARGET_IS_ZERO}, in img_convert()
2287 {"force-share", no_argument, 0, 'U'}, in img_convert()
2288 {"rate-limit", required_argument, 0, 'r'}, in img_convert()
2290 {"oob-writes", no_argument, 0, 'W'}, in img_convert()
2291 {"copy-range-offloading", no_argument, 0, 'C'}, in img_convert()
2299 if (c == -1) { in img_convert()
2304 cmd_help(ccmd, "[-f SRC_FMT | --image-opts] [-T SRC_CACHE]\n" in img_convert()
2305 " [-l SNAPSHOT] [--bitmaps [--skip-broken-bitmaps]] [--salvage]\n" in img_convert()
2306 " [-O TGT_FMT | --target-image-opts] [-o TGT_FMT_OPTS] [-t TGT_CACHE]\n" in img_convert()
2307 " [-b BACKING_FILE [-F BACKING_FMT]] [-S SPARSE_SIZE]\n" in img_convert()
2308 " [-n] [--target-is-zero] [-c]\n" in img_convert()
2309 " [-U] [-r RATE] [-m NUM_PARALLEL] [-W] [-C] [-p] [-q] [--object OBJDEF]\n" in img_convert()
2312 " -f, --source-format SRC_FMT\n" in img_convert()
2314 " --image-opts\n" in img_convert()
2316 " (incompatible with -f|--source-format)\n" in img_convert()
2317 " -T, --source-cache SRC_CACHE\n" in img_convert()
2319 " -l, --snapshot SNAPSHOT\n" in img_convert()
2321 " --bitmaps\n" in img_convert()
2323 " --skip-broken-bitmaps\n" in img_convert()
2325 " --salvage\n" in img_convert()
2327 " -O, --target-format TGT_FMT\n" in img_convert()
2329 " --target-image-opts\n" in img_convert()
2331 " (incompatible with -O|--target-format)\n" in img_convert()
2332 " -o, --target-format-options TGT_FMT_OPTS\n" in img_convert()
2333 " TGT_FMT-specific options\n" in img_convert()
2334 " -t, --target-cache TGT_CACHE\n" in img_convert()
2336 " -b, --backing BACKING_FILE (was -B in <= 10.0)\n" in img_convert()
2338 " -F, --backing-format BACKING_FMT\n" /* -B used for -b in <=10.0 */ in img_convert()
2340 " -S, --sparse-size SPARSE_SIZE[bkKMGTPE]\n" in img_convert()
2343 " -n, --no-create\n" in img_convert()
2344 " omit target volume creation (e.g. on rbd)\n" in img_convert()
2345 " --target-is-zero\n" in img_convert()
2346 " indicates that the target volume is pre-zeroed\n" in img_convert()
2347 " -c, --compress\n" in img_convert()
2349 " -U, --force-share\n" in img_convert()
2351 " -r, --rate-limit RATE\n" in img_convert()
2353 " -m, --parallel NUM_PARALLEL\n" in img_convert()
2355 " -C, --copy-range-offloading\n" in img_convert()
2357 " -W, --oob-writes\n" in img_convert()
2358 " enable out-of-order writes to improve performance\n" in img_convert()
2359 " -p, --progress\n" in img_convert()
2361 " -q, --quiet\n" in img_convert()
2363 " --object OBJDEF\n" in img_convert()
2364 " defines QEMU user-creatable object\n" in img_convert()
2367 " or option strings (key=value,..) with --source-image-opts\n" in img_convert()
2370 " or option string (key=value,..) with --target-image-opts\n" in img_convert()
2422 case 'F': /* can't use -B as it used as -b in <=10.0 */ in img_convert()
2436 "0 to disable sparse detection (fully allocates output).", in img_convert()
2500 error_report("Use of --skip-broken-bitmaps requires --bitmaps"); in img_convert()
2505 error_report("Cannot enable copy offloading when -c is used"); in img_convert()
2510 error_report("Cannot enable copy offloading when -S is used"); in img_convert()
2520 error_report("--target-image-opts requires use of -n flag"); in img_convert()
2525 error_report("-o has no effect when skipping image creation"); in img_convert()
2530 error_report("--target-is-zero requires use of -n flag"); in img_convert()
2534 s.src_num = argc - optind - 1; in img_convert()
2535 out_filename = s.src_num >= 1 ? argv[argc - 1] : NULL; in img_convert()
2552 /* ret is still -EINVAL until here */ in img_convert()
2576 ret = -1; in img_convert()
2582 argv[optind + bs_i], strerror(-s.src_sectors[bs_i])); in img_convert()
2583 ret = -1; in img_convert()
2587 s.src_alignment[bs_i] = DIV_ROUND_UP(src_bs->bl.request_alignment, in img_convert()
2604 ret = -1; in img_convert()
2613 ret = -1; in img_convert()
2622 ret = -1; in img_convert()
2629 ret = -1; in img_convert()
2633 if (!drv->create_opts) { in img_convert()
2635 drv->format_name); in img_convert()
2636 ret = -1; in img_convert()
2640 if (!proto_drv->create_opts) { in img_convert()
2642 proto_drv->format_name); in img_convert()
2643 ret = -1; in img_convert()
2647 create_opts = qemu_opts_append(create_opts, drv->create_opts); in img_convert()
2648 create_opts = qemu_opts_append(create_opts, proto_drv->create_opts); in img_convert()
2654 ret = -1; in img_convert()
2667 /* Get backing file name if -o backing_file was used */ in img_convert()
2675 error_report("Cannot use --target-is-zero when the destination " in img_convert()
2683 ret = -1; in img_convert()
2691 ret = -1; in img_convert()
2707 ret = -1; in img_convert()
2714 ret = -1; in img_convert()
2723 ret = -1; in img_convert()
2732 ret = -1; in img_convert()
2780 /* TODO ultimately we should allow --target-image-opts in img_convert()
2781 * to be used even when -n is not given. in img_convert()
2790 ret = -1; in img_convert()
2797 out_bs->drv->format_name); in img_convert()
2798 ret = -1; in img_convert()
2802 if (s.compressed && !block_driver_can_compress(out_bs->drv)) { in img_convert()
2804 ret = -1; in img_convert()
2813 MAX(out_bs->bl.opt_transfer >> BDRV_SECTOR_BITS, in img_convert()
2814 out_bs->bl.pdiscard_alignment >> in img_convert()
2820 DIV_ROUND_UP(out_bs->bl.request_alignment, in img_convert()
2828 strerror(-output_sectors)); in img_convert()
2829 ret = -1; in img_convert()
2833 ret = -1; in img_convert()
2848 s.target_backing_sectors = -1; in img_convert()
2927 printf("%s\n", str->str); in dump_json_block_graph_info_list()
2943 printf("%s\n", str->str); in dump_json_block_graph_info()
2955 info->children == NULL); in dump_human_image_info()
2957 for (children_list = info->children; children_list; in dump_human_image_info()
2958 children_list = children_list->next) in dump_human_image_info()
2960 BlockChildInfo *child = children_list->value; in dump_human_image_info()
2964 indentation * 4, "", path, child->name); in dump_human_image_info()
2965 child_path = g_strdup_printf("%s%s/", path, child->name); in dump_human_image_info()
2966 dump_human_image_info(child->info, indentation + 1, child_path); in dump_human_image_info()
2975 for (elem = list; elem; elem = elem->next) { in dump_human_image_info_list()
2981 dump_human_image_info(elem->value, 0, "/"); in dump_human_image_info_list()
2995 * @chain: true - enumerate entire backing file chain
2996 * false - only topmost image file
3060 if (info->full_backing_filename) { in collect_image_info_list()
3061 filename = info->full_backing_filename; in collect_image_info_list()
3062 } else if (info->backing_filename) { in collect_image_info_list()
3065 info->backing_filename); in collect_image_info_list()
3068 if (info->backing_filename_format) { in collect_image_info_list()
3069 fmt = info->backing_filename_format; in collect_image_info_list()
3097 {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, in img_info()
3098 {"backing-chain", no_argument, 0, OPTION_BACKING_CHAIN}, in img_info()
3099 {"force-share", no_argument, 0, 'U'}, in img_info()
3105 if (c == -1) { in img_info()
3110 cmd_help(ccmd, "[-f FMT | --image-opts] [--backing-chain] [-U]\n" in img_info()
3111 " [--output human|json] [--object OBJDEF] FILE\n" in img_info()
3113 " -f, --format FMT\n" in img_info()
3115 " --image-opts\n" in img_info()
3117 " (incompatible with -f|--format)\n" in img_info()
3118 " --backing-chain\n" in img_info()
3119 " display information about the backing chain for copy-on-write overlays\n" in img_info()
3120 " -U, --force-share\n" in img_info()
3122 " --output human|json\n" in img_info()
3124 " --object OBJDEF\n" in img_info()
3125 " defines QEMU user-creatable object\n" in img_info()
3128 " with --image-opts, to operate on\n" in img_info()
3153 if (optind != argc - 1) { in img_info()
3172 dump_json_block_graph_info(list->value); in img_info()
3186 if (e->data && !e->has_offset) { in dump_map_entry()
3188 return -1; in dump_map_entry()
3190 if (e->data && !e->zero) { in dump_map_entry()
3191 printf("%#-16"PRIx64"%#-16"PRIx64"%#-16"PRIx64"%s\n", in dump_map_entry()
3192 e->start, e->length, in dump_map_entry()
3193 e->has_offset ? e->offset : 0, in dump_map_entry()
3194 e->filename ?: ""); in dump_map_entry()
3199 if (next && (!next->data || next->zero)) { in dump_map_entry()
3200 next->data = false; in dump_map_entry()
3201 next->zero = true; in dump_map_entry()
3208 e->start, e->length, e->depth, in dump_map_entry()
3209 e->present ? "true" : "false", in dump_map_entry()
3210 e->zero ? "true" : "false", in dump_map_entry()
3211 e->data ? "true" : "false", in dump_map_entry()
3212 e->compressed ? "true" : "false"); in dump_map_entry()
3213 if (e->has_offset) { in dump_map_entry()
3214 printf(", \"offset\": %"PRId64"", e->offset); in dump_map_entry()
3268 filename = file->filename; in get_block_status()
3289 if (curr->length == 0) { in entry_mergeable()
3292 if (curr->zero != next->zero || in entry_mergeable()
3293 curr->data != next->data || in entry_mergeable()
3294 curr->compressed != next->compressed || in entry_mergeable()
3295 curr->depth != next->depth || in entry_mergeable()
3296 curr->present != next->present || in entry_mergeable()
3297 !curr->filename != !next->filename || in entry_mergeable()
3298 curr->has_offset != next->has_offset) { in entry_mergeable()
3301 if (curr->filename && strcmp(curr->filename, next->filename)) { in entry_mergeable()
3304 if (curr->has_offset && curr->offset + curr->length != next->offset) { in entry_mergeable()
3323 int64_t max_length = -1; in img_map()
3330 {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, in img_map()
3331 {"start-offset", required_argument, 0, 's'}, in img_map()
3332 {"max-length", required_argument, 0, 'l'}, in img_map()
3333 {"force-share", no_argument, 0, 'U'}, in img_map()
3340 if (c == -1) { in img_map()
3345 cmd_help(ccmd, "[-f FMT | --image-opts]\n" in img_map()
3346 " [--start-offset OFFSET] [--max-length LENGTH]\n" in img_map()
3347 " [--output human|json] [-U] [--object OBJDEF] FILE\n" in img_map()
3349 " -f, --format FMT\n" in img_map()
3351 " --image-opts\n" in img_map()
3353 " (incompatible with -f|--format)\n" in img_map()
3354 " -s, --start-offset OFFSET\n" in img_map()
3356 " -l, --max-length LENGTH\n" in img_map()
3358 " --output human|json\n" in img_map()
3360 " -U, --force-share\n" in img_map()
3362 " --object OBJDEF\n" in img_map()
3363 " defines QEMU user-creatable object\n" in img_map()
3366 " with --image-opts, to operate on\n" in img_map()
3400 if (optind != argc - 1) { in img_map()
3412 printf("%-16s%-16s%-16s%s\n", "Offset", "Length", "Mapped to", "File"); in img_map()
3422 if (max_length != -1) { in img_map()
3429 int64_t n = length - offset; in img_map()
3433 error_report("Could not read file metadata: %s", strerror(-ret)); in img_map()
3486 {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, in img_snapshot()
3491 {"force-share", no_argument, 0, 'U'}, in img_snapshot()
3498 if (c == -1) { in img_snapshot()
3503 cmd_help(ccmd, "[-f FMT | --image-opts] [-l | -a|-c|-d SNAPSHOT]\n" in img_snapshot()
3504 " [-U] [-q] [--object OBJDEF] FILE\n" in img_snapshot()
3506 " -f, --format FMT\n" in img_snapshot()
3508 " --image-opts\n" in img_snapshot()
3510 " (incompatible with -f|--format)\n" in img_snapshot()
3511 " -l, --list\n" in img_snapshot()
3512 " list snapshots in FILE (default action if no -l|-c|-a|-d is given)\n" in img_snapshot()
3513 " -c, --create SNAPSHOT\n" in img_snapshot()
3515 " -a, --apply SNAPSHOT\n" in img_snapshot()
3517 " -d, --delete SNAPSHOT\n" in img_snapshot()
3519 " (only one of -l|-c|-a|-d can be specified)\n" in img_snapshot()
3520 " -U, --force-share\n" in img_snapshot()
3522 " -q, --quiet\n" in img_snapshot()
3524 " --object OBJDEF\n" in img_snapshot()
3525 " defines QEMU user-creatable object\n" in img_snapshot()
3528 " with --image-opts) to operate on\n" in img_snapshot()
3542 error_exit(argv[0], "Cannot mix '-l', '-a', '-c', '-d'"); in img_snapshot()
3562 if (optind != argc - 1) { in img_snapshot()
3600 snapshot_name, strerror(-ret)); in img_snapshot()
3673 {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, in img_rebase()
3677 {"backing-format", required_argument, 0, 'B'}, in img_rebase()
3678 {"backing-cache", required_argument, 0, 'T'}, in img_rebase()
3679 {"backing-unsafe", no_argument, 0, 'u'}, in img_rebase()
3680 {"force-share", no_argument, 0, 'U'}, in img_rebase()
3688 if (c == -1) { in img_rebase()
3693 cmd_help(ccmd, "[-f FMT | --image-opts] [-t CACHE]\n" in img_rebase()
3694 " [-b BACKING_FILE [-B BACKING_FMT] [-T BACKING_CACHE]] [-u]\n" in img_rebase()
3695 " [-c] [-U] [-p] [-q] [--object OBJDEF] FILE\n" in img_rebase()
3697 " -f, --format FMT\n" in img_rebase()
3699 " --image-opts\n" in img_rebase()
3701 " (incompatible with -f|--format)\n" in img_rebase()
3702 " -t, --cache CACHE\n" in img_rebase()
3704 " -b, --backing BACKING_FILE|\"\"\n" in img_rebase()
3706 " -B, --backing-format BACKING_FMT (was -F in <=10.0)\n" in img_rebase()
3708 " -T, --backing-cache CACHE\n" in img_rebase()
3710 " -u, --backing-unsafe\n" in img_rebase()
3712 " -c, --compress\n" in img_rebase()
3714 " -U, --force-share\n" in img_rebase()
3716 " -p, --progress\n" in img_rebase()
3718 " -q, --quiet\n" in img_rebase()
3720 " --object OBJDEF\n" in img_rebase()
3721 " defines QEMU user-creatable object\n" in img_rebase()
3724 " with --image-opts, to operate on\n" in img_rebase()
3773 if (optind != argc - 1) { in img_rebase()
3778 "Must specify backing file (-b) or use unsafe mode (-u)"); in img_rebase()
3799 /* The source files are opened read-only, don't care about WCE */ in img_rebase()
3812 ret = -1; in img_rebase()
3822 if (compress && !block_driver_can_compress(unfiltered_bs->drv)) { in img_rebase()
3824 ret = -1; in img_rebase()
3833 ret = -1; in img_rebase()
3870 base_bs->filename); in img_rebase()
3892 overlay_filename = bs->exact_filename[0] ? bs->exact_filename in img_rebase()
3893 : bs->filename; in img_rebase()
3902 ret = -1; in img_rebase()
3934 ret = -1; in img_rebase()
3947 * If qemu-img crashes during this step, no harm is done. The content of in img_rebase()
3969 filename, strerror(-size)); in img_rebase()
3970 ret = -1; in img_rebase()
3981 backing_name, strerror(-old_backing_size)); in img_rebase()
3982 ret = -1; in img_rebase()
3990 out_baseimg, strerror(-new_backing_size)); in img_rebase()
3991 ret = -1; in img_rebase()
4005 n = MIN(IO_BUF_SIZE, size - offset); in img_rebase()
4011 strerror(-ret)); in img_rebase()
4030 strerror(-ret)); in img_rebase()
4055 n += offset - QEMU_ALIGN_DOWN(offset, write_align); in img_rebase()
4057 n += QEMU_ALIGN_UP(offset + n, write_align) - (offset + n); in img_rebase()
4058 n = MIN(n, size - offset); in img_rebase()
4066 n_old = MIN(n, MAX(0, old_backing_size - (int64_t) offset)); in img_rebase()
4067 n_new = MIN(n, MAX(0, new_backing_size - (int64_t) offset)); in img_rebase()
4073 memset(buf_old + n_old, 0, n - n_old); in img_rebase()
4084 memset(buf_new + n_new, 0, n - n_new); in img_rebase()
4100 n - written, write_align, &pnum)) in img_rebase()
4111 strerror(-ret)); in img_rebase()
4137 if (ret == -ENOSPC) { in img_rebase()
4140 } else if (ret == -EINVAL && out_baseimg && !out_basefmt) { in img_rebase()
4145 out_baseimg, strerror(-ret)); in img_rebase()
4204 {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, in img_resize()
4211 c = getopt_long(argc, argv, "-hf:q", in img_resize()
4213 if (c == -1) { in img_resize()
4218 cmd_help(ccmd, "[-f FMT | --image-opts] [--preallocation PREALLOC] [--shrink]\n" in img_resize()
4219 " [-q] [--object OBJDEF] FILE [+-]SIZE[bkKMGTPE]\n" in img_resize()
4221 " -f, --format FMT\n" in img_resize()
4223 " --image-opts\n" in img_resize()
4225 " (incompatible with -f|--format)\n" in img_resize()
4226 " --shrink\n" in img_resize()
4228 " --preallocation PREALLOC\n" in img_resize()
4229 " specify FMT-specific preallocation type for the new areas\n" in img_resize()
4230 " -q, --quiet\n" in img_resize()
4232 " --object OBJDEF\n" in img_resize()
4233 " defines QEMU user-creatable object\n" in img_resize()
4236 " with --image-opts, to operate on\n" in img_resize()
4237 " [+-]SIZE[bkKMGTPE]\n" in img_resize()
4238 " new image size or amount by which to shrink (-)/grow (+),\n" in img_resize()
4265 case 1: /* a non-optional argument */ in img_resize()
4268 /* see if we have -size (number) next to filename */ in img_resize()
4271 if (size[0] == '-' && size[1] >= '0' && size[1] <= '9') { in img_resize()
4303 case '-': in img_resize()
4304 relative = -1; in img_resize()
4316 ret = -1; in img_resize()
4327 ret = -1; in img_resize()
4334 strerror(-current_size)); in img_resize()
4335 ret = -1; in img_resize()
4346 ret = -1; in img_resize()
4352 ret = -1; in img_resize()
4357 error_report("Use the --shrink option to perform a shrink operation."); in img_resize()
4361 ret = -1; in img_resize()
4404 if (!drv->bdrv_amend_options) { in print_amend_option_help()
4411 assert(drv->amend_opts); in print_amend_option_help()
4414 qemu_opts_print_help(drv->amend_opts, false); in print_amend_option_help()
4440 {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, in img_amend()
4450 if (c == -1) { in img_amend()
4456 cmd_help(ccmd, "-o FMT_OPTS [-f FMT | --image-opts]\n" in img_amend()
4457 " [-t CACHE] [--force] [-p] [-q] [--object OBJDEF] FILE\n" in img_amend()
4459 " -o, --options FMT_OPTS\n" in img_amend()
4460 " FMT-specfic format options (required)\n" in img_amend()
4461 " -f, --format FMT\n" in img_amend()
4463 " --image-opts\n" in img_amend()
4465 " (incompatible with -f|--format)\n" in img_amend()
4466 " -t, --cache CACHE\n" in img_amend()
4468 " --force\n" in img_amend()
4470 " -p, --progres\n" in img_amend()
4472 " -q, --quiet\n" in img_amend()
4474 " --object OBJDEF\n" in img_amend()
4475 " defines QEMU user-creatable object\n" in img_amend()
4478 " with --image-opts, to operate on\n" in img_amend()
4483 ret = -1; in img_amend()
4514 error_exit(argv[0], "Must specify options (-o)"); in img_amend()
4522 filename = (optind == argc - 1) ? argv[argc - 1] : NULL; in img_amend()
4530 if (optind != argc - 1) { in img_amend()
4532 ret = -1; in img_amend()
4546 ret = -1; in img_amend()
4551 fmt = bs->drv->format_name; in img_amend()
4554 /* If the format was auto-detected, print option help here */ in img_amend()
4560 if (!bs->drv->bdrv_amend_options) { in img_amend()
4564 ret = -1; in img_amend()
4569 assert(bs->drv->amend_opts); in img_amend()
4571 amend_opts = qemu_opts_append(amend_opts, bs->drv->amend_opts); in img_amend()
4575 amend_opts = qemu_opts_append(amend_opts, bs->drv->create_opts); in img_amend()
4585 ret = -1; in img_amend()
4636 error_report("Failed flush request: %s", strerror(-ret)); in bench_undrained_flush_cb()
4647 error_report("Failed request: %s", strerror(-ret)); in bench_cb()
4651 if (b->in_flush) { in bench_cb()
4653 assert(b->in_flight == 0); in bench_cb()
4654 b->in_flush = false; in bench_cb()
4655 } else if (b->in_flight > 0) { in bench_cb()
4656 int remaining = b->n - b->in_flight; in bench_cb()
4658 b->n--; in bench_cb()
4659 b->in_flight--; in bench_cb()
4662 if (b->flush_interval && remaining % b->flush_interval == 0) { in bench_cb()
4663 if (!b->in_flight || !b->drain_on_flush) { in bench_cb()
4666 if (b->drain_on_flush) { in bench_cb()
4667 b->in_flush = true; in bench_cb()
4673 acb = blk_aio_flush(b->blk, cb, b); in bench_cb()
4679 if (b->drain_on_flush) { in bench_cb()
4685 while (b->n > b->in_flight && b->in_flight < b->nrreq) { in bench_cb()
4686 int64_t offset = b->offset; in bench_cb()
4689 * and b->offset is ready for the next submission. in bench_cb()
4691 b->in_flight++; in bench_cb()
4692 b->offset += b->step; in bench_cb()
4693 if (b->image_size <= b->bufsize) { in bench_cb()
4694 b->offset = 0; in bench_cb()
4696 b->offset %= b->image_size - b->bufsize; in bench_cb()
4698 if (b->write) { in bench_cb()
4699 acb = blk_aio_pwritev(b->blk, offset, b->qiov, 0, bench_cb, b); in bench_cb()
4701 acb = blk_aio_preadv(b->blk, offset, b->qiov, 0, bench_cb, b); in bench_cb()
4739 {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, in img_bench()
4744 {"buffer-size", required_argument, 0, 's'}, in img_bench()
4745 {"step-size", required_argument, 0, 'S'}, in img_bench()
4748 {"flush-interval", required_argument, 0, OPTION_FLUSH_INTERVAL}, in img_bench()
4749 {"no-drain", no_argument, 0, OPTION_NO_DRAIN}, in img_bench()
4752 {"force-share", no_argument, 0, 'U'}, in img_bench()
4759 if (c == -1) { in img_bench()
4765 cmd_help(ccmd, "[-f FMT | --image-opts] [-t CACHE]\n" in img_bench()
4766 " [-c COUNT] [-d DEPTH] [-o OFFSET] [-s BUFFER_SIZE] [-S STEP_SIZE]\n" in img_bench()
4767 " [-w [--pattern PATTERN] [--flush-interval INTERVAL [--no-drain]]]\n" in img_bench()
4768 " [-i AIO] [-n] [-U] [-q] FILE\n" in img_bench()
4770 " -f, --format FMT\n" in img_bench()
4772 " --image-opts\n" in img_bench()
4774 " instead of a file name (incompatible with --format)\n" in img_bench()
4775 " -t, --cache CACHE\n" in img_bench()
4777 " -c, --count COUNT\n" in img_bench()
4779 " -d, --depth DEPTH\n" in img_bench()
4781 " -o, --offset OFFSET\n" in img_bench()
4783 " -s, --buffer-size BUFFER_SIZE[bkKMGTPE]\n" in img_bench()
4786 " -S, --step-size STEP_SIZE[bkKMGTPE]\n" in img_bench()
4789 " -w, --write\n" in img_bench()
4791 " --pattern PATTERN\n" in img_bench()
4793 " --flush-interval FLUSH_INTERVAL\n" in img_bench()
4795 " --no-drain\n" in img_bench()
4797 " -i, --aio AIO\n" in img_bench()
4798 " async-io backend (threads, native, io_uring)\n" in img_bench()
4799 " -n, --native\n" in img_bench()
4801 " -U, --force-share\n" in img_bench()
4803 " -q, --quiet\n" in img_bench()
4805 " --object OBJDEF\n" in img_bench()
4806 " defines QEMU user-creatable object\n" in img_bench()
4809 " with --image-opts, to operate on\n" in img_bench()
4822 ret = -1; in img_bench()
4845 ret = -1; in img_bench()
4901 if (optind != argc - 1) { in img_bench()
4904 filename = argv[argc - 1]; in img_bench()
4907 error_report("--flush-interval is only available in write tests"); in img_bench()
4908 ret = -1; in img_bench()
4913 ret = -1; in img_bench()
4920 ret = -1; in img_bench()
4972 (t2.tv_sec - t1.tv_sec) in img_bench()
4973 + ((double)(t2.tv_usec - t1.tv_usec) / 1000000)); in img_bench()
5025 {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, in img_bitmap()
5031 {"disable", no_argument, 0, OPTION_DISABLE}, in img_bitmap()
5033 {"source-file", required_argument, 0, 'b'}, in img_bitmap()
5034 {"source-format", required_argument, 0, 'F'}, in img_bitmap()
5040 if (c == -1) { in img_bitmap()
5046 cmd_help(ccmd, "[-f FMT | --image-opts]\n" in img_bitmap()
5047 " ( --add [-g SIZE] | --remove | --clear | --enable | --disable |\n" in img_bitmap()
5048 " --merge SOURCE [-b SRC_FILE [-F SRC_FMT]] )..\n" in img_bitmap()
5049 " [--object OBJDEF] FILE BITMAP\n" in img_bitmap()
5051 " -f, --format FMT\n" in img_bitmap()
5053 " --image-opts\n" in img_bitmap()
5055 " (incompatible with -f|--format)\n" in img_bitmap()
5056 " --add\n" in img_bitmap()
5058 " -g, --granularity SIZE[bKMGTPE]\n" in img_bitmap()
5059 " sets non-default granularity for the bitmap being added,\n" in img_bitmap()
5061 " --remove\n" in img_bitmap()
5063 " --clear\n" in img_bitmap()
5065 " --enable, --disable\n" in img_bitmap()
5067 " --merge SOURCE\n" in img_bitmap()
5069 " -b, --source-file SRC_FILE\n" in img_bitmap()
5070 " select alternative source file for --merge\n" in img_bitmap()
5071 " -F, --source-format SRC_FMT\n" in img_bitmap()
5073 " --object OBJDEF\n" in img_bitmap()
5074 " defines QEMU user-creatable object\n" in img_bitmap()
5077 " with --image-opts, to operate on\n" in img_bitmap()
5079 " name of the bitmap to add, remove, clear, enable, disable or merge to\n" in img_bitmap()
5090 act->act = BITMAP_ADD; in img_bitmap()
5102 act->act = BITMAP_REMOVE; in img_bitmap()
5107 act->act = BITMAP_CLEAR; in img_bitmap()
5112 act->act = BITMAP_ENABLE; in img_bitmap()
5117 act->act = BITMAP_DISABLE; in img_bitmap()
5122 act->act = BITMAP_MERGE; in img_bitmap()
5123 act->src = optarg; in img_bitmap()
5142 error_report("Need at least one of --add, --remove, --clear, " in img_bitmap()
5143 "--enable, --disable, or --merge"); in img_bitmap()
5148 error_report("granularity only supported with --add"); in img_bitmap()
5152 error_report("-F only supported with -b"); in img_bitmap()
5157 "--merge"); in img_bitmap()
5161 if (optind != argc - 2) { in img_bitmap()
5191 switch (act->act) { in img_bitmap()
5193 qmp_block_dirty_bitmap_add(bs->node_name, bitmap, in img_bitmap()
5199 qmp_block_dirty_bitmap_remove(bs->node_name, bitmap, &err); in img_bitmap()
5203 qmp_block_dirty_bitmap_clear(bs->node_name, bitmap, &err); in img_bitmap()
5207 qmp_block_dirty_bitmap_enable(bs->node_name, bitmap, &err); in img_bitmap()
5211 qmp_block_dirty_bitmap_disable(bs->node_name, bitmap, &err); in img_bitmap()
5212 op = "disable"; in img_bitmap()
5215 do_dirty_bitmap_merge(bs->node_name, bitmap, src_bs->node_name, in img_bitmap()
5216 act->src, &err); in img_bitmap()
5240 error_report("Error while closing the image: %s", strerror(-inactivate_ret)); in img_bitmap()
5285 in->bsz = out->bsz = res; in img_dd_bs()
5294 dd->count = cvtnum("count", arg, true); in img_dd_count()
5296 if (dd->count < 0) { in img_dd_count()
5307 in->filename = g_strdup(arg); in img_dd_if()
5316 out->filename = g_strdup(arg); in img_dd_of()
5325 in->offset = cvtnum("skip", arg, true); in img_dd_skip()
5327 if (in->offset < 0) { in img_dd_skip()
5379 { "image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, in img_dd()
5380 { "output-format", required_argument, 0, 'O'}, in img_dd()
5381 { "force-share", no_argument, 0, 'U'}, in img_dd()
5392 cmd_help(ccmd, "[-f FMT|--image-opts] [-O OUTPUT_FMT] [-U]\n" in img_dd()
5393 " [--object OBJDEF] [bs=BLOCK_SIZE] [count=BLOCKS] if=INPUT of=OUTPUT\n" in img_dd()
5395 " -f, --format FMT\n" in img_dd()
5397 " --image-opts\n" in img_dd()
5399 " (incompatible with -f|--format)\n" in img_dd()
5400 " -O, --output-format OUTPUT_FMT\n" in img_dd()
5402 " -U, --force-share\n" in img_dd()
5404 " --object OBJDEF\n" in img_dd()
5405 " defines QEMU user-creatable object\n" in img_dd()
5413 " with --image-opts, to use for input\n" in img_dd()
5445 ret = -1; in img_dd()
5458 ret = -1; in img_dd()
5463 ret = -1; in img_dd()
5473 ret = -1; in img_dd()
5481 ret = -1; in img_dd()
5488 ret = -1; in img_dd()
5495 ret = -1; in img_dd()
5498 if (!drv->create_opts) { in img_dd()
5500 drv->format_name); in img_dd()
5501 ret = -1; in img_dd()
5504 if (!proto_drv->create_opts) { in img_dd()
5506 proto_drv->format_name); in img_dd()
5507 ret = -1; in img_dd()
5510 create_opts = qemu_opts_append(create_opts, drv->create_opts); in img_dd()
5511 create_opts = qemu_opts_append(create_opts, proto_drv->create_opts); in img_dd()
5518 ret = -1; in img_dd()
5533 size - in.bsz * in.offset, &error_abort); in img_dd()
5541 ret = -1; in img_dd()
5545 /* TODO, we can't honour --image-opts for the target, in img_dd()
5548 * support image-opts style. in img_dd()
5554 ret = -1; in img_dd()
5572 int bytes = (in_pos + in.bsz > size) ? size - in_pos : in.bsz; in img_dd()
5577 strerror(-ret)); in img_dd()
5585 strerror(-ret)); in img_dd()
5618 printf("%s\n", str->str); in dump_json_block_measure_info()
5640 int64_t img_size = -1; in img_measure()
5648 {"source-format", required_argument, 0, 'f'}, /* img_convert */ in img_measure()
5650 {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, in img_measure()
5651 {"source-image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, /* img_convert */ in img_measure()
5653 {"target-format", required_argument, 0, 'O'}, in img_measure()
5654 {"target-format-options", required_argument, 0, 'o'}, /* img_convert */ in img_measure()
5656 {"force-share", no_argument, 0, 'U'}, in img_measure()
5664 long_options, NULL)) != -1) { in img_measure()
5667 cmd_help(ccmd, "[-f FMT|--image-opts] [-l SNAPSHOT]\n" in img_measure()
5668 " [-O TARGET_FMT] [-o TARGET_FMT_OPTS] [--output human|json]\n" in img_measure()
5669 " [--object OBJDEF] (--size SIZE | FILE)\n" in img_measure()
5671 " -f, --format\n" in img_measure()
5673 " --image-opts\n" in img_measure()
5675 " instead of a file name (incompatible with --format)\n" in img_measure()
5676 " -l, --snapshot SNAPSHOT\n" in img_measure()
5678 " -O, --target-format TARGET_FMT\n" in img_measure()
5680 " -o TARGET_FMT_OPTS\n" in img_measure()
5682 " --output human|json\n" in img_measure()
5684 " -U, --force-share\n" in img_measure()
5686 " --object OBJDEF\n" in img_measure()
5687 " defines QEMU user-creatable object\n" in img_measure()
5688 " -s, --size SIZE[bKMGTPE]\n" in img_measure()
5693 " or an option string (key=value,..) with --image-options)\n" in img_measure()
5743 if (argc - optind > 1) { in img_measure()
5746 } else if (argc - optind == 1) { in img_measure()
5751 error_report("--image-opts, -f, and -l require a filename argument."); in img_measure()
5754 if (filename && img_size != -1) { in img_measure()
5755 error_report("--size N cannot be used together with a filename."); in img_measure()
5758 if (!filename && img_size == -1) { in img_measure()
5759 error_report("Either --size N or one filename must be specified."); in img_measure()
5790 if (!drv->create_opts) { in img_measure()
5792 drv->format_name); in img_measure()
5796 create_opts = qemu_opts_append(create_opts, drv->create_opts); in img_measure()
5806 if (img_size != -1) { in img_measure()
5817 printf("required size: %" PRIu64 "\n", info->required); in img_measure()
5818 printf("fully allocated size: %" PRIu64 "\n", info->fully_allocated); in img_measure()
5819 if (info->has_bitmaps) { in img_measure()
5820 printf("bitmaps size: %" PRIu64 "\n", info->bitmaps); in img_measure()
5841 "Update format-specific options of the image" },
5914 while ((c = getopt_long(argc, argv, "+hVT:", long_options, NULL)) != -1) { in main()
5921 " qemu-img [standard options] COMMAND [--help | command options]\n" in main()
5924 " -h, --help\n" in main()
5926 " -V, --version\n" in main()
5928 " -T,--trace TRACE\n" in main()
5932 "Recognized commands (run qemu-img COMMAND --help for command-specific help):\n\n"); in main()
5933 for (cmd = img_cmds; cmd->name != NULL; cmd++) { in main()
5934 printf(" %s - %s\n", cmd->name, cmd->description); in main()
5968 for (cmd = img_cmds; cmd->name != NULL; cmd++) { in main()
5969 if (!strcmp(cmdname, cmd->name)) { in main()
5973 argc -= optind; in main()
5976 return cmd->handler(cmd, argc, argv); in main()