From nobody Mon Feb 9 09:33:25 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1625677418881147.54918386067095; Wed, 7 Jul 2021 10:03:38 -0700 (PDT) Received: from localhost ([::1]:44948 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m1AxV-0003oX-E8 for importer@patchew.org; Wed, 07 Jul 2021 13:03:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41778) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m1Asj-0002h4-CV for qemu-devel@nongnu.org; Wed, 07 Jul 2021 12:58:41 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:33913) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m1Asg-0000D8-Rz for qemu-devel@nongnu.org; Wed, 07 Jul 2021 12:58:41 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-199-VstCD4oVO9m_fmJ57juHXw-1; Wed, 07 Jul 2021 12:58:37 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0917C101F000; Wed, 7 Jul 2021 16:58:36 +0000 (UTC) Received: from localhost.localdomain (ovpn-115-49.ams2.redhat.com [10.36.115.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7A6641036D03; Wed, 7 Jul 2021 16:58:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625677118; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RIrPiEQ3tA6Dzc89klSAnn6Q+mMSCGklqnwTjsNCL9A=; b=fv50AR91BF78/zfjaaf+k63SWYH22W/xl/hd9XXTvhwCYGL5dTdZoyE4QsGJHgRg+Oz4Kw lcRO8PFdCiYTA+3zXJMKMNI5wdVEdaonCPmyaflU/uRec2bL3uxWQYKjdGgQ1u0fpunT5P TNFg0QwgQssNompqYg+NucQqDEsiE1I= X-MC-Unique: VstCD4oVO9m_fmJ57juHXw-1 From: Emanuele Giuseppe Esposito To: qemu-block@nongnu.org Subject: [RFC PATCH 4/6] job.h: categorize job fields Date: Wed, 7 Jul 2021 18:58:11 +0200 Message-Id: <20210707165813.55361-5-eesposit@redhat.com> In-Reply-To: <20210707165813.55361-1-eesposit@redhat.com> References: <20210707165813.55361-1-eesposit@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eesposit@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.439, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Emanuele Giuseppe Esposito , Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org, Wen Congyang , Xie Changlong , Markus Armbruster , Max Reitz , Stefan Hajnoczi , Paolo Bonzini , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1625677420093100001 Content-Type: text/plain; charset="utf-8" This makes it easier to understand what needs to be protected by a lock and what doesn't. Signed-off-by: Emanuele Giuseppe Esposito --- include/qemu/job.h | 101 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 82 insertions(+), 19 deletions(-) diff --git a/include/qemu/job.h b/include/qemu/job.h index ba2f9b2660..4421d08d93 100644 --- a/include/qemu/job.h +++ b/include/qemu/job.h @@ -40,24 +40,40 @@ typedef struct JobTxn JobTxn; * Long-running operation. */ typedef struct Job { - /** The ID of the job. May be NULL for internal jobs. */ + /** + * The ID of the job. May be NULL for internal jobs. + * Set it in job_create and just read. + */ char *id; =20 - /** The type of this job. */ + /** + * The type of this job. + * Set it in job_create and just read. + */ const JobDriver *driver; =20 - /** Reference count of the block job */ + /** + * Reference count of the block job. + * Protected by job_mutex. + */ int refcnt; =20 - /** Current state; See @JobStatus for details. */ + /** + * Current state; See @JobStatus for details. + * Protected by job_mutex. + */ JobStatus status; =20 - /** AioContext to run the job coroutine in */ + /** + * AioContext to run the job coroutine in. + * Atomic. + */ AioContext *aio_context; =20 /** * The coroutine that executes the job. If not NULL, it is reentered = when * busy is false and the job is cancelled. + * Set it in job_create and just read. */ Coroutine *co; =20 @@ -70,13 +86,15 @@ typedef struct Job { /** * Counter for pause request. If non-zero, the block job is either pau= sed, * or if busy =3D=3D true will pause itself as soon as possible. + * Protected by job_mutex. */ int pause_count; =20 /** * Set to false by the job while the coroutine has yielded and may be * re-entered by job_enter(). There may still be I/O or event loop act= ivity - * pending. Accessed under block_job_mutex (in blockjob.c). + * pending. + * Protected by job_mutex. * * When the job is deferred to the main loop, busy is true as long as = the * bottom half is still pending. @@ -86,12 +104,14 @@ typedef struct Job { /** * Set to true by the job while it is in a quiescent state, where * no I/O or event loop activity is pending. + * Protected by job_mutex. */ bool paused; =20 /** * Set to true if the job is paused by user. Can be unpaused with the * block-job-resume QMP command. + * Protected by job_mutex. */ bool user_paused; =20 @@ -100,22 +120,33 @@ typedef struct Job { * always be tested just before toggling the busy flag from false * to true. After a job has been cancelled, it should only yield * if #aio_poll will ("sooner or later") reenter the coroutine. + * Protected by job_mutex. */ bool cancelled; =20 /** * Set to true if the job should abort immediately without waiting * for data to be in sync. + * Protected by job_mutex. */ bool force_cancel; =20 - /** Set to true when the job has deferred work to the main loop. */ + /** + * Set to true when the job has deferred work to the main loop. + * Protected by job_mutex. + */ bool deferred_to_main_loop; =20 - /** True if this job should automatically finalize itself */ + /** + * True if this job should automatically finalize itself. + * Set it in job_create and just read. + */ bool auto_finalize; =20 - /** True if this job should automatically dismiss itself */ + /** + * True if this job should automatically dismiss itself. + * Set it in job_create and just read. + */ bool auto_dismiss; =20 ProgressMeter progress; @@ -124,6 +155,7 @@ typedef struct Job { * Return code from @run and/or @prepare callback(s). * Not final until the job has reached the CONCLUDED status. * 0 on success, -errno on failure. + * Protected by job_mutex. */ int ret; =20 @@ -131,37 +163,68 @@ typedef struct Job { * Error object for a failed job. * If job->ret is nonzero and an error object was not set, it will be = set * to strerror(-job->ret) during job_completed. + * Protected by job_mutex. */ Error *err; =20 - /** The completion function that will be called when the job completes= . */ + /** + * The completion function that will be called when the job completes. + * Set it in job_create and just read. + */ BlockCompletionFunc *cb; =20 - /** The opaque value that is passed to the completion function. */ + /** + * The opaque value that is passed to the completion function. + * Set it in job_create and just read. + */ void *opaque; =20 - /** Notifiers called when a cancelled job is finalised */ + /** + * Notifiers called when a cancelled job is finalised. + * Protected by job_mutex. + */ NotifierList on_finalize_cancelled; =20 - /** Notifiers called when a successfully completed job is finalised */ + /** + * Notifiers called when a successfully completed job is finalised. + * Protected by job_mutex. + */ NotifierList on_finalize_completed; =20 - /** Notifiers called when the job transitions to PENDING */ + /** + * Notifiers called when the job transitions to PENDING. + * Protected by job_mutex. + */ NotifierList on_pending; =20 - /** Notifiers called when the job transitions to READY */ + /** + * Notifiers called when the job transitions to READY. + * Protected by job_mutex. + */ NotifierList on_ready; =20 - /** Notifiers called when the job coroutine yields or terminates */ + /** + * Notifiers called when the job coroutine yields or terminates. + * Protected by job_mutex. + */ NotifierList on_idle; =20 - /** Element of the list of jobs */ + /** + * Element of the list of jobs. + * Protected by job_mutex. + */ QLIST_ENTRY(Job) job_list; =20 - /** Transaction this job is part of */ + /** + * Transaction this job is part of. + * Protected by job_mutex. + */ JobTxn *txn; =20 - /** Element of the list of jobs in a job transaction */ + /** + * Element of the list of jobs in a job transaction. + * Protected by job_mutex. + */ QLIST_ENTRY(Job) txn_list; } Job; =20 --=20 2.31.1