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>
7 Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
9 include/qemu/job.h | 12 ++++++++++++
10 job.c | 34 ++++++++++++++++++++++++++++++++++
11 2 files changed, 46 insertions(+)
13 diff --git a/include/qemu/job.h b/include/qemu/job.h
14 index e502787dd8..963cf2bef5 100644
15 --- a/include/qemu/job.h
16 +++ b/include/qemu/job.h
17 @@ -381,6 +381,18 @@ void job_unlock(void);
19 JobTxn *job_txn_new(void);
22 + * Create a new transaction and set it to sequential mode, i.e. run all jobs
23 + * one after the other instead of at the same time.
25 +JobTxn *job_txn_new_seq(void);
28 + * Helper method to start the first job in a sequential transaction to kick it
29 + * off. Other jobs will be run after this one completes.
31 +void job_txn_start_seq(JobTxn *txn);
34 * Release a reference that was previously acquired with job_txn_add_job or
35 * job_txn_new. If it's the last reference to the object, it will be freed.
36 diff --git a/job.c b/job.c
37 index 93e22d180b..2b31f1e14f 100644
40 @@ -93,6 +93,8 @@ struct JobTxn {
49 @@ -118,6 +120,25 @@ JobTxn *job_txn_new(void)
53 +JobTxn *job_txn_new_seq(void)
55 + JobTxn *txn = job_txn_new();
56 + txn->sequential = true;
60 +void job_txn_start_seq(JobTxn *txn)
62 + assert(txn->sequential);
63 + assert(!txn->aborting);
65 + Job *first = QLIST_FIRST(&txn->jobs);
67 + assert(first->status == JOB_STATUS_CREATED);
72 /* Called with job_mutex held. */
73 static void job_txn_ref_locked(JobTxn *txn)
75 @@ -1057,6 +1078,12 @@ static void job_completed_txn_success_locked(Job *job)
77 QLIST_FOREACH(other_job, &txn->jobs, txn_list) {
78 if (!job_is_completed_locked(other_job)) {
79 + if (txn->sequential) {
81 + /* Needs to be called without holding the job lock */
82 + job_start(other_job);
87 assert(other_job->ret == 0);
88 @@ -1268,6 +1295,13 @@ int job_finish_sync_locked(Job *job,
92 + /* in a sequential transaction jobs with status CREATED can appear at time
93 + * of cancelling, these have not begun work so job_enter won't do anything,
94 + * let's ensure they are marked as ABORTING if required */
95 + if (job->status == JOB_STATUS_CREATED && job->txn->sequential) {
96 + job_update_rc_locked(job);
100 AIO_WAIT_WHILE_UNLOCKED(job->aio_context,
101 (job_enter(job), !job_is_completed(job)));