This patch introduces backend ops struct, that will enable
calling backend specifics callbacks (Vhost-user, VDUSE), in
shared code.
This is an empty shell for now, it will be filled in later
patches.
Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
Reviewed-by: Chenbo Xia <chenbo.xia@intel.com>
---
lib/vhost/socket.c | 2 +-
lib/vhost/vhost.c | 8 +++++++-
lib/vhost/vhost.h | 10 +++++++++-
lib/vhost/vhost_user.c | 8 ++++++++
lib/vhost/vhost_user.h | 1 +
5 files changed, 26 insertions(+), 3 deletions(-)
@@ -221,7 +221,7 @@ vhost_user_add_connection(int fd, struct vhost_user_socket *vsocket)
return;
}
- vid = vhost_new_device();
+ vid = vhost_user_new_device();
if (vid == -1) {
goto err;
}
@@ -676,11 +676,16 @@ reset_device(struct virtio_net *dev)
* there is a new virtio device being attached).
*/
int
-vhost_new_device(void)
+vhost_new_device(struct vhost_backend_ops *ops)
{
struct virtio_net *dev;
int i;
+ if (ops == NULL) {
+ VHOST_LOG_CONFIG("device", ERR, "missing backend ops.\n");
+ return -1;
+ }
+
pthread_mutex_lock(&vhost_dev_lock);
for (i = 0; i < RTE_MAX_VHOST_DEVICE; i++) {
if (vhost_devices[i] == NULL)
@@ -708,6 +713,7 @@ vhost_new_device(void)
dev->backend_req_fd = -1;
dev->postcopy_ufd = -1;
rte_spinlock_init(&dev->backend_req_lock);
+ dev->backend_ops = ops;
return i;
}
@@ -89,6 +89,12 @@
for (iter = val; iter < num; iter++)
#endif
+/**
+ * Structure that contains backend-specific ops.
+ */
+struct vhost_backend_ops {
+};
+
/**
* Structure contains buffer address, length and descriptor index
* from vring to do scatter RX.
@@ -513,6 +519,8 @@ struct virtio_net {
void *extern_data;
/* pre and post vhost user message handlers for the device */
struct rte_vhost_user_extern_ops extern_ops;
+
+ struct vhost_backend_ops *backend_ops;
} __rte_cache_aligned;
static inline void
@@ -812,7 +820,7 @@ get_device(int vid)
return dev;
}
-int vhost_new_device(void);
+int vhost_new_device(struct vhost_backend_ops *ops);
void cleanup_device(struct virtio_net *dev, int destroy);
void reset_device(struct virtio_net *dev);
void vhost_destroy_device(int);
@@ -3464,3 +3464,11 @@ int rte_vhost_host_notifier_ctrl(int vid, uint16_t qid, bool enable)
return ret;
}
+
+static struct vhost_backend_ops vhost_user_backend_ops;
+
+int
+vhost_user_new_device(void)
+{
+ return vhost_new_device(&vhost_user_backend_ops);
+}
@@ -185,5 +185,6 @@ int vhost_user_iotlb_miss(struct virtio_net *dev, uint64_t iova, uint8_t perm);
int read_fd_message(char *ifname, int sockfd, char *buf, int buflen, int *fds, int max_fds,
int *fd_num);
int send_fd_message(char *ifname, int sockfd, char *buf, int buflen, int *fds, int fd_num);
+int vhost_user_new_device(void);
#endif