Skip to content

Commit 13c7863

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: move the initial blkg lookup into blkg_tryget_closest
By moving the initial blkg lookup into blkg_tryget_closest we get a nicely self contained routines that does all the RCU locking. Acked-by: Tejun Heo <tj@kernel.org> Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent a5b9752 commit 13c7863

1 file changed

Lines changed: 14 additions & 19 deletions

File tree

‎block/blk-cgroup.c‎

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1716,26 +1716,28 @@ void blkcg_add_delay(struct blkcg_gq *blkg, u64 now, u64 delta)
17161716

17171717
/**
17181718
* blkg_tryget_closest - try and get a blkg ref on the closet blkg
1719-
* @blkg: blkg to get
1719+
* @bio: target bio
1720+
* @css: target css
17201721
*
1721-
* This needs to be called rcu protected. As the failure mode here is to walk
1722-
* up the blkg tree, this ensure that the blkg->parent pointers are always
1723-
* valid. This returns the blkg that it ended up taking a reference on or %NULL
1724-
* if no reference was taken.
1722+
* As the failure mode here is to walk up the blkg tree, this ensure that the
1723+
* blkg->parent pointers are always valid. This returns the blkg that it ended
1724+
* up taking a reference on or %NULL if no reference was taken.
17251725
*/
1726-
static inline struct blkcg_gq *blkg_tryget_closest(struct blkcg_gq *blkg)
1726+
static inline struct blkcg_gq *blkg_tryget_closest(struct bio *bio,
1727+
struct cgroup_subsys_state *css)
17271728
{
1728-
struct blkcg_gq *ret_blkg = NULL;
1729-
1730-
WARN_ON_ONCE(!rcu_read_lock_held());
1729+
struct blkcg_gq *blkg, *ret_blkg = NULL;
17311730

1731+
rcu_read_lock();
1732+
blkg = blkg_lookup_create(css_to_blkcg(css), bio->bi_disk->queue);
17321733
while (blkg) {
17331734
if (blkg_tryget(blkg)) {
17341735
ret_blkg = blkg;
17351736
break;
17361737
}
17371738
blkg = blkg->parent;
17381739
}
1740+
rcu_read_unlock();
17391741

17401742
return ret_blkg;
17411743
}
@@ -1757,21 +1759,14 @@ static inline struct blkcg_gq *blkg_tryget_closest(struct blkcg_gq *blkg)
17571759
void bio_associate_blkg_from_css(struct bio *bio,
17581760
struct cgroup_subsys_state *css)
17591761
{
1760-
struct request_queue *q = bio->bi_disk->queue;
1761-
17621762
if (bio->bi_blkg)
17631763
blkg_put(bio->bi_blkg);
17641764

17651765
if (css && css->parent) {
1766-
struct blkcg_gq *blkg;
1767-
1768-
rcu_read_lock();
1769-
blkg = blkg_lookup_create(css_to_blkcg(css), q);
1770-
bio->bi_blkg = blkg_tryget_closest(blkg);
1771-
rcu_read_unlock();
1766+
bio->bi_blkg = blkg_tryget_closest(bio, css);
17721767
} else {
1773-
blkg_get(q->root_blkg);
1774-
bio->bi_blkg = q->root_blkg;
1768+
blkg_get(bio->bi_disk->queue->root_blkg);
1769+
bio->bi_blkg = bio->bi_disk->queue->root_blkg;
17751770
}
17761771
}
17771772
EXPORT_SYMBOL_GPL(bio_associate_blkg_from_css);

0 commit comments

Comments
 (0)