ublk: inline ublk_check_and_get_req() into ublk_user_copy()
ublk_check_and_get_req() has a single callsite in ublk_user_copy(). It takes a ton of arguments in order to pass local variables from ublk_user_copy() to ublk_check_and_get_req() and vice versa. And more are about to be added. Combine the functions to reduce the argument passing noise. Signed-off-by: Caleb Sander Mateos <csander@purestorage.com> Reviewed-by: Ming Lei <ming.lei@redhat.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
parent
5bfbbc9938
commit
ca80afd870
|
|
@ -2664,66 +2664,51 @@ static inline bool ublk_check_ubuf_dir(const struct request *req,
|
|||
return false;
|
||||
}
|
||||
|
||||
static struct request *ublk_check_and_get_req(struct kiocb *iocb,
|
||||
struct iov_iter *iter, size_t *off, int dir,
|
||||
struct ublk_io **io)
|
||||
static ssize_t
|
||||
ublk_user_copy(struct kiocb *iocb, struct iov_iter *iter, int dir)
|
||||
{
|
||||
struct ublk_device *ub = iocb->ki_filp->private_data;
|
||||
struct ublk_queue *ubq;
|
||||
struct request *req;
|
||||
struct ublk_io *io;
|
||||
size_t buf_off;
|
||||
u16 tag, q_id;
|
||||
ssize_t ret;
|
||||
|
||||
if (!user_backed_iter(iter))
|
||||
return ERR_PTR(-EACCES);
|
||||
return -EACCES;
|
||||
|
||||
if (ub->dev_info.state == UBLK_S_DEV_DEAD)
|
||||
return ERR_PTR(-EACCES);
|
||||
return -EACCES;
|
||||
|
||||
tag = ublk_pos_to_tag(iocb->ki_pos);
|
||||
q_id = ublk_pos_to_hwq(iocb->ki_pos);
|
||||
buf_off = ublk_pos_to_buf_off(iocb->ki_pos);
|
||||
|
||||
if (q_id >= ub->dev_info.nr_hw_queues)
|
||||
return ERR_PTR(-EINVAL);
|
||||
return -EINVAL;
|
||||
|
||||
ubq = ublk_get_queue(ub, q_id);
|
||||
if (!ublk_dev_support_user_copy(ub))
|
||||
return ERR_PTR(-EACCES);
|
||||
return -EACCES;
|
||||
|
||||
if (tag >= ub->dev_info.queue_depth)
|
||||
return ERR_PTR(-EINVAL);
|
||||
return -EINVAL;
|
||||
|
||||
*io = &ubq->ios[tag];
|
||||
req = __ublk_check_and_get_req(ub, q_id, tag, *io, buf_off);
|
||||
io = &ubq->ios[tag];
|
||||
req = __ublk_check_and_get_req(ub, q_id, tag, io, buf_off);
|
||||
if (!req)
|
||||
return ERR_PTR(-EINVAL);
|
||||
return -EINVAL;
|
||||
|
||||
if (!ublk_check_ubuf_dir(req, dir))
|
||||
goto fail;
|
||||
|
||||
*off = buf_off;
|
||||
return req;
|
||||
fail:
|
||||
ublk_put_req_ref(*io, req);
|
||||
return ERR_PTR(-EACCES);
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
ublk_user_copy(struct kiocb *iocb, struct iov_iter *iter, int dir)
|
||||
{
|
||||
struct request *req;
|
||||
struct ublk_io *io;
|
||||
size_t buf_off;
|
||||
size_t ret;
|
||||
|
||||
req = ublk_check_and_get_req(iocb, iter, &buf_off, dir, &io);
|
||||
if (IS_ERR(req))
|
||||
return PTR_ERR(req);
|
||||
if (!ublk_check_ubuf_dir(req, dir)) {
|
||||
ret = -EACCES;
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = ublk_copy_user_pages(req, buf_off, iter, dir);
|
||||
ublk_put_req_ref(io, req);
|
||||
|
||||
out:
|
||||
ublk_put_req_ref(io, req);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue