From: Joe Thornber Date: Mon, 21 Oct 2013 10:44:57 +0000 (+0100) Subject: dm cache policy mq: protect residency method with existing mutex X-Git-Tag: v3.13-rc4~11^2~43 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=99ba2ae4cd876bbcedb01d94c1a7952ce171418e;p=kernel%2Fkernel-generic.git dm cache policy mq: protect residency method with existing mutex It is safe to use a mutex in mq_residency() at this point since it is only called from ioctl context. But future-proof mq_residency() by using might_sleep() to catch new contexts that cannot sleep. Signed-off-by: Joe Thornber Signed-off-by: Mike Snitzer --- diff --git a/drivers/md/dm-cache-policy-mq.c b/drivers/md/dm-cache-policy-mq.c index 4296155..db490f7 100644 --- a/drivers/md/dm-cache-policy-mq.c +++ b/drivers/md/dm-cache-policy-mq.c @@ -1001,10 +1001,14 @@ static void mq_force_mapping(struct dm_cache_policy *p, static dm_cblock_t mq_residency(struct dm_cache_policy *p) { + dm_cblock_t r; struct mq_policy *mq = to_mq_policy(p); - /* FIXME: lock mutex, not sure we can block here */ - return to_cblock(mq->nr_cblocks_allocated); + mutex_lock(&mq->lock); + r = to_cblock(mq->nr_cblocks_allocated); + mutex_unlock(&mq->lock); + + return r; } static void mq_tick(struct dm_cache_policy *p)