mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2025-01-01 10:42:11 +00:00
bsg-lib: initialize the bsg_job in bsg_transport_sg_io_fn
Directly initialize the bsg_job structure instead of relying on the ->.initialize_rq_fn indirection. This also removes the superflous initialization of the second request used for BIDI requests. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Hannes Reinecke <hare@suse.de> Link: https://lore.kernel.org/r/20211021060607.264371-5-hch@lst.de Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
parent
8c6aabd1c7
commit
237ea1602f
@ -31,6 +31,7 @@ static int bsg_transport_sg_io_fn(struct request_queue *q, struct sg_io_v4 *hdr,
|
|||||||
struct bsg_job *job;
|
struct bsg_job *job;
|
||||||
struct request *rq;
|
struct request *rq;
|
||||||
struct bio *bio;
|
struct bio *bio;
|
||||||
|
void *reply;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (hdr->protocol != BSG_PROTOCOL_SCSI ||
|
if (hdr->protocol != BSG_PROTOCOL_SCSI ||
|
||||||
@ -39,22 +40,28 @@ static int bsg_transport_sg_io_fn(struct request_queue *q, struct sg_io_v4 *hdr,
|
|||||||
if (!capable(CAP_SYS_RAWIO))
|
if (!capable(CAP_SYS_RAWIO))
|
||||||
return -EPERM;
|
return -EPERM;
|
||||||
|
|
||||||
rq = blk_get_request(q, hdr->dout_xfer_len ?
|
rq = blk_mq_alloc_request(q, hdr->dout_xfer_len ?
|
||||||
REQ_OP_DRV_OUT : REQ_OP_DRV_IN, 0);
|
REQ_OP_DRV_OUT : REQ_OP_DRV_IN, 0);
|
||||||
if (IS_ERR(rq))
|
if (IS_ERR(rq))
|
||||||
return PTR_ERR(rq);
|
return PTR_ERR(rq);
|
||||||
rq->timeout = timeout;
|
rq->timeout = timeout;
|
||||||
|
|
||||||
job = blk_mq_rq_to_pdu(rq);
|
job = blk_mq_rq_to_pdu(rq);
|
||||||
|
reply = job->reply;
|
||||||
|
memset(job, 0, sizeof(*job));
|
||||||
|
job->reply = reply;
|
||||||
|
job->reply_len = SCSI_SENSE_BUFFERSIZE;
|
||||||
|
job->dd_data = job + 1;
|
||||||
|
|
||||||
job->request_len = hdr->request_len;
|
job->request_len = hdr->request_len;
|
||||||
job->request = memdup_user(uptr64(hdr->request), hdr->request_len);
|
job->request = memdup_user(uptr64(hdr->request), hdr->request_len);
|
||||||
if (IS_ERR(job->request)) {
|
if (IS_ERR(job->request)) {
|
||||||
ret = PTR_ERR(job->request);
|
ret = PTR_ERR(job->request);
|
||||||
goto out_put_request;
|
goto out_free_rq;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hdr->dout_xfer_len && hdr->din_xfer_len) {
|
if (hdr->dout_xfer_len && hdr->din_xfer_len) {
|
||||||
job->bidi_rq = blk_get_request(rq->q, REQ_OP_DRV_IN, 0);
|
job->bidi_rq = blk_mq_alloc_request(rq->q, REQ_OP_DRV_IN, 0);
|
||||||
if (IS_ERR(job->bidi_rq)) {
|
if (IS_ERR(job->bidi_rq)) {
|
||||||
ret = PTR_ERR(job->bidi_rq);
|
ret = PTR_ERR(job->bidi_rq);
|
||||||
goto out_free_job_request;
|
goto out_free_job_request;
|
||||||
@ -134,11 +141,11 @@ static int bsg_transport_sg_io_fn(struct request_queue *q, struct sg_io_v4 *hdr,
|
|||||||
blk_rq_unmap_user(job->bidi_bio);
|
blk_rq_unmap_user(job->bidi_bio);
|
||||||
out_free_bidi_rq:
|
out_free_bidi_rq:
|
||||||
if (job->bidi_rq)
|
if (job->bidi_rq)
|
||||||
blk_put_request(job->bidi_rq);
|
blk_mq_free_request(job->bidi_rq);
|
||||||
out_free_job_request:
|
out_free_job_request:
|
||||||
kfree(job->request);
|
kfree(job->request);
|
||||||
out_put_request:
|
out_free_rq:
|
||||||
blk_put_request(rq);
|
blk_mq_free_request(rq);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -302,18 +309,6 @@ static int bsg_init_rq(struct blk_mq_tag_set *set, struct request *req,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* called right before the request is given to the request_queue user */
|
|
||||||
static void bsg_initialize_rq(struct request *req)
|
|
||||||
{
|
|
||||||
struct bsg_job *job = blk_mq_rq_to_pdu(req);
|
|
||||||
void *reply = job->reply;
|
|
||||||
|
|
||||||
memset(job, 0, sizeof(*job));
|
|
||||||
job->reply = reply;
|
|
||||||
job->reply_len = SCSI_SENSE_BUFFERSIZE;
|
|
||||||
job->dd_data = job + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void bsg_exit_rq(struct blk_mq_tag_set *set, struct request *req,
|
static void bsg_exit_rq(struct blk_mq_tag_set *set, struct request *req,
|
||||||
unsigned int hctx_idx)
|
unsigned int hctx_idx)
|
||||||
{
|
{
|
||||||
@ -350,7 +345,6 @@ static const struct blk_mq_ops bsg_mq_ops = {
|
|||||||
.queue_rq = bsg_queue_rq,
|
.queue_rq = bsg_queue_rq,
|
||||||
.init_request = bsg_init_rq,
|
.init_request = bsg_init_rq,
|
||||||
.exit_request = bsg_exit_rq,
|
.exit_request = bsg_exit_rq,
|
||||||
.initialize_rq_fn = bsg_initialize_rq,
|
|
||||||
.complete = bsg_complete,
|
.complete = bsg_complete,
|
||||||
.timeout = bsg_timeout,
|
.timeout = bsg_timeout,
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user