blkcg: add sanity check for blkcg policy operations
Subsystems (2)
PATCH 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 | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
block/blk-cgroup.c +23 -0
@@ -1397,6 +1397,26 @@ void blkcg_deactivate_policy(struct request_queue *q,EXPORT_SYMBOL_GPL (blkcg_deactivate_policy);/** +* blkcg_policy_check_ops - check policy's operations +* @pol: blkcg policy to check +* +* Make sure cpd/pd_alloc_fn and cpd/pd_free_fn in pairs. +* Return true on success and false on failure. +*/ +static bool blkcg_policy_check_ops (struct blkcg_policy *pol) +{ +if ((pol->cpd_alloc_fn && !pol->cpd_free_fn) || + (!pol->cpd_alloc_fn && pol->cpd_free_fn)) +return false; + +if ((pol->pd_alloc_fn && !pol->pd_free_fn) || + (!pol->pd_alloc_fn && pol->pd_free_fn)) +return false; + +return true; +} + +/** * blkcg_policy_register - register a blkcg policy * @pol: blkcg policy to register *
@@ -1419,6 +1439,9 @@ int blkcg_policy_register(struct blkcg_policy *pol)if (i >=BLKCG_MAX_POLS ) goto err_unlock; +if (!blkcg_policy_check_ops (pol)) + goto err_unlock; +/* register @pol */ pol->plid = i; blkcg_policy[pol->plid] = pol;
Signature · 1 line
2.9.4
Quoted 24 lines · weiping zhang
+ *
blkcg_policy_check_ops- check policy's operations
+ * @pol: blkcg policy to check
+ *
+ * Make sure cpd/pd_alloc_fn and cpd/pd_free_fn in pairs.
+ * Return true on success and false on failure.
+ */block/blk-cgroup.c +14
-0+static bool blkcg_policy_check_ops (struct blkcg_policy *pol) +{ +if ((pol->cpd_alloc_fn && !pol->cpd_free_fn) || + (!pol->cpd_alloc_fn && pol->cpd_free_fn)) +return false; + +if ((pol->pd_alloc_fn && !pol->pd_free_fn) || + (!pol->pd_alloc_fn && pol->pd_free_fn)) +return false; + +return true; +} + +/** * blkcg_policy_register - register a blkcg policy * @pol: blkcg policy to register *
block/blk-cgroup.c int blkcg_policy_register(struct blkcg_policy *pol) · line 1444
Quoted 6 lines
block/blk-cgroup.c +3
-0@@ -1419,6 +1439,9 @@ int blkcg_policy_register(struct blkcg_policy *pol)if (i >=BLKCG_MAX_POLS ) goto err_unlock; +if (!blkcg_policy_check_ops (pol)) + goto err_unlock; +
Can you merge it into the caller?
+ if ((pol->cpd_alloc_fn && !pol->cpd_free_fn) ||
+ (!pol->cpd_alloc_fn && pol->cpd_free_fn))
+ goto err_unlock;
+
+ if ((pol->pd_alloc_fn && !pol->pd_free_fn) ||
+ (!pol->pd_alloc_fn && pol->pd_free_fn))
+ goto err_unlock;
Signature · 6 lines
Johannes Thumshirn Storage [email protected] +49 911 74053 689 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N�rnberg GF: Felix Imend�rffer, Jane Smithard, Graham Norton HRB 21284 (AG N�rnberg) Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
Quoted 36 lines · Johannes Thumshirn
Quoted 24 lines · weiping zhang
+ *
blkcg_policy_check_ops- check policy's operations
+ * @pol: blkcg policy to check
+ *
+ * Make sure cpd/pd_alloc_fn and cpd/pd_free_fn in pairs.
+ * Return true on success and false on failure.
+ */block/blk-cgroup.c +14
-0+static bool blkcg_policy_check_ops (struct blkcg_policy *pol) +{ +if ((pol->cpd_alloc_fn && !pol->cpd_free_fn) || + (!pol->cpd_alloc_fn && pol->cpd_free_fn)) +return false; + +if ((pol->pd_alloc_fn && !pol->pd_free_fn) || + (!pol->pd_alloc_fn && pol->pd_free_fn)) +return false; + +return true; +} + +/** * blkcg_policy_register - register a blkcg policy * @pol: blkcg policy to register * block/blk-cgroup.c int blkcg_policy_register(struct blkcg_policy *pol) · line 1444
Quoted 6 lines
block/blk-cgroup.c +3
-0@@ -1419,6 +1439,9 @@ int blkcg_policy_register(struct blkcg_policy *pol)if (i >=BLKCG_MAX_POLS ) goto err_unlock; +if (!blkcg_policy_check_ops (pol)) + goto err_unlock; +Can you merge it into the caller?
block/blk-cgroup.c void blkcg_deactivate_policy(struct request_queue *q,
Quoted 7 lines
block/blk-cgroup.c +7
-0+if ((pol->cpd_alloc_fn && !pol->cpd_free_fn) || + (!pol->cpd_alloc_fn && pol->cpd_free_fn)) + goto err_unlock; + +if ((pol->pd_alloc_fn && !pol->pd_free_fn) || + (!pol->pd_alloc_fn && pol->pd_free_fn)) + goto err_unlock;
It's ok for me, I send V2 later.
Thanks
Weiping