v5: Address comments from Max Reitz: 2.4 -> 2.5 in qapi docs. Don't leak txn object. English syntax fixes. Really leave the "cancelled" status of failed job. Remove a superfluous added line.
v4: Address comments from John and Stefan, including: Rename function: backup_cleanup_sync_bitmap. Rename and add comments for .commit and .abort. Call .commit and .abort for both txn and non-txn. Drop patch 9 in v3. Improve the txn implementation. Acquire context locks as accessing them. Add refcnt patch for BlockJob. Adjust txn unit test code. This is based on top of the work by Stefan Hajnoczi and John Snow. Recap: motivation for block job transactions -------------------------------------------- If an incremental backup block job fails then we reclaim the bitmap so the job can be retried. The problem comes when multiple jobs are started as part of a qmp 'transaction' command. We need to group these jobs in a transaction so that either all jobs complete successfully or all bitmaps are reclaimed. Without transactions, there is a case where some jobs complete successfully and throw away their bitmaps, making it impossible to retry the backup by rerunning the command if one of the jobs fails. How does this implementation work? ---------------------------------- These patches add a BlockJobTxn object with the following API: txn = block_job_txn_new(); block_job_txn_add_job(txn, job1); block_job_txn_add_job(txn, job2); The jobs either both complete successfully or they both fail/cancel. If the user cancels job1 then job2 will also be cancelled and vice versa. Jobs objects stay alive waiting for other jobs to complete, even if the coroutines have returned. They can be cancelled by the user during this time. Job blockers are still in effect and no other block job can run on this device in the meantime (since QEMU currently only allows 1 job per device). This is the main drawback to this approach but reasonable since you probably don't want to run other jobs/operations until you're sure the backup was successful (you won't be able to retry a failed backup if there's a new job running). Fam Zheng (6): backup: Extract dirty bitmap handling as a separate function blockjob: Introduce reference count blockjob: Add .commit and .abort block job actions blockjob: Add "completed" and "ret" in BlockJob blockjob: Simplify block_job_finish_sync block: Add block job transactions John Snow (4): qapi: Add transaction support to block-dirty-bitmap operations iotests: add transactional incremental backup test block: rename BlkTransactionState and BdrvActionOps iotests: 124 - transactional failure test Kashyap Chamarthy (1): qmp-commands.hx: Update the supported 'transaction' operations Stefan Hajnoczi (3): blockdev: make BlockJobTxn available to qmp 'transaction' block/backup: support block job transactions tests: add BlockJobTxn unit test block.c | 19 ++- block/backup.c | 49 ++++-- block/mirror.c | 2 +- blockdev.c | 361 ++++++++++++++++++++++++++++++++++++--------- blockjob.c | 184 +++++++++++++++++++---- docs/bitmaps.md | 6 +- hmp.c | 2 +- include/block/block.h | 2 +- include/block/block_int.h | 6 +- include/block/blockjob.h | 83 ++++++++++- qapi-schema.json | 6 +- qapi/block-core.json | 16 +- qmp-commands.hx | 21 ++- tests/Makefile | 3 + tests/qemu-iotests/124 | 182 ++++++++++++++++++++++- tests/qemu-iotests/124.out | 4 +- tests/test-blockjob-txn.c | 244 ++++++++++++++++++++++++++++++ 17 files changed, 1048 insertions(+), 142 deletions(-) create mode 100644 tests/test-blockjob-txn.c -- 2.4.3