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 | 31 +++++++++++++++++++++++++++++++
10 2 files changed, 43 insertions(+)
12 diff --git a/include/qemu/job.h b/include/qemu/job.h
13 index efc6fa7544..942ee43bca 100644
14 --- a/include/qemu/job.h
15 +++ b/include/qemu/job.h
16 @@ -285,6 +285,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 3999b7728c..3ae018cdad 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 @@ -847,6 +868,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);
84 @@ -1017,6 +1041,13 @@ int job_finish_sync(Job *job, void (*finish)(Job *, Error **errp), Error **errp)
88 + /* in a sequential transaction jobs with status CREATED can appear at time
89 + * of cancelling, these have not begun work so job_enter won't do anything,
90 + * let's ensure they are marked as ABORTING if required */
91 + if (job->status == JOB_STATUS_CREATED && job->txn->sequential) {
95 AIO_WAIT_WHILE(job->aio_context,
96 (job_enter(job), !job_is_completed(job)));