Commit 5b794f98 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Martin K. Petersen

scsi: core: Remove the sense and sense_len fields from struct scsi_request

Just use the sense_buffer field in struct scsi_cmnd for the sense data and
move the sense_len field over to struct scsi_cmnd.

Link: https://lore.kernel.org/r/20220224175552.988286-5-hch@lst.deReviewed-by: default avatarBart Van Assche <bvanassche@acm.org>
Reviewed-by: default avatarJohn Garry <john.garry@huawei.com>
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent ce70fd9a
...@@ -76,11 +76,12 @@ static int scsi_bsg_sg_io_fn(struct request_queue *q, struct sg_io_v4 *hdr, ...@@ -76,11 +76,12 @@ static int scsi_bsg_sg_io_fn(struct request_queue *q, struct sg_io_v4 *hdr,
hdr->info |= SG_INFO_CHECK; hdr->info |= SG_INFO_CHECK;
hdr->response_len = 0; hdr->response_len = 0;
if (sreq->sense_len && hdr->response) { if (scmd->sense_len && hdr->response) {
int len = min_t(unsigned int, hdr->max_response_len, int len = min_t(unsigned int, hdr->max_response_len,
sreq->sense_len); scmd->sense_len);
if (copy_to_user(uptr64(hdr->response), sreq->sense, len)) if (copy_to_user(uptr64(hdr->response), scmd->sense_buffer,
len))
ret = -EFAULT; ret = -EFAULT;
else else
hdr->response_len = len; hdr->response_len = len;
......
...@@ -369,6 +369,7 @@ static int scsi_fill_sghdr_rq(struct scsi_device *sdev, struct request *rq, ...@@ -369,6 +369,7 @@ static int scsi_fill_sghdr_rq(struct scsi_device *sdev, struct request *rq,
static int scsi_complete_sghdr_rq(struct request *rq, struct sg_io_hdr *hdr, static int scsi_complete_sghdr_rq(struct request *rq, struct sg_io_hdr *hdr,
struct bio *bio) struct bio *bio)
{ {
struct scsi_cmnd *scmd = blk_mq_rq_to_pdu(rq);
struct scsi_request *req = scsi_req(rq); struct scsi_request *req = scsi_req(rq);
int r, ret = 0; int r, ret = 0;
...@@ -388,10 +389,10 @@ static int scsi_complete_sghdr_rq(struct request *rq, struct sg_io_hdr *hdr, ...@@ -388,10 +389,10 @@ static int scsi_complete_sghdr_rq(struct request *rq, struct sg_io_hdr *hdr,
hdr->resid = req->resid_len; hdr->resid = req->resid_len;
hdr->sb_len_wr = 0; hdr->sb_len_wr = 0;
if (req->sense_len && hdr->sbp) { if (scmd->sense_len && hdr->sbp) {
int len = min((unsigned int) hdr->mx_sb_len, req->sense_len); int len = min((unsigned int) hdr->mx_sb_len, scmd->sense_len);
if (!copy_to_user(hdr->sbp, req->sense, len)) if (!copy_to_user(hdr->sbp, scmd->sense_buffer, len))
hdr->sb_len_wr = len; hdr->sb_len_wr = len;
else else
ret = -EFAULT; ret = -EFAULT;
...@@ -520,7 +521,6 @@ static int sg_io(struct scsi_device *sdev, struct sg_io_hdr *hdr, fmode_t mode) ...@@ -520,7 +521,6 @@ static int sg_io(struct scsi_device *sdev, struct sg_io_hdr *hdr, fmode_t mode)
static int sg_scsi_ioctl(struct request_queue *q, fmode_t mode, static int sg_scsi_ioctl(struct request_queue *q, fmode_t mode,
struct scsi_ioctl_command __user *sic) struct scsi_ioctl_command __user *sic)
{ {
enum { OMAX_SB_LEN = 16 }; /* For backward compatibility */
struct request *rq; struct request *rq;
struct scsi_request *req; struct scsi_request *req;
int err; int err;
...@@ -613,10 +613,10 @@ static int sg_scsi_ioctl(struct request_queue *q, fmode_t mode, ...@@ -613,10 +613,10 @@ static int sg_scsi_ioctl(struct request_queue *q, fmode_t mode,
err = req->result & 0xff; /* only 8 bit SCSI status */ err = req->result & 0xff; /* only 8 bit SCSI status */
if (err) { if (err) {
if (req->sense_len && req->sense) { if (scmd->sense_len && scmd->sense_buffer) {
bytes = (OMAX_SB_LEN > req->sense_len) ? /* limit sense len for backward compatibility */
req->sense_len : OMAX_SB_LEN; if (copy_to_user(sic->data, scmd->sense_buffer,
if (copy_to_user(sic->data, req->sense, bytes)) min(scmd->sense_len, 16U)))
err = -EFAULT; err = -EFAULT;
} }
} else { } else {
......
...@@ -256,10 +256,11 @@ int __scsi_execute(struct scsi_device *sdev, const unsigned char *cmd, ...@@ -256,10 +256,11 @@ int __scsi_execute(struct scsi_device *sdev, const unsigned char *cmd,
if (resid) if (resid)
*resid = rq->resid_len; *resid = rq->resid_len;
if (sense && rq->sense_len) if (sense && scmd->sense_len)
memcpy(sense, rq->sense, SCSI_SENSE_BUFFERSIZE); memcpy(sense, scmd->sense_buffer, SCSI_SENSE_BUFFERSIZE);
if (sshdr) if (sshdr)
scsi_normalize_sense(rq->sense, rq->sense_len, sshdr); scsi_normalize_sense(scmd->sense_buffer, scmd->sense_len,
sshdr);
ret = rq->result; ret = rq->result;
out: out:
blk_mq_free_request(req); blk_mq_free_request(req);
...@@ -876,9 +877,8 @@ static int scsi_io_completion_nz_result(struct scsi_cmnd *cmd, int result, ...@@ -876,9 +877,8 @@ static int scsi_io_completion_nz_result(struct scsi_cmnd *cmd, int result,
/* /*
* SG_IO wants current and deferred errors * SG_IO wants current and deferred errors
*/ */
scsi_req(req)->sense_len = cmd->sense_len = min(8 + cmd->sense_buffer[7],
min(8 + cmd->sense_buffer[7], SCSI_SENSE_BUFFERSIZE);
SCSI_SENSE_BUFFERSIZE);
} }
if (sense_current) if (sense_current)
*blk_statp = scsi_result_to_blk_status(cmd, result); *blk_statp = scsi_result_to_blk_status(cmd, result);
...@@ -1126,13 +1126,10 @@ EXPORT_SYMBOL(scsi_alloc_sgtables); ...@@ -1126,13 +1126,10 @@ EXPORT_SYMBOL(scsi_alloc_sgtables);
static void scsi_initialize_rq(struct request *rq) static void scsi_initialize_rq(struct request *rq)
{ {
struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(rq); struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(rq);
struct scsi_request *req = &cmd->req;
memset(cmd->cmnd, 0, sizeof(cmd->cmnd)); memset(cmd->cmnd, 0, sizeof(cmd->cmnd));
cmd->cmd_len = MAX_COMMAND_SIZE; cmd->cmd_len = MAX_COMMAND_SIZE;
cmd->sense_len = 0;
req->sense_len = 0;
init_rcu_head(&cmd->rcu); init_rcu_head(&cmd->rcu);
cmd->jiffies_at_alloc = jiffies; cmd->jiffies_at_alloc = jiffies;
cmd->retries = 0; cmd->retries = 0;
...@@ -1824,7 +1821,6 @@ static int scsi_mq_init_request(struct blk_mq_tag_set *set, struct request *rq, ...@@ -1824,7 +1821,6 @@ static int scsi_mq_init_request(struct blk_mq_tag_set *set, struct request *rq,
kmem_cache_alloc_node(scsi_sense_cache, GFP_KERNEL, numa_node); kmem_cache_alloc_node(scsi_sense_cache, GFP_KERNEL, numa_node);
if (!cmd->sense_buffer) if (!cmd->sense_buffer)
return -ENOMEM; return -ENOMEM;
cmd->req.sense = cmd->sense_buffer;
if (scsi_host_get_prot(shost)) { if (scsi_host_get_prot(shost)) {
sg = (void *)cmd + sizeof(struct scsi_cmnd) + sg = (void *)cmd + sizeof(struct scsi_cmnd) +
......
...@@ -1323,6 +1323,7 @@ sg_rq_end_io_usercontext(struct work_struct *work) ...@@ -1323,6 +1323,7 @@ sg_rq_end_io_usercontext(struct work_struct *work)
static void static void
sg_rq_end_io(struct request *rq, blk_status_t status) sg_rq_end_io(struct request *rq, blk_status_t status)
{ {
struct scsi_cmnd *scmd = blk_mq_rq_to_pdu(rq);
struct sg_request *srp = rq->end_io_data; struct sg_request *srp = rq->end_io_data;
struct scsi_request *req = scsi_req(rq); struct scsi_request *req = scsi_req(rq);
Sg_device *sdp; Sg_device *sdp;
...@@ -1343,7 +1344,7 @@ sg_rq_end_io(struct request *rq, blk_status_t status) ...@@ -1343,7 +1344,7 @@ sg_rq_end_io(struct request *rq, blk_status_t status)
if (unlikely(atomic_read(&sdp->detaching))) if (unlikely(atomic_read(&sdp->detaching)))
pr_info("%s: device detaching\n", __func__); pr_info("%s: device detaching\n", __func__);
sense = req->sense; sense = scmd->sense_buffer;
result = req->result; result = req->result;
resid = req->resid_len; resid = req->resid_len;
...@@ -1380,8 +1381,8 @@ sg_rq_end_io(struct request *rq, blk_status_t status) ...@@ -1380,8 +1381,8 @@ sg_rq_end_io(struct request *rq, blk_status_t status)
} }
} }
if (req->sense_len) if (scmd->sense_len)
memcpy(srp->sense_b, req->sense, SCSI_SENSE_BUFFERSIZE); memcpy(srp->sense_b, scmd->sense_buffer, SCSI_SENSE_BUFFERSIZE);
/* Rely on write phase to clean out srp status values, so no "else" */ /* Rely on write phase to clean out srp status values, so no "else" */
......
...@@ -999,7 +999,7 @@ static int sr_read_cdda_bpc(struct cdrom_device_info *cdi, void __user *ubuf, ...@@ -999,7 +999,7 @@ static int sr_read_cdda_bpc(struct cdrom_device_info *cdi, void __user *ubuf,
if (scsi_req(rq)->result) { if (scsi_req(rq)->result) {
struct scsi_sense_hdr sshdr; struct scsi_sense_hdr sshdr;
scsi_normalize_sense(req->sense, req->sense_len, scsi_normalize_sense(scmd->sense_buffer, scmd->sense_len,
&sshdr); &sshdr);
*last_sense = sshdr.sense_key; *last_sense = sshdr.sense_key;
ret = -EIO; ret = -EIO;
......
...@@ -514,6 +514,7 @@ static void st_do_stats(struct scsi_tape *STp, struct request *req) ...@@ -514,6 +514,7 @@ static void st_do_stats(struct scsi_tape *STp, struct request *req)
static void st_scsi_execute_end(struct request *req, blk_status_t status) static void st_scsi_execute_end(struct request *req, blk_status_t status)
{ {
struct scsi_cmnd *scmd = blk_mq_rq_to_pdu(req);
struct st_request *SRpnt = req->end_io_data; struct st_request *SRpnt = req->end_io_data;
struct scsi_request *rq = scsi_req(req); struct scsi_request *rq = scsi_req(req);
struct scsi_tape *STp = SRpnt->stp; struct scsi_tape *STp = SRpnt->stp;
...@@ -525,8 +526,8 @@ static void st_scsi_execute_end(struct request *req, blk_status_t status) ...@@ -525,8 +526,8 @@ static void st_scsi_execute_end(struct request *req, blk_status_t status)
st_do_stats(STp, req); st_do_stats(STp, req);
tmp = SRpnt->bio; tmp = SRpnt->bio;
if (rq->sense_len) if (scmd->sense_len)
memcpy(SRpnt->sense, rq->sense, SCSI_SENSE_BUFFERSIZE); memcpy(SRpnt->sense, scmd->sense_buffer, SCSI_SENSE_BUFFERSIZE);
if (SRpnt->waiting) if (SRpnt->waiting)
complete(SRpnt->waiting); complete(SRpnt->waiting);
......
...@@ -1031,6 +1031,7 @@ static sector_t pscsi_get_blocks(struct se_device *dev) ...@@ -1031,6 +1031,7 @@ static sector_t pscsi_get_blocks(struct se_device *dev)
static void pscsi_req_done(struct request *req, blk_status_t status) static void pscsi_req_done(struct request *req, blk_status_t status)
{ {
struct se_cmd *cmd = req->end_io_data; struct se_cmd *cmd = req->end_io_data;
struct scsi_cmnd *scmd = blk_mq_rq_to_pdu(req);
int result = scsi_req(req)->result; int result = scsi_req(req)->result;
enum sam_status scsi_status = result & 0xff; enum sam_status scsi_status = result & 0xff;
u8 *cdb = cmd->priv; u8 *cdb = cmd->priv;
...@@ -1040,7 +1041,7 @@ static void pscsi_req_done(struct request *req, blk_status_t status) ...@@ -1040,7 +1041,7 @@ static void pscsi_req_done(struct request *req, blk_status_t status)
" 0x%02x Result: 0x%08x\n", cmd, cdb[0], result); " 0x%02x Result: 0x%08x\n", cmd, cdb[0], result);
} }
pscsi_complete_cmd(cmd, scsi_status, scsi_req(req)->sense); pscsi_complete_cmd(cmd, scsi_status, scmd->sense_buffer);
switch (host_byte(result)) { switch (host_byte(result)) {
case DID_OK: case DID_OK:
......
...@@ -112,6 +112,7 @@ struct scsi_cmnd { ...@@ -112,6 +112,7 @@ struct scsi_cmnd {
reconnects. Probably == sector reconnects. Probably == sector
size */ size */
unsigned sense_len;
unsigned char *sense_buffer; unsigned char *sense_buffer;
/* obtained by REQUEST SENSE when /* obtained by REQUEST SENSE when
* CHECK CONDITION is received on original * CHECK CONDITION is received on original
......
...@@ -6,10 +6,8 @@ ...@@ -6,10 +6,8 @@
struct scsi_request { struct scsi_request {
int result; int result;
unsigned int sense_len;
unsigned int resid_len; /* residual count */ unsigned int resid_len; /* residual count */
int retries; int retries;
void *sense;
}; };
static inline struct scsi_request *scsi_req(struct request *rq) static inline struct scsi_request *scsi_req(struct request *rq)
......
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