vhost: implement vhost_vq_get_addr method
use vhost_vq_get_addr callback to get the vq address from backend Signed-off-by: Cindy Lu <lulu@redhat.com> Message-Id: <20200701145538.22333-10-lulu@redhat.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Acked-by: Jason Wang <jasowang@redhat.com>
This commit is contained in:
parent
35f20bb769
commit
b4ab225c34
@ -773,15 +773,25 @@ static int vhost_virtqueue_set_addr(struct vhost_dev *dev,
|
||||
struct vhost_virtqueue *vq,
|
||||
unsigned idx, bool enable_log)
|
||||
{
|
||||
struct vhost_vring_addr addr = {
|
||||
.index = idx,
|
||||
.desc_user_addr = (uint64_t)(unsigned long)vq->desc,
|
||||
.avail_user_addr = (uint64_t)(unsigned long)vq->avail,
|
||||
.used_user_addr = (uint64_t)(unsigned long)vq->used,
|
||||
.log_guest_addr = vq->used_phys,
|
||||
.flags = enable_log ? (1 << VHOST_VRING_F_LOG) : 0,
|
||||
};
|
||||
int r = dev->vhost_ops->vhost_set_vring_addr(dev, &addr);
|
||||
struct vhost_vring_addr addr;
|
||||
int r;
|
||||
memset(&addr, 0, sizeof(struct vhost_vring_addr));
|
||||
|
||||
if (dev->vhost_ops->vhost_vq_get_addr) {
|
||||
r = dev->vhost_ops->vhost_vq_get_addr(dev, &addr, vq);
|
||||
if (r < 0) {
|
||||
VHOST_OPS_DEBUG("vhost_vq_get_addr failed");
|
||||
return -errno;
|
||||
}
|
||||
} else {
|
||||
addr.desc_user_addr = (uint64_t)(unsigned long)vq->desc;
|
||||
addr.avail_user_addr = (uint64_t)(unsigned long)vq->avail;
|
||||
addr.used_user_addr = (uint64_t)(unsigned long)vq->used;
|
||||
}
|
||||
addr.index = idx;
|
||||
addr.log_guest_addr = vq->used_phys;
|
||||
addr.flags = enable_log ? (1 << VHOST_VRING_F_LOG) : 0;
|
||||
r = dev->vhost_ops->vhost_set_vring_addr(dev, &addr);
|
||||
if (r < 0) {
|
||||
VHOST_OPS_DEBUG("vhost_set_vring_addr failed");
|
||||
return -errno;
|
||||
|
@ -118,6 +118,9 @@ typedef int (*vhost_dev_start_op)(struct vhost_dev *dev, bool started);
|
||||
typedef int (*vhost_vq_get_addr_op)(struct vhost_dev *dev,
|
||||
struct vhost_vring_addr *addr,
|
||||
struct vhost_virtqueue *vq);
|
||||
|
||||
typedef int (*vhost_get_device_id_op)(struct vhost_dev *dev, uint32_t *dev_id);
|
||||
|
||||
typedef struct VhostOps {
|
||||
VhostBackendType backend_type;
|
||||
vhost_backend_init vhost_backend_init;
|
||||
@ -160,6 +163,7 @@ typedef struct VhostOps {
|
||||
vhost_set_inflight_fd_op vhost_set_inflight_fd;
|
||||
vhost_dev_start_op vhost_dev_start;
|
||||
vhost_vq_get_addr_op vhost_vq_get_addr;
|
||||
vhost_get_device_id_op vhost_get_device_id;
|
||||
} VhostOps;
|
||||
|
||||
extern const VhostOps user_ops;
|
||||
|
Loading…
Reference in New Issue
Block a user