ublk: consolidate UBLK_IO_FLAG_OWNED_BY_SRV checks
Every ublk I/O command except UBLK_IO_FETCH_REQ checks that the ublk_io has UBLK_IO_FLAG_OWNED_BY_SRV set. Consolidate the separate checks into a single one in __ublk_ch_uring_cmd(), analogous to those for UBLK_IO_FLAG_ACTIVE and UBLK_IO_FLAG_NEED_GET_DATA. Signed-off-by: Caleb Sander Mateos <csander@purestorage.com> Reviewed-by: Ming Lei <ming.lei@redhat.com> Link: https://lore.kernel.org/r/20250505172624.1121839-1-csander@purestorage.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
parent
18b8144a1b
commit
e96ee7e1de
|
|
@ -1926,16 +1926,12 @@ static int ublk_register_io_buf(struct io_uring_cmd *cmd,
|
|||
unsigned int index, unsigned int issue_flags)
|
||||
{
|
||||
struct ublk_device *ub = cmd->file->private_data;
|
||||
const struct ublk_io *io = &ubq->ios[tag];
|
||||
struct request *req;
|
||||
int ret;
|
||||
|
||||
if (!ublk_support_zero_copy(ubq))
|
||||
return -EINVAL;
|
||||
|
||||
if (!(io->flags & UBLK_IO_FLAG_OWNED_BY_SRV))
|
||||
return -EINVAL;
|
||||
|
||||
req = __ublk_check_and_get_req(ub, ubq, tag, 0);
|
||||
if (!req)
|
||||
return -EINVAL;
|
||||
|
|
@ -1951,17 +1947,12 @@ static int ublk_register_io_buf(struct io_uring_cmd *cmd,
|
|||
}
|
||||
|
||||
static int ublk_unregister_io_buf(struct io_uring_cmd *cmd,
|
||||
const struct ublk_queue *ubq, unsigned int tag,
|
||||
const struct ublk_queue *ubq,
|
||||
unsigned int index, unsigned int issue_flags)
|
||||
{
|
||||
const struct ublk_io *io = &ubq->ios[tag];
|
||||
|
||||
if (!ublk_support_zero_copy(ubq))
|
||||
return -EINVAL;
|
||||
|
||||
if (!(io->flags & UBLK_IO_FLAG_OWNED_BY_SRV))
|
||||
return -EINVAL;
|
||||
|
||||
return io_buffer_unregister_bvec(cmd, index, issue_flags);
|
||||
}
|
||||
|
||||
|
|
@ -2015,12 +2006,8 @@ static int ublk_commit_and_fetch(const struct ublk_queue *ubq,
|
|||
struct ublk_io *io, struct io_uring_cmd *cmd,
|
||||
const struct ublksrv_io_cmd *ub_cmd)
|
||||
{
|
||||
struct request *req;
|
||||
struct request *req = io->req;
|
||||
|
||||
if (!(io->flags & UBLK_IO_FLAG_OWNED_BY_SRV))
|
||||
return -EINVAL;
|
||||
|
||||
req = io->req;
|
||||
if (ublk_need_map_io(ubq)) {
|
||||
/*
|
||||
* COMMIT_AND_FETCH_REQ has to provide IO buffer if
|
||||
|
|
@ -2104,6 +2091,11 @@ static int __ublk_ch_uring_cmd(struct io_uring_cmd *cmd,
|
|||
goto out;
|
||||
}
|
||||
|
||||
/* only UBLK_IO_FETCH_REQ is allowed if io is not OWNED_BY_SRV */
|
||||
if (!(io->flags & UBLK_IO_FLAG_OWNED_BY_SRV) &&
|
||||
_IOC_NR(cmd_op) != UBLK_IO_FETCH_REQ)
|
||||
goto out;
|
||||
|
||||
/*
|
||||
* ensure that the user issues UBLK_IO_NEED_GET_DATA
|
||||
* iff the driver have set the UBLK_IO_FLAG_NEED_GET_DATA.
|
||||
|
|
@ -2121,7 +2113,7 @@ static int __ublk_ch_uring_cmd(struct io_uring_cmd *cmd,
|
|||
case UBLK_IO_REGISTER_IO_BUF:
|
||||
return ublk_register_io_buf(cmd, ubq, tag, ub_cmd->addr, issue_flags);
|
||||
case UBLK_IO_UNREGISTER_IO_BUF:
|
||||
return ublk_unregister_io_buf(cmd, ubq, tag, ub_cmd->addr, issue_flags);
|
||||
return ublk_unregister_io_buf(cmd, ubq, ub_cmd->addr, issue_flags);
|
||||
case UBLK_IO_FETCH_REQ:
|
||||
ret = ublk_fetch(cmd, ubq, io, ub_cmd->addr);
|
||||
if (ret)
|
||||
|
|
@ -2133,8 +2125,6 @@ static int __ublk_ch_uring_cmd(struct io_uring_cmd *cmd,
|
|||
goto out;
|
||||
break;
|
||||
case UBLK_IO_NEED_GET_DATA:
|
||||
if (!(io->flags & UBLK_IO_FLAG_OWNED_BY_SRV))
|
||||
goto out;
|
||||
io->addr = ub_cmd->addr;
|
||||
if (!ublk_get_data(ubq, io))
|
||||
return -EIOCBQUEUED;
|
||||
|
|
|
|||
Loading…
Reference in New Issue