Skip to content

Commit 7e26cb6

Browse files
Ming Leiaxboe
authored andcommitted
ublk: rely on ->canceling for dealing with ublk_nosrv_dev_should_queue_io
Now ublk deals with ublk_nosrv_dev_should_queue_io() by keeping request queue as quiesced. This way is fragile because queue quiesce crosses syscalls or process contexts. Switch to rely on ubq->canceling for dealing with ublk_nosrv_dev_should_queue_io(), because it has been used for this purpose during io_uring context exiting, and it can be reused before recovering too. In ublk_queue_rq(), the request will be added to requeue list without kicking off requeue in case of ubq->canceling, and finally requests added in requeue list will be dispatched from either ublk_stop_dev() or ublk_ctrl_end_recovery(). Meantime we have to move reset of ubq->canceling from ublk_ctrl_start_recovery() to ublk_ctrl_end_recovery(), when IO handling can be recovered completely. Then blk_mq_quiesce_queue() and blk_mq_unquiesce_queue() are always used in same context. Signed-off-by: Ming Lei <ming.lei@redhat.com> Reviewed-by: Uday Shankar <ushankar@purestorage.com> Link: https://lore.kernel.org/r/20250416035444.99569-4-ming.lei@redhat.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 00b3b0d commit 7e26cb6

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

drivers/block/ublk_drv.c

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1734,13 +1734,19 @@ static void ublk_wait_tagset_rqs_idle(struct ublk_device *ub)
17341734

17351735
static void __ublk_quiesce_dev(struct ublk_device *ub)
17361736
{
1737+
int i;
1738+
17371739
pr_devel("%s: quiesce ub: dev_id %d state %s\n",
17381740
__func__, ub->dev_info.dev_id,
17391741
ub->dev_info.state == UBLK_S_DEV_LIVE ?
17401742
"LIVE" : "QUIESCED");
17411743
blk_mq_quiesce_queue(ub->ub_disk->queue);
1744+
/* mark every queue as canceling */
1745+
for (i = 0; i < ub->dev_info.nr_hw_queues; i++)
1746+
ublk_get_queue(ub, i)->canceling = true;
17421747
ublk_wait_tagset_rqs_idle(ub);
17431748
ub->dev_info.state = UBLK_S_DEV_QUIESCED;
1749+
blk_mq_unquiesce_queue(ub->ub_disk->queue);
17441750
}
17451751

17461752
static void ublk_force_abort_dev(struct ublk_device *ub)
@@ -2961,7 +2967,6 @@ static void ublk_queue_reinit(struct ublk_device *ub, struct ublk_queue *ubq)
29612967
/* We have to reset it to NULL, otherwise ub won't accept new FETCH_REQ */
29622968
ubq->ubq_daemon = NULL;
29632969
ubq->timeout = false;
2964-
ubq->canceling = false;
29652970

29662971
for (i = 0; i < ubq->q_depth; i++) {
29672972
struct ublk_io *io = &ubq->ios[i];
@@ -3048,20 +3053,18 @@ static int ublk_ctrl_end_recovery(struct ublk_device *ub,
30483053
pr_devel("%s: new ublksrv_pid %d, dev id %d\n",
30493054
__func__, ublksrv_pid, header->dev_id);
30503055

3051-
if (ublk_nosrv_dev_should_queue_io(ub)) {
3052-
ub->dev_info.state = UBLK_S_DEV_LIVE;
3053-
blk_mq_unquiesce_queue(ub->ub_disk->queue);
3054-
pr_devel("%s: queue unquiesced, dev id %d.\n",
3055-
__func__, header->dev_id);
3056-
blk_mq_kick_requeue_list(ub->ub_disk->queue);
3057-
} else {
3058-
blk_mq_quiesce_queue(ub->ub_disk->queue);
3059-
ub->dev_info.state = UBLK_S_DEV_LIVE;
3060-
for (i = 0; i < ub->dev_info.nr_hw_queues; i++) {
3061-
ublk_get_queue(ub, i)->fail_io = false;
3062-
}
3063-
blk_mq_unquiesce_queue(ub->ub_disk->queue);
3056+
blk_mq_quiesce_queue(ub->ub_disk->queue);
3057+
ub->dev_info.state = UBLK_S_DEV_LIVE;
3058+
for (i = 0; i < ub->dev_info.nr_hw_queues; i++) {
3059+
struct ublk_queue *ubq = ublk_get_queue(ub, i);
3060+
3061+
ubq->canceling = false;
3062+
ubq->fail_io = false;
30643063
}
3064+
blk_mq_unquiesce_queue(ub->ub_disk->queue);
3065+
pr_devel("%s: queue unquiesced, dev id %d.\n",
3066+
__func__, header->dev_id);
3067+
blk_mq_kick_requeue_list(ub->ub_disk->queue);
30653068

30663069
ret = 0;
30673070
out_unlock:

0 commit comments

Comments
 (0)