blkcg: clean up blkg_tryget_closest()
The implementation of blkg_tryget_closest() wasn't super obvious and became a point of suspicion when debugging [1]. So let's clean it up so it's obviously not the problem. Also add missing RCU read locking to bio_clone_blkg_association(), which got exposed by adding the RCU read lock held check in blkg_tryget_closest(). [1] https://lore.kernel.org/linux-block/a7e97e4b-0dd8-3a54-23b7-a0f27b17fde8@kernel.dk/ Signed-off-by: Dennis Zhou <dennis@kernel.org> Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
parent
5816a0932b
commit
6ab2187992
@ -2096,8 +2096,12 @@ EXPORT_SYMBOL_GPL(bio_associate_blkg);
|
|||||||
*/
|
*/
|
||||||
void bio_clone_blkg_association(struct bio *dst, struct bio *src)
|
void bio_clone_blkg_association(struct bio *dst, struct bio *src)
|
||||||
{
|
{
|
||||||
|
rcu_read_lock();
|
||||||
|
|
||||||
if (src->bi_blkg)
|
if (src->bi_blkg)
|
||||||
__bio_associate_blkg(dst, src->bi_blkg);
|
__bio_associate_blkg(dst, src->bi_blkg);
|
||||||
|
|
||||||
|
rcu_read_unlock();
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(bio_clone_blkg_association);
|
EXPORT_SYMBOL_GPL(bio_clone_blkg_association);
|
||||||
#endif /* CONFIG_BLK_CGROUP */
|
#endif /* CONFIG_BLK_CGROUP */
|
||||||
|
@ -499,22 +499,33 @@ static inline void blkg_get(struct blkcg_gq *blkg)
|
|||||||
*/
|
*/
|
||||||
static inline bool blkg_tryget(struct blkcg_gq *blkg)
|
static inline bool blkg_tryget(struct blkcg_gq *blkg)
|
||||||
{
|
{
|
||||||
return percpu_ref_tryget(&blkg->refcnt);
|
return blkg && percpu_ref_tryget(&blkg->refcnt);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* blkg_tryget_closest - try and get a blkg ref on the closet blkg
|
* blkg_tryget_closest - try and get a blkg ref on the closet blkg
|
||||||
* @blkg: blkg to get
|
* @blkg: blkg to get
|
||||||
*
|
*
|
||||||
* This walks up the blkg tree to find the closest non-dying blkg and returns
|
* This needs to be called rcu protected. As the failure mode here is to walk
|
||||||
* the blkg that it did association with as it may not be the passed in blkg.
|
* up the blkg tree, this ensure that the blkg->parent pointers are always
|
||||||
|
* valid. This returns the blkg that it ended up taking a reference on or %NULL
|
||||||
|
* if no reference was taken.
|
||||||
*/
|
*/
|
||||||
static inline struct blkcg_gq *blkg_tryget_closest(struct blkcg_gq *blkg)
|
static inline struct blkcg_gq *blkg_tryget_closest(struct blkcg_gq *blkg)
|
||||||
{
|
{
|
||||||
while (blkg && !percpu_ref_tryget(&blkg->refcnt))
|
struct blkcg_gq *ret_blkg = NULL;
|
||||||
blkg = blkg->parent;
|
|
||||||
|
|
||||||
return blkg;
|
WARN_ON_ONCE(!rcu_read_lock_held());
|
||||||
|
|
||||||
|
while (blkg) {
|
||||||
|
if (blkg_tryget(blkg)) {
|
||||||
|
ret_blkg = blkg;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
blkg = blkg->parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret_blkg;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user