1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: Stefan Reiter <s.reiter@proxmox.com>
3 Date: Thu, 20 Aug 2020 14:31:59 +0200
4 Subject: [PATCH] PVE: Add sequential job transaction support
7 include/qemu/job.h | 12 ++++++++++++
8 job.c | 24 ++++++++++++++++++++++++
9 2 files changed, 36 insertions(+)
11 diff --git a/include/qemu/job.h b/include/qemu/job.h
12 index 32aabb1c60..f7a6a0926a 100644
13 --- a/include/qemu/job.h
14 +++ b/include/qemu/job.h
15 @@ -280,6 +280,18 @@ typedef enum JobCreateFlags {
17 JobTxn *job_txn_new(void);
20 + * Create a new transaction and set it to sequential mode, i.e. run all jobs
21 + * one after the other instead of at the same time.
23 +JobTxn *job_txn_new_seq(void);
26 + * Helper method to start the first job in a sequential transaction to kick it
27 + * off. Other jobs will be run after this one completes.
29 +void job_txn_start_seq(JobTxn *txn);
32 * Release a reference that was previously acquired with job_txn_add_job or
33 * job_txn_new. If it's the last reference to the object, it will be freed.
34 diff --git a/job.c b/job.c
35 index b8139c80a4..97ee97a192 100644
38 @@ -72,6 +72,8 @@ struct JobTxn {
46 /* Right now, this mutex is only needed to synchronize accesses to job->busy
47 @@ -102,6 +104,25 @@ JobTxn *job_txn_new(void)
51 +JobTxn *job_txn_new_seq(void)
53 + JobTxn *txn = job_txn_new();
54 + txn->sequential = true;
58 +void job_txn_start_seq(JobTxn *txn)
60 + assert(txn->sequential);
61 + assert(!txn->aborting);
63 + Job *first = QLIST_FIRST(&txn->jobs);
65 + assert(first->status == JOB_STATUS_CREATED);
70 static void job_txn_ref(JobTxn *txn)
73 @@ -841,6 +862,9 @@ static void job_completed_txn_success(Job *job)
75 QLIST_FOREACH(other_job, &txn->jobs, txn_list) {
76 if (!job_is_completed(other_job)) {
77 + if (txn->sequential) {
78 + job_start(other_job);
82 assert(other_job->ret == 0);