On 19-07-12 10:47:22, Ming Lei wrote: > diff --git a/block/blk-mq.c b/block/blk-mq.c > index e5ef40c603ca..028c5d78e409 100644 > --- a/block/blk-mq.c > +++ b/block/blk-mq.c > @@ -2205,6 +2205,64 @@ int blk_mq_alloc_rqs(struct blk_mq_tag_set *set, struct blk_mq_tags *tags, > return -ENOMEM; > } > > +static bool blk_mq_count_inflight_rq(struct request *rq, void *data, > + bool reserved) > +{ > + unsigned *count = data; > + > + if ((blk_mq_rq_state(rq) == MQ_RQ_IN_FLIGHT)) > + (*count)++; > + > + return true; > +} > + > +unsigned blk_mq_tags_inflight_rqs(struct blk_mq_tags *tags) > +{ > + unsigned count = 0; > + > + blk_mq_all_tag_busy_iter(tags, blk_mq_count_inflight_rq, &count); > + > + return count; > +} Ming, Maybe it can be static? > + > +static void blk_mq_drain_inflight_rqs(struct blk_mq_hw_ctx *hctx) > +{ > + while (1) { > + if (!blk_mq_tags_inflight_rqs(hctx->tags)) > + break; > + msleep(5); > + } > +}