Skip to content

Commit e48ec69

Browse files
author
Jens Axboe
committed
block: extend queue_flag bitops
Add test_and_clear and test_and_set. Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
1 parent e180f59 commit e48ec69

2 files changed

Lines changed: 30 additions & 8 deletions

File tree

‎block/blk-core.c‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,7 @@ void blk_plug_device(struct request_queue *q)
205205
if (blk_queue_stopped(q))
206206
return;
207207

208-
if (!test_bit(QUEUE_FLAG_PLUGGED, &q->queue_flags)) {
209-
__set_bit(QUEUE_FLAG_PLUGGED, &q->queue_flags);
208+
if (!queue_flag_test_and_set(QUEUE_FLAG_PLUGGED, q)) {
210209
mod_timer(&q->unplug_timer, jiffies + q->unplug_delay);
211210
blk_add_trace_generic(q, NULL, 0, BLK_TA_PLUG);
212211
}
@@ -221,10 +220,9 @@ int blk_remove_plug(struct request_queue *q)
221220
{
222221
WARN_ON(!irqs_disabled());
223222

224-
if (!test_bit(QUEUE_FLAG_PLUGGED, &q->queue_flags))
223+
if (!queue_flag_test_and_clear(QUEUE_FLAG_PLUGGED, q))
225224
return 0;
226225

227-
queue_flag_clear(QUEUE_FLAG_PLUGGED, q);
228226
del_timer(&q->unplug_timer);
229227
return 1;
230228
}
@@ -328,8 +326,7 @@ void blk_start_queue(struct request_queue *q)
328326
* one level of recursion is ok and is much faster than kicking
329327
* the unplug handling
330328
*/
331-
if (!test_bit(QUEUE_FLAG_REENTER, &q->queue_flags)) {
332-
queue_flag_set(QUEUE_FLAG_REENTER, q);
329+
if (!queue_flag_test_and_set(QUEUE_FLAG_REENTER, q)) {
333330
q->request_fn(q);
334331
queue_flag_clear(QUEUE_FLAG_REENTER, q);
335332
} else {
@@ -394,8 +391,7 @@ void __blk_run_queue(struct request_queue *q)
394391
* handling reinvoke the handler shortly if we already got there.
395392
*/
396393
if (!elv_queue_empty(q)) {
397-
if (!test_bit(QUEUE_FLAG_REENTER, &q->queue_flags)) {
398-
queue_flag_set(QUEUE_FLAG_REENTER, q);
394+
if (!queue_flag_test_and_set(QUEUE_FLAG_REENTER, q)) {
399395
q->request_fn(q);
400396
queue_flag_clear(QUEUE_FLAG_REENTER, q);
401397
} else {

‎include/linux/blkdev.h‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,32 @@ static inline void queue_flag_set_unlocked(unsigned int flag,
428428
__set_bit(flag, &q->queue_flags);
429429
}
430430

431+
static inline int queue_flag_test_and_clear(unsigned int flag,
432+
struct request_queue *q)
433+
{
434+
WARN_ON_ONCE(!queue_is_locked(q));
435+
436+
if (test_bit(flag, &q->queue_flags)) {
437+
__clear_bit(flag, &q->queue_flags);
438+
return 1;
439+
}
440+
441+
return 0;
442+
}
443+
444+
static inline int queue_flag_test_and_set(unsigned int flag,
445+
struct request_queue *q)
446+
{
447+
WARN_ON_ONCE(!queue_is_locked(q));
448+
449+
if (!test_bit(flag, &q->queue_flags)) {
450+
__set_bit(flag, &q->queue_flags);
451+
return 0;
452+
}
453+
454+
return 1;
455+
}
456+
431457
static inline void queue_flag_set(unsigned int flag, struct request_queue *q)
432458
{
433459
WARN_ON_ONCE(!queue_is_locked(q));

0 commit comments

Comments
 (0)