From patchwork Tue Feb 8 14:34:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emanuele Giuseppe Esposito X-Patchwork-Id: 1589972 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=EtBY8b0i; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JtSqF4YNqz9s09 for ; Wed, 9 Feb 2022 03:18:17 +1100 (AEDT) Received: from localhost ([::1]:56418 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHTC2-0000tc-Nu for incoming@patchwork.ozlabs.org; Tue, 08 Feb 2022 11:18:14 -0500 Received: from eggs.gnu.org ([209.51.188.92]:54814) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHRaj-0003Es-CE for qemu-devel@nongnu.org; Tue, 08 Feb 2022 09:35:38 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:33379) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHRae-0008CK-IS for qemu-devel@nongnu.org; Tue, 08 Feb 2022 09:35:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644330928; 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=gNBbZkukQ3AnjfEbC9paP9AFXWuGkbanuvLy2sbnq0I=; b=EtBY8b0ixcoHcYAqtU66njgbN6y1sQDS7Wn5K37uBb/WKkTPOWoYBtBbO4Kb8U+qRLr/Rv JdXuZxTUqhczwO2kui4NDzGj9VLgN1eGhGjvtlzbz6xta3Y0UDb2aCd+TM+lPNmomL8hfG 9ki0IRdiJP6rp/iy+V8J8IdDlD+mjbs= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-288-IiLzObvuN-S6zdu9pJhpMg-1; Tue, 08 Feb 2022 09:35:25 -0500 X-MC-Unique: IiLzObvuN-S6zdu9pJhpMg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 35DD68143F2; Tue, 8 Feb 2022 14:35:24 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4052E74E88; Tue, 8 Feb 2022 14:35:23 +0000 (UTC) From: Emanuele Giuseppe Esposito To: qemu-block@nongnu.org Subject: [PATCH v5 04/20] job.c: move inner aiocontext lock in callbacks Date: Tue, 8 Feb 2022 09:34:57 -0500 Message-Id: <20220208143513.1077229-5-eesposit@redhat.com> In-Reply-To: <20220208143513.1077229-1-eesposit@redhat.com> References: <20220208143513.1077229-1-eesposit@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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 Received-SPF: pass client-ip=170.10.133.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , Vladimir Sementsov-Ogievskiy , Wen Congyang , Xie Changlong , Emanuele Giuseppe Esposito , Markus Armbruster , qemu-devel@nongnu.org, Hanna Reitz , Stefan Hajnoczi , Paolo Bonzini , John Snow Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Instead of having the lock in job_tnx_apply, move it inside in the callback. This will be helpful for next commits, when we introduce job_lock/unlock pairs. job_transition_to_pending() and job_needs_finalize() do not need to be protected by the aiocontext lock. No functional change intended. Signed-off-by: Emanuele Giuseppe Esposito --- job.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/job.c b/job.c index f13939d3c6..d8c13ac0d1 100644 --- a/job.c +++ b/job.c @@ -149,7 +149,6 @@ static void job_txn_del_job(Job *job) static int job_txn_apply(Job *job, int fn(Job *)) { - AioContext *inner_ctx; Job *other_job, *next; JobTxn *txn = job->txn; int rc = 0; @@ -164,10 +163,7 @@ static int job_txn_apply(Job *job, int fn(Job *)) aio_context_release(job->aio_context); QLIST_FOREACH_SAFE(other_job, &txn->jobs, txn_list, next) { - inner_ctx = other_job->aio_context; - aio_context_acquire(inner_ctx); rc = fn(other_job); - aio_context_release(inner_ctx); if (rc) { break; } @@ -717,11 +713,15 @@ static void job_clean(Job *job) static int job_finalize_single(Job *job) { + AioContext *ctx = job->aio_context; + assert(job_is_completed(job)); /* Ensure abort is called for late-transactional failures */ job_update_rc(job); + aio_context_acquire(ctx); + if (!job->ret) { job_commit(job); } else { @@ -729,6 +729,8 @@ static int job_finalize_single(Job *job) } job_clean(job); + aio_context_release(ctx); + if (job->cb) { job->cb(job->opaque, job->ret); } @@ -833,8 +835,8 @@ static void job_completed_txn_abort(Job *job) assert(job_cancel_requested(other_job)); job_finish_sync(other_job, NULL, NULL); } - job_finalize_single(other_job); aio_context_release(ctx); + job_finalize_single(other_job); } /* @@ -849,11 +851,16 @@ static void job_completed_txn_abort(Job *job) static int job_prepare(Job *job) { + AioContext *ctx = job->aio_context; assert(qemu_in_main_thread()); + if (job->ret == 0 && job->driver->prepare) { + aio_context_acquire(ctx); job->ret = job->driver->prepare(job); + aio_context_release(ctx); job_update_rc(job); } + return job->ret; }