diff options
author | Dennis Zhou (Facebook) <dennisszhou@gmail.com> | 2018-09-11 14:41:27 -0400 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2018-09-21 22:29:03 -0400 |
commit | 49f4c2dc2b5066e9211101c59cc0828e81d41614 (patch) | |
tree | 217391585a20535d3c2606d98659786bf73682e2 /block/blk-cgroup.c | |
parent | 27e6fa996c534c32702aa4d32db0ffa383acd050 (diff) |
blkcg: update blkg_lookup_create to do locking
To know when to create a blkg, the general pattern is to do a
blkg_lookup and if that fails, lock and then do a lookup again and if
that fails finally create. It doesn't make much sense for everyone who
wants to do creation to write this themselves.
This changes blkg_lookup_create to do locking and implement this
pattern. The old blkg_lookup_create is renamed to __blkg_lookup_create.
If a call site wants to do its own error handling or already owns the
queue lock, they can use __blkg_lookup_create. This will be used in
upcoming patches.
Signed-off-by: Dennis Zhou <dennisszhou@gmail.com>
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Acked-by: Tejun Heo <tj@kernel.org>
Reviewed-by: Liu Bo <bo.liu@linux.alibaba.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'block/blk-cgroup.c')
-rw-r--r-- | block/blk-cgroup.c | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c index c19f9078da1e..cd0d97bed83d 100644 --- a/block/blk-cgroup.c +++ b/block/blk-cgroup.c | |||
@@ -259,7 +259,7 @@ err_free_blkg: | |||
259 | } | 259 | } |
260 | 260 | ||
261 | /** | 261 | /** |
262 | * blkg_lookup_create - lookup blkg, try to create one if not there | 262 | * __blkg_lookup_create - lookup blkg, try to create one if not there |
263 | * @blkcg: blkcg of interest | 263 | * @blkcg: blkcg of interest |
264 | * @q: request_queue of interest | 264 | * @q: request_queue of interest |
265 | * | 265 | * |
@@ -272,8 +272,8 @@ err_free_blkg: | |||
272 | * value on error. If @q is dead, returns ERR_PTR(-EINVAL). If @q is not | 272 | * value on error. If @q is dead, returns ERR_PTR(-EINVAL). If @q is not |
273 | * dead and bypassing, returns ERR_PTR(-EBUSY). | 273 | * dead and bypassing, returns ERR_PTR(-EBUSY). |
274 | */ | 274 | */ |
275 | struct blkcg_gq *blkg_lookup_create(struct blkcg *blkcg, | 275 | struct blkcg_gq *__blkg_lookup_create(struct blkcg *blkcg, |
276 | struct request_queue *q) | 276 | struct request_queue *q) |
277 | { | 277 | { |
278 | struct blkcg_gq *blkg; | 278 | struct blkcg_gq *blkg; |
279 | 279 | ||
@@ -310,6 +310,31 @@ struct blkcg_gq *blkg_lookup_create(struct blkcg *blkcg, | |||
310 | } | 310 | } |
311 | } | 311 | } |
312 | 312 | ||
313 | /** | ||
314 | * blkg_lookup_create - find or create a blkg | ||
315 | * @blkcg: target block cgroup | ||
316 | * @q: target request_queue | ||
317 | * | ||
318 | * This looks up or creates the blkg representing the unique pair | ||
319 | * of the blkcg and the request_queue. | ||
320 | */ | ||
321 | struct blkcg_gq *blkg_lookup_create(struct blkcg *blkcg, | ||
322 | struct request_queue *q) | ||
323 | { | ||
324 | struct blkcg_gq *blkg = blkg_lookup(blkcg, q); | ||
325 | unsigned long flags; | ||
326 | |||
327 | if (unlikely(!blkg)) { | ||
328 | spin_lock_irqsave(q->queue_lock, flags); | ||
329 | |||
330 | blkg = __blkg_lookup_create(blkcg, q); | ||
331 | |||
332 | spin_unlock_irqrestore(q->queue_lock, flags); | ||
333 | } | ||
334 | |||
335 | return blkg; | ||
336 | } | ||
337 | |||
313 | static void blkg_destroy(struct blkcg_gq *blkg) | 338 | static void blkg_destroy(struct blkcg_gq *blkg) |
314 | { | 339 | { |
315 | struct blkcg *blkcg = blkg->blkcg; | 340 | struct blkcg *blkcg = blkg->blkcg; |