From patchwork Wed May 23 13:11:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 919054 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40rYKl2bjbz9s2R for ; Wed, 23 May 2018 23:30:19 +1000 (AEST) Received: from localhost ([::1]:33398 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fLTqL-0007CM-1V for incoming@patchwork.ozlabs.org; Wed, 23 May 2018 09:30:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53126) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fLTZI-00025Z-5B for qemu-devel@nongnu.org; Wed, 23 May 2018 09:12:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fLTZE-00079c-MK for qemu-devel@nongnu.org; Wed, 23 May 2018 09:12:40 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:36080 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fLTZ4-00072O-Ee; Wed, 23 May 2018 09:12:26 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 25B3040711C1; Wed, 23 May 2018 13:12:26 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.36.118.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 77C138578B; Wed, 23 May 2018 13:12:25 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 23 May 2018 15:11:36 +0200 Message-Id: <20180523131155.12359-28-kwolf@redhat.com> In-Reply-To: <20180523131155.12359-1-kwolf@redhat.com> References: <20180523131155.12359-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 23 May 2018 13:12:26 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 23 May 2018 13:12:26 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 27/46] job: Convert block_job_cancel_async() to Job 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: kwolf@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" block_job_cancel_async() did two things that were still block job specific: * Setting job->force. This field makes sense on the Job level, so we can just move it. While at it, rename it to job->force_cancel to make its purpose more obvious. * Resetting the I/O status. This can't be moved because generic Jobs don't have an I/O status. What the function really implements is a user resume, except without entering the coroutine. Consequently, it makes sense to call the .user_resume driver callback here which already resets the I/O status. The old block_job_cancel_async() has two separate if statements that check job->iostatus != BLOCK_DEVICE_IO_STATUS_OK and job->user_paused. However, the former condition always implies the latter (as is asserted in block_job_iostatus_reset()), so changing the explicit call of block_job_iostatus_reset() on the former condition with the .user_resume callback on the latter condition is equivalent and doesn't need to access any BlockJob specific state. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- include/block/blockjob.h | 6 ------ include/qemu/job.h | 6 ++++++ block/mirror.c | 4 ++-- blockjob.c | 25 +++++++++++++------------ 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/include/block/blockjob.h b/include/block/blockjob.h index 3f405d1fa7..d975efea20 100644 --- a/include/block/blockjob.h +++ b/include/block/blockjob.h @@ -51,12 +51,6 @@ typedef struct BlockJob { BlockBackend *blk; /** - * Set to true if the job should abort immediately without waiting - * for data to be in sync. - */ - bool force; - - /** * Set to true when the job is ready to be completed. */ bool ready; diff --git a/include/qemu/job.h b/include/qemu/job.h index 3e817beee9..2648c74281 100644 --- a/include/qemu/job.h +++ b/include/qemu/job.h @@ -97,6 +97,12 @@ typedef struct Job { */ bool cancelled; + /** + * Set to true if the job should abort immediately without waiting + * for data to be in sync. + */ + bool force_cancel; + /** Set to true when the job has deferred work to the main loop. */ bool deferred_to_main_loop; diff --git a/block/mirror.c b/block/mirror.c index e9a90ea730..c3951d1ca2 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -871,7 +871,7 @@ static void coroutine_fn mirror_run(void *opaque) trace_mirror_before_sleep(s, cnt, s->synced, delay_ns); job_sleep_ns(&s->common.job, delay_ns); if (job_is_cancelled(&s->common.job) && - (!s->synced || s->common.force)) + (!s->synced || s->common.job.force_cancel)) { break; } @@ -884,7 +884,7 @@ immediate_exit: * or it was cancelled prematurely so that we do not guarantee that * the target is a copy of the source. */ - assert(ret < 0 || ((s->common.force || !s->synced) && + assert(ret < 0 || ((s->common.job.force_cancel || !s->synced) && job_is_cancelled(&s->common.job))); assert(need_drain); mirror_wait_for_all_io(s); diff --git a/blockjob.c b/blockjob.c index 34c57da304..4cac3670ad 100644 --- a/blockjob.c +++ b/blockjob.c @@ -270,19 +270,20 @@ static int block_job_prepare(BlockJob *job) return job->job.ret; } -static void block_job_cancel_async(BlockJob *job, bool force) +static void job_cancel_async(Job *job, bool force) { - if (job->iostatus != BLOCK_DEVICE_IO_STATUS_OK) { - block_job_iostatus_reset(job); - } - if (job->job.user_paused) { - /* Do not call block_job_enter here, the caller will handle it. */ - job->job.user_paused = false; - job->job.pause_count--; + if (job->user_paused) { + /* Do not call job_enter here, the caller will handle it. */ + job->user_paused = false; + if (job->driver->user_resume) { + job->driver->user_resume(job); + } + assert(job->pause_count > 0); + job->pause_count--; } - job->job.cancelled = true; + job->cancelled = true; /* To prevent 'force == false' overriding a previous 'force == true' */ - job->force |= force; + job->force_cancel |= force; } static int block_job_txn_apply(BlockJobTxn *txn, int fn(BlockJob *), bool lock) @@ -367,7 +368,7 @@ static void block_job_completed_txn_abort(BlockJob *job) * on the caller, so leave it. */ QLIST_FOREACH(other_job, &txn->jobs, txn_list) { if (other_job != job) { - block_job_cancel_async(other_job, false); + job_cancel_async(&other_job->job, false); } } while (!QLIST_EMPTY(&txn->jobs)) { @@ -527,7 +528,7 @@ void block_job_cancel(BlockJob *job, bool force) job_do_dismiss(&job->job); return; } - block_job_cancel_async(job, force); + job_cancel_async(&job->job, force); if (!job_started(&job->job)) { block_job_completed(job, -ECANCELED); } else if (job->job.deferred_to_main_loop) {