On 2015/02/02 10:06, Linhaifeng wrote: > On 2015/2/1 18:36, Tetsuya Mukawa wrote: >> This patch should be put on "lib/librte_vhost: vhost-user support" >> patch series written by Xie, Huawei. >> >> There are 2 type of vhost devices. One is cuse, the other is vhost-user. >> So far, one of them we can use. To use the other, DPDK is needed to be >> recompiled. > If we use vhost-user we also should install cuse and fuse module ? > I think is not a good idea. >
OK, I am going to rethink how to implement the abstraction. Thanks, Tetsuya >> The patch introduces rte_vhost_dev_type parameter. Using type parameter, >> the DPDK application can use both vhost devices without recompile. >> >> The type parameter should be specified when following vhost APIs are called. >> - int rte_vhost_driver_register(); >> - int rte_vhost_driver_session_start(); >> >> Signed-off-by: Tetsuya Mukawa <mukawa at igel.co.jp> >> --- >> examples/vhost/main.c | 4 +- >> lib/librte_vhost/Makefile | 4 +- >> lib/librte_vhost/rte_virtio_net.h | 15 +++++- >> lib/librte_vhost/vhost-net.c | 74 >> ++++++++++++++++++++++++++++ >> lib/librte_vhost/vhost_cuse/vhost-net-cdev.c | 5 +- >> lib/librte_vhost/vhost_cuse/vhost-net-cdev.h | 42 ++++++++++++++++ >> lib/librte_vhost/vhost_user/vhost-net-user.c | 4 +- >> lib/librte_vhost/vhost_user/vhost-net-user.h | 7 +++ >> 8 files changed, 145 insertions(+), 10 deletions(-) >> create mode 100644 lib/librte_vhost/vhost-net.c >> create mode 100644 lib/librte_vhost/vhost_cuse/vhost-net-cdev.h >> >> diff --git a/examples/vhost/main.c b/examples/vhost/main.c >> index 04f0118..545df72 100644 >> --- a/examples/vhost/main.c >> +++ b/examples/vhost/main.c >> @@ -3040,14 +3040,14 @@ main(int argc, char *argv[]) >> rte_vhost_feature_disable(1ULL << VIRTIO_NET_F_MRG_RXBUF); >> >> /* Register CUSE device to handle IOCTLs. */ >> - ret = rte_vhost_driver_register((char *)&dev_basename); >> + ret = rte_vhost_driver_register((char *)&dev_basename, VHOST_DEV_CUSE); >> if (ret != 0) >> rte_exit(EXIT_FAILURE,"CUSE device setup failure.\n"); >> >> rte_vhost_driver_callback_register(&virtio_net_device_ops); >> >> /* Start CUSE session. */ >> - rte_vhost_driver_session_start(); >> + rte_vhost_driver_session_start(VHOST_DEV_CUSE); >> return 0; >> >> } >> diff --git a/lib/librte_vhost/Makefile b/lib/librte_vhost/Makefile >> index 22319b8..cc95415 100644 >> --- a/lib/librte_vhost/Makefile >> +++ b/lib/librte_vhost/Makefile >> @@ -39,8 +39,8 @@ CFLAGS += -I vhost_cuse -lfuse >> CFLAGS += -I vhost_user >> LDFLAGS += -lfuse >> # all source are stored in SRCS-y >> -SRCS-$(CONFIG_RTE_LIBRTE_VHOST) := virtio-net.c vhost_rxtx.c >> -#SRCS-$(CONFIG_RTE_LIBRTE_VHOST) += vhost_cuse/vhost-net-cdev.c >> vhost_cuse/virtio-net-cdev.c vhost_cuse/eventfd_copy.c >> +SRCS-$(CONFIG_RTE_LIBRTE_VHOST) := virtio-net.c vhost-net.c vhost_rxtx.c >> +SRCS-$(CONFIG_RTE_LIBRTE_VHOST) += vhost_cuse/vhost-net-cdev.c >> vhost_cuse/virtio-net-cdev.c vhost_cuse/eventfd_copy.c >> SRCS-$(CONFIG_RTE_LIBRTE_VHOST) += vhost_user/vhost-net-user.c >> vhost_user/virtio-net-user.c vhost_user/fd_man.c >> >> # install includes >> diff --git a/lib/librte_vhost/rte_virtio_net.h >> b/lib/librte_vhost/rte_virtio_net.h >> index 611a3d4..7b3952c 100644 >> --- a/lib/librte_vhost/rte_virtio_net.h >> +++ b/lib/librte_vhost/rte_virtio_net.h >> @@ -166,6 +166,15 @@ gpa_to_vva(struct virtio_net *dev, uint64_t guest_pa) >> } >> >> /** >> + * Enum for vhost device types. >> + */ >> +enum rte_vhost_dev_type { >> + VHOST_DEV_CUSE, /* cuse driver */ >> + VHOST_DEV_USER, /* vhost-user driver */ >> + VHOST_DEV_MAX /* the number of vhost driver types */ >> +}; >> + >> +/** >> * Disable features in feature_mask. Returns 0 on success. >> */ >> int rte_vhost_feature_disable(uint64_t feature_mask); >> @@ -181,12 +190,14 @@ uint64_t rte_vhost_feature_get(void); >> int rte_vhost_enable_guest_notification(struct virtio_net *dev, uint16_t >> queue_id, int enable); >> >> /* Register vhost driver. dev_name could be different for multiple instance >> support. */ >> -int rte_vhost_driver_register(const char *dev_name); >> +int rte_vhost_driver_register(const char *dev_name, >> + enum rte_vhost_dev_type dev_type); >> >> /* Register callbacks. */ >> int rte_vhost_driver_callback_register(struct virtio_net_device_ops const * >> const); >> + >> /* Start vhost driver session blocking loop. */ >> -int rte_vhost_driver_session_start(void); >> +int rte_vhost_driver_session_start(enum rte_vhost_dev_type dev_type); >> >> /** >> * This function adds buffers to the virtio devices RX virtqueue. Buffers >> can >> diff --git a/lib/librte_vhost/vhost-net.c b/lib/librte_vhost/vhost-net.c >> new file mode 100644 >> index 0000000..d0316d7 >> --- /dev/null >> +++ b/lib/librte_vhost/vhost-net.c >> @@ -0,0 +1,74 @@ >> +/*- >> + * BSD LICENSE >> + * >> + * Copyright(c) 2015 IGEL Co.,Ltd. All rights reserved. >> + * All rights reserved. >> + * >> + * Redistribution and use in source and binary forms, with or without >> + * modification, are permitted provided that the following conditions >> + * are met: >> + * >> + * * Redistributions of source code must retain the above copyright >> + * notice, this list of conditions and the following disclaimer. >> + * * Redistributions in binary form must reproduce the above copyright >> + * notice, this list of conditions and the following disclaimer in >> + * the documentation and/or other materials provided with the >> + * distribution. >> + * * Neither the name of IGEL Co.,Ltd. nor the names of its >> + * contributors may be used to endorse or promote products derived >> + * from this software without specific prior written permission. >> + * >> + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS >> + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT >> + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR >> + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT >> + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, >> + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT >> + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, >> + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY >> + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT >> + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE >> + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >> + */ >> + >> +#include "rte_virtio_net.h" >> + >> +#include "vhost_cuse/vhost-net-cdev.h" >> +#include "vhost_user/vhost-net-user.h" >> + >> +/* >> + * Register vhost driver. >> + * dev_name could be different for multiple instance support. >> + */ >> +int >> +rte_vhost_driver_register(const char *dev_name, >> + enum rte_vhost_dev_type dev_type) >> +{ >> + if (dev_name == NULL) >> + return -EINVAL; >> + >> + switch (dev_type) { >> + case VHOST_DEV_CUSE: >> + return rte_vhost_cuse_driver_register(dev_name); >> + case VHOST_DEV_USER: >> + return rte_vhost_user_driver_register(dev_name); >> + default: >> + break; >> + } >> + return -ENODEV; >> +} >> + >> +/* Start vhost driver session blocking loop. */ >> +int >> +rte_vhost_driver_session_start(enum rte_vhost_dev_type dev_type) >> +{ >> + switch (dev_type) { >> + case VHOST_DEV_CUSE: >> + return rte_vhost_cuse_driver_session_start(); >> + case VHOST_DEV_USER: >> + return rte_vhost_user_driver_session_start(); >> + default: >> + break; >> + } >> + return -ENODEV; >> +} >> diff --git a/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c >> b/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c >> index 6b68abf..d1cd365 100644 >> --- a/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c >> +++ b/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c >> @@ -45,6 +45,7 @@ >> #include <rte_virtio_net.h> >> >> #include "virtio-net-cdev.h" >> +#include "vhost-net-cdev.h" >> #include "vhost-net.h" >> #include "eventfd_copy.h" >> >> @@ -354,7 +355,7 @@ static const struct cuse_lowlevel_ops vhost_net_ops = { >> * vhost_net_device_ops are also passed when the device is registered in >> app. >> */ >> int >> -rte_vhost_driver_register(const char *dev_name) >> +rte_vhost_cuse_driver_register(const char *dev_name) >> { >> struct cuse_info cuse_info; >> char device_name[PATH_MAX] = ""; >> @@ -409,7 +410,7 @@ rte_vhost_driver_register(const char *dev_name) >> * release and ioctl calls. >> */ >> int >> -rte_vhost_driver_session_start(void) >> +rte_vhost_cuse_driver_session_start(void) >> { >> fuse_session_loop(session); >> >> diff --git a/lib/librte_vhost/vhost_cuse/vhost-net-cdev.h >> b/lib/librte_vhost/vhost_cuse/vhost-net-cdev.h >> new file mode 100644 >> index 0000000..ad8d28f >> --- /dev/null >> +++ b/lib/librte_vhost/vhost_cuse/vhost-net-cdev.h >> @@ -0,0 +1,42 @@ >> +/*- >> + * BSD LICENSE >> + * >> + * Copyright(c) 2015 IGEL Co.,Ltd. All rights reserved. >> + * All rights reserved. >> + * >> + * Redistribution and use in source and binary forms, with or without >> + * modification, are permitted provided that the following conditions >> + * are met: >> + * >> + * * Redistributions of source code must retain the above copyright >> + * notice, this list of conditions and the following disclaimer. >> + * * Redistributions in binary form must reproduce the above copyright >> + * notice, this list of conditions and the following disclaimer in >> + * the documentation and/or other materials provided with the >> + * distribution. >> + * * Neither the name of IGEL Co.,Ltd. nor the names of its >> + * contributors may be used to endorse or promote products derived >> + * from this software without specific prior written permission. >> + * >> + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS >> + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT >> + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR >> + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT >> + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, >> + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT >> + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, >> + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY >> + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT >> + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE >> + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >> + */ >> +#ifndef _VHOST_NET_CDEV_H >> +#define _VHOST_NET_CDEV_H >> + >> +int >> +rte_vhost_cuse_driver_register(const char *dev_name); >> + >> +int >> +rte_vhost_cuse_driver_session_start(void); >> + >> +#endif >> diff --git a/lib/librte_vhost/vhost_user/vhost-net-user.c >> b/lib/librte_vhost/vhost_user/vhost-net-user.c >> index e6df8a8..aaf5dec 100644 >> --- a/lib/librte_vhost/vhost_user/vhost-net-user.c >> +++ b/lib/librte_vhost/vhost_user/vhost-net-user.c >> @@ -428,7 +428,7 @@ vserver_message_handler(int connfd, void *dat) >> * Creates and initialise the vhost server. >> */ >> int >> -rte_vhost_driver_register(const char *path) >> +rte_vhost_user_driver_register(const char *path) >> { >> struct vhost_server *vserver; >> >> @@ -461,7 +461,7 @@ rte_vhost_driver_register(const char *path) >> >> >> int >> -rte_vhost_driver_session_start(void) >> +rte_vhost_user_driver_session_start(void) >> { >> fdset_event_dispatch(&g_vhost_server.fdset); >> return 0; >> diff --git a/lib/librte_vhost/vhost_user/vhost-net-user.h >> b/lib/librte_vhost/vhost_user/vhost-net-user.h >> index e2a91a9..b4fa82f 100644 >> --- a/lib/librte_vhost/vhost_user/vhost-net-user.h >> +++ b/lib/librte_vhost/vhost_user/vhost-net-user.h >> @@ -103,4 +103,11 @@ typedef struct VhostUserMsg { >> #define VHOST_USER_VERSION (0x1) >> >> >> /*****************************************************************************/ >> + >> +int >> +rte_vhost_user_driver_register(const char *path); >> + >> +int >> +rte_vhost_user_driver_session_start(void); >> + >> #endif >>