From 8f371c7d64ebf922bacd8ac4169d4e736bbd7ddc Mon Sep 17 00:00:00 2001 From: Pawel Wodkowski Date: Fri, 2 Jun 2017 19:48:11 +0200 Subject: [PATCH] vhost: introduce spdk_vhost_vring_desc_to_iov Extract vring_dev to iovec translation logic to common place. Change-Id: I0c6fc5582dfe341e867ce6749ff29d14a9d12d94 Signed-off-by: Pawel Wodkowski Reviewed-on: https://review.gerrithub.io/363582 Tested-by: SPDK Automated Test System Reviewed-by: Daniel Verkamp Reviewed-by: Ben Walker --- lib/vhost/vhost.c | 9 +++++++++ lib/vhost/vhost_internal.h | 3 +++ lib/vhost/vhost_scsi.c | 6 ++---- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c index 8cd381e94f..ef8feb63a4 100644 --- a/lib/vhost/vhost.c +++ b/lib/vhost/vhost.c @@ -150,6 +150,15 @@ spdk_vhost_vring_desc_is_wr(struct vring_desc *cur_desc) return !!(cur_desc->flags & VRING_DESC_F_WRITE); } +bool +spdk_vhost_vring_desc_to_iov(struct spdk_vhost_dev *vdev, struct iovec *iov, + const struct vring_desc *desc) +{ + iov->iov_base = spdk_vhost_gpa_to_vva(vdev, desc->addr); + iov->iov_len = desc->len; + return !iov->iov_base; +} + struct spdk_vhost_dev * spdk_vhost_dev_find_by_vid(int vid) { diff --git a/lib/vhost/vhost_internal.h b/lib/vhost/vhost_internal.h index 58c6d8aa9b..f7b39c8f6e 100644 --- a/lib/vhost/vhost_internal.h +++ b/lib/vhost/vhost_internal.h @@ -100,6 +100,9 @@ struct vring_desc *spdk_vhost_vring_desc_get_next(struct vring_desc *vq_desc, struct vring_desc *cur_desc); bool spdk_vhost_vring_desc_is_wr(struct vring_desc *cur_desc); +bool spdk_vhost_vring_desc_to_iov(struct spdk_vhost_dev *vdev, struct iovec *iov, + const struct vring_desc *desc); + struct spdk_vhost_dev *spdk_vhost_dev_find_by_vid(int vid); int spdk_vhost_dev_construct(struct spdk_vhost_dev *vdev, const char *name, uint64_t cpumask, diff --git a/lib/vhost/vhost_scsi.c b/lib/vhost/vhost_scsi.c index 9d36801743..74af6746da 100644 --- a/lib/vhost/vhost_scsi.c +++ b/lib/vhost/vhost_scsi.c @@ -358,8 +358,7 @@ task_data_setup(struct spdk_vhost_task *task, /* All remaining descriptors are data. */ while (iovcnt < iovcnt_max) { - iovs[iovcnt].iov_base = spdk_vhost_gpa_to_vva(vdev, desc->addr); - iovs[iovcnt].iov_len = desc->len; + spdk_vhost_vring_desc_to_iov(vdev, &iovs[iovcnt], desc); len += desc->len; iovcnt++; @@ -395,8 +394,7 @@ task_data_setup(struct spdk_vhost_task *task, /* Process descriptors up to response. */ while (!spdk_vhost_vring_desc_is_wr(desc) && iovcnt < iovcnt_max) { - iovs[iovcnt].iov_base = spdk_vhost_gpa_to_vva(vdev, desc->addr); - iovs[iovcnt].iov_len = desc->len; + spdk_vhost_vring_desc_to_iov(vdev, &iovs[iovcnt], desc); len += desc->len; iovcnt++;