Skip to content

Commit 602380d

Browse files
Ming Leiaxboe
authored andcommitted
blk-mq: add blk_mq_all_tag_iter
Add a new blk_mq_all_tag_iter function to iterate over all allocated scheduler tags and driver tags. This is more flexible than the existing blk_mq_all_tag_busy_iter function as it allows the callers to do whatever they want on allocated request instead of being limited to started requests. It will be used to implement draining allocated requests on specified hctx in this patchset. [hch: switch from the two booleans to a more readable flags field and consolidate the tags iter functions] Signed-off-by: Ming Lei <ming.lei@redhat.com> Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Hannes Reinecke <hare@suse.de> Reviewed-by: Daniel Wagner <dwagner@suse.de> Reviewed-by: Bart van Assche <bvanassche@acm.org> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 600c3b0 commit 602380d

2 files changed

Lines changed: 34 additions & 18 deletions

File tree

‎block/blk-mq-tag.c‎

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -256,14 +256,17 @@ struct bt_tags_iter_data {
256256
struct blk_mq_tags *tags;
257257
busy_tag_iter_fn *fn;
258258
void *data;
259-
bool reserved;
259+
unsigned int flags;
260260
};
261261

262+
#define BT_TAG_ITER_RESERVED (1 << 0)
263+
#define BT_TAG_ITER_STARTED (1 << 1)
264+
262265
static bool bt_tags_iter(struct sbitmap *bitmap, unsigned int bitnr, void *data)
263266
{
264267
struct bt_tags_iter_data *iter_data = data;
265268
struct blk_mq_tags *tags = iter_data->tags;
266-
bool reserved = iter_data->reserved;
269+
bool reserved = iter_data->flags & BT_TAG_ITER_RESERVED;
267270
struct request *rq;
268271

269272
if (!reserved)
@@ -274,10 +277,12 @@ static bool bt_tags_iter(struct sbitmap *bitmap, unsigned int bitnr, void *data)
274277
* test and set the bit before assining ->rqs[].
275278
*/
276279
rq = tags->rqs[bitnr];
277-
if (rq && blk_mq_request_started(rq))
278-
return iter_data->fn(rq, iter_data->data, reserved);
279-
280-
return true;
280+
if (!rq)
281+
return true;
282+
if ((iter_data->flags & BT_TAG_ITER_STARTED) &&
283+
!blk_mq_request_started(rq))
284+
return true;
285+
return iter_data->fn(rq, iter_data->data, reserved);
281286
}
282287

283288
/**
@@ -290,39 +295,47 @@ static bool bt_tags_iter(struct sbitmap *bitmap, unsigned int bitnr, void *data)
290295
* @reserved) where rq is a pointer to a request. Return true
291296
* to continue iterating tags, false to stop.
292297
* @data: Will be passed as second argument to @fn.
293-
* @reserved: Indicates whether @bt is the breserved_tags member or the
294-
* bitmap_tags member of struct blk_mq_tags.
298+
* @flags: BT_TAG_ITER_*
295299
*/
296300
static void bt_tags_for_each(struct blk_mq_tags *tags, struct sbitmap_queue *bt,
297-
busy_tag_iter_fn *fn, void *data, bool reserved)
301+
busy_tag_iter_fn *fn, void *data, unsigned int flags)
298302
{
299303
struct bt_tags_iter_data iter_data = {
300304
.tags = tags,
301305
.fn = fn,
302306
.data = data,
303-
.reserved = reserved,
307+
.flags = flags,
304308
};
305309

306310
if (tags->rqs)
307311
sbitmap_for_each_set(&bt->sb, bt_tags_iter, &iter_data);
308312
}
309313

314+
static void __blk_mq_all_tag_iter(struct blk_mq_tags *tags,
315+
busy_tag_iter_fn *fn, void *priv, unsigned int flags)
316+
{
317+
WARN_ON_ONCE(flags & BT_TAG_ITER_RESERVED);
318+
319+
if (tags->nr_reserved_tags)
320+
bt_tags_for_each(tags, &tags->breserved_tags, fn, priv,
321+
flags | BT_TAG_ITER_RESERVED);
322+
bt_tags_for_each(tags, &tags->bitmap_tags, fn, priv, flags);
323+
}
324+
310325
/**
311-
* blk_mq_all_tag_busy_iter - iterate over all started requests in a tag map
326+
* blk_mq_all_tag_iter - iterate over all requests in a tag map
312327
* @tags: Tag map to iterate over.
313-
* @fn: Pointer to the function that will be called for each started
328+
* @fn: Pointer to the function that will be called for each
314329
* request. @fn will be called as follows: @fn(rq, @priv,
315330
* reserved) where rq is a pointer to a request. 'reserved'
316331
* indicates whether or not @rq is a reserved request. Return
317332
* true to continue iterating tags, false to stop.
318333
* @priv: Will be passed as second argument to @fn.
319334
*/
320-
static void blk_mq_all_tag_busy_iter(struct blk_mq_tags *tags,
321-
busy_tag_iter_fn *fn, void *priv)
335+
void blk_mq_all_tag_iter(struct blk_mq_tags *tags, busy_tag_iter_fn *fn,
336+
void *priv)
322337
{
323-
if (tags->nr_reserved_tags)
324-
bt_tags_for_each(tags, &tags->breserved_tags, fn, priv, true);
325-
bt_tags_for_each(tags, &tags->bitmap_tags, fn, priv, false);
338+
return __blk_mq_all_tag_iter(tags, fn, priv, 0);
326339
}
327340

328341
/**
@@ -342,7 +355,8 @@ void blk_mq_tagset_busy_iter(struct blk_mq_tag_set *tagset,
342355

343356
for (i = 0; i < tagset->nr_hw_queues; i++) {
344357
if (tagset->tags && tagset->tags[i])
345-
blk_mq_all_tag_busy_iter(tagset->tags[i], fn, priv);
358+
__blk_mq_all_tag_iter(tagset->tags[i], fn, priv,
359+
BT_TAG_ITER_STARTED);
346360
}
347361
}
348362
EXPORT_SYMBOL(blk_mq_tagset_busy_iter);

‎block/blk-mq-tag.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ extern int blk_mq_tag_update_depth(struct blk_mq_hw_ctx *hctx,
3434
extern void blk_mq_tag_wakeup_all(struct blk_mq_tags *tags, bool);
3535
void blk_mq_queue_tag_busy_iter(struct request_queue *q, busy_iter_fn *fn,
3636
void *priv);
37+
void blk_mq_all_tag_iter(struct blk_mq_tags *tags, busy_tag_iter_fn *fn,
38+
void *priv);
3739

3840
static inline struct sbq_wait_state *bt_wait_ptr(struct sbitmap_queue *bt,
3941
struct blk_mq_hw_ctx *hctx)

0 commit comments

Comments
 (0)