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
6 Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
8 include/qemu/job.h | 12 ++++++++++++
9 job.c | 24 ++++++++++++++++++++++++
10 2 files changed, 36 insertions(+)
12 diff --git a/include/qemu/job.h b/include/qemu/job.h
13 index 32aabb1c60..f7a6a0926a 100644
14 --- a/include/qemu/job.h
15 +++ b/include/qemu/job.h
16 @@ -280,6 +280,18 @@ typedef enum JobCreateFlags {
18 JobTxn *job_txn_new(void);
21 + * Create a new transaction and set it to sequential mode, i.e. run all jobs
22 + * one after the other instead of at the same time.
24 +JobTxn *job_txn_new_seq(void);
27 + * Helper method to start the first job in a sequential transaction to kick it
28 + * off. Other jobs will be run after this one completes.
30 +void job_txn_start_seq(JobTxn *txn);
33 * Release a reference that was previously acquired with job_txn_add_job or
34 * job_txn_new. If it's the last reference to the object, it will be freed.
35 diff --git a/job.c b/job.c
36 index b8139c80a4..97ee97a192 100644
39 @@ -72,6 +72,8 @@ struct JobTxn {
47 /* Right now, this mutex is only needed to synchronize accesses to job->busy
48 @@ -102,6 +104,25 @@ JobTxn *job_txn_new(void)
52 +JobTxn *job_txn_new_seq(void)
54 + JobTxn *txn = job_txn_new();
55 + txn->sequential = true;
59 +void job_txn_start_seq(JobTxn *txn)
61 + assert(txn->sequential);
62 + assert(!txn->aborting);
64 + Job *first = QLIST_FIRST(&txn->jobs);
66 + assert(first->status == JOB_STATUS_CREATED);
71 static void job_txn_ref(JobTxn *txn)
74 @@ -841,6 +862,9 @@ static void job_completed_txn_success(Job *job)
76 QLIST_FOREACH(other_job, &txn->jobs, txn_list) {
77 if (!job_is_completed(other_job)) {
78 + if (txn->sequential) {
79 + job_start(other_job);
83 assert(other_job->ret == 0);