]> git.proxmox.com Git - pve-qemu.git/blob - debian/patches/pve/0050-PVE-Add-sequential-job-transaction-support.patch
Add transaction patches and fix for blocking finish
[pve-qemu.git] / debian / patches / pve / 0050-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 ---
7 include/qemu/job.h | 12 ++++++++++++
8 job.c | 24 ++++++++++++++++++++++++
9 2 files changed, 36 insertions(+)
10
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 {
16 */
17 JobTxn *job_txn_new(void);
18
19 +/**
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.
22 + */
23 +JobTxn *job_txn_new_seq(void);
24 +
25 +/**
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.
28 + */
29 +void job_txn_start_seq(JobTxn *txn);
30 +
31 /**
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
36 --- a/job.c
37 +++ b/job.c
38 @@ -72,6 +72,8 @@ struct JobTxn {
39
40 /* Reference count */
41 int refcnt;
42 +
43 + bool sequential;
44 };
45
46 /* Right now, this mutex is only needed to synchronize accesses to job->busy
47 @@ -102,6 +104,25 @@ JobTxn *job_txn_new(void)
48 return txn;
49 }
50
51 +JobTxn *job_txn_new_seq(void)
52 +{
53 + JobTxn *txn = job_txn_new();
54 + txn->sequential = true;
55 + return txn;
56 +}
57 +
58 +void job_txn_start_seq(JobTxn *txn)
59 +{
60 + assert(txn->sequential);
61 + assert(!txn->aborting);
62 +
63 + Job *first = QLIST_FIRST(&txn->jobs);
64 + assert(first);
65 + assert(first->status == JOB_STATUS_CREATED);
66 +
67 + job_start(first);
68 +}
69 +
70 static void job_txn_ref(JobTxn *txn)
71 {
72 txn->refcnt++;
73 @@ -841,6 +862,9 @@ static void job_completed_txn_success(Job *job)
74 */
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);
79 + }
80 return;
81 }
82 assert(other_job->ret == 0);