qemu-img should use QMP commands whenever possible in order to ensure feature completeness of both online and offline image operations. For the "commit" command, this is relatively easy, so implement it first (in the hope that indeed others will follow).
As qemu-img does not have access to QMP (due to QMP being intertwined with basically everything in qemu), we cannot directly use QMP, but at least use the functions the corresponding QMP commands are using (which would be "block-commit", in this case). This series depends on "block-commit: speed is an optional parameter". v4: Introduced block_job_complete_sync() following Kevin's suggestion - Added patch 2 (introduce block_job_complete_sync()) - Patch 3 (previously 2): - use the new function - use qemu_aio_wait() instead (reading block_job_cancel_sync() was worth it) Note: I thought about dropping the necessity for the CB if block_job_*_sync() was used for finishing the block job; this does not work, however, as there are block jobs which call block_job_completed() before block_job_complete() has been called (e.g. commit on a non-active BDS). This is not relevant right now (mirror is the only block job used by qemu-img), however, it might become in the future. Dropping the CB would be nice right now, but it may break in an ugly way later, therefore I decided against it. git-backport-diff against v3: Key: [----] : patches are identical [####] : number of functional differences between upstream/downstream patch [down] : patch is downstream-only The flags [FC] indicate (F)unctional and (C)ontextual differences, respectively 001/6:[----] [--] 'block-commit: Expose granularity' 002/6:[down] 'blockjob: Introduce block_job_complete_sync()' 003/6:[0008] [FC] 'qemu-img: Implement commit like QMP' 004/6:[----] [-C] 'qemu-img: Enable progress output for commit' 005/6:[----] [--] 'qemu-img: Specify backing file for commit' 006/6:[----] [--] 'iotests: Commit tests for two-layer backing chains' v3: - Patch 1: fixed indentation of commit_start() declaration in block_int.h [Eric] - Patch 2: moved out of this series which now depends on it [Kevin, in a sense] - Patch 3 (now 2/5): wait for actual completion of the blockjob (CB called) and evaluate the return value [Kevin] - Patch 4 (now 3/5): factor in the granularity of the blockjob [Kevin] - Patch 5 (now 4/5): - s/backing_file/base/g in documentation [Fam] - s/unto/into/g, s/shall/will/ [Eric] - s/filename/base/ in a certain spot [Fam] v2 (mostly following Eric's comments): - Patch 1: - allow giving the granularity as 0 in order to enforce the default value - use is_power_of_2() instead of manually inlining it - use "if (!has_x) { x = DEFAULT_VALUE; }" (which is the common pattern in blockdev.c) instead of "x = has_x ? x : DEFAULT_VALUE;" - Patch 2: - "if (!has_x) { x = DEFAULT_VALUE; }" with a fixed condition - Patch 3: - don't use obsolete error_is_set() - use bs->backing_hd instead of bdrv_find_base(), as the latter actually finds the very base of the backing chain which does not correspond to the current qemu-img commit behavior (which is to commit into the first backing file) - Added patches 5 and 6 Max Reitz (6): block-commit: Expose granularity blockjob: Introduce block_job_complete_sync() qemu-img: Implement commit like QMP qemu-img: Enable progress output for commit qemu-img: Specify backing file for commit iotests: Commit tests for two-layer backing chains block/Makefile.objs | 2 +- block/commit.c | 16 +- block/mirror.c | 4 +- blockdev.c | 22 +- blockjob.c | 24 +- include/block/block_int.h | 10 +- include/block/blockjob.h | 15 + qapi-schema.json | 6 +- qemu-img-cmds.hx | 4 +- qemu-img.c | 140 ++- qemu-img.texi | 8 +- tests/qemu-iotests/020 | 57 +- tests/qemu-iotests/020.out | 2168 ++++++++++++++++++++++++++++++++++++++++++++ 13 files changed, 2430 insertions(+), 46 deletions(-) -- 1.9.2