All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mike Christie <michael.christie@oracle.com>
To: hch@lst.de, loberman@redhat.com, martin.petersen@oracle.com,
	linux-scsi@vger.kernel.org, target-devel@vger.kernel.org,
	mst@redhat.com, stefanha@redhat.com
Cc: Mike Christie <michael.christie@oracle.com>
Subject: [PATCH 11/14] vhost-scsi: Convert to new submission API
Date: Thu, 11 Feb 2021 06:27:25 -0600	[thread overview]
Message-ID: <20210211122728.31721-12-michael.christie@oracle.com> (raw)
In-Reply-To: <20210211122728.31721-1-michael.christie@oracle.com>

target_submit_cmd_map_sgls is being removed, so convert vhost-scsi
to the new submission API. This has it use
target_init_cmd/target_submit_prep/target_submit because we need to
have lio core map sgls which is now done in target_submit_prep,
and in the last patches we will do the target_submit step from
the lio workqueue.

Note: vhost-scsi never calls target_stop_session so
target_submit_cmd_map_sgls never failed (in the new API
target_init_cmd handles target_stop_session being called when cmds
are being submitted). If it were to have used target_stop_session
and got an error, we would have hit a refcount bug like xen and usb,
because it does:

if (rc < 0) {
	transport_send_check_condition_and_sense(se_cmd,
			TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE, 0);
	transport_generic_free_cmd(se_cmd, 0);
}

transport_send_check_condition_and_sense calls queue_status which
does transport_generic_free_cmd, and then we do an extra
transport_generic_free_cmd call above which would have dropped
the refcount to -1 and the refcount code would spit out errors.

Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Mike Christie <michael.christie@oracle.com>
---
 drivers/vhost/scsi.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c
index 4ce9f00ae10e..76508d408bb3 100644
--- a/drivers/vhost/scsi.c
+++ b/drivers/vhost/scsi.c
@@ -789,7 +789,6 @@ static void vhost_scsi_submission_work(struct work_struct *work)
 	struct vhost_scsi_nexus *tv_nexus;
 	struct se_cmd *se_cmd = &cmd->tvc_se_cmd;
 	struct scatterlist *sg_ptr, *sg_prot_ptr = NULL;
-	int rc;
 
 	/* FIXME: BIDI operation */
 	if (cmd->tvc_sgl_count) {
@@ -805,18 +804,17 @@ static void vhost_scsi_submission_work(struct work_struct *work)
 	tv_nexus = cmd->tvc_nexus;
 
 	se_cmd->tag = 0;
-	rc = target_submit_cmd_map_sgls(se_cmd, tv_nexus->tvn_se_sess,
-			cmd->tvc_cdb, &cmd->tvc_sense_buf[0],
+	target_init_cmd(se_cmd, tv_nexus->tvn_se_sess, &cmd->tvc_sense_buf[0],
 			cmd->tvc_lun, cmd->tvc_exp_data_len,
 			vhost_scsi_to_tcm_attr(cmd->tvc_task_attr),
-			cmd->tvc_data_direction, TARGET_SCF_ACK_KREF,
-			sg_ptr, cmd->tvc_sgl_count, NULL, 0, sg_prot_ptr,
-			cmd->tvc_prot_sgl_count);
-	if (rc < 0) {
-		transport_send_check_condition_and_sense(se_cmd,
-				TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE, 0);
-		transport_generic_free_cmd(se_cmd, 0);
-	}
+			cmd->tvc_data_direction, TARGET_SCF_ACK_KREF);
+
+	if (target_submit_prep(se_cmd, cmd->tvc_cdb, sg_ptr,
+			       cmd->tvc_sgl_count, NULL, 0, sg_prot_ptr,
+			       cmd->tvc_prot_sgl_count))
+		return;
+
+	target_submit(se_cmd);
 }
 
 static void
-- 
2.25.1


  parent reply	other threads:[~2021-02-11 12:33 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-11 12:27 [PATCH 01/14] target: remove target_submit_cmd_map_sgls Mike Christie
2021-02-11 12:27 ` [PATCH 01/14] target: move t_task_cdb initialization Mike Christie
2021-02-11 12:27 ` [PATCH 02/14] target: drop kref_get_unless_zero in target_get_sess_cmd Mike Christie
2021-02-11 15:09   ` Christoph Hellwig
2021-02-11 12:27 ` [PATCH 03/14] target: rename transport_init_se_cmd Mike Christie
2021-02-11 15:10   ` Christoph Hellwig
2021-02-11 12:27 ` [PATCH 04/14] target: break up target_submit_cmd_map_sgls Mike Christie
2021-02-11 15:12   ` Christoph Hellwig
2021-02-11 12:27 ` [PATCH 05/14] srpt: Convert to new submission API Mike Christie
2021-02-11 15:13   ` Christoph Hellwig
2021-02-11 12:27 ` [PATCH 06/14] ibmvscsi_tgt: " Mike Christie
2021-02-11 15:14   ` Christoph Hellwig
2021-02-11 12:27 ` [PATCH 07/14] qla2xxx: " Mike Christie
2021-02-11 15:14   ` Christoph Hellwig
2021-02-11 12:27 ` [PATCH 08/14] tcm_loop: " Mike Christie
2021-02-11 15:14   ` Christoph Hellwig
2021-02-11 12:27 ` [PATCH 09/14] sbp_target: " Mike Christie
2021-02-11 15:15   ` Christoph Hellwig
2021-02-11 12:27 ` [PATCH 10/14] usb gadget: " Mike Christie
2021-02-11 15:15   ` Christoph Hellwig
2021-02-11 12:27 ` Mike Christie [this message]
2021-02-11 12:27 ` [PATCH 12/14] xen-scsiback: " Mike Christie
2021-02-11 15:16   ` Christoph Hellwig
2021-02-11 12:27 ` [PATCH 13/14] tcm_fc: " Mike Christie
2021-02-11 15:16   ` Christoph Hellwig
2021-02-11 12:27 ` [PATCH 14/14] target: remove target_submit_cmd_map_sgls Mike Christie
2021-02-11 15:17   ` Christoph Hellwig
2021-02-11 18:11     ` Mike Christie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210211122728.31721-12-michael.christie@oracle.com \
    --to=michael.christie@oracle.com \
    --cc=hch@lst.de \
    --cc=linux-scsi@vger.kernel.org \
    --cc=loberman@redhat.com \
    --cc=martin.petersen@oracle.com \
    --cc=mst@redhat.com \
    --cc=stefanha@redhat.com \
    --cc=target-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.