Commit 637ab21e284f4e9188acc2746695f7f6452b4a22

Authored by Asias He
Committed by Nicholas Bellinger
1 parent 7ea206cf3b

tcm_vhost: Add vhost_scsi_send_bad_target() helper

Share the send bad target code with other use cases.

Signed-off-by: Asias He <asias@redhat.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>

Showing 1 changed file with 18 additions and 13 deletions Side-by-side Diff

drivers/vhost/tcm_vhost.c
... ... @@ -578,6 +578,23 @@
578 578 }
579 579 }
580 580  
  581 +static void vhost_scsi_send_bad_target(struct vhost_scsi *vs,
  582 + struct vhost_virtqueue *vq, int head, unsigned out)
  583 +{
  584 + struct virtio_scsi_cmd_resp __user *resp;
  585 + struct virtio_scsi_cmd_resp rsp;
  586 + int ret;
  587 +
  588 + memset(&rsp, 0, sizeof(rsp));
  589 + rsp.response = VIRTIO_SCSI_S_BAD_TARGET;
  590 + resp = vq->iov[out].iov_base;
  591 + ret = __copy_to_user(resp, &rsp, sizeof(rsp));
  592 + if (!ret)
  593 + vhost_add_used_and_signal(&vs->dev, vq, head, 0);
  594 + else
  595 + pr_err("Faulted on virtio_scsi_cmd_resp\n");
  596 +}
  597 +
581 598 static void vhost_scsi_handle_vq(struct vhost_scsi *vs,
582 599 struct vhost_virtqueue *vq)
583 600 {
... ... @@ -673,19 +690,7 @@
673 690  
674 691 /* Target does not exist, fail the request */
675 692 if (unlikely(!tv_tpg)) {
676   - struct virtio_scsi_cmd_resp __user *resp;
677   - struct virtio_scsi_cmd_resp rsp;
678   -
679   - memset(&rsp, 0, sizeof(rsp));
680   - rsp.response = VIRTIO_SCSI_S_BAD_TARGET;
681   - resp = vq->iov[out].iov_base;
682   - ret = __copy_to_user(resp, &rsp, sizeof(rsp));
683   - if (!ret)
684   - vhost_add_used_and_signal(&vs->dev,
685   - vq, head, 0);
686   - else
687   - pr_err("Faulted on virtio_scsi_cmd_resp\n");
688   -
  693 + vhost_scsi_send_bad_target(vs, vq, head, out);
689 694 continue;
690 695 }
691 696