From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <ciara.loftus@intel.com>
Received: from mga11.intel.com (mga11.intel.com [192.55.52.93])
 by dpdk.org (Postfix) with ESMTP id EC2425963
 for <dev@dpdk.org>; Fri,  5 Jun 2015 11:04:39 +0200 (CEST)
Received: from orsmga002.jf.intel.com ([10.7.209.21])
 by fmsmga102.fm.intel.com with ESMTP; 05 Jun 2015 02:04:39 -0700
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.13,557,1427785200"; d="scan'208";a="741470692"
Received: from irsmsx153.ger.corp.intel.com ([163.33.192.75])
 by orsmga002.jf.intel.com with ESMTP; 05 Jun 2015 02:04:37 -0700
Received: from irsmsx106.ger.corp.intel.com ([169.254.8.189]) by
 IRSMSX153.ger.corp.intel.com ([169.254.9.95]) with mapi id 14.03.0224.002;
 Fri, 5 Jun 2015 10:04:36 +0100
From: "Loftus, Ciara" <ciara.loftus@intel.com>
To: "Xie, Huawei" <huawei.xie@intel.com>, "dev@dpdk.org" <dev@dpdk.org>
Thread-Topic: [PATCH v2] vhost: provide vhost API to unregister vhost unix
 domain socket
Thread-Index: AQHQnz9yYsNsooWne0G8i+2wLVNxYp2dnnVA
Date: Fri, 5 Jun 2015 09:04:35 +0000
Message-ID: <74F120C019F4A64C9B78E802F6AD4CC220567AC8@IRSMSX106.ger.corp.intel.com>
References: <1433209800-29091-1-git-send-email-huawei.xie@intel.com>
 <1433474786-704-1-git-send-email-huawei.xie@intel.com>
In-Reply-To: <1433474786-704-1-git-send-email-huawei.xie@intel.com>
Accept-Language: en-GB, en-US
Content-Language: en-US
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
x-originating-ip: [163.33.239.180]
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0
Subject: Re: [dpdk-dev] [PATCH v2] vhost: provide vhost API to unregister
 vhost unix domain socket
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: patches and discussions about DPDK <dev.dpdk.org>
List-Unsubscribe: <http://dpdk.org/ml/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <http://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Fri, 05 Jun 2015 09:04:40 -0000



> -----Original Message-----
> From: Xie, Huawei
> Sent: Friday, June 05, 2015 4:26 AM
> To: dev@dpdk.org
> Cc: Loftus, Ciara; Xie, Huawei; Sun, Peng A
> Subject: [PATCH v2] vhost: provide vhost API to unregister vhost unix dom=
ain
> socket
>=20
> rte_vhost_driver_unregister will remove the listenfd from event list, and
> then close it.
>=20
> Signed-off-by: Huawei Xie <huawei.xie@intel.com>
> Signed-off-by: Peng Sun <peng.a.sun@intel.com>
> ---
>  lib/librte_vhost/rte_virtio_net.h            |  3 ++
>  lib/librte_vhost/vhost_cuse/vhost-net-cdev.c |  9 ++++
>  lib/librte_vhost/vhost_user/vhost-net-user.c | 68
> +++++++++++++++++++++++-----
>  lib/librte_vhost/vhost_user/vhost-net-user.h |  2 +-
>  4 files changed, 69 insertions(+), 13 deletions(-)
>=20
> diff --git a/lib/librte_vhost/rte_virtio_net.h
> b/lib/librte_vhost/rte_virtio_net.h
> index 5d38185..5630fbc 100644
> --- a/lib/librte_vhost/rte_virtio_net.h
> +++ b/lib/librte_vhost/rte_virtio_net.h
> @@ -188,6 +188,9 @@ int rte_vhost_enable_guest_notification(struct
> virtio_net *dev, uint16_t queue_i
>  /* Register vhost driver. dev_name could be different for multiple insta=
nce
> support. */
>  int rte_vhost_driver_register(const char *dev_name);
>=20
> +/* Unregister vhost driver. This is only meaningful to vhost user. */
> +int rte_vhost_driver_unregister(const char *dev_name);
> +
>  /* Register callbacks. */
>  int rte_vhost_driver_callback_register(struct virtio_net_device_ops cons=
t *
> const);
>  /* Start vhost driver session blocking loop. */
> diff --git a/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
> b/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
> index 6b68abf..1ae7c49 100644
> --- a/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
> +++ b/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
> @@ -405,6 +405,15 @@ rte_vhost_driver_register(const char *dev_name)
>  }
>=20
>  /**
> + * An empty function for unregister
> + */
> +int
> +rte_vhost_driver_unregister(const char *dev_name __rte_unused)
> +{
> +	return 0;
> +}
> +
> +/**
>   * The CUSE session is launched allowing the application to receive open=
,
>   * release and ioctl calls.
>   */
> diff --git a/lib/librte_vhost/vhost_user/vhost-net-user.c
> b/lib/librte_vhost/vhost_user/vhost-net-user.c
> index 31f1215..87a4711 100644
> --- a/lib/librte_vhost/vhost_user/vhost-net-user.c
> +++ b/lib/librte_vhost/vhost_user/vhost-net-user.c
> @@ -66,6 +66,8 @@ struct connfd_ctx {
>  struct _vhost_server {
>  	struct vhost_server *server[MAX_VHOST_SERVER];
>  	struct fdset fdset;
> +	int vserver_cnt;
> +	pthread_mutex_t server_mutex;
>  };
>=20
>  static struct _vhost_server g_vhost_server =3D {
> @@ -74,10 +76,10 @@ static struct _vhost_server g_vhost_server =3D {
>  		.fd_mutex =3D PTHREAD_MUTEX_INITIALIZER,
>  		.num =3D 0
>  	},
> +	.vserver_cnt =3D 0,
> +	.server_mutex =3D PTHREAD_MUTEX_INITIALIZER,
>  };
>=20
> -static int vserver_idx;
> -
>  static const char *vhost_message_str[VHOST_USER_MAX] =3D {
>  	[VHOST_USER_NONE] =3D "VHOST_USER_NONE",
>  	[VHOST_USER_GET_FEATURES] =3D "VHOST_USER_GET_FEATURES",
> @@ -427,7 +429,6 @@ vserver_message_handler(int connfd, void *dat, int
> *remove)
>  	}
>  }
>=20
> -
>  /**
>   * Creates and initialise the vhost server.
>   */
> @@ -436,34 +437,77 @@ rte_vhost_driver_register(const char *path)
>  {
>  	struct vhost_server *vserver;
>=20
> -	if (vserver_idx =3D=3D 0)
> +	pthread_mutex_lock(&g_vhost_server.server_mutex);
> +	if (ops =3D=3D NULL)
>  		ops =3D get_virtio_net_callbacks();
> -	if (vserver_idx =3D=3D MAX_VHOST_SERVER)
> +
> +	if (g_vhost_server.vserver_cnt =3D=3D MAX_VHOST_SERVER) {
> +		RTE_LOG(ERR, VHOST_CONFIG,
> +			"error: the number of servers reaches maximum\n");
> +		pthread_mutex_unlock(&g_vhost_server.server_mutex);
>  		return -1;
> +	}
>=20
>  	vserver =3D calloc(sizeof(struct vhost_server), 1);
> -	if (vserver =3D=3D NULL)
> +	if (vserver =3D=3D NULL) {
> +		pthread_mutex_unlock(&g_vhost_server.server_mutex);
>  		return -1;
> -
> -	unlink(path);
> +	}
>=20
>  	vserver->listenfd =3D uds_socket(path);
>  	if (vserver->listenfd < 0) {
>  		free(vserver);
> +		pthread_mutex_unlock(&g_vhost_server.server_mutex);
>  		return -1;
>  	}
> -	vserver->path =3D path;
> +
> +	vserver->path =3D strdup(path);
>=20
>  	fdset_add(&g_vhost_server.fdset, vserver->listenfd,
> -		vserver_new_vq_conn, NULL,
> -		vserver);
> +		vserver_new_vq_conn, NULL, vserver);
>=20
> -	g_vhost_server.server[vserver_idx++] =3D vserver;
> +	g_vhost_server.server[g_vhost_server.vserver_cnt++] =3D vserver;
> +	pthread_mutex_unlock(&g_vhost_server.server_mutex);
>=20
>  	return 0;
>  }
>=20
>=20
> +/**
> + * Unregister the specified vhost server
> + */
> +int
> +rte_vhost_driver_unregister(const char *path)
> +{
> +	int i;
> +	int count;
> +
> +	pthread_mutex_lock(&g_vhost_server.server_mutex);
> +
> +	for (i =3D 0; i < g_vhost_server.vserver_cnt; i++) {
> +		if (!strcmp(g_vhost_server.server[i]->path, path)) {
> +			fdset_del(&g_vhost_server.fdset,
> +				g_vhost_server.server[i]->listenfd);
> +
> +			close(g_vhost_server.server[i]->listenfd);
> +			free(g_vhost_server.server[i]->path);
> +			free(g_vhost_server.server[i]);
> +
> +			unlink(path);
> +
> +			count =3D --g_vhost_server.vserver_cnt;
> +			g_vhost_server.server[i] =3D
> g_vhost_server.server[count];
> +			g_vhost_server.server[count] =3D NULL;
> +
> 	pthread_mutex_unlock(&g_vhost_server.server_mutex);
> +
> +			return 0;
> +		}
> +	}
> +	pthread_mutex_unlock(&g_vhost_server.server_mutex);
> +
> +	return -1;
> +}
> +
>  int
>  rte_vhost_driver_session_start(void)
>  {
> diff --git a/lib/librte_vhost/vhost_user/vhost-net-user.h
> b/lib/librte_vhost/vhost_user/vhost-net-user.h
> index 1b6be6c..2e72f3c 100644
> --- a/lib/librte_vhost/vhost_user/vhost-net-user.h
> +++ b/lib/librte_vhost/vhost_user/vhost-net-user.h
> @@ -41,7 +41,7 @@
>  #include "fd_man.h"
>=20
>  struct vhost_server {
> -	const char *path; /**< The path the uds is bind to. */
> +	char *path; /**< The path the uds is bind to. */
>  	int listenfd;     /**< The listener sockfd. */
>  };
>=20
> --
> 1.8.1.4

Acked-by: Ciara Loftus <ciara.loftus@intel.com>