From patchwork Fri May 26 19:23:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Cody X-Patchwork-Id: 9751035 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4686C60209 for ; Fri, 26 May 2017 19:28:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 362D32843C for ; Fri, 26 May 2017 19:28:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2B2BB28446; Fri, 26 May 2017 19:28:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C1F5D2843C for ; Fri, 26 May 2017 19:28:22 +0000 (UTC) Received: from localhost ([::1]:38096 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dEKuL-00050Z-TT for patchwork-qemu-devel@patchwork.kernel.org; Fri, 26 May 2017 15:28:22 -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) 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 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) 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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); } +static void block_job_cancel_async(BlockJob *job) +{ + if (job->iostatus != 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 = false; + job->pause_count--; + } + job->cancelled = 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, depending * on the caller, so leave it. */ if (other_job != job) { - other_job->cancelled = 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 = false; block_job_iostatus_reset(job); + job->user_paused = 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 = 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) void block_job_iostatus_reset(BlockJob *job) { + if (job->iostatus == BLOCK_DEVICE_IO_STATUS_OK) { + return; + } + assert(job->user_paused && job->pause_count > 0); job->iostatus = BLOCK_DEVICE_IO_STATUS_OK; }