virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: Asias He <asias@redhat.com>
To: Nicholas Bellinger <nab@linux-iscsi.org>
Cc: kvm@vger.kernel.org, "Michael S. Tsirkin" <mst@redhat.com>,
	virtualization@lists.linux-foundation.org,
	target-devel@vger.kernel.org,
	Stefan Hajnoczi <stefanha@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>
Subject: [PATCH v2 3/4] tcm_vhost: Add vhost_scsi_send_bad_target() helper
Date: Wed, 10 Apr 2013 15:06:15 +0800	[thread overview]
Message-ID: <1365577576-26183-4-git-send-email-asias@redhat.com> (raw)
In-Reply-To: <1365577576-26183-1-git-send-email-asias@redhat.com>
In-Reply-To: <1365564191-20928-1-git-send-email-asias@redhat.com>

Share the send bad target code with other use cases.

Signed-off-by: Asias He <asias@redhat.com>
---
 drivers/vhost/tcm_vhost.c | 31 ++++++++++++++++++-------------
 1 file changed, 18 insertions(+), 13 deletions(-)

diff --git a/drivers/vhost/tcm_vhost.c b/drivers/vhost/tcm_vhost.c
index 210d59e..1bb0fb4 100644
--- a/drivers/vhost/tcm_vhost.c
+++ b/drivers/vhost/tcm_vhost.c
@@ -578,6 +578,23 @@ static void tcm_vhost_submission_work(struct work_struct *work)
 	}
 }
 
+static void vhost_scsi_send_bad_target(struct vhost_scsi *vs,
+	struct vhost_virtqueue *vq, int head, unsigned out)
+{
+	struct virtio_scsi_cmd_resp __user *resp;
+	struct virtio_scsi_cmd_resp rsp;
+	int ret;
+
+	memset(&rsp, 0, sizeof(rsp));
+	rsp.response = VIRTIO_SCSI_S_BAD_TARGET;
+	resp = vq->iov[out].iov_base;
+	ret = __copy_to_user(resp, &rsp, sizeof(rsp));
+	if (!ret)
+		vhost_add_used_and_signal(&vs->dev, vq, head, 0);
+	else
+		pr_err("Faulted on virtio_scsi_cmd_resp\n");
+}
+
 static void vhost_scsi_handle_vq(struct vhost_scsi *vs,
 	struct vhost_virtqueue *vq)
 {
@@ -673,19 +690,7 @@ static void vhost_scsi_handle_vq(struct vhost_scsi *vs,
 
 		/* Target does not exist, fail the request */
 		if (unlikely(!tv_tpg)) {
-			struct virtio_scsi_cmd_resp __user *resp;
-			struct virtio_scsi_cmd_resp rsp;
-
-			memset(&rsp, 0, sizeof(rsp));
-			rsp.response = VIRTIO_SCSI_S_BAD_TARGET;
-			resp = vq->iov[out].iov_base;
-			ret = __copy_to_user(resp, &rsp, sizeof(rsp));
-			if (!ret)
-				vhost_add_used_and_signal(&vs->dev,
-							  vq, head, 0);
-			else
-				pr_err("Faulted on virtio_scsi_cmd_resp\n");
-
+			vhost_scsi_send_bad_target(vs, vq, head, out);
 			continue;
 		}
 
-- 
1.8.1.4

  parent reply	other threads:[~2013-04-10  7:06 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-09  9:16 [PATCH] tcm_vhost: Fix tv_cmd leak in vhost_scsi_handle_vq Asias He
2013-04-09  8:26 ` Michael S. Tsirkin
2013-04-09 15:46 ` Nicholas A. Bellinger
     [not found] ` <1365522402.24346.146.camel@haakon2.linux-iscsi.org>
2013-04-10  3:23   ` [PATCH 0/3] tcm_vhost fix cmd leak and bad target Asias He
2013-04-10  6:19     ` Asias He
2013-04-10  7:06     ` [PATCH v2 0/4] tcm_vhost fix cmd leak and send " Asias He
2013-04-10 21:19       ` Nicholas A. Bellinger
2013-04-11  7:22         ` Michael S. Tsirkin
2013-04-11  8:42           ` Asias He
2013-04-10  7:06     ` [PATCH v2 1/4] tcm_vhost: Remove double check of response Asias He
2013-04-10  7:06     ` [PATCH v2 2/4] tcm_vhost: Fix tv_cmd leak in vhost_scsi_handle_vq Asias He
2013-04-10  7:06     ` Asias He [this message]
2013-04-10  7:06     ` [PATCH v2 4/4] tcm_vhost: Send bad target to guest when cmd fails Asias He
2013-04-10  3:23   ` [PATCH 1/3] tcm_vhost: Fix tv_cmd leak in vhost_scsi_handle_vq Asias He
2013-04-10  3:23   ` [PATCH 2/3] tcm_vhost: Add vhost_scsi_send_bad_target() helper Asias He
2013-04-10  3:23   ` [PATCH 3/3] tcm_vhost: Send bad target to guest when cmd fails Asias He
2013-04-10  3:37   ` [PATCH] tcm_vhost: Fix tv_cmd leak in vhost_scsi_handle_vq Asias He
2013-04-14  8:43   ` Michael S. Tsirkin

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=1365577576-26183-4-git-send-email-asias@redhat.com \
    --to=asias@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=nab@linux-iscsi.org \
    --cc=pbonzini@redhat.com \
    --cc=stefanha@redhat.com \
    --cc=target-devel@vger.kernel.org \
    --cc=virtualization@lists.linux-foundation.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).