Not all vhost-user backends support ops->vhost_reset_device(). Instead of adding backend check and call backend ops directly, it's better to implement a function in vhost framework, so that it could hide vhost_ops details.
SIgned-off-by: Michael Qiu <qiud...@archeros.com> --- hw/virtio/vhost.c | 14 ++++++++++++++ include/hw/virtio/vhost.h | 1 + 2 files changed, 15 insertions(+) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index b643f42..26667ae 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1854,3 +1854,17 @@ int vhost_net_set_backend(struct vhost_dev *hdev, return -ENOSYS; } + +int vhost_dev_reset(struct vhost_dev *hdev) +{ + int ret = 0; + + /* should only be called after backend is connected */ + assert(hdev->vhost_ops); + + if (hdev->vhost_ops->vhost_reset_device) { + ret = hdev->vhost_ops->vhost_reset_device(hdev); + } + + return ret; +} diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 58a73e7..b8b7c20 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -114,6 +114,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque, void vhost_dev_cleanup(struct vhost_dev *hdev); int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev); void vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev); +int vhost_dev_reset(struct vhost_dev *hdev); int vhost_dev_enable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev); void vhost_dev_disable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev); -- 1.8.3.1