[v18,62/83] sg: work on sg_mrq_sanity()

Message ID 20210427215733.417746-64-dgilbert@interlog.com
State New
Headers show
Series
  • sg: add v4 interface, request sharing
Related show

Commit Message

Douglas Gilbert April 27, 2021, 9:57 p.m.
Work for following share variable blocking patch.

Signed-off-by: Douglas Gilbert <dgilbert@interlog.com>
---
 drivers/scsi/sg.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

Patch

diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 5e6c67bac5cd..e43bb1673adc 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -1059,9 +1059,11 @@  sg_mrq_complets(struct sg_io_v4 *cop, struct sg_io_v4 *a_hds,
 static int
 sg_mrq_sanity(struct sg_device *sdp, struct sg_io_v4 *cop,
 	      struct sg_io_v4 *a_hds, u8 *cdb_ap, struct sg_fd *sfp,
-	      bool immed, u32 tot_reqs)
+	      bool immed, u32 tot_reqs, bool *share_on_othp)
 {
 	bool have_mrq_sense = (cop->response && cop->max_response_len);
+	bool share_on_oth = false;
+	bool share;
 	int k;
 	u32 cdb_alen = cop->request_len;
 	u32 cdb_mxlen = cdb_alen / tot_reqs;
@@ -1084,12 +1086,13 @@  sg_mrq_sanity(struct sg_device *sdp, struct sg_io_v4 *cop,
 			       __func__, rip, k);
 			return -ERANGE;
 		}
+		share = !!(flags & SGV4_FLAG_SHARE);
 		if (immed) {	/* only accept async submits on current fd */
 			if (unlikely(flags & SGV4_FLAG_DO_ON_OTHER)) {
 				SG_LOG(1, sfp, "%s: %s %u, %s\n", __func__,
 				       rip, k, "no IMMED with ON_OTHER");
 				return -ERANGE;
-			} else if (unlikely(flags & SGV4_FLAG_SHARE)) {
+			} else if (unlikely(share)) {
 				SG_LOG(1, sfp, "%s: %s %u, %s\n", __func__,
 				       rip, k, "no IMMED with FLAG_SHARE");
 				return -ERANGE;
@@ -1100,8 +1103,11 @@  sg_mrq_sanity(struct sg_device *sdp, struct sg_io_v4 *cop,
 			}
 			/* N.B. SGV4_FLAG_SIG_ON_OTHER is allowed */
 		}
-		if (!sg_fd_is_shared(sfp)) {
-			if (unlikely(flags & SGV4_FLAG_SHARE)) {
+		if (sg_fd_is_shared(sfp)) {
+			if (!share_on_oth && share)
+				share_on_oth = true;
+		} else {
+			if (unlikely(share)) {
 				SG_LOG(1, sfp, "%s: %s %u, no share\n",
 				       __func__, rip, k);
 				return -ERANGE;
@@ -1124,6 +1130,8 @@  sg_mrq_sanity(struct sg_device *sdp, struct sg_io_v4 *cop,
 			hp->max_response_len = cop->max_response_len;
 		}
 	}
+	if (share_on_othp)
+		*share_on_othp = share_on_othp;
 	return 0;
 }
 
@@ -1241,7 +1249,8 @@  sg_do_multi_req(struct sg_comm_wr_t *cwrp, bool blocking)
 		}
 	}
 	/* do sanity checks on all requests before starting */
-	res = sg_mrq_sanity(sdp, cop, a_hds, cdb_ap, fp, immed, tot_reqs);
+	res = sg_mrq_sanity(sdp, cop, a_hds, cdb_ap, fp, immed, tot_reqs,
+			    NULL);
 	if (unlikely(res))
 		goto fini;
 	set_this = false;