Skip to content

Commit 8a0ac14

Browse files
KAGA-KOKOaxboe
authored andcommitted
block: Move the queue_flag_*() functions from a public into a private header file
This patch helps to avoid that new code gets introduced in block drivers that manipulates queue flags without holding the queue lock when that lock should be held. Cc: Christoph Hellwig <[email protected]> Cc: Hannes Reinecke <[email protected]> Cc: Ming Lei <[email protected]> Reviewed-by: Johannes Thumshirn <[email protected]> Reviewed-by: Martin K. Petersen <[email protected]> Signed-off-by: Bart Van Assche <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 1db2008 commit 8a0ac14

File tree

2 files changed

+69
-69
lines changed

2 files changed

+69
-69
lines changed

block/blk.h

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,75 @@ extern struct kmem_cache *request_cachep;
4141
extern struct kobj_type blk_queue_ktype;
4242
extern struct ida blk_queue_ida;
4343

44+
/*
45+
* @q->queue_lock is set while a queue is being initialized. Since we know
46+
* that no other threads access the queue object before @q->queue_lock has
47+
* been set, it is safe to manipulate queue flags without holding the
48+
* queue_lock if @q->queue_lock == NULL. See also blk_alloc_queue_node() and
49+
* blk_init_allocated_queue().
50+
*/
51+
static inline void queue_lockdep_assert_held(struct request_queue *q)
52+
{
53+
if (q->queue_lock)
54+
lockdep_assert_held(q->queue_lock);
55+
}
56+
57+
static inline void queue_flag_set_unlocked(unsigned int flag,
58+
struct request_queue *q)
59+
{
60+
if (test_bit(QUEUE_FLAG_INIT_DONE, &q->queue_flags) &&
61+
kref_read(&q->kobj.kref))
62+
lockdep_assert_held(q->queue_lock);
63+
__set_bit(flag, &q->queue_flags);
64+
}
65+
66+
static inline void queue_flag_clear_unlocked(unsigned int flag,
67+
struct request_queue *q)
68+
{
69+
if (test_bit(QUEUE_FLAG_INIT_DONE, &q->queue_flags) &&
70+
kref_read(&q->kobj.kref))
71+
lockdep_assert_held(q->queue_lock);
72+
__clear_bit(flag, &q->queue_flags);
73+
}
74+
75+
static inline int queue_flag_test_and_clear(unsigned int flag,
76+
struct request_queue *q)
77+
{
78+
queue_lockdep_assert_held(q);
79+
80+
if (test_bit(flag, &q->queue_flags)) {
81+
__clear_bit(flag, &q->queue_flags);
82+
return 1;
83+
}
84+
85+
return 0;
86+
}
87+
88+
static inline int queue_flag_test_and_set(unsigned int flag,
89+
struct request_queue *q)
90+
{
91+
queue_lockdep_assert_held(q);
92+
93+
if (!test_bit(flag, &q->queue_flags)) {
94+
__set_bit(flag, &q->queue_flags);
95+
return 0;
96+
}
97+
98+
return 1;
99+
}
100+
101+
static inline void queue_flag_set(unsigned int flag, struct request_queue *q)
102+
{
103+
queue_lockdep_assert_held(q);
104+
__set_bit(flag, &q->queue_flags);
105+
}
106+
107+
static inline void queue_flag_clear(unsigned int flag, struct request_queue *q)
108+
{
109+
queue_lockdep_assert_held(q);
110+
__clear_bit(flag, &q->queue_flags);
111+
}
112+
44113
static inline struct blk_flush_queue *blk_get_flush_queue(
45114
struct request_queue *q, struct blk_mq_ctx *ctx)
46115
{

include/linux/blkdev.h

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -712,75 +712,6 @@ void blk_queue_flag_clear(unsigned int flag, struct request_queue *q);
712712
bool blk_queue_flag_test_and_set(unsigned int flag, struct request_queue *q);
713713
bool blk_queue_flag_test_and_clear(unsigned int flag, struct request_queue *q);
714714

715-
/*
716-
* @q->queue_lock is set while a queue is being initialized. Since we know
717-
* that no other threads access the queue object before @q->queue_lock has
718-
* been set, it is safe to manipulate queue flags without holding the
719-
* queue_lock if @q->queue_lock == NULL. See also blk_alloc_queue_node() and
720-
* blk_init_allocated_queue().
721-
*/
722-
static inline void queue_lockdep_assert_held(struct request_queue *q)
723-
{
724-
if (q->queue_lock)
725-
lockdep_assert_held(q->queue_lock);
726-
}
727-
728-
static inline void queue_flag_set_unlocked(unsigned int flag,
729-
struct request_queue *q)
730-
{
731-
if (test_bit(QUEUE_FLAG_INIT_DONE, &q->queue_flags) &&
732-
kref_read(&q->kobj.kref))
733-
lockdep_assert_held(q->queue_lock);
734-
__set_bit(flag, &q->queue_flags);
735-
}
736-
737-
static inline void queue_flag_clear_unlocked(unsigned int flag,
738-
struct request_queue *q)
739-
{
740-
if (test_bit(QUEUE_FLAG_INIT_DONE, &q->queue_flags) &&
741-
kref_read(&q->kobj.kref))
742-
lockdep_assert_held(q->queue_lock);
743-
__clear_bit(flag, &q->queue_flags);
744-
}
745-
746-
static inline int queue_flag_test_and_clear(unsigned int flag,
747-
struct request_queue *q)
748-
{
749-
queue_lockdep_assert_held(q);
750-
751-
if (test_bit(flag, &q->queue_flags)) {
752-
__clear_bit(flag, &q->queue_flags);
753-
return 1;
754-
}
755-
756-
return 0;
757-
}
758-
759-
static inline int queue_flag_test_and_set(unsigned int flag,
760-
struct request_queue *q)
761-
{
762-
queue_lockdep_assert_held(q);
763-
764-
if (!test_bit(flag, &q->queue_flags)) {
765-
__set_bit(flag, &q->queue_flags);
766-
return 0;
767-
}
768-
769-
return 1;
770-
}
771-
772-
static inline void queue_flag_set(unsigned int flag, struct request_queue *q)
773-
{
774-
queue_lockdep_assert_held(q);
775-
__set_bit(flag, &q->queue_flags);
776-
}
777-
778-
static inline void queue_flag_clear(unsigned int flag, struct request_queue *q)
779-
{
780-
queue_lockdep_assert_held(q);
781-
__clear_bit(flag, &q->queue_flags);
782-
}
783-
784715
#define blk_queue_tagged(q) test_bit(QUEUE_FLAG_QUEUED, &(q)->queue_flags)
785716
#define blk_queue_stopped(q) test_bit(QUEUE_FLAG_STOPPED, &(q)->queue_flags)
786717
#define blk_queue_dying(q) test_bit(QUEUE_FLAG_DYING, &(q)->queue_flags)

0 commit comments

Comments
 (0)