[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 07/35] hw/virtio: move vhost_set_backend_type() to vhost.c
From: |
Michael S. Tsirkin |
Subject: |
[PULL 07/35] hw/virtio: move vhost_set_backend_type() to vhost.c |
Date: |
Sat, 4 Sep 2021 17:36:15 -0400 |
From: Tiberiu Georgescu <tiberiu.georgescu@nutanix.com>
Just a small refactor patch.
vhost_set_backend_type() gets called only in vhost.c, so we can move the
function there and make it static. We can then extern the visibility of
kernel_ops, to match the other VhostOps in vhost-backend.h.
The VhostOps constants now make more sense in vhost.h
Suggested-by: Raphael Norwitz <raphael.norwitz@nutanix.com>
Signed-off-by: Tiberiu Georgescu <tiberiu.georgescu@nutanix.com>
Message-Id: <20210809134015.67941-1-tiberiu.georgescu@nutanix.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
include/hw/virtio/vhost-backend.h | 6 ------
include/hw/virtio/vhost.h | 4 ++++
hw/virtio/vhost-backend.c | 30 +-----------------------------
hw/virtio/vhost.c | 29 +++++++++++++++++++++++++++++
4 files changed, 34 insertions(+), 35 deletions(-)
diff --git a/include/hw/virtio/vhost-backend.h
b/include/hw/virtio/vhost-backend.h
index 8475c5a29d..81bf3109f8 100644
--- a/include/hw/virtio/vhost-backend.h
+++ b/include/hw/virtio/vhost-backend.h
@@ -173,12 +173,6 @@ typedef struct VhostOps {
vhost_force_iommu_op vhost_force_iommu;
} VhostOps;
-extern const VhostOps user_ops;
-extern const VhostOps vdpa_ops;
-
-int vhost_set_backend_type(struct vhost_dev *dev,
- VhostBackendType backend_type);
-
int vhost_backend_update_device_iotlb(struct vhost_dev *dev,
uint64_t iova, uint64_t uaddr,
uint64_t len,
diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h
index 045d0fd9f2..5ee306568b 100644
--- a/include/hw/virtio/vhost.h
+++ b/include/hw/virtio/vhost.h
@@ -95,6 +95,10 @@ struct vhost_dev {
const VhostDevConfigOps *config_ops;
};
+extern const VhostOps kernel_ops;
+extern const VhostOps user_ops;
+extern const VhostOps vdpa_ops;
+
struct vhost_net {
struct vhost_dev dev;
struct vhost_virtqueue vqs[2];
diff --git a/hw/virtio/vhost-backend.c b/hw/virtio/vhost-backend.c
index 594d770b75..b65f8f7e97 100644
--- a/hw/virtio/vhost-backend.c
+++ b/hw/virtio/vhost-backend.c
@@ -293,7 +293,7 @@ static void vhost_kernel_set_iotlb_callback(struct
vhost_dev *dev,
qemu_set_fd_handler((uintptr_t)dev->opaque, NULL, NULL, NULL);
}
-static const VhostOps kernel_ops = {
+const VhostOps kernel_ops = {
.backend_type = VHOST_BACKEND_TYPE_KERNEL,
.vhost_backend_init = vhost_kernel_init,
.vhost_backend_cleanup = vhost_kernel_cleanup,
@@ -328,34 +328,6 @@ static const VhostOps kernel_ops = {
};
#endif
-int vhost_set_backend_type(struct vhost_dev *dev, VhostBackendType
backend_type)
-{
- int r = 0;
-
- switch (backend_type) {
-#ifdef CONFIG_VHOST_KERNEL
- case VHOST_BACKEND_TYPE_KERNEL:
- dev->vhost_ops = &kernel_ops;
- break;
-#endif
-#ifdef CONFIG_VHOST_USER
- case VHOST_BACKEND_TYPE_USER:
- dev->vhost_ops = &user_ops;
- break;
-#endif
-#ifdef CONFIG_VHOST_VDPA
- case VHOST_BACKEND_TYPE_VDPA:
- dev->vhost_ops = &vdpa_ops;
- break;
-#endif
- default:
- error_report("Unknown vhost backend type");
- r = -1;
- }
-
- return r;
-}
-
int vhost_backend_update_device_iotlb(struct vhost_dev *dev,
uint64_t iova, uint64_t uaddr,
uint64_t len,
diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
index 3c0b537f89..e21e144510 100644
--- a/hw/virtio/vhost.c
+++ b/hw/virtio/vhost.c
@@ -174,6 +174,35 @@ static uint64_t vhost_get_log_size(struct vhost_dev *dev)
return log_size;
}
+static int vhost_set_backend_type(struct vhost_dev *dev,
+ VhostBackendType backend_type)
+{
+ int r = 0;
+
+ switch (backend_type) {
+#ifdef CONFIG_VHOST_KERNEL
+ case VHOST_BACKEND_TYPE_KERNEL:
+ dev->vhost_ops = &kernel_ops;
+ break;
+#endif
+#ifdef CONFIG_VHOST_USER
+ case VHOST_BACKEND_TYPE_USER:
+ dev->vhost_ops = &user_ops;
+ break;
+#endif
+#ifdef CONFIG_VHOST_VDPA
+ case VHOST_BACKEND_TYPE_VDPA:
+ dev->vhost_ops = &vdpa_ops;
+ break;
+#endif
+ default:
+ error_report("Unknown vhost backend type");
+ r = -1;
+ }
+
+ return r;
+}
+
static struct vhost_log *vhost_log_alloc(uint64_t size, bool share)
{
Error *err = NULL;
--
MST
- [PULL 05/35] q35: catch invalid cpu hotplug configuration, (continued)
- [PULL 05/35] q35: catch invalid cpu hotplug configuration, Michael S. Tsirkin, 2021/09/04
- [PULL 06/35] hw/acpi: refactor acpi hp modules so that targets can just use what they need, Michael S. Tsirkin, 2021/09/04
- Re: [PULL 06/35] hw/acpi: refactor acpi hp modules so that targets can just use what they need, Philippe Mathieu-Daudé, 2021/09/06
- Re: [PULL 06/35] hw/acpi: refactor acpi hp modules so that targets can just use what they need, Ani Sinha, 2021/09/06
- Re: [PULL 06/35] hw/acpi: refactor acpi hp modules so that targets can just use what they need, Philippe Mathieu-Daudé, 2021/09/06
- Re: [PULL 06/35] hw/acpi: refactor acpi hp modules so that targets can just use what they need, Ani Sinha, 2021/09/06
- Re: [PULL 06/35] hw/acpi: refactor acpi hp modules so that targets can just use what they need, Ani Sinha, 2021/09/07
- Re: [PULL 06/35] hw/acpi: refactor acpi hp modules so that targets can just use what they need, Philippe Mathieu-Daudé, 2021/09/07
- Re: [PULL 06/35] hw/acpi: refactor acpi hp modules so that targets can just use what they need, Ani Sinha, 2021/09/07
- Re: [PULL 06/35] hw/acpi: refactor acpi hp modules so that targets can just use what they need, Ani Sinha, 2021/09/07
[PULL 07/35] hw/virtio: move vhost_set_backend_type() to vhost.c,
Michael S. Tsirkin <=
[PULL 09/35] acpi: Delete broken ACPI_GED_X86 macro, Michael S. Tsirkin, 2021/09/04
[PULL 10/35] Use PCI_HOST_BRIDGE macro, Michael S. Tsirkin, 2021/09/04
[PULL 11/35] virtio-balloon: don't start free page hinting if postcopy is possible, Michael S. Tsirkin, 2021/09/04
[PULL 12/35] virtio-balloon: free page hinting cleanups, Michael S. Tsirkin, 2021/09/04
[PULL 13/35] virtio-bus: introduce iommu_enabled(), Michael S. Tsirkin, 2021/09/04
[PULL 14/35] virtio-pci: implement iommu_enabled(), Michael S. Tsirkin, 2021/09/04
[PULL 16/35] hw/i386/acpi-build: Get NUMA information from struct NumaState, Michael S. Tsirkin, 2021/09/04
[PULL 17/35] hw/pci: remove all references to find_i440fx function, Michael S. Tsirkin, 2021/09/04
[PULL 20/35] hw/virtio: Document virtio_queue_packed_empty_rcu is called within RCU, Michael S. Tsirkin, 2021/09/04
[PULL 21/35] hw/virtio: Remove NULL check in virtio_free_region_cache(), Michael S. Tsirkin, 2021/09/04