Skip to contentSkip to conversation

Add wrapper for blkcg policy operatins

PATCH In review weiping zhang 1 participant 4 messages Sep 1, 2017 – Sep 15, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover Add wrapper for blkcg policy operatins

The first patch is the V2 of [PATCH] blkcg: check pol->cpd_free_fn before free cpd, it fixs a checking before free cpd.

The second patch add some wrappers for struct blkcg_policy->xxx_fn, because not every block cgroup policy implement all operations.

weiping zhang (2):
blkcg: check pol->cpd_free_fn before free cpd
blkcg: add wrappers for struct blkcg_policy operations

 block/blk-cgroup.c         | 57 +++++++++++++++++-------------------
 include/linux/blk-cgroup.h | 72 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 99 insertions(+), 30 deletions(-)
Signature · 1 line
2.9.4
#1 lore raw

PATCH v2 1/2 blkcg: check pol->cpd_free_fn before free cpd

check pol->cpd_free_fn() instead of pol->cpd_alloc_fn() when free cpd.

---
 block/blk-cgroup.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
block/blk-cgroup.c +2 -2
index 0480892..0c45870 100644
@@ -1450,7 +1450,7 @@ int blkcg_policy_register(struct blkcg_policy *pol)
 	return 0;
 
 err_free_cpds:
-	if (pol->cpd_alloc_fn) {
+	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]);
@@ -1490,7 +1490,7 @@ void blkcg_policy_unregister(struct blkcg_policy *pol)
 	/* remove cpds and unregister */
 	mutex_lock(&blkcg_pol_mutex);
 
-	if (pol->cpd_alloc_fn) {
+	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]);
Signature · 1 line
2.9.4
#2 lore raw

PATCH v2 2/2 blkcg: add wrappers for struct blkcg_policy operations

In reply to weiping zhang

Some blkcg policies may not implement all operations in struct blkcg_policy, add wrappers for these pol->xxx_fn.

---
 block/blk-cgroup.c         | 53 ++++++++++++++++------------------
 include/linux/blk-cgroup.h | 72 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 97 insertions(+), 28 deletions(-)
block/blk-cgroup.c +25 -28
index 0c45870..8588739 100644
@@ -71,7 +71,7 @@ static void blkg_free(struct blkcg_gq *blkg)
 
 	for (i = 0; i < BLKCG_MAX_POLS; i++)
 		if (blkg->pd[i])
-			blkcg_policy[i]->pd_free_fn(blkg->pd[i]);
+			blkg_pol_free_pd(blkcg_policy[i], blkg->pd[i]);
 
 	if (blkg->blkcg != &blkcg_root)
 		blk_exit_rl(blkg->q, &blkg->rl);
@@ -124,7 +124,7 @@ static struct blkcg_gq *blkg_alloc(struct blkcg *blkcg, struct request_queue *q,
 			continue;
 
 		/* alloc per-policy data and attach it to blkg */
-		pd = pol->pd_alloc_fn(gfp_mask, q->node);
+		pd = blkg_pol_alloc_pd(pol, gfp_mask, q->node);
 		if (!pd)
 			goto err_free;
 
@@ -218,8 +218,8 @@ static struct blkcg_gq *blkg_create(struct blkcg *blkcg,
 	for (i = 0; i < BLKCG_MAX_POLS; i++) {
 		struct blkcg_policy *pol = blkcg_policy[i];
 
-		if (blkg->pd[i] && pol->pd_init_fn)
-			pol->pd_init_fn(blkg->pd[i]);
+		if (blkg->pd[i])
+			blkg_pol_init_pd(pol, blkg->pd[i]);
 	}
 
 	/* insert */
@@ -232,8 +232,8 @@ static struct blkcg_gq *blkg_create(struct blkcg *blkcg,
 		for (i = 0; i < BLKCG_MAX_POLS; i++) {
 			struct blkcg_policy *pol = blkcg_policy[i];
 
-			if (blkg->pd[i] && pol->pd_online_fn)
-				pol->pd_online_fn(blkg->pd[i]);
+			if (blkg->pd[i])
+				blkg_pol_online_pd(pol, blkg->pd[i]);
 		}
 	}
 	blkg->online = true;
@@ -323,8 +323,8 @@ static void blkg_destroy(struct blkcg_gq *blkg)
 	for (i = 0; i < BLKCG_MAX_POLS; i++) {
 		struct blkcg_policy *pol = blkcg_policy[i];
 
-		if (blkg->pd[i] && pol->pd_offline_fn)
-			pol->pd_offline_fn(blkg->pd[i]);
+		if (blkg->pd[i])
+			blkg_pol_offline_pd(pol, blkg->pd[i]);
 	}
 
 	if (parent) {
@@ -457,8 +457,8 @@ static int blkcg_reset_stats(struct cgroup_subsys_state *css,
 		for (i = 0; i < BLKCG_MAX_POLS; i++) {
 			struct blkcg_policy *pol = blkcg_policy[i];
 
-			if (blkg->pd[i] && pol->pd_reset_stats_fn)
-				pol->pd_reset_stats_fn(blkg->pd[i]);
+			if (blkg->pd[i])
+				blkg_pol_reset_pd_stats(pol, blkg->pd[i]);
 		}
 	}
 
@@ -1045,7 +1045,7 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
 
 	for (i = 0; i < BLKCG_MAX_POLS; i++)
 		if (blkcg->cpd[i])
-			blkcg_policy[i]->cpd_free_fn(blkcg->cpd[i]);
+			blkcg_pol_free_cpd(blkcg_policy[i], blkcg->cpd[i]);
 
 	mutex_unlock(&blkcg_pol_mutex);
 
@@ -1084,7 +1084,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
 		if (!pol || !pol->cpd_alloc_fn)
 			continue;
 
-		cpd = pol->cpd_alloc_fn(GFP_KERNEL);
+		cpd = blkcg_pol_alloc_cpd(pol, GFP_KERNEL);
 		if (!cpd) {
 			ret = ERR_PTR(-ENOMEM);
 			goto free_pd_blkcg;
@@ -1092,8 +1092,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
 		blkcg->cpd[i] = cpd;
 		cpd->blkcg = blkcg;
 		cpd->plid = i;
-		if (pol->cpd_init_fn)
-			pol->cpd_init_fn(cpd);
+		blkcg_pol_init_cpd(pol, cpd);
 	}
 
 	spin_lock_init(&blkcg->lock);
@@ -1110,7 +1109,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
 free_pd_blkcg:
 	for (i--; i >= 0; i--)
 		if (blkcg->cpd[i])
-			blkcg_policy[i]->cpd_free_fn(blkcg->cpd[i]);
+			blkcg_pol_free_cpd(blkcg_policy[i], blkcg->cpd[i]);
 free_blkcg:
 	kfree(blkcg);
 	mutex_unlock(&blkcg_pol_mutex);
@@ -1244,7 +1243,7 @@ static void blkcg_bind(struct cgroup_subsys_state *root_css)
 
 		list_for_each_entry(blkcg, &all_blkcgs, all_blkcgs_node)
 			if (blkcg->cpd[pol->plid])
-				pol->cpd_bind_fn(blkcg->cpd[pol->plid]);
+				blkcg_pol_bind_cpd(pol, blkcg->cpd[pol->plid]);
 	}
 	mutex_unlock(&blkcg_pol_mutex);
 }
@@ -1301,7 +1300,7 @@ int blkcg_activate_policy(struct request_queue *q,
 		blk_queue_bypass_start(q);
 pd_prealloc:
 	if (!pd_prealloc) {
-		pd_prealloc = pol->pd_alloc_fn(GFP_KERNEL, q->node);
+		pd_prealloc = blkg_pol_alloc_pd(pol, GFP_KERNEL, q->node);
 		if (!pd_prealloc) {
 			ret = -ENOMEM;
 			goto out_bypass_end;
@@ -1316,7 +1315,7 @@ int blkcg_activate_policy(struct request_queue *q,
 		if (blkg->pd[pol->plid])
 			continue;
 
-		pd = pol->pd_alloc_fn(GFP_NOWAIT | __GFP_NOWARN, q->node);
+		pd = blkg_pol_alloc_pd(pol, GFP_NOWAIT | __GFP_NOWARN, q->node);
 		if (!pd)
 			swap(pd, pd_prealloc);
 		if (!pd) {
@@ -1327,8 +1326,7 @@ int blkcg_activate_policy(struct request_queue *q,
 		blkg->pd[pol->plid] = pd;
 		pd->blkg = blkg;
 		pd->plid = pol->plid;
-		if (pol->pd_init_fn)
-			pol->pd_init_fn(pd);
+		blkg_pol_init_pd(pol, pd);
 	}
 
 	__set_bit(pol->plid, q->blkcg_pols);
@@ -1341,7 +1339,7 @@ int blkcg_activate_policy(struct request_queue *q,
 	else
 		blk_queue_bypass_end(q);
 	if (pd_prealloc)
-		pol->pd_free_fn(pd_prealloc);
+		blkg_pol_free_pd(pol, pd_prealloc);
 	return ret;
 }
 EXPORT_SYMBOL_GPL(blkcg_activate_policy);
@@ -1376,9 +1374,8 @@ void blkcg_deactivate_policy(struct request_queue *q,
 		spin_lock(&blkg->blkcg->lock);
 
 		if (blkg->pd[pol->plid]) {
-			if (pol->pd_offline_fn)
-				pol->pd_offline_fn(blkg->pd[pol->plid]);
-			pol->pd_free_fn(blkg->pd[pol->plid]);
+			blkg_pol_offline_pd(pol, blkg->pd[pol->plid]);
+			blkg_pol_free_pd(pol, blkg->pd[pol->plid]);
 			blkg->pd[pol->plid] = NULL;
 		}
 
@@ -1426,14 +1423,14 @@ int blkcg_policy_register(struct blkcg_policy *pol)
 		list_for_each_entry(blkcg, &all_blkcgs, all_blkcgs_node) {
 			struct blkcg_policy_data *cpd;
 
-			cpd = pol->cpd_alloc_fn(GFP_KERNEL);
+			cpd = blkcg_pol_alloc_cpd(pol, GFP_KERNEL);
 			if (!cpd)
 				goto err_free_cpds;
 
 			blkcg->cpd[pol->plid] = cpd;
 			cpd->blkcg = blkcg;
 			cpd->plid = pol->plid;
-			pol->cpd_init_fn(cpd);
+			blkcg_pol_init_cpd(pol, cpd);
 		}
 	}
 
@@ -1453,7 +1450,7 @@ int blkcg_policy_register(struct blkcg_policy *pol)
 	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_pol_free_cpd(pol, blkcg->cpd[pol->plid]);
 				blkcg->cpd[pol->plid] = NULL;
 			}
 		}
@@ -1493,7 +1490,7 @@ void blkcg_policy_unregister(struct blkcg_policy *pol)
 	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_pol_free_cpd(pol, blkcg->cpd[pol->plid]);
 				blkcg->cpd[pol->plid] = NULL;
 			}
 		}
include/linux/blk-cgroup.h +72 -0

78 lines not on this page · raw message

Signature · 1 line
2.9.4
#3 lore raw
In reply to weiping zhang
Quoted 6 lines · weiping zhang

The first patch is the V2 of [PATCH] blkcg: check pol->cpd_free_fn before free cpd, it fixs a checking before free cpd.

The second patch add some wrappers for struct blkcg_policy->xxx_fn, because not every block cgroup policy implement all operations.

Quoted 8 lines

weiping zhang (2):
blkcg: check pol->cpd_free_fn before free cpd
blkcg: add wrappers for struct blkcg_policy operations

 block/blk-cgroup.c         | 57 +++++++++++++++++-------------------
 include/linux/blk-cgroup.h | 72 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 99 insertions(+), 30 deletions(-)

Hello Jens,

ping