Skip to contentSkip to conversation

blkcg: add sanity check for blkcg policy operations

PATCH Superseded weiping zhang 3 participants 3 messages Oct 11, 2017 – Oct 12, 2017

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 blkcg: add sanity check for blkcg policy operations

blkcg policy should keep cpd/pd's alloc_fn and free_fn in pairs, otherwise policy would register fail.

---
 block/blk-cgroup.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
block/blk-cgroup.c +10 -0
index e7ec676..67b01c5 100644
@@ -1419,6 +1419,16 @@ int blkcg_policy_register(struct blkcg_policy *pol)
 	if (i >= BLKCG_MAX_POLS)
 		goto err_unlock;
 
+	/* Make sure cpd_alloc_fn and cpd_free_fn in pairs */
+	if ((pol->cpd_alloc_fn && !pol->cpd_free_fn) ||
+		(!pol->cpd_alloc_fn && pol->cpd_free_fn))
+		goto err_unlock;
+
+	/* Make sure pd_alloc_fn and pd_free_fn in pairs */
+	if ((pol->pd_alloc_fn && !pol->pd_free_fn) ||
+		(!pol->pd_alloc_fn && pol->pd_free_fn))
+		goto err_unlock;
+
 	/* register @pol */
 	pol->plid = i;
 	blkcg_policy[pol->plid] = pol;
Signature · 1 line
2.9.4
maintainer
#1 lore raw
Quoted 13 lines · weiping zhang

blkcg policy should keep cpd/pd's alloc_fn and free_fn in pairs, otherwise policy would register fail.

---
 block/blk-cgroup.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
block/blk-cgroup.c +0 -0
index e7ec676..67b01c5 100644

block/blk-cgroup.c int blkcg_policy_register(struct blkcg_policy *pol) · line 1425

Quoted 7 lines
block/blk-cgroup.c +4 -0
@@ -1419,6 +1419,16 @@ int blkcg_policy_register(struct blkcg_policy *pol)
 	if (i >= BLKCG_MAX_POLS)
 		goto err_unlock;
 
+	/* Make sure cpd_alloc_fn and cpd_free_fn in pairs */
+	if ((pol->cpd_alloc_fn && !pol->cpd_free_fn) ||
+		(!pol->cpd_alloc_fn && pol->cpd_free_fn))
+		goto err_unlock;

This might be cleaner (and more readable) as:

        if (!pol->cpd_alloc_fn ^ !pol->cpd_free_fn)
                goto err_unlock;

Ditto for the pd part.

Signature · 1 line
Jens Axboe
#2 lore raw
Quoted 24 lines · Jens Axboe
Quoted 13 lines · weiping zhang

blkcg policy should keep cpd/pd's alloc_fn and free_fn in pairs, otherwise policy would register fail.

---
 block/blk-cgroup.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
block/blk-cgroup.c +0 -0
index e7ec676..67b01c5 100644

block/blk-cgroup.c int blkcg_policy_register(struct blkcg_policy *pol) · line 1425

Quoted 7 lines
block/blk-cgroup.c +4 -0
@@ -1419,6 +1419,16 @@ int blkcg_policy_register(struct blkcg_policy *pol)
 	if (i >= BLKCG_MAX_POLS)
 		goto err_unlock;
 
+	/* Make sure cpd_alloc_fn and cpd_free_fn in pairs */
+	if ((pol->cpd_alloc_fn && !pol->cpd_free_fn) ||
+		(!pol->cpd_alloc_fn && pol->cpd_free_fn))
+		goto err_unlock;

This might be cleaner (and more readable) as:

Quoted 5 lines
        if (!pol->cpd_alloc_fn ^ !pol->cpd_free_fn)
                goto err_unlock;

Ditto for the pd part.

Really nice, I'll send v3.

Thanks