blk-cgroup: factor out blkcg_free_all_cpd()
authorJason Yan <yanaijie@huawei.com>
Wed, 29 Jun 2022 07:09:17 +0000 (15:09 +0800)
committerJens Axboe <axboe@kernel.dk>
Wed, 29 Jun 2022 17:09:53 +0000 (11:09 -0600)
To reduce some duplicated code, factor out blkcg_free_all_cpd(). No
functional change.

Signed-off-by: Jason Yan <yanaijie@huawei.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20220629070917.3113016-3-yanaijie@huawei.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/blk-cgroup.c

index 34a9452f93a7f1f9d82b8716ebdf3c988b300a8a..27a2d0ca0c707c545a0b5af46723ef6da88b6484 100644 (file)
@@ -1533,6 +1533,18 @@ void blkcg_deactivate_policy(struct request_queue *q,
 }
 EXPORT_SYMBOL_GPL(blkcg_deactivate_policy);
 
+static void blkcg_free_all_cpd(struct blkcg_policy *pol)
+{
+       struct blkcg *blkcg;
+
+       list_for_each_entry(blkcg, &all_blkcgs, all_blkcgs_node) {
+               if (blkcg->cpd[pol->plid]) {
+                       pol->cpd_free_fn(blkcg->cpd[pol->plid]);
+                       blkcg->cpd[pol->plid] = NULL;
+               }
+       }
+}
+
 /**
  * blkcg_policy_register - register a blkcg policy
  * @pol: blkcg policy to register
@@ -1597,14 +1609,9 @@ int blkcg_policy_register(struct blkcg_policy *pol)
        return 0;
 
 err_free_cpds:
-       if (pol->cpd_free_fn) {
-               list_for_each_entry(blkcg, &all_blkcgs, all_blkcgs_node) {
-                       if (blkcg->cpd[pol->plid]) {
-                               pol->cpd_free_fn(blkcg->cpd[pol->plid]);
-                               blkcg->cpd[pol->plid] = NULL;
-                       }
-               }
-       }
+       if (pol->cpd_free_fn)
+               blkcg_free_all_cpd(pol);
+
        blkcg_policy[pol->plid] = NULL;
 err_unlock:
        mutex_unlock(&blkcg_pol_mutex);
@@ -1621,8 +1628,6 @@ EXPORT_SYMBOL_GPL(blkcg_policy_register);
  */
 void blkcg_policy_unregister(struct blkcg_policy *pol)
 {
-       struct blkcg *blkcg;
-
        mutex_lock(&blkcg_pol_register_mutex);
 
        if (WARN_ON(blkcg_policy[pol->plid] != pol))
@@ -1637,14 +1642,9 @@ void blkcg_policy_unregister(struct blkcg_policy *pol)
        /* remove cpds and unregister */
        mutex_lock(&blkcg_pol_mutex);
 
-       if (pol->cpd_free_fn) {
-               list_for_each_entry(blkcg, &all_blkcgs, all_blkcgs_node) {
-                       if (blkcg->cpd[pol->plid]) {
-                               pol->cpd_free_fn(blkcg->cpd[pol->plid]);
-                               blkcg->cpd[pol->plid] = NULL;
-                       }
-               }
-       }
+       if (pol->cpd_free_fn)
+               blkcg_free_all_cpd(pol);
+
        blkcg_policy[pol->plid] = NULL;
 
        mutex_unlock(&blkcg_pol_mutex);