From nobody Tue May 14 09:11:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1561130476; cv=none; d=zoho.com; s=zohoarc; b=gL/7aJ0NnZzp1K6SAFqK+G43/mJjnKWHoogOB7+gTojOjoUhdEZaPTaNmbidSDFohA69QKICX0fWe3fstY2CdCFnn6IMdmXfMJS+Ia0ok0dYJU1TkoyXtfn2kavrjzHbPfpIC4wZM9IUK2xPj9ZdhzDBhjEfkXi40NiNvNQTtvo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1561130476; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=rJiWNZ+tHgzghpF6i5+FrpObDB/X40r06ZYzik65kg8=; b=MODdR0X/666hfYMp4Cr4e3WSwnhBD4Z9lIHUZt1pNlEMp2a7kUPnJd+v/fxYOBtdml5m0BTO/D9JOFLHtL411O0HfKNs0A6pd5emjOt9IXFSpMjFtt498HZ8fxUgsA3lutk92C8ufOaHACH8V4yxicrtX3uG0jX+BOxWQ5foMrI= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1561130476207546.5524606168915; Fri, 21 Jun 2019 08:21:16 -0700 (PDT) Received: from localhost ([::1]:36058 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1heLLm-0007Eu-RU for importer@patchew.org; Fri, 21 Jun 2019 11:21:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54138) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1heLGT-00037O-75 for qemu-devel@nongnu.org; Fri, 21 Jun 2019 11:15:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1heLGR-00078H-Il for qemu-devel@nongnu.org; Fri, 21 Jun 2019 11:15:45 -0400 Received: from relay.sw.ru ([185.231.240.75]:37038) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1heLGR-000762-8d; Fri, 21 Jun 2019 11:15:43 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1heLGN-0002HP-7Z; Fri, 21 Jun 2019 18:15:39 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Fri, 21 Jun 2019 18:15:38 +0300 Message-Id: <20190621151538.30384-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190621151538.30384-1-vsementsov@virtuozzo.com> References: <20190621151538.30384-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH v2] blockjob: drain all job nodes in block_job_drain X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, jsnow@redhat.com, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Instead of draining additional nodes in each job code, let's do it in common block_job_drain, draining just all job's children. BlockJobDriver.drain becomes unused, so, drop it at all. It's also a first step to finally get rid of blockjob->blk. Signed-off-by: Vladimir Sementsov-Ogievskiy --- v2: apply Max's suggestions: - drop BlockJobDriver.drain - do firtly loop of bdrv_drained_begin and then separate loop of bdrv_drained_end. Hmm, a question here: should I call bdrv_drained_end in reverse order? Or it's OK as is? include/block/blockjob_int.h | 11 ----------- block/backup.c | 18 +----------------- block/mirror.c | 26 +++----------------------- blockjob.c | 13 ++++++++----- 4 files changed, 12 insertions(+), 56 deletions(-) diff --git a/include/block/blockjob_int.h b/include/block/blockjob_int.h index e4a318dd15..e1abf4ee85 100644 --- a/include/block/blockjob_int.h +++ b/include/block/blockjob_int.h @@ -52,17 +52,6 @@ struct BlockJobDriver { * besides job->blk to the new AioContext. */ void (*attached_aio_context)(BlockJob *job, AioContext *new_context); - - /* - * If the callback is not NULL, it will be invoked when the job has to= be - * synchronously cancelled or completed; it should drain BlockDriverSt= ates - * as required to ensure progress. - * - * Block jobs must use the default implementation for job_driver.drain, - * which will in turn call this callback after doing generic block job - * stuff. - */ - void (*drain)(BlockJob *job); }; =20 /** diff --git a/block/backup.c b/block/backup.c index 715e1d3be8..7930004bbd 100644 --- a/block/backup.c +++ b/block/backup.c @@ -320,21 +320,6 @@ void backup_do_checkpoint(BlockJob *job, Error **errp) hbitmap_set(backup_job->copy_bitmap, 0, backup_job->len); } =20 -static void backup_drain(BlockJob *job) -{ - BackupBlockJob *s =3D container_of(job, BackupBlockJob, common); - - /* Need to keep a reference in case blk_drain triggers execution - * of backup_complete... - */ - if (s->target) { - BlockBackend *target =3D s->target; - blk_ref(target); - blk_drain(target); - blk_unref(target); - } -} - static BlockErrorAction backup_error_action(BackupBlockJob *job, bool read, int error) { @@ -493,8 +478,7 @@ static const BlockJobDriver backup_job_driver =3D { .commit =3D backup_commit, .abort =3D backup_abort, .clean =3D backup_clean, - }, - .drain =3D backup_drain, + } }; =20 static int64_t backup_calculate_cluster_size(BlockDriverState *target, diff --git a/block/mirror.c b/block/mirror.c index d17be4cdbc..6bea99558f 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -644,14 +644,11 @@ static int mirror_exit_common(Job *job) bdrv_ref(mirror_top_bs); bdrv_ref(target_bs); =20 - /* Remove target parent that still uses BLK_PERM_WRITE/RESIZE before + /* + * Remove target parent that still uses BLK_PERM_WRITE/RESIZE before * inserting target_bs at s->to_replace, where we might not be able to= get * these permissions. - * - * Note that blk_unref() alone doesn't necessarily drop permissions be= cause - * we might be running nested inside mirror_drain(), which takes an ex= tra - * reference, so use an explicit blk_set_perm() first. */ - blk_set_perm(s->target, 0, BLK_PERM_ALL, &error_abort); + */ blk_unref(s->target); s->target =3D NULL; =20 @@ -1143,21 +1140,6 @@ static bool mirror_drained_poll(BlockJob *job) return !!s->in_flight; } =20 -static void mirror_drain(BlockJob *job) -{ - MirrorBlockJob *s =3D container_of(job, MirrorBlockJob, common); - - /* Need to keep a reference in case blk_drain triggers execution - * of mirror_complete... - */ - if (s->target) { - BlockBackend *target =3D s->target; - blk_ref(target); - blk_drain(target); - blk_unref(target); - } -} - static const BlockJobDriver mirror_job_driver =3D { .job_driver =3D { .instance_size =3D sizeof(MirrorBlockJob), @@ -1172,7 +1154,6 @@ static const BlockJobDriver mirror_job_driver =3D { .complete =3D mirror_complete, }, .drained_poll =3D mirror_drained_poll, - .drain =3D mirror_drain, }; =20 static const BlockJobDriver commit_active_job_driver =3D { @@ -1189,7 +1170,6 @@ static const BlockJobDriver commit_active_job_driver = =3D { .complete =3D mirror_complete, }, .drained_poll =3D mirror_drained_poll, - .drain =3D mirror_drain, }; =20 static void coroutine_fn diff --git a/blockjob.c b/blockjob.c index 458ae76f51..059dc199ba 100644 --- a/blockjob.c +++ b/blockjob.c @@ -92,12 +92,15 @@ void block_job_free(Job *job) void block_job_drain(Job *job) { BlockJob *bjob =3D container_of(job, BlockJob, job); - const JobDriver *drv =3D job->driver; - BlockJobDriver *bjdrv =3D container_of(drv, BlockJobDriver, job_driver= ); + GSList *l; =20 - blk_drain(bjob->blk); - if (bjdrv->drain) { - bjdrv->drain(bjob); + for (l =3D bjob->nodes; l; l =3D l->next) { + BdrvChild *c =3D l->data; + bdrv_drained_begin(c->bs); + } + for (l =3D bjob->nodes; l; l =3D l->next) { + BdrvChild *c =3D l->data; + bdrv_drained_end(c->bs); } } =20 --=20 2.18.0