From mboxrd@z Thu Jan 1 00:00:00 1970 From: Tiwei Bie Subject: Re: [PATCH v4 1/1] net/virtio-user: add support for server mode Date: Wed, 4 Apr 2018 13:37:17 +0800 Message-ID: <20180404053717.trp4pchameeirymv@debian> References: <20180321030343.64399-1-zhiyong.yang@intel.com> <20180403122009.52876-1-zhiyong.yang@intel.com> <20180403122009.52876-2-zhiyong.yang@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Cc: "Tan, Jianfeng" , dev@dpdk.org, maxime.coquelin@redhat.com, thomas@monjalon.net, zhihong.wang@intel.com To: zhiyong.yang@intel.com Return-path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id 6236B1BB87 for ; Wed, 4 Apr 2018 07:39:42 +0200 (CEST) Content-Disposition: inline In-Reply-To: List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On Tue, Apr 03, 2018 at 11:16:26PM +0800, Tan, Jianfeng wrote: > On 4/3/2018 8:20 PM, zhiyong.yang@intel.com wrote: [...] > > @@ -267,21 +270,27 @@ virtio_user_dev_setup(struct virtio_user_dev *dev) > > dev->vhostfds = NULL; > > dev->tapfds = NULL; > > Add a check here: > if (dev->is_server && !is_vhost_user_by_type(dev->path)) > return error; > > > - if (is_vhost_user_by_type(dev->path)) { > > - dev->ops = &ops_user; > > + if (dev->is_server) { > > + dev->ops = &ops_user;/* server mode only supports vhost user*/ > > } else { > > - dev->ops = &ops_kernel; > > - > > - dev->vhostfds = malloc(dev->max_queue_pairs * sizeof(int)); > > - dev->tapfds = malloc(dev->max_queue_pairs * sizeof(int)); > > - if (!dev->vhostfds || !dev->tapfds) { > > - PMD_INIT_LOG(ERR, "Failed to malloc"); > > - return -1; > > - } > > - > > - for (q = 0; q < dev->max_queue_pairs; ++q) { > > - dev->vhostfds[q] = -1; > > - dev->tapfds[q] = -1; > > + if (is_vhost_user_by_type(dev->path)) { > > + dev->ops = &ops_user; > > + } else { > > + dev->ops = &ops_kernel; > > + > > + dev->vhostfds = malloc(dev->max_queue_pairs * > > + sizeof(int)); > > + dev->tapfds = malloc(dev->max_queue_pairs * > > + sizeof(int)); > > + if (!dev->vhostfds || !dev->tapfds) { > > + PMD_INIT_LOG(ERR, "Failed to malloc"); > > + return -1; > > + } > > + > > + for (q = 0; q < dev->max_queue_pairs; ++q) { > > + dev->vhostfds[q] = -1; > > + dev->tapfds[q] = -1; > > + } > > } > > } Hi Zhiyong, I think we can keep using is_vhost_user_by_type() to determine the ops for dev->ops. And you just need to add a check in the vhost-kernel case. Something like this: --- i/drivers/net/virtio/virtio_user/virtio_user_dev.c +++ w/drivers/net/virtio/virtio_user/virtio_user_dev.c @@ -270,6 +270,9 @@ virtio_user_dev_setup(struct virtio_user_dev *dev) if (is_vhost_user_by_type(dev->path)) { dev->ops = &ops_user; } else { + if (dev->is_server) + return -1; + dev->ops = &ops_kernel; dev->vhostfds = malloc(dev->max_queue_pairs * sizeof(int)); Thanks