Commit 10f34f64 authored by Paolo Bonzini's avatar Paolo Bonzini Committed by Rusty Russell

virtio-scsi: push vq lock/unlock into virtscsi_vq_done

Avoid duplicated code in all of the callers.

Cc: linux-scsi@vger.kernel.org
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
Signed-off-by: default avatarWanlong Gao <gaowanlong@cn.fujitsu.com>
Reviewed-by: default avatarAsias He <asias@redhat.com>
Signed-off-by: default avatarRusty Russell <rusty@rustcorp.com.au>
parent 7f82b3c9
...@@ -165,28 +165,30 @@ static void virtscsi_complete_cmd(struct virtio_scsi *vscsi, void *buf) ...@@ -165,28 +165,30 @@ static void virtscsi_complete_cmd(struct virtio_scsi *vscsi, void *buf)
sc->scsi_done(sc); sc->scsi_done(sc);
} }
static void virtscsi_vq_done(struct virtio_scsi *vscsi, struct virtqueue *vq, static void virtscsi_vq_done(struct virtio_scsi *vscsi,
struct virtio_scsi_vq *virtscsi_vq,
void (*fn)(struct virtio_scsi *vscsi, void *buf)) void (*fn)(struct virtio_scsi *vscsi, void *buf))
{ {
void *buf; void *buf;
unsigned int len; unsigned int len;
unsigned long flags;
struct virtqueue *vq = virtscsi_vq->vq;
spin_lock_irqsave(&virtscsi_vq->vq_lock, flags);
do { do {
virtqueue_disable_cb(vq); virtqueue_disable_cb(vq);
while ((buf = virtqueue_get_buf(vq, &len)) != NULL) while ((buf = virtqueue_get_buf(vq, &len)) != NULL)
fn(vscsi, buf); fn(vscsi, buf);
} while (!virtqueue_enable_cb(vq)); } while (!virtqueue_enable_cb(vq));
spin_unlock_irqrestore(&virtscsi_vq->vq_lock, flags);
} }
static void virtscsi_req_done(struct virtqueue *vq) static void virtscsi_req_done(struct virtqueue *vq)
{ {
struct Scsi_Host *sh = virtio_scsi_host(vq->vdev); struct Scsi_Host *sh = virtio_scsi_host(vq->vdev);
struct virtio_scsi *vscsi = shost_priv(sh); struct virtio_scsi *vscsi = shost_priv(sh);
unsigned long flags;
spin_lock_irqsave(&vscsi->req_vq.vq_lock, flags); virtscsi_vq_done(vscsi, &vscsi->req_vq, virtscsi_complete_cmd);
virtscsi_vq_done(vscsi, vq, virtscsi_complete_cmd);
spin_unlock_irqrestore(&vscsi->req_vq.vq_lock, flags);
}; };
static void virtscsi_complete_free(struct virtio_scsi *vscsi, void *buf) static void virtscsi_complete_free(struct virtio_scsi *vscsi, void *buf)
...@@ -203,11 +205,8 @@ static void virtscsi_ctrl_done(struct virtqueue *vq) ...@@ -203,11 +205,8 @@ static void virtscsi_ctrl_done(struct virtqueue *vq)
{ {
struct Scsi_Host *sh = virtio_scsi_host(vq->vdev); struct Scsi_Host *sh = virtio_scsi_host(vq->vdev);
struct virtio_scsi *vscsi = shost_priv(sh); struct virtio_scsi *vscsi = shost_priv(sh);
unsigned long flags;
spin_lock_irqsave(&vscsi->ctrl_vq.vq_lock, flags); virtscsi_vq_done(vscsi, &vscsi->ctrl_vq, virtscsi_complete_free);
virtscsi_vq_done(vscsi, vq, virtscsi_complete_free);
spin_unlock_irqrestore(&vscsi->ctrl_vq.vq_lock, flags);
}; };
static int virtscsi_kick_event(struct virtio_scsi *vscsi, static int virtscsi_kick_event(struct virtio_scsi *vscsi,
...@@ -342,11 +341,8 @@ static void virtscsi_event_done(struct virtqueue *vq) ...@@ -342,11 +341,8 @@ static void virtscsi_event_done(struct virtqueue *vq)
{ {
struct Scsi_Host *sh = virtio_scsi_host(vq->vdev); struct Scsi_Host *sh = virtio_scsi_host(vq->vdev);
struct virtio_scsi *vscsi = shost_priv(sh); struct virtio_scsi *vscsi = shost_priv(sh);
unsigned long flags;
spin_lock_irqsave(&vscsi->event_vq.vq_lock, flags); virtscsi_vq_done(vscsi, &vscsi->event_vq, virtscsi_complete_event);
virtscsi_vq_done(vscsi, vq, virtscsi_complete_event);
spin_unlock_irqrestore(&vscsi->event_vq.vq_lock, flags);
}; };
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment