Commit 470e900c authored by Kanchan Joshi's avatar Kanchan Joshi Committed by Jens Axboe

nvme: refactor nvme_alloc_request

nvme_alloc_request expects a large number of parameters.
Split this out into two functions to reduce number of parameters.
First one retains the name nvme_alloc_request, while second one is
named nvme_map_user_request.
Signed-off-by: default avatarKanchan Joshi <joshi.k@samsung.com>
Signed-off-by: default avatarAnuj Gupta <anuj20.g@samsung.com>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20220930062749.152261-8-anuj20.g@samsung.comSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 38c0ddab
...@@ -70,54 +70,57 @@ static int nvme_finish_user_metadata(struct request *req, void __user *ubuf, ...@@ -70,54 +70,57 @@ static int nvme_finish_user_metadata(struct request *req, void __user *ubuf,
} }
static struct request *nvme_alloc_user_request(struct request_queue *q, static struct request *nvme_alloc_user_request(struct request_queue *q,
struct nvme_command *cmd, void __user *ubuffer, struct nvme_command *cmd, blk_opf_t rq_flags,
unsigned bufflen, void __user *meta_buffer, unsigned meta_len, blk_mq_req_flags_t blk_flags)
u32 meta_seed, void **metap, unsigned timeout, bool vec,
blk_opf_t rq_flags, blk_mq_req_flags_t blk_flags)
{ {
struct nvme_ns *ns = q->queuedata;
struct block_device *bdev = ns ? ns->disk->part0 : NULL;
struct request *req; struct request *req;
struct bio *bio = NULL;
void *meta = NULL;
int ret;
req = blk_mq_alloc_request(q, nvme_req_op(cmd) | rq_flags, blk_flags); req = blk_mq_alloc_request(q, nvme_req_op(cmd) | rq_flags, blk_flags);
if (IS_ERR(req)) if (IS_ERR(req))
return req; return req;
nvme_init_request(req, cmd); nvme_init_request(req, cmd);
if (timeout)
req->timeout = timeout;
nvme_req(req)->flags |= NVME_REQ_USERCMD; nvme_req(req)->flags |= NVME_REQ_USERCMD;
return req;
}
if (ubuffer && bufflen) { static int nvme_map_user_request(struct request *req, void __user *ubuffer,
ret = blk_rq_map_user_io(req, NULL, ubuffer, bufflen, unsigned bufflen, void __user *meta_buffer, unsigned meta_len,
GFP_KERNEL, vec, 0, 0, rq_data_dir(req)); u32 meta_seed, void **metap, bool vec)
if (ret) {
goto out; struct request_queue *q = req->q;
bio = req->bio; struct nvme_ns *ns = q->queuedata;
if (bdev) struct block_device *bdev = ns ? ns->disk->part0 : NULL;
bio_set_dev(bio, bdev); struct bio *bio = NULL;
if (bdev && meta_buffer && meta_len) { void *meta = NULL;
meta = nvme_add_user_metadata(req, meta_buffer, int ret;
meta_len, meta_seed);
if (IS_ERR(meta)) { ret = blk_rq_map_user_io(req, NULL, ubuffer, bufflen, GFP_KERNEL, vec,
ret = PTR_ERR(meta); 0, 0, rq_data_dir(req));
goto out_unmap;
} if (ret)
*metap = meta; goto out;
bio = req->bio;
if (bdev)
bio_set_dev(bio, bdev);
if (bdev && meta_buffer && meta_len) {
meta = nvme_add_user_metadata(req, meta_buffer, meta_len,
meta_seed);
if (IS_ERR(meta)) {
ret = PTR_ERR(meta);
goto out_unmap;
} }
*metap = meta;
} }
return req; return ret;
out_unmap: out_unmap:
if (bio) if (bio)
blk_rq_unmap_user(bio); blk_rq_unmap_user(bio);
out: out:
blk_mq_free_request(req); blk_mq_free_request(req);
return ERR_PTR(ret); return ret;
} }
static int nvme_submit_user_cmd(struct request_queue *q, static int nvme_submit_user_cmd(struct request_queue *q,
...@@ -132,11 +135,18 @@ static int nvme_submit_user_cmd(struct request_queue *q, ...@@ -132,11 +135,18 @@ static int nvme_submit_user_cmd(struct request_queue *q,
u32 effects; u32 effects;
int ret; int ret;
req = nvme_alloc_user_request(q, cmd, ubuffer, bufflen, meta_buffer, req = nvme_alloc_user_request(q, cmd, 0, 0);
meta_len, meta_seed, &meta, timeout, vec, 0, 0);
if (IS_ERR(req)) if (IS_ERR(req))
return PTR_ERR(req); return PTR_ERR(req);
req->timeout = timeout;
if (ubuffer && bufflen) {
ret = nvme_map_user_request(req, ubuffer, bufflen, meta_buffer,
meta_len, meta_seed, &meta, vec);
if (ret)
return ret;
}
bio = req->bio; bio = req->bio;
ctrl = nvme_req(req)->ctrl; ctrl = nvme_req(req)->ctrl;
...@@ -456,6 +466,7 @@ static int nvme_uring_cmd_io(struct nvme_ctrl *ctrl, struct nvme_ns *ns, ...@@ -456,6 +466,7 @@ static int nvme_uring_cmd_io(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
blk_opf_t rq_flags = 0; blk_opf_t rq_flags = 0;
blk_mq_req_flags_t blk_flags = 0; blk_mq_req_flags_t blk_flags = 0;
void *meta = NULL; void *meta = NULL;
int ret;
if (!capable(CAP_SYS_ADMIN)) if (!capable(CAP_SYS_ADMIN))
return -EACCES; return -EACCES;
...@@ -495,13 +506,18 @@ static int nvme_uring_cmd_io(struct nvme_ctrl *ctrl, struct nvme_ns *ns, ...@@ -495,13 +506,18 @@ static int nvme_uring_cmd_io(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
rq_flags |= REQ_POLLED; rq_flags |= REQ_POLLED;
retry: retry:
req = nvme_alloc_user_request(q, &c, nvme_to_user_ptr(d.addr), req = nvme_alloc_user_request(q, &c, rq_flags, blk_flags);
d.data_len, nvme_to_user_ptr(d.metadata),
d.metadata_len, 0, &meta, d.timeout_ms ?
msecs_to_jiffies(d.timeout_ms) : 0, vec, rq_flags,
blk_flags);
if (IS_ERR(req)) if (IS_ERR(req))
return PTR_ERR(req); return PTR_ERR(req);
req->timeout = d.timeout_ms ? msecs_to_jiffies(d.timeout_ms) : 0;
if (d.addr && d.data_len) {
ret = nvme_map_user_request(req, nvme_to_user_ptr(d.addr),
d.data_len, nvme_to_user_ptr(d.metadata),
d.metadata_len, 0, &meta, vec);
if (ret)
return ret;
}
if (issue_flags & IO_URING_F_IOPOLL && rq_flags & REQ_POLLED) { if (issue_flags & IO_URING_F_IOPOLL && rq_flags & REQ_POLLED) {
if (unlikely(!req->bio)) { if (unlikely(!req->bio)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment