From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 846B662417 for ; Thu, 20 Aug 2020 15:49:30 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 7FB902D95F for ; Thu, 20 Aug 2020 15:49:00 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 9CBD12D947 for ; Thu, 20 Aug 2020 15:48:59 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 623FB449B0 for ; Thu, 20 Aug 2020 15:48:59 +0200 (CEST) From: Stefan Reiter To: pve-devel@lists.proxmox.com Date: Thu, 20 Aug 2020 15:48:36 +0200 Message-Id: <20200820134837.27407-2-s.reiter@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200820134837.27407-1-s.reiter@proxmox.com> References: <20200820134837.27407-1-s.reiter@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.056 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [RFC qemu 1/2] PVE: Add sequential job transaction support X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 20 Aug 2020 13:49:30 -0000 Signed-off-by: Stefan Reiter --- include/qemu/job.h | 12 ++++++++++++ job.c | 24 ++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/include/qemu/job.h b/include/qemu/job.h index 32aabb1c60..f7a6a0926a 100644 --- a/include/qemu/job.h +++ b/include/qemu/job.h @@ -280,6 +280,18 @@ typedef enum JobCreateFlags { */ JobTxn *job_txn_new(void); +/** + * Create a new transaction and set it to sequential mode, i.e. run all jobs + * one after the other instead of at the same time. + */ +JobTxn *job_txn_new_seq(void); + +/** + * Helper method to start the first job in a sequential transaction to kick it + * off. Other jobs will be run after this one completes. + */ +void job_txn_start_seq(JobTxn *txn); + /** * Release a reference that was previously acquired with job_txn_add_job or * job_txn_new. If it's the last reference to the object, it will be freed. diff --git a/job.c b/job.c index bcbbb0be02..901f84dceb 100644 --- a/job.c +++ b/job.c @@ -72,6 +72,8 @@ struct JobTxn { /* Reference count */ int refcnt; + + bool sequential; }; /* Right now, this mutex is only needed to synchronize accesses to job->busy @@ -102,6 +104,25 @@ JobTxn *job_txn_new(void) return txn; } +JobTxn *job_txn_new_seq(void) +{ + JobTxn *txn = job_txn_new(); + txn->sequential = true; + return txn; +} + +void job_txn_start_seq(JobTxn *txn) +{ + assert(txn->sequential); + assert(!txn->aborting); + + Job *first = QLIST_FIRST(&txn->jobs); + assert(first); + assert(first->status == JOB_STATUS_CREATED); + + job_start(first); +} + static void job_txn_ref(JobTxn *txn) { txn->refcnt++; @@ -841,6 +862,9 @@ static void job_completed_txn_success(Job *job) */ QLIST_FOREACH(other_job, &txn->jobs, txn_list) { if (!job_is_completed(other_job)) { + if (txn->sequential) { + job_start(other_job); + } return; } assert(other_job->ret == 0); -- 2.20.1