]> git.proxmox.com Git - pve-qemu.git/blob - debian/patches/pve/0042-PVE-Add-sequential-job-transaction-support.patch
clean up pve/ patches by squashing patches of patches
[pve-qemu.git] / debian / patches / pve / 0042-PVE-Add-sequential-job-transaction-support.patch
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
5
6 Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
7 ---
8 include/qemu/job.h | 12 ++++++++++++
9 job.c | 31 +++++++++++++++++++++++++++++++
10 2 files changed, 43 insertions(+)
11
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 {
17 */
18 JobTxn *job_txn_new(void);
19
20 +/**
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.
23 + */
24 +JobTxn *job_txn_new_seq(void);
25 +
26 +/**
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.
29 + */
30 +void job_txn_start_seq(JobTxn *txn);
31 +
32 /**
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 f9884e7d9d..05b7797e82 100644
37 --- a/job.c
38 +++ b/job.c
39 @@ -72,6 +72,8 @@ struct JobTxn {
40
41 /* Reference count */
42 int refcnt;
43 +
44 + bool sequential;
45 };
46
47 /* Right now, this mutex is only needed to synchronize accesses to job->busy
48 @@ -102,6 +104,25 @@ JobTxn *job_txn_new(void)
49 return txn;
50 }
51
52 +JobTxn *job_txn_new_seq(void)
53 +{
54 + JobTxn *txn = job_txn_new();
55 + txn->sequential = true;
56 + return txn;
57 +}
58 +
59 +void job_txn_start_seq(JobTxn *txn)
60 +{
61 + assert(txn->sequential);
62 + assert(!txn->aborting);
63 +
64 + Job *first = QLIST_FIRST(&txn->jobs);
65 + assert(first);
66 + assert(first->status == JOB_STATUS_CREATED);
67 +
68 + job_start(first);
69 +}
70 +
71 static void job_txn_ref(JobTxn *txn)
72 {
73 txn->refcnt++;
74 @@ -841,6 +862,9 @@ static void job_completed_txn_success(Job *job)
75 */
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);
80 + }
81 return;
82 }
83 assert(other_job->ret == 0);
84 @@ -1011,6 +1035,13 @@ int job_finish_sync(Job *job, void (*finish)(Job *, Error **errp), Error **errp)
85 return -EBUSY;
86 }
87
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) {
92 + job_update_rc(job);
93 + }
94 +
95 AIO_WAIT_WHILE(job->aio_context,
96 (job_enter(job), !job_is_completed(job)));
97