From nobody Tue Feb 10 14:49:52 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E8DBD18C33; Tue, 3 Feb 2026 08:06:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770105983; cv=none; b=Mw/m5Lcb8eYnSZU50gIklL9YL8GsGdZvNuOKLJeZbuzYE6m6aZ69Q3oMaceLOlEmjn8tUNvjXvKPhF++szE7jFFVxt5sT3S2zUhO9UMnxVhAi/to4d/CqnEPStF9H3QXXCEHd5sZoMtc8378SgDJeAIWnmf4hkOW8BXvMKJ1haw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770105983; c=relaxed/simple; bh=HHnajLh6kYJlxQ+LpyBqhym9lefYoo/+5GGH5ivhc2U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UHclmg9WlOI2kYXuaR+u7uM9k7EMVsUeENUuh5yrTFwzP4A6E3aaV2Z46u/udAuogbITZnyVf1bAiHspS8qjZ+xi1U4RL5WDynNh407U8W7pynLtTg6Es0ihUFiB0zt/fa1R+6udoVR5wAg6Lz8jMZHgNA7WQBRlYWJUB2BtGjQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1C6EFC19421; Tue, 3 Feb 2026 08:06:20 +0000 (UTC) From: Yu Kuai To: tj@kernel.org, josef@toxicpanda.com, axboe@kernel.dk Cc: cgroups@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, yukuai@fnnas.com, zhengqixing@huawei.com, mkoutny@suse.com, hch@infradead.org, ming.lei@redhat.com, nilay@linux.ibm.com Subject: [PATCH v2 5/7] blk-cgroup: factor policy pd teardown loop into helper Date: Tue, 3 Feb 2026 16:06:00 +0800 Message-ID: <20260203080602.726505-6-yukuai@fnnas.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260203080602.726505-1-yukuai@fnnas.com> References: <20260203080602.726505-1-yukuai@fnnas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Zheng Qixing Move the teardown sequence which offlines and frees per-policy blkg_policy_data (pd) into a helper for readability. No functional change intended. Signed-off-by: Zheng Qixing Reviewed-by: Christoph Hellwig Reviewed-by: Yu Kuai Signed-off-by: Yu Kuai --- block/blk-cgroup.c | 58 +++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 31 deletions(-) diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c index f5b14a1d6973..0206050f81ea 100644 --- a/block/blk-cgroup.c +++ b/block/blk-cgroup.c @@ -1562,6 +1562,31 @@ struct cgroup_subsys io_cgrp_subsys =3D { }; EXPORT_SYMBOL_GPL(io_cgrp_subsys); =20 +/* + * Tear down per-blkg policy data for @pol on @q. + */ +static void blkcg_policy_teardown_pds(struct request_queue *q, + const struct blkcg_policy *pol) +{ + struct blkcg_gq *blkg; + + list_for_each_entry(blkg, &q->blkg_list, q_node) { + struct blkcg *blkcg =3D blkg->blkcg; + struct blkg_policy_data *pd; + + spin_lock(&blkcg->lock); + pd =3D blkg->pd[pol->plid]; + if (pd) { + if (pd->online && pol->pd_offline_fn) + pol->pd_offline_fn(pd); + pd->online =3D false; + pol->pd_free_fn(pd); + blkg->pd[pol->plid] =3D NULL; + } + spin_unlock(&blkcg->lock); + } +} + /** * blkcg_activate_policy - activate a blkcg policy on a gendisk * @disk: gendisk of interest @@ -1677,21 +1702,7 @@ int blkcg_activate_policy(struct gendisk *disk, cons= t struct blkcg_policy *pol) enomem: /* alloc failed, take down everything */ spin_lock_irq(&q->queue_lock); - list_for_each_entry(blkg, &q->blkg_list, q_node) { - struct blkcg *blkcg =3D blkg->blkcg; - struct blkg_policy_data *pd; - - spin_lock(&blkcg->lock); - pd =3D blkg->pd[pol->plid]; - if (pd) { - if (pd->online && pol->pd_offline_fn) - pol->pd_offline_fn(pd); - pd->online =3D false; - pol->pd_free_fn(pd); - blkg->pd[pol->plid] =3D NULL; - } - spin_unlock(&blkcg->lock); - } + blkcg_policy_teardown_pds(q, pol); spin_unlock_irq(&q->queue_lock); ret =3D -ENOMEM; goto out; @@ -1710,7 +1721,6 @@ void blkcg_deactivate_policy(struct gendisk *disk, const struct blkcg_policy *pol) { struct request_queue *q =3D disk->queue; - struct blkcg_gq *blkg; unsigned int memflags; =20 if (!blkcg_policy_enabled(q, pol)) @@ -1721,22 +1731,8 @@ void blkcg_deactivate_policy(struct gendisk *disk, =20 mutex_lock(&q->blkcg_mutex); spin_lock_irq(&q->queue_lock); - __clear_bit(pol->plid, q->blkcg_pols); - - list_for_each_entry(blkg, &q->blkg_list, q_node) { - struct blkcg *blkcg =3D blkg->blkcg; - - spin_lock(&blkcg->lock); - if (blkg->pd[pol->plid]) { - if (blkg->pd[pol->plid]->online && pol->pd_offline_fn) - pol->pd_offline_fn(blkg->pd[pol->plid]); - pol->pd_free_fn(blkg->pd[pol->plid]); - blkg->pd[pol->plid] =3D NULL; - } - spin_unlock(&blkcg->lock); - } - + blkcg_policy_teardown_pds(q, pol); spin_unlock_irq(&q->queue_lock); mutex_unlock(&q->blkcg_mutex); =20 --=20 2.51.0