Commit 332ebbf7 authored by Bart Van Assche's avatar Bart Van Assche Committed by Jens Axboe

block: Document what queue type each function is intended for

Some functions in block/blk-core.c must only be used on blk-sq queues
while others are safe to use against any queue type. Document which
functions are intended for blk-sq queues and issue a warning if the
blk-sq API is misused. This does not only help block driver authors
but will also make it easier to remove the blk-sq code once that code
is declared obsolete.
Signed-off-by: default avatarBart Van Assche <bart.vanassche@sandisk.com>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Cc: Hannes Reinecke <hare@suse.com>
Cc: Omar Sandoval <osandov@fb.com>
Cc: Ming Lei <ming.lei@redhat.com>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 2fff8a92
...@@ -241,6 +241,7 @@ static void blk_delay_work(struct work_struct *work) ...@@ -241,6 +241,7 @@ static void blk_delay_work(struct work_struct *work)
void blk_delay_queue(struct request_queue *q, unsigned long msecs) void blk_delay_queue(struct request_queue *q, unsigned long msecs)
{ {
lockdep_assert_held(q->queue_lock); lockdep_assert_held(q->queue_lock);
WARN_ON_ONCE(q->mq_ops);
if (likely(!blk_queue_dead(q))) if (likely(!blk_queue_dead(q)))
queue_delayed_work(kblockd_workqueue, &q->delay_work, queue_delayed_work(kblockd_workqueue, &q->delay_work,
...@@ -260,6 +261,7 @@ EXPORT_SYMBOL(blk_delay_queue); ...@@ -260,6 +261,7 @@ EXPORT_SYMBOL(blk_delay_queue);
void blk_start_queue_async(struct request_queue *q) void blk_start_queue_async(struct request_queue *q)
{ {
lockdep_assert_held(q->queue_lock); lockdep_assert_held(q->queue_lock);
WARN_ON_ONCE(q->mq_ops);
queue_flag_clear(QUEUE_FLAG_STOPPED, q); queue_flag_clear(QUEUE_FLAG_STOPPED, q);
blk_run_queue_async(q); blk_run_queue_async(q);
...@@ -279,6 +281,7 @@ void blk_start_queue(struct request_queue *q) ...@@ -279,6 +281,7 @@ void blk_start_queue(struct request_queue *q)
{ {
lockdep_assert_held(q->queue_lock); lockdep_assert_held(q->queue_lock);
WARN_ON(!irqs_disabled()); WARN_ON(!irqs_disabled());
WARN_ON_ONCE(q->mq_ops);
queue_flag_clear(QUEUE_FLAG_STOPPED, q); queue_flag_clear(QUEUE_FLAG_STOPPED, q);
__blk_run_queue(q); __blk_run_queue(q);
...@@ -302,6 +305,7 @@ EXPORT_SYMBOL(blk_start_queue); ...@@ -302,6 +305,7 @@ EXPORT_SYMBOL(blk_start_queue);
void blk_stop_queue(struct request_queue *q) void blk_stop_queue(struct request_queue *q)
{ {
lockdep_assert_held(q->queue_lock); lockdep_assert_held(q->queue_lock);
WARN_ON_ONCE(q->mq_ops);
cancel_delayed_work(&q->delay_work); cancel_delayed_work(&q->delay_work);
queue_flag_set(QUEUE_FLAG_STOPPED, q); queue_flag_set(QUEUE_FLAG_STOPPED, q);
...@@ -356,6 +360,7 @@ EXPORT_SYMBOL(blk_sync_queue); ...@@ -356,6 +360,7 @@ EXPORT_SYMBOL(blk_sync_queue);
inline void __blk_run_queue_uncond(struct request_queue *q) inline void __blk_run_queue_uncond(struct request_queue *q)
{ {
lockdep_assert_held(q->queue_lock); lockdep_assert_held(q->queue_lock);
WARN_ON_ONCE(q->mq_ops);
if (unlikely(blk_queue_dead(q))) if (unlikely(blk_queue_dead(q)))
return; return;
...@@ -383,6 +388,7 @@ EXPORT_SYMBOL_GPL(__blk_run_queue_uncond); ...@@ -383,6 +388,7 @@ EXPORT_SYMBOL_GPL(__blk_run_queue_uncond);
void __blk_run_queue(struct request_queue *q) void __blk_run_queue(struct request_queue *q)
{ {
lockdep_assert_held(q->queue_lock); lockdep_assert_held(q->queue_lock);
WARN_ON_ONCE(q->mq_ops);
if (unlikely(blk_queue_stopped(q))) if (unlikely(blk_queue_stopped(q)))
return; return;
...@@ -407,6 +413,7 @@ EXPORT_SYMBOL(__blk_run_queue); ...@@ -407,6 +413,7 @@ EXPORT_SYMBOL(__blk_run_queue);
void blk_run_queue_async(struct request_queue *q) void blk_run_queue_async(struct request_queue *q)
{ {
lockdep_assert_held(q->queue_lock); lockdep_assert_held(q->queue_lock);
WARN_ON_ONCE(q->mq_ops);
if (likely(!blk_queue_stopped(q) && !blk_queue_dead(q))) if (likely(!blk_queue_stopped(q) && !blk_queue_dead(q)))
mod_delayed_work(kblockd_workqueue, &q->delay_work, 0); mod_delayed_work(kblockd_workqueue, &q->delay_work, 0);
...@@ -425,6 +432,8 @@ void blk_run_queue(struct request_queue *q) ...@@ -425,6 +432,8 @@ void blk_run_queue(struct request_queue *q)
{ {
unsigned long flags; unsigned long flags;
WARN_ON_ONCE(q->mq_ops);
spin_lock_irqsave(q->queue_lock, flags); spin_lock_irqsave(q->queue_lock, flags);
__blk_run_queue(q); __blk_run_queue(q);
spin_unlock_irqrestore(q->queue_lock, flags); spin_unlock_irqrestore(q->queue_lock, flags);
...@@ -453,6 +462,7 @@ static void __blk_drain_queue(struct request_queue *q, bool drain_all) ...@@ -453,6 +462,7 @@ static void __blk_drain_queue(struct request_queue *q, bool drain_all)
int i; int i;
lockdep_assert_held(q->queue_lock); lockdep_assert_held(q->queue_lock);
WARN_ON_ONCE(q->mq_ops);
while (true) { while (true) {
bool drain = false; bool drain = false;
...@@ -531,6 +541,8 @@ static void __blk_drain_queue(struct request_queue *q, bool drain_all) ...@@ -531,6 +541,8 @@ static void __blk_drain_queue(struct request_queue *q, bool drain_all)
*/ */
void blk_queue_bypass_start(struct request_queue *q) void blk_queue_bypass_start(struct request_queue *q)
{ {
WARN_ON_ONCE(q->mq_ops);
spin_lock_irq(q->queue_lock); spin_lock_irq(q->queue_lock);
q->bypass_depth++; q->bypass_depth++;
queue_flag_set(QUEUE_FLAG_BYPASS, q); queue_flag_set(QUEUE_FLAG_BYPASS, q);
...@@ -557,6 +569,9 @@ EXPORT_SYMBOL_GPL(blk_queue_bypass_start); ...@@ -557,6 +569,9 @@ EXPORT_SYMBOL_GPL(blk_queue_bypass_start);
* @q: queue of interest * @q: queue of interest
* *
* Leave bypass mode and restore the normal queueing behavior. * Leave bypass mode and restore the normal queueing behavior.
*
* Note: although blk_queue_bypass_start() is only called for blk-sq queues,
* this function is called for both blk-sq and blk-mq queues.
*/ */
void blk_queue_bypass_end(struct request_queue *q) void blk_queue_bypass_end(struct request_queue *q)
{ {
...@@ -954,6 +969,8 @@ static blk_qc_t blk_queue_bio(struct request_queue *q, struct bio *bio); ...@@ -954,6 +969,8 @@ static blk_qc_t blk_queue_bio(struct request_queue *q, struct bio *bio);
int blk_init_allocated_queue(struct request_queue *q) int blk_init_allocated_queue(struct request_queue *q)
{ {
WARN_ON_ONCE(q->mq_ops);
q->fq = blk_alloc_flush_queue(q, NUMA_NO_NODE, q->cmd_size); q->fq = blk_alloc_flush_queue(q, NUMA_NO_NODE, q->cmd_size);
if (!q->fq) if (!q->fq)
return -ENOMEM; return -ENOMEM;
...@@ -1091,6 +1108,8 @@ int blk_update_nr_requests(struct request_queue *q, unsigned int nr) ...@@ -1091,6 +1108,8 @@ int blk_update_nr_requests(struct request_queue *q, unsigned int nr)
struct request_list *rl; struct request_list *rl;
int on_thresh, off_thresh; int on_thresh, off_thresh;
WARN_ON_ONCE(q->mq_ops);
spin_lock_irq(q->queue_lock); spin_lock_irq(q->queue_lock);
q->nr_requests = nr; q->nr_requests = nr;
blk_queue_congestion_threshold(q); blk_queue_congestion_threshold(q);
...@@ -1329,6 +1348,7 @@ static struct request *get_request(struct request_queue *q, unsigned int op, ...@@ -1329,6 +1348,7 @@ static struct request *get_request(struct request_queue *q, unsigned int op,
struct request *rq; struct request *rq;
lockdep_assert_held(q->queue_lock); lockdep_assert_held(q->queue_lock);
WARN_ON_ONCE(q->mq_ops);
rl = blk_get_rl(q, bio); /* transferred to @rq on success */ rl = blk_get_rl(q, bio); /* transferred to @rq on success */
retry: retry:
...@@ -1373,6 +1393,8 @@ static struct request *blk_old_get_request(struct request_queue *q, ...@@ -1373,6 +1393,8 @@ static struct request *blk_old_get_request(struct request_queue *q,
{ {
struct request *rq; struct request *rq;
WARN_ON_ONCE(q->mq_ops);
/* create ioc upfront */ /* create ioc upfront */
create_io_context(gfp_mask, q->node); create_io_context(gfp_mask, q->node);
...@@ -1424,6 +1446,7 @@ EXPORT_SYMBOL(blk_get_request); ...@@ -1424,6 +1446,7 @@ EXPORT_SYMBOL(blk_get_request);
void blk_requeue_request(struct request_queue *q, struct request *rq) void blk_requeue_request(struct request_queue *q, struct request *rq)
{ {
lockdep_assert_held(q->queue_lock); lockdep_assert_held(q->queue_lock);
WARN_ON_ONCE(q->mq_ops);
blk_delete_timer(rq); blk_delete_timer(rq);
blk_clear_rq_complete(rq); blk_clear_rq_complete(rq);
...@@ -2495,6 +2518,7 @@ struct request *blk_peek_request(struct request_queue *q) ...@@ -2495,6 +2518,7 @@ struct request *blk_peek_request(struct request_queue *q)
int ret; int ret;
lockdep_assert_held(q->queue_lock); lockdep_assert_held(q->queue_lock);
WARN_ON_ONCE(q->mq_ops);
while ((rq = __elv_next_request(q)) != NULL) { while ((rq = __elv_next_request(q)) != NULL) {
...@@ -2615,6 +2639,7 @@ void blk_dequeue_request(struct request *rq) ...@@ -2615,6 +2639,7 @@ void blk_dequeue_request(struct request *rq)
void blk_start_request(struct request *req) void blk_start_request(struct request *req)
{ {
lockdep_assert_held(req->q->queue_lock); lockdep_assert_held(req->q->queue_lock);
WARN_ON_ONCE(req->q->mq_ops);
blk_dequeue_request(req); blk_dequeue_request(req);
...@@ -2646,6 +2671,7 @@ struct request *blk_fetch_request(struct request_queue *q) ...@@ -2646,6 +2671,7 @@ struct request *blk_fetch_request(struct request_queue *q)
struct request *rq; struct request *rq;
lockdep_assert_held(q->queue_lock); lockdep_assert_held(q->queue_lock);
WARN_ON_ONCE(q->mq_ops);
rq = blk_peek_request(q); rq = blk_peek_request(q);
if (rq) if (rq)
...@@ -2797,6 +2823,7 @@ void blk_finish_request(struct request *req, blk_status_t error) ...@@ -2797,6 +2823,7 @@ void blk_finish_request(struct request *req, blk_status_t error)
struct request_queue *q = req->q; struct request_queue *q = req->q;
lockdep_assert_held(req->q->queue_lock); lockdep_assert_held(req->q->queue_lock);
WARN_ON_ONCE(q->mq_ops);
if (req->rq_flags & RQF_STATS) if (req->rq_flags & RQF_STATS)
blk_stat_add(req); blk_stat_add(req);
...@@ -2851,6 +2878,8 @@ static bool blk_end_bidi_request(struct request *rq, blk_status_t error, ...@@ -2851,6 +2878,8 @@ static bool blk_end_bidi_request(struct request *rq, blk_status_t error,
struct request_queue *q = rq->q; struct request_queue *q = rq->q;
unsigned long flags; unsigned long flags;
WARN_ON_ONCE(q->mq_ops);
if (blk_update_bidi_request(rq, error, nr_bytes, bidi_bytes)) if (blk_update_bidi_request(rq, error, nr_bytes, bidi_bytes))
return true; return true;
...@@ -2880,6 +2909,7 @@ static bool __blk_end_bidi_request(struct request *rq, blk_status_t error, ...@@ -2880,6 +2909,7 @@ static bool __blk_end_bidi_request(struct request *rq, blk_status_t error,
unsigned int nr_bytes, unsigned int bidi_bytes) unsigned int nr_bytes, unsigned int bidi_bytes)
{ {
lockdep_assert_held(rq->q->queue_lock); lockdep_assert_held(rq->q->queue_lock);
WARN_ON_ONCE(rq->q->mq_ops);
if (blk_update_bidi_request(rq, error, nr_bytes, bidi_bytes)) if (blk_update_bidi_request(rq, error, nr_bytes, bidi_bytes))
return true; return true;
...@@ -2906,6 +2936,7 @@ static bool __blk_end_bidi_request(struct request *rq, blk_status_t error, ...@@ -2906,6 +2936,7 @@ static bool __blk_end_bidi_request(struct request *rq, blk_status_t error,
bool blk_end_request(struct request *rq, blk_status_t error, bool blk_end_request(struct request *rq, blk_status_t error,
unsigned int nr_bytes) unsigned int nr_bytes)
{ {
WARN_ON_ONCE(rq->q->mq_ops);
return blk_end_bidi_request(rq, error, nr_bytes, 0); return blk_end_bidi_request(rq, error, nr_bytes, 0);
} }
EXPORT_SYMBOL(blk_end_request); EXPORT_SYMBOL(blk_end_request);
...@@ -2948,6 +2979,7 @@ bool __blk_end_request(struct request *rq, blk_status_t error, ...@@ -2948,6 +2979,7 @@ bool __blk_end_request(struct request *rq, blk_status_t error,
unsigned int nr_bytes) unsigned int nr_bytes)
{ {
lockdep_assert_held(rq->q->queue_lock); lockdep_assert_held(rq->q->queue_lock);
WARN_ON_ONCE(rq->q->mq_ops);
return __blk_end_bidi_request(rq, error, nr_bytes, 0); return __blk_end_bidi_request(rq, error, nr_bytes, 0);
} }
...@@ -2967,6 +2999,7 @@ void __blk_end_request_all(struct request *rq, blk_status_t error) ...@@ -2967,6 +2999,7 @@ void __blk_end_request_all(struct request *rq, blk_status_t error)
unsigned int bidi_bytes = 0; unsigned int bidi_bytes = 0;
lockdep_assert_held(rq->q->queue_lock); lockdep_assert_held(rq->q->queue_lock);
WARN_ON_ONCE(rq->q->mq_ops);
if (unlikely(blk_bidi_rq(rq))) if (unlikely(blk_bidi_rq(rq)))
bidi_bytes = blk_rq_bytes(rq->next_rq); bidi_bytes = blk_rq_bytes(rq->next_rq);
......
...@@ -143,6 +143,8 @@ static inline struct request *__elv_next_request(struct request_queue *q) ...@@ -143,6 +143,8 @@ static inline struct request *__elv_next_request(struct request_queue *q)
struct request *rq; struct request *rq;
struct blk_flush_queue *fq = blk_get_flush_queue(q, NULL); struct blk_flush_queue *fq = blk_get_flush_queue(q, NULL);
WARN_ON_ONCE(q->mq_ops);
while (1) { while (1) {
if (!list_empty(&q->queue_head)) { if (!list_empty(&q->queue_head)) {
rq = list_entry_rq(q->queue_head.next); rq = list_entry_rq(q->queue_head.next);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment