From nobody Tue Apr 15 06:11:09 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 149582693124173.18152117533339; Fri, 26 May 2017 12:28:51 -0700 (PDT) Received: from localhost ([::1]:38100 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dEKum-0007fQ-MH for importer@patchew.org; Fri, 26 May 2017 15:28:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46281) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dEKqY-0002Tf-PI for qemu-devel@nongnu.org; Fri, 26 May 2017 15:24:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dEKqX-0005xs-NN for qemu-devel@nongnu.org; Fri, 26 May 2017 15:24:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34652) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dEKqS-0005v9-60; Fri, 26 May 2017 15:24:20 -0400 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 mx1.redhat.com (Postfix) with ESMTPS id 2E2583D943; Fri, 26 May 2017 19:24:19 +0000 (UTC) Received: from localhost (ovpn-117-108.phx2.redhat.com [10.3.117.108]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EF455176C7; Fri, 26 May 2017 19:24:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2E2583D943 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jcody@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 2E2583D943 From: Jeff Cody To: qemu-block@nongnu.org Date: Fri, 26 May 2017 15:23:59 -0400 Message-Id: <20170526192404.32186-8-jcody@redhat.com> In-Reply-To: <20170526192404.32186-1-jcody@redhat.com> References: <20170526192404.32186-1-jcody@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 26 May 2017 19:24:19 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 07/12] blockjob: introduce block_job_cancel_async, check iostatus invariants X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, jcody@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com, Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paolo Bonzini The new functions helps respecting the invariant that the coroutine is entered with false user_resume, zero pause count and no error recorded in the iostatus. Resetting the iostatus is now common to all of block_job_cancel_async, block_job_user_resume and block_job_iostatus_reset, albeit with slight differences: - block_job_cancel_async resets the iostatus, and resumes the job if there was an error, but the coroutine is not restarted immediately. For example the caller may continue with a call to block_job_finish_sync. - block_job_user_resume resets the iostatus. It wants to resume the job unconditionally, even if there was no error. - block_job_iostatus_reset doesn't resume the job at all. Maybe that's a bug but it should be fixed separately. block_job_iostatus_reset does the least common denominator, so add some checking but otherwise leave it as the entry point for resetting the iostatus. Reviewed-by: Stefan Hajnoczi Signed-off-by: Paolo Bonzini Message-id: 20170508141310.8674-8-pbonzini@redhat.com Signed-off-by: Jeff Cody --- blockjob.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/blockjob.c b/blockjob.c index cd1f4c0..eae8fe7 100644 --- a/blockjob.c +++ b/blockjob.c @@ -304,6 +304,19 @@ static void block_job_completed_single(BlockJob *job) block_job_unref(job); } =20 +static void block_job_cancel_async(BlockJob *job) +{ + if (job->iostatus !=3D BLOCK_DEVICE_IO_STATUS_OK) { + block_job_iostatus_reset(job); + } + if (job->user_paused) { + /* Do not call block_job_enter here, the caller will handle it. */ + job->user_paused =3D false; + job->pause_count--; + } + job->cancelled =3D true; +} + static void block_job_completed_txn_abort(BlockJob *job) { AioContext *ctx; @@ -328,7 +341,7 @@ static void block_job_completed_txn_abort(BlockJob *job) * them; this job, however, may or may not be cancelled, depen= ding * on the caller, so leave it. */ if (other_job !=3D job) { - other_job->cancelled =3D true; + block_job_cancel_async(other_job); } continue; } @@ -411,8 +424,8 @@ bool block_job_user_paused(BlockJob *job) void block_job_user_resume(BlockJob *job) { if (job && job->user_paused && job->pause_count > 0) { - job->user_paused =3D false; block_job_iostatus_reset(job); + job->user_paused =3D false; block_job_resume(job); } } @@ -420,8 +433,7 @@ void block_job_user_resume(BlockJob *job) void block_job_cancel(BlockJob *job) { if (block_job_started(job)) { - job->cancelled =3D true; - block_job_iostatus_reset(job); + block_job_cancel_async(job); block_job_enter(job); } else { block_job_completed(job, -ECANCELED); @@ -765,6 +777,10 @@ void block_job_yield(BlockJob *job) =20 void block_job_iostatus_reset(BlockJob *job) { + if (job->iostatus =3D=3D BLOCK_DEVICE_IO_STATUS_OK) { + return; + } + assert(job->user_paused && job->pause_count > 0); job->iostatus =3D BLOCK_DEVICE_IO_STATUS_OK; } =20 --=20 2.9.3