From nobody Mon Apr 29 18:54:05 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=1564739603; cv=none; d=zoho.com; s=zohoarc; b=dJW2hZ7ipjpsnR8kp66QzpQNVoyCMqXkM014Xvidc5Q5vX20OT4nVZKXR75ZpGdypMOnYVzkPpGIxEg7MnS26cRZe3VJP2JWxqRqV+gFJwZYvws8s/dAfyW1ieMCSl6Dt0PUNclyibZoyUfW+e8xIFTnoayuVyoN+X94U6fbaNw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1564739603; h=Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=CKshKRrd3G8rjg7NYFCMvjwLIMzttpk5qgznCDJdvGo=; b=ZaOoGb6fy9PXMOV7/E72JHyq2OJ9lNHsBEIVD2Jo4f9E11ySJS8cQbNcuKXvkbzvm1xFjRl6RGpmQw7FYQAo4t4FMtMDKVlaMY76AhzDWD5AySxfOpPERzeHaP+UhiCit4w1kxSWjr9Yak7G9VshcrTCxo6yyy7Cyj0SVTJYnY4= 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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1564739603656987.2038129706434; Fri, 2 Aug 2019 02:53:23 -0700 (PDT) Received: from localhost ([::1]:33132 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1htUFO-0000Bo-GK for importer@patchew.org; Fri, 02 Aug 2019 05:53:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58017) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1htUEx-00088s-Qn for qemu-devel@nongnu.org; Fri, 02 Aug 2019 05:52:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1htUEw-0001WH-HF for qemu-devel@nongnu.org; Fri, 02 Aug 2019 05:52:47 -0400 Received: from relay.sw.ru ([185.231.240.75]:50418) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1htUEt-0001Uq-NX; Fri, 02 Aug 2019 05:52: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 1htUEq-0006c4-5d; Fri, 02 Aug 2019 12:52:40 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Date: Fri, 2 Aug 2019 12:52:39 +0300 Message-Id: <20190802095239.31975-1-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH v4] 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, qemu-devel@nongnu.org, mreitz@redhat.com, den@openvz.org, jsnow@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 --- v4: keep ref/unref around job nodes draining [John, Max] v3: just resend, as I've some auto returned mails and not sure that v2 reached recipients. 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 | 22 +++++++++++++++++----- 4 files changed, 21 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 8cb75fb409..8456ccd89d 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 20b7f557da..f64ee3197b 100644 --- a/blockjob.c +++ b/blockjob.c @@ -92,13 +92,25 @@ 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 *nodes =3D NULL, *el; =20 - blk_drain(bjob->blk); - if (bjdrv->drain) { - bjdrv->drain(bjob); + for (el =3D bjob->nodes; el; el =3D el->next) { + BdrvChild *c =3D el->data; + bdrv_ref(c->bs); + nodes =3D g_slist_prepend(nodes, c->bs); + } + + for (el =3D nodes; el; el =3D el->next) { + BlockDriverState *bs =3D el->data; + bdrv_drained_begin(bs); } + for (el =3D nodes; el; el =3D el->next) { + BlockDriverState *bs =3D el->data; + bdrv_drained_end(bs); + bdrv_unref(bs); + } + + g_slist_free(nodes); } =20 static char *child_job_get_parent_desc(BdrvChild *c) --=20 2.18.0