From patchwork Wed May 9 16:26:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10390067 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 16A9860170 for ; Wed, 9 May 2018 16:46:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 05BBC2863E for ; Wed, 9 May 2018 16:46:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EE6FB28640; Wed, 9 May 2018 16:46:49 +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=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, 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 6C5332863E for ; Wed, 9 May 2018 16:46:49 +0000 (UTC) Received: from localhost ([::1]:57642 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGSEq-0000pt-Nz for patchwork-qemu-devel@patchwork.kernel.org; Wed, 09 May 2018 12:46:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52616) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGRwW-0005nm-OH for qemu-devel@nongnu.org; Wed, 09 May 2018 12:27:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fGRwV-0002Xk-FM for qemu-devel@nongnu.org; Wed, 09 May 2018 12:27:52 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:42988 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 1fGRwP-0002NL-QM; Wed, 09 May 2018 12:27:45 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0051B77067; Wed, 9 May 2018 16:27:45 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-193.ams2.redhat.com [10.36.117.193]) by smtp.corp.redhat.com (Postfix) with ESMTP id A5C4C2023433; Wed, 9 May 2018 16:27:43 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 9 May 2018 18:26:21 +0200 Message-Id: <20180509162637.15575-27-kwolf@redhat.com> In-Reply-To: <20180509162637.15575-1-kwolf@redhat.com> References: <20180509162637.15575-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Wed, 09 May 2018 16:27:45 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Wed, 09 May 2018 16:27:45 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.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] [PATCH 26/42] 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, jcody@redhat.com, armbru@redhat.com, mreitz@redhat.com, jsnow@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 e5af02f751..8477fc5a78 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 12edb822d8..b96ec10413 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 dcf0856c97..f18240e34c 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 9280e92062..ca88e166e1 100644 --- a/blockjob.c +++ b/blockjob.c @@ -271,19 +271,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) @@ -368,7 +369,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)) { @@ -528,7 +529,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) {