Skip to content

Commit cfc1ece

Browse files
calebsanderkawasaki
authored andcommitted
ublk: handle UBLK_IO_FETCH_REQ first
Check for UBLK_IO_FETCH_REQ first in __ublk_ch_uring_cmd() and return early. This allows removing the allowances for NULL io->task and UBLK_IO_FLAG_OWNED_BY_SRV unset that only apply to FETCH. Signed-off-by: Caleb Sander Mateos <[email protected]> Reviewed-by: Ming Lei <[email protected]>
1 parent 506f6d3 commit cfc1ece

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

drivers/block/ublk_drv.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2197,8 +2197,18 @@ static int __ublk_ch_uring_cmd(struct io_uring_cmd *cmd,
21972197
goto out;
21982198

21992199
io = &ubq->ios[tag];
2200+
/* UBLK_IO_FETCH_REQ can be handled on any task, which sets io->task */
2201+
if (unlikely(_IOC_NR(cmd_op) == UBLK_IO_FETCH_REQ)) {
2202+
ret = ublk_fetch(cmd, ubq, io, ub_cmd->addr);
2203+
if (ret)
2204+
goto out;
2205+
2206+
ublk_prep_cancel(cmd, issue_flags, ubq, tag);
2207+
return -EIOCBQUEUED;
2208+
}
2209+
22002210
task = READ_ONCE(io->task);
2201-
if (task && task != current)
2211+
if (task != current)
22022212
goto out;
22032213

22042214
/* there is pending io cmd, something must be wrong */
@@ -2207,9 +2217,7 @@ static int __ublk_ch_uring_cmd(struct io_uring_cmd *cmd,
22072217
goto out;
22082218
}
22092219

2210-
/* only UBLK_IO_FETCH_REQ is allowed if io is not OWNED_BY_SRV */
2211-
if (!(io->flags & UBLK_IO_FLAG_OWNED_BY_SRV) &&
2212-
_IOC_NR(cmd_op) != UBLK_IO_FETCH_REQ)
2220+
if (!(io->flags & UBLK_IO_FLAG_OWNED_BY_SRV))
22132221
goto out;
22142222

22152223
/*
@@ -2225,11 +2233,6 @@ static int __ublk_ch_uring_cmd(struct io_uring_cmd *cmd,
22252233
return ublk_register_io_buf(cmd, ubq, tag, ub_cmd->addr, issue_flags);
22262234
case UBLK_IO_UNREGISTER_IO_BUF:
22272235
return ublk_unregister_io_buf(cmd, ubq, ub_cmd->addr, issue_flags);
2228-
case UBLK_IO_FETCH_REQ:
2229-
ret = ublk_fetch(cmd, ubq, io, ub_cmd->addr);
2230-
if (ret)
2231-
goto out;
2232-
break;
22332236
case UBLK_IO_COMMIT_AND_FETCH_REQ:
22342237
ret = ublk_commit_and_fetch(ubq, io, cmd, ub_cmd, issue_flags);
22352238
if (ret)

0 commit comments

Comments
 (0)