From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pa0-f50.google.com (mail-pa0-f50.google.com [209.85.220.50]) by dpdk.org (Postfix) with ESMTP id AACA32A61 for ; Mon, 2 Feb 2015 02:40:50 +0100 (CET) Received: by mail-pa0-f50.google.com with SMTP id rd3so75620415pab.9 for ; Sun, 01 Feb 2015 17:40:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :subject:references:in-reply-to:content-type :content-transfer-encoding; bh=Rh0n2C+ONn2BS/Dyy27UH96/v+1olH3UNbK+tXcFVFs=; b=AW3TtyHvMFi+OkAPCl5l6rtkHvnFF8vlNG2NsdwcILulAMyRVZcllXIoyhZaXzUq/g O+V6FkyeN/e3yLBnRb7JRmZkggbwOP/yhSz2U1h5GcdoN1NdmpJu8B+RUB6HyOHR9HUk qgR/QlkkSqVL/oA2vTyOjz3hCMY5xLC2gIo84xXKBJRqBNLub+z9uGUkdI3b994U+QVf a09+SznweyK6MNKqQ15IwQ14D9067xEMWPjqShC43UfITy7PtTKYSYgXTWgjm3AvJYFK sdVdn4aWfrSLgMLHqImCpzsyFl57l1MWo4Fb248jiHJC24F9kTU2JIi13K9kTuPrqCBj M92A== X-Gm-Message-State: ALoCoQlXb1Eote1c7KH4tc0HhGQxvLVyjq7lbRTnAD3OOEoMGOEknS4GWYqrQQYGn5HMdZW0yURi X-Received: by 10.70.23.229 with SMTP id p5mr25672327pdf.88.1422841249861; Sun, 01 Feb 2015 17:40:49 -0800 (PST) Received: from [10.16.129.101] (napt.igel.co.jp. [219.106.231.132]) by mx.google.com with ESMTPSA id kl11sm16994239pbd.89.2015.02.01.17.40.48 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 01 Feb 2015 17:40:49 -0800 (PST) Message-ID: <54CED59E.7020105@igel.co.jp> Date: Mon, 02 Feb 2015 10:40:46 +0900 From: Tetsuya Mukawa User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: Linhaifeng , dev@dpdk.org References: <1422786993-25076-1-git-send-email-mukawa@igel.co.jp> <54CECD84.1040606@huawei.com> In-Reply-To: <54CECD84.1040606@huawei.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Subject: Re: [dpdk-dev] [PATCH v1] librte_vhost: Add an abstraction to hide vhost-user and cuse devices. X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 02 Feb 2015 01:40:51 -0000 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-use= r. >> 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 paramete= r, >> the DPDK application can use both vhost devices without recompile. >> >> The type parameter should be specified when following vhost APIs are c= alled. >> - int rte_vhost_driver_register(); >> - int rte_vhost_driver_session_start(); >> >> Signed-off-by: Tetsuya Mukawa >> --- >> 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); >> =20 >> /* Register CUSE device to handle IOCTLs. */ >> - ret =3D rte_vhost_driver_register((char *)&dev_basename); >> + ret =3D rte_vhost_driver_register((char *)&dev_basename, VHOST_DEV_C= USE); >> if (ret !=3D 0) >> rte_exit(EXIT_FAILURE,"CUSE device setup failure.\n"); >> =20 >> rte_vhost_driver_callback_register(&virtio_net_device_ops); >> =20 >> /* Start CUSE session. */ >> - rte_vhost_driver_session_start(); >> + rte_vhost_driver_session_start(VHOST_DEV_CUSE); >> return 0; >> =20 >> } >> 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 +=3D -I vhost_cuse -lfuse >> CFLAGS +=3D -I vhost_user >> LDFLAGS +=3D -lfuse >> # all source are stored in SRCS-y >> -SRCS-$(CONFIG_RTE_LIBRTE_VHOST) :=3D virtio-net.c vhost_rxtx.c >> -#SRCS-$(CONFIG_RTE_LIBRTE_VHOST) +=3D vhost_cuse/vhost-net-cdev.c vho= st_cuse/virtio-net-cdev.c vhost_cuse/eventfd_copy.c >> +SRCS-$(CONFIG_RTE_LIBRTE_VHOST) :=3D virtio-net.c vhost-net.c vhost_r= xtx.c >> +SRCS-$(CONFIG_RTE_LIBRTE_VHOST) +=3D vhost_cuse/vhost-net-cdev.c vhos= t_cuse/virtio-net-cdev.c vhost_cuse/eventfd_copy.c >> SRCS-$(CONFIG_RTE_LIBRTE_VHOST) +=3D vhost_user/vhost-net-user.c vhos= t_user/virtio-net-user.c vhost_user/fd_man.c >> =20 >> # 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) >> } >> =20 >> /** >> + * 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, uint1= 6_t queue_id, int enable); >> =20 >> /* Register vhost driver. dev_name could be different for multiple in= stance 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); >> =20 >> /* Register callbacks. */ >> int rte_vhost_driver_callback_register(struct virtio_net_device_ops c= onst * 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);= >> =20 >> /** >> * This function adds buffers to the virtio devices RX virtqueue. Buf= fers can >> diff --git a/lib/librte_vhost/vhost-net.c b/lib/librte_vhost/vhost-net= =2Ec >> 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 witho= ut >> + * modification, are permitted provided that the following conditio= ns >> + * are met: >> + * >> + * * Redistributions of source code must retain the above copyrig= ht >> + * notice, this list of conditions and the following disclaimer= =2E >> + * * Redistributions in binary form must reproduce the above copy= right >> + * 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 deri= ved >> + * from this software without specific prior written permission= =2E >> + * >> + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUT= ORS >> + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NO= T >> + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNES= S FOR >> + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYR= IGHT >> + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDE= NTAL, >> + * 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 O= N ANY >> + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR T= ORT >> + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF TH= E USE >> + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAM= AGE. >> + */ >> + >> +#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 =3D=3D 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 >> =20 >> #include "virtio-net-cdev.h" >> +#include "vhost-net-cdev.h" >> #include "vhost-net.h" >> #include "eventfd_copy.h" >> =20 >> @@ -354,7 +355,7 @@ static const struct cuse_lowlevel_ops vhost_net_op= s =3D { >> * 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] =3D ""; >> @@ -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); >> =20 >> 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 witho= ut >> + * modification, are permitted provided that the following conditio= ns >> + * are met: >> + * >> + * * Redistributions of source code must retain the above copyrig= ht >> + * notice, this list of conditions and the following disclaimer= =2E >> + * * Redistributions in binary form must reproduce the above copy= right >> + * 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 deri= ved >> + * from this software without specific prior written permission= =2E >> + * >> + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUT= ORS >> + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NO= T >> + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNES= S FOR >> + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYR= IGHT >> + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDE= NTAL, >> + * 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 O= N ANY >> + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR T= ORT >> + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF TH= E USE >> + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAM= AGE. >> + */ >> +#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; >> =20 >> @@ -461,7 +461,7 @@ rte_vhost_driver_register(const char *path) >> =20 >> =20 >> 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) >> =20 >> /********************************************************************= *********/ >> + >> +int >> +rte_vhost_user_driver_register(const char *path); >> + >> +int >> +rte_vhost_user_driver_session_start(void); >> + >> #endif >>