From patchwork Tue Nov 1 12:51:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Cody X-Patchwork-Id: 9407353 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 8282B60585 for ; Tue, 1 Nov 2016 13:00:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 73C692984A for ; Tue, 1 Nov 2016 13:00:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 668372980E; Tue, 1 Nov 2016 13:00:51 +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 055A62980E for ; Tue, 1 Nov 2016 13:00:51 +0000 (UTC) Received: from localhost ([::1]:47708 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c1YgL-0003Vj-VH for patchwork-qemu-devel@patchwork.kernel.org; Tue, 01 Nov 2016 09:00:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34113) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c1YXW-0004Xx-4b for qemu-devel@nongnu.org; Tue, 01 Nov 2016 08:51:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c1YXV-0003pB-4R for qemu-devel@nongnu.org; Tue, 01 Nov 2016 08:51:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33146) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1c1YXS-0003nb-6v; Tue, 01 Nov 2016 08:51:38 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 65D6D80B56; Tue, 1 Nov 2016 12:51:37 +0000 (UTC) Received: from localhost (ovpn-112-28.phx2.redhat.com [10.3.112.28]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uA1Cpak7017681 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 1 Nov 2016 08:51:37 -0400 From: Jeff Cody To: qemu-block@nongnu.org Date: Tue, 1 Nov 2016 08:51:09 -0400 Message-Id: <1478004671-19154-13-git-send-email-jcody@redhat.com> In-Reply-To: <1478004671-19154-1-git-send-email-jcody@redhat.com> References: <1478004671-19154-1-git-send-email-jcody@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 01 Nov 2016 12:51:37 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL v2 12/14] Blockjobs: Internalize user_pause logic 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 Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: John Snow BlockJobs will begin hiding their state in preparation for some refactorings anyway, so let's internalize the user_pause mechanism instead of leaving it to callers to correctly manage. Signed-off-by: John Snow Reviewed-by: Kevin Wolf Reviewed-by: Jeff Cody Message-id: 1477584421-1399-6-git-send-email-jsnow@redhat.com Signed-off-by: Jeff Cody --- blockdev.c | 12 +++++------- blockjob.c | 22 ++++++++++++++++++++-- include/block/blockjob.h | 26 ++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 9 deletions(-) diff --git a/blockdev.c b/blockdev.c index b6a74916..102ca9f 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3610,7 +3610,7 @@ void qmp_block_job_cancel(const char *device, force = false; } - if (job->user_paused && !force) { + if (block_job_user_paused(job) && !force) { error_setg(errp, "The block job for device '%s' is currently paused", device); goto out; @@ -3627,13 +3627,12 @@ void qmp_block_job_pause(const char *device, Error **errp) AioContext *aio_context; BlockJob *job = find_block_job(device, &aio_context, errp); - if (!job || job->user_paused) { + if (!job || block_job_user_paused(job)) { return; } - job->user_paused = true; trace_qmp_block_job_pause(job); - block_job_pause(job); + block_job_user_pause(job); aio_context_release(aio_context); } @@ -3642,14 +3641,13 @@ void qmp_block_job_resume(const char *device, Error **errp) AioContext *aio_context; BlockJob *job = find_block_job(device, &aio_context, errp); - if (!job || !job->user_paused) { + if (!job || !block_job_user_paused(job)) { return; } - job->user_paused = false; trace_qmp_block_job_resume(job); block_job_iostatus_reset(job); - block_job_resume(job); + block_job_user_resume(job); aio_context_release(aio_context); } diff --git a/blockjob.c b/blockjob.c index 309ef9a..d880ad2 100644 --- a/blockjob.c +++ b/blockjob.c @@ -373,11 +373,22 @@ void block_job_pause(BlockJob *job) job->pause_count++; } +void block_job_user_pause(BlockJob *job) +{ + job->user_paused = true; + block_job_pause(job); +} + static bool block_job_should_pause(BlockJob *job) { return job->pause_count > 0; } +bool block_job_user_paused(BlockJob *job) +{ + return job ? job->user_paused : 0; +} + void coroutine_fn block_job_pause_point(BlockJob *job) { if (!block_job_should_pause(job)) { @@ -414,6 +425,14 @@ void block_job_resume(BlockJob *job) block_job_enter(job); } +void block_job_user_resume(BlockJob *job) +{ + if (job && job->user_paused && job->pause_count > 0) { + job->user_paused = false; + block_job_resume(job); + } +} + void block_job_enter(BlockJob *job) { if (job->co && !job->busy) { @@ -644,8 +663,7 @@ BlockErrorAction block_job_error_action(BlockJob *job, BlockdevOnError on_err, } if (action == BLOCK_ERROR_ACTION_STOP) { /* make the pause user visible, which will be resumed from QMP. */ - job->user_paused = true; - block_job_pause(job); + block_job_user_pause(job); block_job_iostatus_set_err(job, error); } return action; diff --git a/include/block/blockjob.h b/include/block/blockjob.h index c031fe7..d31ea43 100644 --- a/include/block/blockjob.h +++ b/include/block/blockjob.h @@ -379,6 +379,23 @@ void coroutine_fn block_job_pause_point(BlockJob *job); void block_job_pause(BlockJob *job); /** + * block_job_user_pause: + * @job: The job to be paused. + * + * Asynchronously pause the specified job. + * Do not allow a resume until a matching call to block_job_user_resume. + */ +void block_job_user_pause(BlockJob *job); + +/** + * block_job_paused: + * @job: The job to query. + * + * Returns true if the job is user-paused. + */ +bool block_job_user_paused(BlockJob *job); + +/** * block_job_resume: * @job: The job to be resumed. * @@ -387,6 +404,15 @@ void block_job_pause(BlockJob *job); void block_job_resume(BlockJob *job); /** + * block_job_user_resume: + * @job: The job to be resumed. + * + * Resume the specified job. + * Must be paired with a preceding block_job_user_pause. + */ +void block_job_user_resume(BlockJob *job); + +/** * block_job_enter: * @job: The job to enter. *