From: weiping zhang <zhangweiping@didichuxing.com>
To: <axboe@kernel.dk>
Cc: <linux-block@vger.kernel.org>
Subject: [PATCH] blkcg: add sanity check for blkcg policy operations
Date: Wed, 11 Oct 2017 00:00:55 +0800 [thread overview]
Message-ID: <20171010160050.GA1601@localhost.didichuxing.com> (raw)
blkcg policy should keep cpd/pd's alloc_fn and free_fn in pairs,
otherwise policy would register fail.
Signed-off-by: weiping zhang <zhangweiping@didichuxing.com>
---
block/blk-cgroup.c | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
index e7ec676..557c122 100644
--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -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;
--
2.9.4
next reply other threads:[~2017-10-10 16:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-10 16:00 weiping zhang [this message]
2017-10-11 7:58 ` [PATCH] blkcg: add sanity check for blkcg policy operations Johannes Thumshirn
2017-10-11 9:44 ` weiping zhang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171010160050.GA1601@localhost.didichuxing.com \
--to=zhangweiping@didichuxing.com \
--cc=axboe@kernel.dk \
--cc=linux-block@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.