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.de
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: John Garry <john.garry@huawei.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
This commit is contained in:
Christoph Hellwig 2022-02-24 18:55:48 +01:00 committed by Martin K. Petersen
parent ce70fd9a55
commit 5b794f9807
9 changed files with 30 additions and 31 deletions

View File

@ -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->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,
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;
else
hdr->response_len = len;

View File

@ -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,
struct bio *bio)
{
struct scsi_cmnd *scmd = blk_mq_rq_to_pdu(rq);
struct scsi_request *req = scsi_req(rq);
int r, ret = 0;
@ -388,10 +389,10 @@ static int scsi_complete_sghdr_rq(struct request *rq, struct sg_io_hdr *hdr,
hdr->resid = req->resid_len;
hdr->sb_len_wr = 0;
if (req->sense_len && hdr->sbp) {
int len = min((unsigned int) hdr->mx_sb_len, req->sense_len);
if (scmd->sense_len && hdr->sbp) {
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;
else
ret = -EFAULT;
@ -520,7 +521,6 @@ out_put_request:
static int sg_scsi_ioctl(struct request_queue *q, fmode_t mode,
struct scsi_ioctl_command __user *sic)
{
enum { OMAX_SB_LEN = 16 }; /* For backward compatibility */
struct request *rq;
struct scsi_request *req;
int err;
@ -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 */
if (err) {
if (req->sense_len && req->sense) {
bytes = (OMAX_SB_LEN > req->sense_len) ?
req->sense_len : OMAX_SB_LEN;
if (copy_to_user(sic->data, req->sense, bytes))
if (scmd->sense_len && scmd->sense_buffer) {
/* limit sense len for backward compatibility */
if (copy_to_user(sic->data, scmd->sense_buffer,
min(scmd->sense_len, 16U)))
err = -EFAULT;
}
} else {

View File

@ -256,10 +256,11 @@ int __scsi_execute(struct scsi_device *sdev, const unsigned char *cmd,
if (resid)
*resid = rq->resid_len;
if (sense && rq->sense_len)
memcpy(sense, rq->sense, SCSI_SENSE_BUFFERSIZE);
if (sense && scmd->sense_len)
memcpy(sense, scmd->sense_buffer, SCSI_SENSE_BUFFERSIZE);
if (sshdr)
scsi_normalize_sense(rq->sense, rq->sense_len, sshdr);
scsi_normalize_sense(scmd->sense_buffer, scmd->sense_len,
sshdr);
ret = rq->result;
out:
blk_mq_free_request(req);
@ -876,9 +877,8 @@ static int scsi_io_completion_nz_result(struct scsi_cmnd *cmd, int result,
/*
* SG_IO wants current and deferred errors
*/
scsi_req(req)->sense_len =
min(8 + cmd->sense_buffer[7],
SCSI_SENSE_BUFFERSIZE);
cmd->sense_len = min(8 + cmd->sense_buffer[7],
SCSI_SENSE_BUFFERSIZE);
}
if (sense_current)
*blk_statp = scsi_result_to_blk_status(cmd, result);
@ -1126,13 +1126,10 @@ EXPORT_SYMBOL(scsi_alloc_sgtables);
static void scsi_initialize_rq(struct request *rq)
{
struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(rq);
struct scsi_request *req = &cmd->req;
memset(cmd->cmnd, 0, sizeof(cmd->cmnd));
cmd->cmd_len = MAX_COMMAND_SIZE;
req->sense_len = 0;
cmd->sense_len = 0;
init_rcu_head(&cmd->rcu);
cmd->jiffies_at_alloc = jiffies;
cmd->retries = 0;
@ -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);
if (!cmd->sense_buffer)
return -ENOMEM;
cmd->req.sense = cmd->sense_buffer;
if (scsi_host_get_prot(shost)) {
sg = (void *)cmd + sizeof(struct scsi_cmnd) +

View File

@ -1323,6 +1323,7 @@ sg_rq_end_io_usercontext(struct work_struct *work)
static void
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 scsi_request *req = scsi_req(rq);
Sg_device *sdp;
@ -1343,7 +1344,7 @@ sg_rq_end_io(struct request *rq, blk_status_t status)
if (unlikely(atomic_read(&sdp->detaching)))
pr_info("%s: device detaching\n", __func__);
sense = req->sense;
sense = scmd->sense_buffer;
result = req->result;
resid = req->resid_len;
@ -1380,8 +1381,8 @@ sg_rq_end_io(struct request *rq, blk_status_t status)
}
}
if (req->sense_len)
memcpy(srp->sense_b, req->sense, SCSI_SENSE_BUFFERSIZE);
if (scmd->sense_len)
memcpy(srp->sense_b, scmd->sense_buffer, SCSI_SENSE_BUFFERSIZE);
/* Rely on write phase to clean out srp status values, so no "else" */

View File

@ -999,7 +999,7 @@ static int sr_read_cdda_bpc(struct cdrom_device_info *cdi, void __user *ubuf,
if (scsi_req(rq)->result) {
struct scsi_sense_hdr sshdr;
scsi_normalize_sense(req->sense, req->sense_len,
scsi_normalize_sense(scmd->sense_buffer, scmd->sense_len,
&sshdr);
*last_sense = sshdr.sense_key;
ret = -EIO;

View File

@ -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)
{
struct scsi_cmnd *scmd = blk_mq_rq_to_pdu(req);
struct st_request *SRpnt = req->end_io_data;
struct scsi_request *rq = scsi_req(req);
struct scsi_tape *STp = SRpnt->stp;
@ -525,8 +526,8 @@ static void st_scsi_execute_end(struct request *req, blk_status_t status)
st_do_stats(STp, req);
tmp = SRpnt->bio;
if (rq->sense_len)
memcpy(SRpnt->sense, rq->sense, SCSI_SENSE_BUFFERSIZE);
if (scmd->sense_len)
memcpy(SRpnt->sense, scmd->sense_buffer, SCSI_SENSE_BUFFERSIZE);
if (SRpnt->waiting)
complete(SRpnt->waiting);

View File

@ -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)
{
struct se_cmd *cmd = req->end_io_data;
struct scsi_cmnd *scmd = blk_mq_rq_to_pdu(req);
int result = scsi_req(req)->result;
enum sam_status scsi_status = result & 0xff;
u8 *cdb = cmd->priv;
@ -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);
}
pscsi_complete_cmd(cmd, scsi_status, scsi_req(req)->sense);
pscsi_complete_cmd(cmd, scsi_status, scmd->sense_buffer);
switch (host_byte(result)) {
case DID_OK:

View File

@ -112,6 +112,7 @@ struct scsi_cmnd {
reconnects. Probably == sector
size */
unsigned sense_len;
unsigned char *sense_buffer;
/* obtained by REQUEST SENSE when
* CHECK CONDITION is received on original

View File

@ -6,10 +6,8 @@
struct scsi_request {
int result;
unsigned int sense_len;
unsigned int resid_len; /* residual count */
int retries;
void *sense;
};
static inline struct scsi_request *scsi_req(struct request *rq)