From patchwork Sun Feb 1 10:36:33 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tetsuya Mukawa X-Patchwork-Id: 2892 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 261962A61; Sun, 1 Feb 2015 11:36:52 +0100 (CET) Received: from mail-pa0-f52.google.com (mail-pa0-f52.google.com [209.85.220.52]) by dpdk.org (Postfix) with ESMTP id A0C1B2A5B for ; Sun, 1 Feb 2015 11:36:49 +0100 (CET) Received: by mail-pa0-f52.google.com with SMTP id kx10so70384561pab.11 for ; Sun, 01 Feb 2015 02:36:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Mn25kpmdP/gKnwyyi89kmCkDMtF/BaiZuw3RvIMYNm8=; b=gBOzftGXrSMo6p21EagVnR9hFDk5x4gJTMGHbMCbI/nR2IatRxDot+L3XRhscednST Kp2MdjUSAju6yZPaM+xiwVEJWnirnBVSCDIsau4PkyZMGPTlDuMI8Lkd0K0HL0KB2NgV MCs9e/Ss0z0tNxzhSpJpahCKqdptN0eBcWTK+NXeCnF3crmV76TNkqaC108/5p87Vdlc EmknO8WhUUYIvm9DtYh+iYTSn+iO8P9UsQXdXLl1TSXsoYWyZRNNYgR96XW1PlqdjUCn z4pRx6GI6hUlXpXSvs+bj/7ONmy/+Smsu0PDLyH+CBqLUQylU5tKCl+7QmXo9MNwk9jA 4MOQ== X-Gm-Message-State: ALoCoQkkdKg14+uHsGA9fYzv1CVpdXFMOLUSecOWtKbNxPlBMcsA+l+jAXHm5IXzsiJMKIYhnz+e X-Received: by 10.68.107.197 with SMTP id he5mr1549916pbb.93.1422787008826; Sun, 01 Feb 2015 02:36:48 -0800 (PST) Received: from eris.hq.igel.co.jp (napt.igel.co.jp. [219.106.231.132]) by mx.google.com with ESMTPSA id ku12sm15920829pab.39.2015.02.01.02.36.46 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 01 Feb 2015 02:36:48 -0800 (PST) From: Tetsuya Mukawa To: dev@dpdk.org Date: Sun, 1 Feb 2015 19:36:33 +0900 Message-Id: <1422786993-25076-1-git-send-email-mukawa@igel.co.jp> X-Mailer: git-send-email 1.9.1 Subject: [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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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. 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 --- 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 #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