[PATCH 13.5] blkcg: make blkg_lookup_create() return ERR_PTR valueon failure

From: Tejun Heo
Date: Tue Jan 24 2012 - 14:30:06 EST


Update blkg_lookup_create() so that it indicates the cause of failure
with ERR_PTR value. This is primarily to allow the caller to
determine whether the failure is transitional due to queue being
bypassed temporarily.

Signed-off-by: Tejun Heo <tj@xxxxxxxxxx>
Cc: Vivek Goyal <vgoyal@xxxxxxxxxx>
---
block/blk-cgroup.c | 15 +++++++++------
block/blk-throttle.c | 2 +-
block/cfq-iosched.c | 5 ++++-
3 files changed, 14 insertions(+), 8 deletions(-)

Index: work/block/blk-cgroup.c
===================================================================
--- work.orig/block/blk-cgroup.c
+++ work/block/blk-cgroup.c
@@ -471,8 +471,7 @@ struct blkio_group *blkg_lookup_create(s
__releases(q->queue_lock) __acquires(q->queue_lock)
{
struct blkio_policy_type *pol = blkio_policy[plid];
- struct blkio_group *blkg = NULL;
- struct blkio_group *new_blkg = NULL;
+ struct blkio_group *blkg, *new_blkg = NULL;

WARN_ON_ONCE(!rcu_read_lock_held());
lockdep_assert_held(q->queue_lock);
@@ -484,14 +483,14 @@ struct blkio_group *blkg_lookup_create(s
* fail on a bypassing queue.
*/
if (unlikely(blk_queue_bypass(q)))
- return NULL;
+ return ERR_PTR(blk_queue_dead(q) ? -EINVAL : -EBUSY);

blkg = blkg_lookup(blkcg, q, plid);
if (blkg)
return blkg;

if (!css_tryget(&blkcg->css))
- return NULL;
+ return ERR_PTR(-EINVAL);

/*
* Allocate and initialize.
@@ -522,8 +521,10 @@ struct blkio_group *blkg_lookup_create(s
css_put(&blkcg->css);

/* did bypass get turned on inbetween? */
- if (unlikely(blk_queue_bypass(q)))
+ if (unlikely(blk_queue_bypass(q))) {
+ blkg = ERR_PTR(blk_queue_dead(q) ? -EINVAL : -EBUSY);
goto out;
+ }

/* did someone beat us to it? */
blkg = blkg_lookup(blkcg, q, plid);
@@ -531,8 +532,10 @@ struct blkio_group *blkg_lookup_create(s
goto out;

/* did alloc fail? */
- if (unlikely(!new_blkg || !new_blkg->stats_cpu))
+ if (unlikely(!new_blkg || !new_blkg->stats_cpu)) {
+ blkg = ERR_PTR(-ENOMEM);
goto out;
+ }

/* insert */
spin_lock(&blkcg->lock);
Index: work/block/blk-throttle.c
===================================================================
--- work.orig/block/blk-throttle.c
+++ work/block/blk-throttle.c
@@ -289,7 +289,7 @@ static struct throtl_grp *throtl_lookup_
blkg = blkg_lookup_create(blkcg, q, BLKIO_POLICY_THROTL);

/* if %NULL and @q is alive, fall back to root_tg */
- if (blkg)
+ if (!IS_ERR(blkg))
tg = tg_of_blkg(blkg);
else if (!blk_queue_dead(q))
tg = td->root_tg;
Index: work/block/cfq-iosched.c
===================================================================
--- work.orig/block/cfq-iosched.c
+++ work/block/cfq-iosched.c
@@ -1106,7 +1106,10 @@ static struct cfq_group *cfq_lookup_crea
struct blkio_group *blkg;

blkg = blkg_lookup_create(blkcg, cfqd->queue, BLKIO_POLICY_PROP);
- return cfqg_of_blkg(blkg);
+ if (!IS_ERR(blkg))
+ return cfqg_of_blkg(blkg);
+ else
+ return NULL;
}

static inline struct cfq_group *cfq_ref_get_cfqg(struct cfq_group *cfqg)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/