diff mbox series

[6/7] Introduce scsi_in_[sg]et_resid() and scsi_out_[sg]et_resid()

Message ID 20190122185724.71598-7-bvanassche@acm.org (mailing list archive)
State Superseded
Headers show
Series Fix handling of bidi commands | expand

Commit Message

Bart Van Assche Jan. 22, 2019, 6:57 p.m. UTC
This patch does not change any functionality.

Cc: Douglas Gilbert <dgilbert@interlog.com>
Cc: Hannes Reinecke <hare@suse.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Lee Duncan <lduncan@suse.com>
Cc: Chris Leech <cleech@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 drivers/scsi/libiscsi.c    | 12 ++++++------
 drivers/scsi/scsi_debug.c  |  9 +++++----
 drivers/scsi/sd.c          |  4 ++--
 drivers/scsi/virtio_scsi.c |  4 ++--
 include/scsi/scsi_cmnd.h   | 24 ++++++++++++++++++++++--
 5 files changed, 37 insertions(+), 16 deletions(-)
diff mbox series

Patch

diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c
index b8d325ce8754..fe5b3371553c 100644
--- a/drivers/scsi/libiscsi.c
+++ b/drivers/scsi/libiscsi.c
@@ -650,8 +650,8 @@  static void fail_scsi_task(struct iscsi_task *task, int err)
 	if (!scsi_bidi_cmnd(sc))
 		scsi_set_resid(sc, scsi_bufflen(sc));
 	else {
-		scsi_out(sc)->resid = scsi_out(sc)->length;
-		scsi_in(sc)->resid = scsi_in(sc)->length;
+		scsi_out_set_resid(sc, scsi_out(sc)->length);
+		scsi_in_set_resid(sc, scsi_in(sc)->length);
 	}
 
 	/* regular RX path uses back_lock */
@@ -912,7 +912,7 @@  static void iscsi_scsi_cmd_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
 		if (scsi_bidi_cmnd(sc) && res_count > 0 &&
 				(rhdr->flags & ISCSI_FLAG_CMD_BIDI_OVERFLOW ||
 				 res_count <= scsi_in(sc)->length))
-			scsi_in(sc)->resid = res_count;
+			scsi_in_set_resid(sc, res_count);
 		else
 			sc->result = (DID_BAD_TARGET << 16) | rhdr->cmd_status;
 	}
@@ -962,7 +962,7 @@  iscsi_data_in_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
 		if (res_count > 0 &&
 		    (rhdr->flags & ISCSI_FLAG_CMD_OVERFLOW ||
 		     res_count <= scsi_in(sc)->length))
-			scsi_in(sc)->resid = res_count;
+			scsi_in_set_resid(sc, res_count);
 		else
 			sc->result = (DID_BAD_TARGET << 16) | rhdr->cmd_status;
 	}
@@ -1807,8 +1807,8 @@  int iscsi_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *sc)
 	if (!scsi_bidi_cmnd(sc))
 		scsi_set_resid(sc, scsi_bufflen(sc));
 	else {
-		scsi_out(sc)->resid = scsi_out(sc)->length;
-		scsi_in(sc)->resid = scsi_in(sc)->length;
+		scsi_out_set_resid(sc, scsi_out(sc)->length);
+		scsi_in_set_resid(sc, scsi_in(sc)->length);
 	}
 	sc->scsi_done(sc);
 	return 0;
diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index e253c0129b40..822aed12ca31 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -1019,7 +1019,7 @@  static int fill_from_dev_buffer(struct scsi_cmnd *scp, unsigned char *arr,
 
 	act_len = sg_copy_from_buffer(sdb->table.sgl, sdb->table.nents,
 				      arr, arr_len);
-	sdb->resid = scsi_bufflen(scp) - act_len;
+	scsi_in_set_resid(scp, scsi_bufflen(scp) - act_len);
 
 	return 0;
 }
@@ -1044,9 +1044,10 @@  static int p_fill_from_dev_buffer(struct scsi_cmnd *scp, const void *arr,
 	act_len = sg_pcopy_from_buffer(sdb->table.sgl, sdb->table.nents,
 				       arr, arr_len, skip);
 	pr_debug("%s: off_dst=%u, scsi_bufflen=%u, act_len=%u, resid=%d\n",
-		 __func__, off_dst, scsi_bufflen(scp), act_len, sdb->resid);
+		 __func__, off_dst, scsi_bufflen(scp), act_len,
+		 scsi_in_get_resid(scp));
 	n = (int)scsi_bufflen(scp) - ((int)off_dst + act_len);
-	sdb->resid = min(sdb->resid, n);
+	scsi_in_set_resid(scp, min(scsi_in_get_resid(scp), n));
 	return 0;
 }
 
@@ -2774,7 +2775,7 @@  static int resp_read_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
 	if (unlikely(ret == -1))
 		return DID_ERROR << 16;
 
-	scsi_in(scp)->resid = scsi_bufflen(scp) - ret;
+	scsi_in_set_resid(scp, scsi_bufflen(scp) - ret);
 
 	if (unlikely(sqcp)) {
 		if (sqcp->inj_recovered) {
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index b0eb83526c54..2219ba81f0b3 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -844,7 +844,7 @@  static blk_status_t sd_setup_unmap_cmnd(struct scsi_cmnd *cmd)
 	cmd->allowed = SD_MAX_RETRIES;
 	cmd->transfersize = data_len;
 	rq->timeout = SD_TIMEOUT;
-	scsi_req(rq)->resid_len = data_len;
+	scsi_set_resid(cmd, data_len);
 
 	return scsi_init_io(cmd);
 }
@@ -908,7 +908,7 @@  static blk_status_t sd_setup_write_same10_cmnd(struct scsi_cmnd *cmd,
 	cmd->allowed = SD_MAX_RETRIES;
 	cmd->transfersize = data_len;
 	rq->timeout = unmap ? SD_TIMEOUT : SD_WRITE_SAME_TIMEOUT;
-	scsi_req(rq)->resid_len = data_len;
+	scsi_set_resid(cmd, data_len);
 
 	return scsi_init_io(cmd);
 }
diff --git a/drivers/scsi/virtio_scsi.c b/drivers/scsi/virtio_scsi.c
index 772b976e4ee4..47888649f6b8 100644
--- a/drivers/scsi/virtio_scsi.c
+++ b/drivers/scsi/virtio_scsi.c
@@ -108,8 +108,8 @@  static void virtscsi_compute_resid(struct scsi_cmnd *sc, u32 resid)
 		return;
 	}
 
-	scsi_in(sc)->resid = min(resid, scsi_in(sc)->length);
-	scsi_out(sc)->resid = resid - scsi_in(sc)->resid;
+	scsi_in_set_resid(sc, min(resid, scsi_in(sc)->length));
+	scsi_out_set_resid(sc, resid - scsi_in_get_resid(sc));
 }
 
 /**
diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h
index 673980ed7db6..8f3ed55a5ee5 100644
--- a/include/scsi/scsi_cmnd.h
+++ b/include/scsi/scsi_cmnd.h
@@ -227,16 +227,36 @@  static inline unsigned scsi_bufflen(struct scsi_cmnd *cmd)
 	return cmd->sdb.length;
 }
 
-static inline void scsi_set_resid(struct scsi_cmnd *cmd, int resid)
+static inline void scsi_in_set_resid(struct scsi_cmnd *cmd, int resid)
+{
+	scsi_in_cmd(cmd)->sdb.resid = resid;
+}
+
+static inline int scsi_in_get_resid(struct scsi_cmnd *cmd)
+{
+	return scsi_in_cmd(cmd)->sdb.resid;
+}
+
+static inline void scsi_out_set_resid(struct scsi_cmnd *cmd, int resid)
 {
 	cmd->sdb.resid = resid;
 }
 
-static inline int scsi_get_resid(struct scsi_cmnd *cmd)
+static inline int scsi_out_get_resid(struct scsi_cmnd *cmd)
 {
 	return cmd->sdb.resid;
 }
 
+static inline void scsi_set_resid(struct scsi_cmnd *cmd, int resid)
+{
+	return scsi_out_set_resid(cmd, resid);
+}
+
+static inline int scsi_get_resid(struct scsi_cmnd *cmd)
+{
+	return scsi_out_get_resid(cmd);
+}
+
 #define scsi_for_each_sg(cmd, sg, nseg, __i)			\
 	for_each_sg(scsi_sglist(cmd), sg, nseg, __i)