Skip to content

Commit 4c8a951

Browse files
Ming Leiaxboe
authored andcommitted
ublk: setup ublk_io correctly in case of ublk_get_data() failure
If ublk_get_data() fails, -EIOCBQUEUED is returned and the current command becomes ASYNC. And the only reason is that mapping data can't move on, because of no enough pages or pending signal, then the current ublk request has to be requeued. Once the request need to be requeued, we have to setup `ublk_io` correctly, including io->cmd and flags, otherwise the request may not be forwarded to ublk server successfully. Fixes: 9810362 ("ublk: don't call ublk_dispatch_req() for NEED_GET_DATA") Reported-by: Changhui Zhong <[email protected]> Closes: https://lore.kernel.org/linux-block/CAGVVp+VN9QcpHUz_0nasFf5q9i1gi8H8j-G-6mkBoqa3TyjRHA@mail.gmail.com/ Signed-off-by: Ming Lei <[email protected]> Tested-by: Changhui Zhong <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 81b4d1a commit 4c8a951

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

drivers/block/ublk_drv.c

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,8 +1148,8 @@ static inline void __ublk_complete_rq(struct request *req)
11481148
blk_mq_end_request(req, res);
11491149
}
11501150

1151-
static void ublk_complete_io_cmd(struct ublk_io *io, struct request *req,
1152-
int res, unsigned issue_flags)
1151+
static struct io_uring_cmd *__ublk_prep_compl_io_cmd(struct ublk_io *io,
1152+
struct request *req)
11531153
{
11541154
/* read cmd first because req will overwrite it */
11551155
struct io_uring_cmd *cmd = io->cmd;
@@ -1164,6 +1164,13 @@ static void ublk_complete_io_cmd(struct ublk_io *io, struct request *req,
11641164
io->flags &= ~UBLK_IO_FLAG_ACTIVE;
11651165

11661166
io->req = req;
1167+
return cmd;
1168+
}
1169+
1170+
static void ublk_complete_io_cmd(struct ublk_io *io, struct request *req,
1171+
int res, unsigned issue_flags)
1172+
{
1173+
struct io_uring_cmd *cmd = __ublk_prep_compl_io_cmd(io, req);
11671174

11681175
/* tell ublksrv one io request is coming */
11691176
io_uring_cmd_done(cmd, res, 0, issue_flags);
@@ -2157,10 +2164,9 @@ static int ublk_commit_and_fetch(const struct ublk_queue *ubq,
21572164
return 0;
21582165
}
21592166

2160-
static bool ublk_get_data(const struct ublk_queue *ubq, struct ublk_io *io)
2167+
static bool ublk_get_data(const struct ublk_queue *ubq, struct ublk_io *io,
2168+
struct request *req)
21612169
{
2162-
struct request *req = io->req;
2163-
21642170
/*
21652171
* We have handled UBLK_IO_NEED_GET_DATA command,
21662172
* so clear UBLK_IO_FLAG_NEED_GET_DATA now and just
@@ -2187,6 +2193,7 @@ static int __ublk_ch_uring_cmd(struct io_uring_cmd *cmd,
21872193
u32 cmd_op = cmd->cmd_op;
21882194
unsigned tag = ub_cmd->tag;
21892195
int ret = -EINVAL;
2196+
struct request *req;
21902197

21912198
pr_devel("%s: received: cmd op %d queue %d tag %d result %d\n",
21922199
__func__, cmd->cmd_op, ub_cmd->q_id, tag,
@@ -2245,11 +2252,19 @@ static int __ublk_ch_uring_cmd(struct io_uring_cmd *cmd,
22452252
goto out;
22462253
break;
22472254
case UBLK_IO_NEED_GET_DATA:
2248-
io->addr = ub_cmd->addr;
2249-
if (!ublk_get_data(ubq, io))
2250-
return -EIOCBQUEUED;
2251-
2252-
return UBLK_IO_RES_OK;
2255+
/*
2256+
* ublk_get_data() may fail and fallback to requeue, so keep
2257+
* uring_cmd active first and prepare for handling new requeued
2258+
* request
2259+
*/
2260+
req = io->req;
2261+
ublk_fill_io_cmd(io, cmd, ub_cmd->addr);
2262+
io->flags &= ~UBLK_IO_FLAG_OWNED_BY_SRV;
2263+
if (likely(ublk_get_data(ubq, io, req))) {
2264+
__ublk_prep_compl_io_cmd(io, req);
2265+
return UBLK_IO_RES_OK;
2266+
}
2267+
break;
22532268
default:
22542269
goto out;
22552270
}

0 commit comments

Comments
 (0)