mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-02 07:13:54 -06:00
block: Add block job transactions
Sometimes block jobs must execute as a transaction group. Finishing jobs wait until all other jobs are ready to complete successfully. Failure or cancellation of one job cancels the other jobs in the group. Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com> Signed-off-by: Fam Zheng <famz@redhat.com> Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 1446765200-3054-10-git-send-email-jsnow@redhat.com [Rewrite the implementation which is now contained in block_job_completed. --Fam] Signed-off-by: Fam Zheng <famz@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com> Signed-off-by: John Snow <jsnow@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
94db6d2d30
commit
c55a832fdd
3 changed files with 172 additions and 2 deletions
|
@ -14,6 +14,7 @@ typedef struct BlockDriver BlockDriver;
|
|||
typedef struct BlockJob BlockJob;
|
||||
typedef struct BdrvChild BdrvChild;
|
||||
typedef struct BdrvChildRole BdrvChildRole;
|
||||
typedef struct BlockJobTxn BlockJobTxn;
|
||||
|
||||
typedef struct BlockDriverInfo {
|
||||
/* in bytes, 0 if irrelevant */
|
||||
|
|
|
@ -162,6 +162,9 @@ struct BlockJob {
|
|||
*/
|
||||
int ret;
|
||||
|
||||
/** Non-NULL if this job is part of a transaction */
|
||||
BlockJobTxn *txn;
|
||||
QLIST_ENTRY(BlockJob) txn_list;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -405,4 +408,39 @@ void block_job_defer_to_main_loop(BlockJob *job,
|
|||
BlockJobDeferToMainLoopFn *fn,
|
||||
void *opaque);
|
||||
|
||||
/**
|
||||
* block_job_txn_new:
|
||||
*
|
||||
* Allocate and return a new block job transaction. Jobs can be added to the
|
||||
* transaction using block_job_txn_add_job().
|
||||
*
|
||||
* The transaction is automatically freed when the last job completes or is
|
||||
* cancelled.
|
||||
*
|
||||
* All jobs in the transaction either complete successfully or fail/cancel as a
|
||||
* group. Jobs wait for each other before completing. Cancelling one job
|
||||
* cancels all jobs in the transaction.
|
||||
*/
|
||||
BlockJobTxn *block_job_txn_new(void);
|
||||
|
||||
/**
|
||||
* block_job_txn_unref:
|
||||
*
|
||||
* Release a reference that was previously acquired with block_job_txn_add_job
|
||||
* or block_job_txn_new. If it's the last reference to the object, it will be
|
||||
* freed.
|
||||
*/
|
||||
void block_job_txn_unref(BlockJobTxn *txn);
|
||||
|
||||
/**
|
||||
* block_job_txn_add_job:
|
||||
* @txn: The transaction (may be NULL)
|
||||
* @job: Job to add to the transaction
|
||||
*
|
||||
* Add @job to the transaction. The @job must not already be in a transaction.
|
||||
* The caller must call either block_job_txn_unref() or block_job_completed()
|
||||
* to release the reference that is automatically grabbed here.
|
||||
*/
|
||||
void block_job_txn_add_job(BlockJobTxn *txn, BlockJob *job);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue