All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] Add wrapper for blkcg policy operatins
@ 2017-09-01 14:16 weiping zhang
  2017-09-01 14:17 ` [PATCH v2 1/2] blkcg: check pol->cpd_free_fn before free cpd weiping zhang
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: weiping zhang @ 2017-09-01 14:16 UTC (permalink / raw)
  To: axboe; +Cc: linux-block

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(-)

-- 
2.9.4

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 1/2] blkcg: check pol->cpd_free_fn before free cpd
  2017-09-01 14:16 [PATCH v2 0/2] Add wrapper for blkcg policy operatins weiping zhang
@ 2017-09-01 14:17 ` weiping zhang
  2017-09-01 14:18 ` [PATCH v2 2/2] blkcg: add wrappers for struct blkcg_policy operations weiping zhang
  2017-09-15 14:01 ` [PATCH v2 0/2] Add wrapper for blkcg policy operatins weiping zhang
  2 siblings, 0 replies; 4+ messages in thread
From: weiping zhang @ 2017-09-01 14:17 UTC (permalink / raw)
  To: axboe; +Cc: linux-block

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

Signed-off-by: weiping zhang <zhangweiping@didichuxing.com>
---
 block/blk-cgroup.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
index 0480892..0c45870 100644
--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -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]);
-- 
2.9.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2 2/2] blkcg: add wrappers for struct blkcg_policy operations
  2017-09-01 14:16 [PATCH v2 0/2] Add wrapper for blkcg policy operatins weiping zhang
  2017-09-01 14:17 ` [PATCH v2 1/2] blkcg: check pol->cpd_free_fn before free cpd weiping zhang
@ 2017-09-01 14:18 ` weiping zhang
  2017-09-15 14:01 ` [PATCH v2 0/2] Add wrapper for blkcg policy operatins weiping zhang
  2 siblings, 0 replies; 4+ messages in thread
From: weiping zhang @ 2017-09-01 14:18 UTC (permalink / raw)
  To: axboe; +Cc: linux-block

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

Signed-off-by: weiping zhang <zhangweiping@didichuxing.com>
---
 block/blk-cgroup.c         | 53 ++++++++++++++++------------------
 include/linux/blk-cgroup.h | 72 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 97 insertions(+), 28 deletions(-)

diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
index 0c45870..8588739 100644
--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -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;
 			}
 		}
diff --git a/include/linux/blk-cgroup.h b/include/linux/blk-cgroup.h
index 7104bea..08904d6 100644
--- a/include/linux/blk-cgroup.h
+++ b/include/linux/blk-cgroup.h
@@ -166,6 +166,78 @@ struct blkcg_policy {
 	blkcg_pol_reset_pd_stats_fn	*pd_reset_stats_fn;
 };
 
+static inline struct blkcg_policy_data *
+blkcg_pol_alloc_cpd(struct blkcg_policy *pol, gfp_t gfp)
+{
+	if(pol->cpd_alloc_fn)
+		return pol->cpd_alloc_fn(gfp);
+	return NULL;
+}
+
+static inline void
+blkcg_pol_init_cpd(struct blkcg_policy *pol, struct blkcg_policy_data * cpd)
+{
+	if (pol->cpd_init_fn)
+		pol->cpd_init_fn(cpd);
+}
+
+static inline void
+blkcg_pol_free_cpd(struct blkcg_policy *pol, struct blkcg_policy_data * cpd)
+{
+	if (pol->cpd_free_fn)
+		pol->cpd_free_fn(cpd);
+}
+
+static inline void
+blkcg_pol_bind_cpd(struct blkcg_policy *pol, struct blkcg_policy_data * cpd)
+{
+	if (pol->cpd_bind_fn)
+		pol->cpd_bind_fn(cpd);
+}
+
+static inline struct blkg_policy_data *
+blkg_pol_alloc_pd(const struct blkcg_policy *pol, gfp_t gfp, int node)
+{
+	if (pol->pd_alloc_fn)
+		return pol->pd_alloc_fn(gfp, node);
+	return NULL;
+}
+
+static inline void
+blkg_pol_init_pd(const struct blkcg_policy *pol, struct blkg_policy_data *pd)
+{
+	if (pol->pd_init_fn)
+		pol->pd_init_fn(pd);
+}
+
+static inline void
+blkg_pol_online_pd(struct blkcg_policy *pol, struct blkg_policy_data *pd)
+{
+	if (pol->pd_online_fn)
+		pol->pd_online_fn(pd);
+}
+
+static inline void
+blkg_pol_offline_pd(const struct blkcg_policy *pol, struct blkg_policy_data *pd)
+{
+	if (pol->pd_offline_fn)
+		pol->pd_offline_fn(pd);
+}
+
+static inline void
+blkg_pol_free_pd(const struct blkcg_policy *pol, struct blkg_policy_data *pd)
+{
+	if (pol->pd_free_fn)
+		pol->pd_free_fn(pd);
+}
+
+static inline void
+blkg_pol_reset_pd_stats(struct blkcg_policy *pol, struct blkg_policy_data *pd)
+{
+	if (pol->pd_reset_stats_fn)
+		pol->pd_reset_stats_fn(pd);
+}
+
 extern struct blkcg blkcg_root;
 extern struct cgroup_subsys_state * const blkcg_root_css;
 
-- 
2.9.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 0/2] Add wrapper for blkcg policy operatins
  2017-09-01 14:16 [PATCH v2 0/2] Add wrapper for blkcg policy operatins weiping zhang
  2017-09-01 14:17 ` [PATCH v2 1/2] blkcg: check pol->cpd_free_fn before free cpd weiping zhang
  2017-09-01 14:18 ` [PATCH v2 2/2] blkcg: add wrappers for struct blkcg_policy operations weiping zhang
@ 2017-09-15 14:01 ` weiping zhang
  2 siblings, 0 replies; 4+ messages in thread
From: weiping zhang @ 2017-09-15 14:01 UTC (permalink / raw)
  To: axboe; +Cc: linux-block

On Fri, Sep 01, 2017 at 10:16:45PM +0800, weiping zhang wrote:
> 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(-)
> 
Hello Jens,

ping

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-09-15 14:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-01 14:16 [PATCH v2 0/2] Add wrapper for blkcg policy operatins weiping zhang
2017-09-01 14:17 ` [PATCH v2 1/2] blkcg: check pol->cpd_free_fn before free cpd weiping zhang
2017-09-01 14:18 ` [PATCH v2 2/2] blkcg: add wrappers for struct blkcg_policy operations weiping zhang
2017-09-15 14:01 ` [PATCH v2 0/2] Add wrapper for blkcg policy operatins weiping zhang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.