Back to home page

LXR

 
 

    


0001 #ifndef INT_BLK_MQ_TAG_H
0002 #define INT_BLK_MQ_TAG_H
0003 
0004 #include "blk-mq.h"
0005 
0006 /*
0007  * Tag address space map.
0008  */
0009 struct blk_mq_tags {
0010     unsigned int nr_tags;
0011     unsigned int nr_reserved_tags;
0012 
0013     atomic_t active_queues;
0014 
0015     struct sbitmap_queue bitmap_tags;
0016     struct sbitmap_queue breserved_tags;
0017 
0018     struct request **rqs;
0019     struct list_head page_list;
0020 };
0021 
0022 
0023 extern struct blk_mq_tags *blk_mq_init_tags(unsigned int nr_tags, unsigned int reserved_tags, int node, int alloc_policy);
0024 extern void blk_mq_free_tags(struct blk_mq_tags *tags);
0025 
0026 extern unsigned int blk_mq_get_tag(struct blk_mq_alloc_data *data);
0027 extern void blk_mq_put_tag(struct blk_mq_hw_ctx *hctx, struct blk_mq_ctx *ctx,
0028                unsigned int tag);
0029 extern bool blk_mq_has_free_tags(struct blk_mq_tags *tags);
0030 extern ssize_t blk_mq_tag_sysfs_show(struct blk_mq_tags *tags, char *page);
0031 extern int blk_mq_tag_update_depth(struct blk_mq_tags *tags, unsigned int depth);
0032 extern void blk_mq_tag_wakeup_all(struct blk_mq_tags *tags, bool);
0033 void blk_mq_queue_tag_busy_iter(struct request_queue *q, busy_iter_fn *fn,
0034         void *priv);
0035 
0036 static inline struct sbq_wait_state *bt_wait_ptr(struct sbitmap_queue *bt,
0037                          struct blk_mq_hw_ctx *hctx)
0038 {
0039     if (!hctx)
0040         return &bt->ws[0];
0041     return sbq_wait_ptr(bt, &hctx->wait_index);
0042 }
0043 
0044 enum {
0045     BLK_MQ_TAG_CACHE_MIN    = 1,
0046     BLK_MQ_TAG_CACHE_MAX    = 64,
0047 };
0048 
0049 enum {
0050     BLK_MQ_TAG_FAIL     = -1U,
0051     BLK_MQ_TAG_MIN      = BLK_MQ_TAG_CACHE_MIN,
0052     BLK_MQ_TAG_MAX      = BLK_MQ_TAG_FAIL - 1,
0053 };
0054 
0055 extern bool __blk_mq_tag_busy(struct blk_mq_hw_ctx *);
0056 extern void __blk_mq_tag_idle(struct blk_mq_hw_ctx *);
0057 
0058 static inline bool blk_mq_tag_busy(struct blk_mq_hw_ctx *hctx)
0059 {
0060     if (!(hctx->flags & BLK_MQ_F_TAG_SHARED))
0061         return false;
0062 
0063     return __blk_mq_tag_busy(hctx);
0064 }
0065 
0066 static inline void blk_mq_tag_idle(struct blk_mq_hw_ctx *hctx)
0067 {
0068     if (!(hctx->flags & BLK_MQ_F_TAG_SHARED))
0069         return;
0070 
0071     __blk_mq_tag_idle(hctx);
0072 }
0073 
0074 /*
0075  * This helper should only be used for flush request to share tag
0076  * with the request cloned from, and both the two requests can't be
0077  * in flight at the same time. The caller has to make sure the tag
0078  * can't be freed.
0079  */
0080 static inline void blk_mq_tag_set_rq(struct blk_mq_hw_ctx *hctx,
0081         unsigned int tag, struct request *rq)
0082 {
0083     hctx->tags->rqs[tag] = rq;
0084 }
0085 
0086 #endif