Re: [PATCH 11/11] block: Move the queue_flag_*() functions from a public into a private header file

2018-03-02 Thread Martin K. Petersen

Bart,

> 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.

Reviewed-by: Martin K. Petersen 

-- 
Martin K. Petersen  Oracle Linux Engineering


Re: [PATCH 11/11] block: Move the queue_flag_*() functions from a public into a private header file

2018-03-01 Thread Johannes Thumshirn
Looks good,
Reviewed-by: Johannes Thumshirn 
-- 
Johannes Thumshirn  Storage
jthumsh...@suse.de+49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850


[PATCH 11/11] block: Move the queue_flag_*() functions from a public into a private header file

2018-02-28 Thread Bart Van Assche
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.

Signed-off-by: Bart Van Assche 
Cc: Christoph Hellwig 
Cc: Hannes Reinecke 
Cc: Johannes Thumshirn 
Cc: Ming Lei 
---
 block/blk.h| 69 ++
 include/linux/blkdev.h | 69 --
 2 files changed, 69 insertions(+), 69 deletions(-)

diff --git a/block/blk.h b/block/blk.h
index 46db5dc83dcb..b034fd2460c4 100644
--- a/block/blk.h
+++ b/block/blk.h
@@ -41,6 +41,75 @@ extern struct kmem_cache *request_cachep;
 extern struct kobj_type blk_queue_ktype;
 extern struct ida blk_queue_ida;
 
+/*
+ * @q->queue_lock is set while a queue is being initialized. Since we know
+ * that no other threads access the queue object before @q->queue_lock has
+ * been set, it is safe to manipulate queue flags without holding the
+ * queue_lock if @q->queue_lock == NULL. See also blk_alloc_queue_node() and
+ * blk_init_allocated_queue().
+ */
+static inline void queue_lockdep_assert_held(struct request_queue *q)
+{
+   if (q->queue_lock)
+   lockdep_assert_held(q->queue_lock);
+}
+
+static inline void queue_flag_set_unlocked(unsigned int flag,
+  struct request_queue *q)
+{
+   if (test_bit(QUEUE_FLAG_INIT_DONE, >queue_flags) &&
+   kref_read(>kobj.kref))
+   lockdep_assert_held(q->queue_lock);
+   __set_bit(flag, >queue_flags);
+}
+
+static inline void queue_flag_clear_unlocked(unsigned int flag,
+struct request_queue *q)
+{
+   if (test_bit(QUEUE_FLAG_INIT_DONE, >queue_flags) &&
+   kref_read(>kobj.kref))
+   lockdep_assert_held(q->queue_lock);
+   __clear_bit(flag, >queue_flags);
+}
+
+static inline int queue_flag_test_and_clear(unsigned int flag,
+   struct request_queue *q)
+{
+   queue_lockdep_assert_held(q);
+
+   if (test_bit(flag, >queue_flags)) {
+   __clear_bit(flag, >queue_flags);
+   return 1;
+   }
+
+   return 0;
+}
+
+static inline int queue_flag_test_and_set(unsigned int flag,
+ struct request_queue *q)
+{
+   queue_lockdep_assert_held(q);
+
+   if (!test_bit(flag, >queue_flags)) {
+   __set_bit(flag, >queue_flags);
+   return 0;
+   }
+
+   return 1;
+}
+
+static inline void queue_flag_set(unsigned int flag, struct request_queue *q)
+{
+   queue_lockdep_assert_held(q);
+   __set_bit(flag, >queue_flags);
+}
+
+static inline void queue_flag_clear(unsigned int flag, struct request_queue *q)
+{
+   queue_lockdep_assert_held(q);
+   __clear_bit(flag, >queue_flags);
+}
+
 static inline struct blk_flush_queue *blk_get_flush_queue(
struct request_queue *q, struct blk_mq_ctx *ctx)
 {
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 1f3ec9a7fbc7..478c1845c179 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -710,75 +710,6 @@ void blk_queue_flag_clear(unsigned int flag, struct 
request_queue *q);
 bool blk_queue_flag_test_and_set(unsigned int flag, struct request_queue *q);
 bool blk_queue_flag_test_and_clear(unsigned int flag, struct request_queue *q);
 
-/*
- * @q->queue_lock is set while a queue is being initialized. Since we know
- * that no other threads access the queue object before @q->queue_lock has
- * been set, it is safe to manipulate queue flags without holding the
- * queue_lock if @q->queue_lock == NULL. See also blk_alloc_queue_node() and
- * blk_init_allocated_queue().
- */
-static inline void queue_lockdep_assert_held(struct request_queue *q)
-{
-   if (q->queue_lock)
-   lockdep_assert_held(q->queue_lock);
-}
-
-static inline void queue_flag_set_unlocked(unsigned int flag,
-  struct request_queue *q)
-{
-   if (test_bit(QUEUE_FLAG_INIT_DONE, >queue_flags) &&
-   kref_read(>kobj.kref))
-   lockdep_assert_held(q->queue_lock);
-   __set_bit(flag, >queue_flags);
-}
-
-static inline void queue_flag_clear_unlocked(unsigned int flag,
-struct request_queue *q)
-{
-   if (test_bit(QUEUE_FLAG_INIT_DONE, >queue_flags) &&
-   kref_read(>kobj.kref))
-   lockdep_assert_held(q->queue_lock);
-   __clear_bit(flag, >queue_flags);
-}
-
-static inline int queue_flag_test_and_clear(unsigned int flag,
-   struct request_queue *q)
-{
-   queue_lockdep_assert_held(q);
-
-   if (test_bit(flag, >queue_flags)) {
-   __clear_bit(flag, >queue_flags);
-   return 1;
-   }
-
-