To specify we use measure call for commit size calculations, we add a new 'for_commit' option to the measure call. This will be used in following commit to do a different measurement.
Signed-off-by: Jean-Louis Dupond <jean-lo...@dupond.be> --- block/qcow2.c | 16 +++++++++++++ include/block/block_int-common.h | 4 ++++ qapi/block-core.json | 28 ++++++++++++++++++++++ qemu-img.c | 40 ++++++++++++++++++++++++++++---- 4 files changed, 83 insertions(+), 5 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 7774e7f090..19028e051c 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3945,6 +3945,7 @@ qcow2_co_create_opts(BlockDriver *drv, const char *filename, QemuOpts *opts, { BLOCK_OPT_COMPAT_LEVEL, "version" }, { BLOCK_OPT_DATA_FILE_RAW, "data-file-raw" }, { BLOCK_OPT_COMPRESSION_TYPE, "compression-type" }, + { BLOCK_OPT_FOR_COMMIT, "for-commit" }, { NULL, NULL }, }; @@ -6066,6 +6067,20 @@ void qcow2_signal_corruption(BlockDriverState *bs, bool fatal, int64_t offset, .def_value_str = "16" \ } +static QemuOptsList qcow2_measure_opts = { + .name = "qcow2-measure-opts", + .head = QTAILQ_HEAD_INITIALIZER(qcow2_measure_opts.head), + .desc = { + { \ + .name = BLOCK_OPT_FOR_COMMIT, \ + .type = QEMU_OPT_BOOL, \ + .help = "Use measure for commit", \ + .def_value_str = "off" \ + }, \ + { /* end of list */ } + } +}; + static QemuOptsList qcow2_create_opts = { .name = "qcow2-create-opts", .head = QTAILQ_HEAD_INITIALIZER(qcow2_create_opts.head), @@ -6190,6 +6205,7 @@ BlockDriver bdrv_qcow2 = { .create_opts = &qcow2_create_opts, .amend_opts = &qcow2_amend_opts, + .measure_opts = &qcow2_measure_opts, .strong_runtime_opts = qcow2_strong_runtime_opts, .mutable_opts = mutable_opts, .bdrv_co_check = qcow2_co_check, diff --git a/include/block/block_int-common.h b/include/block/block_int-common.h index ebb4e56a50..26d521459d 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -57,6 +57,7 @@ #define BLOCK_OPT_DATA_FILE_RAW "data_file_raw" #define BLOCK_OPT_COMPRESSION_TYPE "compression_type" #define BLOCK_OPT_EXTL2 "extended_l2" +#define BLOCK_OPT_FOR_COMMIT "for_commit" #define BLOCK_PROBE_BUF_SIZE 512 @@ -177,6 +178,9 @@ struct BlockDriver { /* List of options for image amend */ QemuOptsList *amend_opts; + /* List of options for image measure */ + QemuOptsList *measure_opts; + /* * If this driver supports reopening images this contains a * NULL-terminated list of the runtime options that can be diff --git a/qapi/block-core.json b/qapi/block-core.json index b1937780e1..ab897be404 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -5557,6 +5557,34 @@ 'features': [ 'unstable' ], 'allow-preconfig': true } + ## + # @BlockdevMeasureOptionsQcow2: + # + # Driver specific image measure options for qcow2. + # + # @for-commit: Use the measure command to calculate commit image size + # + # Since: 10.0 + ## + { 'struct': 'BlockdevMeasureOptionsQcow2', + 'data': { '*for-commit': 'bool' } } + + ## + # @BlockdevMeasureOptions: + # + # Options for measuring an image format + # + # @driver: Block driver of the node to measure. + # + # Since: 10.0 + ## + { 'union': 'BlockdevMeasureOptions', + 'base': { + 'driver': 'BlockdevDriver' }, + 'discriminator': 'driver', + 'data': { + 'qcow2': 'BlockdevMeasureOptionsQcow2' } } + ## # @BlockErrorAction: # diff --git a/qemu-img.c b/qemu-img.c index 2044c22a4c..a4673c3f32 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -5327,6 +5327,31 @@ out: return 0; } +static int print_measure_option_help(const char *format) +{ + BlockDriver *drv; + + GRAPH_RDLOCK_GUARD_MAINLOOP(); + + /* Find driver and parse its options */ + drv = bdrv_find_format(format); + if (!drv) { + error_report("Unknown file format '%s'", format); + return 1; + } + + if (!drv->measure_opts) { + error_report("Format driver '%s' does not support measure options", + format); + return 1; + } + + printf("Measure options for '%s':\n", format); + qemu_opts_print_help(drv->measure_opts, false); + + return 0; +} + static void dump_json_block_measure_info(BlockMeasureInfo *info) { GString *str; @@ -5366,7 +5391,7 @@ static int img_measure(int argc, char **argv) QemuOpts *opts = NULL; QemuOpts *object_opts = NULL; QemuOpts *sn_opts = NULL; - QemuOptsList *create_opts = NULL; + QemuOptsList *all_opts = NULL; bool image_opts = false; uint64_t img_size = UINT64_MAX; BlockMeasureInfo *info = NULL; @@ -5491,10 +5516,15 @@ static int img_measure(int argc, char **argv) drv->format_name); goto out; } + if (options && has_help_option(options)) { + ret = print_measure_option_help(drv->format_name); + goto out; + } - create_opts = qemu_opts_append(create_opts, drv->create_opts); - create_opts = qemu_opts_append(create_opts, bdrv_file.create_opts); - opts = qemu_opts_create(create_opts, NULL, 0, &error_abort); + all_opts = qemu_opts_append(all_opts, drv->create_opts); + all_opts = qemu_opts_append(all_opts, bdrv_file.create_opts); + all_opts = qemu_opts_append(all_opts, drv->measure_opts); + opts = qemu_opts_create(all_opts, NULL, 0, &error_abort); if (options) { if (!qemu_opts_do_parse(opts, options, NULL, &local_err)) { error_report_err(local_err); @@ -5529,7 +5559,7 @@ out: qemu_opts_del(object_opts); qemu_opts_del(opts); qemu_opts_del(sn_opts); - qemu_opts_free(create_opts); + qemu_opts_free(all_opts); g_free(options); blk_unref(in_blk); return ret; -- 2.49.0