[dpdk-dev,3/3] vhost: call api to unregister vhost driver

Message ID 1435807983-20383-4-git-send-email-changchun.ouyang@intel.com (mailing list archive)
State Superseded, archived
Headers

Commit Message

Ouyang Changchun July 2, 2015, 3:33 a.m. UTC
  The commit will break vhost sample when it runs in second time:
292959c71961acde0cda6e77e737bb0a4df1559c

It should call api to unregister vhost driver when sample exit/quit, then
the socket file will be removed(by calling unlink), and thus make vhost sample
work correctly in second time startup.

Signed-off-by: Changchun Ouyang <changchun.ouyang@intel.com>
---
 examples/vhost/main.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
  

Comments

Huawei Xie July 2, 2015, 9:38 a.m. UTC | #1
On 7/2/2015 11:33 AM, Ouyang, Changchun wrote:
>  
>  	/* Start CUSE session. */
>  	rte_vhost_driver_session_start();
> +
> +	/* Unregister vhost driver. */
> +	ret = rte_vhost_driver_unregister((char *)&dev_basename);
> +	if (ret != 0)
> +		rte_exit(EXIT_FAILURE,"vhost driver unregister failure.\n");
> +
Better remove the above code.
It is duplicated with signal handler and actually
rte_vhost_driver_session_start never returns.

>  	return 0;
>  
>  }
  
Huawei Xie July 2, 2015, 4:04 p.m. UTC | #2
On 7/2/2015 11:33 AM, Ouyang, Changchun wrote:
> The commit will break vhost sample when it runs in second time:
> 292959c71961acde0cda6e77e737bb0a4df1559c
>
> It should call api to unregister vhost driver when sample exit/quit, then
> the socket file will be removed(by calling unlink), and thus make vhost sample
> work correctly in second time startup.
>
> Signed-off-by: Changchun Ouyang <changchun.ouyang@intel.com>
> ---
>  examples/vhost/main.c | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
>
> diff --git a/examples/vhost/main.c b/examples/vhost/main.c
> index 72c4773..90666b3 100644
> --- a/examples/vhost/main.c
> +++ b/examples/vhost/main.c
> @@ -2871,6 +2871,16 @@ setup_mempool_tbl(int socket, uint32_t index, char *pool_name,
>  	}
>  }
>  
> +/* When we receive a HUP signal, unregister vhost driver */
> +static void
> +sighup_handler(__rte_unused int signum)
> +{
> +	/* Unregister vhost driver. */
> +	int ret = rte_vhost_driver_unregister((char *)&dev_basename);
> +	if (ret != 0)
> +		rte_exit(EXIT_FAILURE, "vhost driver unregister failure.\n");
> +	exit(0);
> +}
>  
>  /*
>   * Main function, does initialisation and calls the per-lcore functions. The CUSE
> @@ -2887,6 +2897,8 @@ main(int argc, char *argv[])
>  	uint16_t queue_id;
>  	static pthread_t tid;
>  
> +	signal(SIGINT, sighup_handler);
> +

ignor if duplciated.
sighup->sigint

>  	/* init EAL */
>  	ret = rte_eal_init(argc, argv);
>  	if (ret < 0)
> @@ -3060,6 +3072,12 @@ main(int argc, char *argv[])
>  
>  	/* Start CUSE session. */
>  	rte_vhost_driver_session_start();
> +
> +	/* Unregister vhost driver. */
> +	ret = rte_vhost_driver_unregister((char *)&dev_basename);
> +	if (ret != 0)
> +		rte_exit(EXIT_FAILURE,"vhost driver unregister failure.\n");
> +
>  	return 0;
>  
>  }
  
Ouyang Changchun July 3, 2015, 2:03 a.m. UTC | #3
> -----Original Message-----
> From: Xie, Huawei
> Sent: Thursday, July 2, 2015 5:38 PM
> To: Ouyang, Changchun; dev@dpdk.org
> Cc: Cao, Waterman; Xu, Qian Q
> Subject: Re: [PATCH 3/3] vhost: call api to unregister vhost driver
> 
> On 7/2/2015 11:33 AM, Ouyang, Changchun wrote:
> >
> >  	/* Start CUSE session. */
> >  	rte_vhost_driver_session_start();
> > +
> > +	/* Unregister vhost driver. */
> > +	ret = rte_vhost_driver_unregister((char *)&dev_basename);
> > +	if (ret != 0)
> > +		rte_exit(EXIT_FAILURE,"vhost driver unregister failure.\n");
> > +
> Better remove the above code.
> It is duplicated with signal handler and actually
> rte_vhost_driver_session_start never returns.

How about call one function to replace the code snippet?
I think we need unregister there, it give us a clear example what the vhost lib caller need to do at the ramp down stage. 
Maybe 'never return' will be changed some day.

> 
> >  	return 0;
> >
> >  }
  
Ouyang Changchun July 3, 2015, 2:04 a.m. UTC | #4
> -----Original Message-----
> From: Xie, Huawei
> Sent: Friday, July 3, 2015 12:04 AM
> To: Ouyang, Changchun; dev@dpdk.org
> Cc: Cao, Waterman; Xu, Qian Q
> Subject: Re: [PATCH 3/3] vhost: call api to unregister vhost driver
> 
> On 7/2/2015 11:33 AM, Ouyang, Changchun wrote:
> > The commit will break vhost sample when it runs in second time:
> > 292959c71961acde0cda6e77e737bb0a4df1559c
> >
> > It should call api to unregister vhost driver when sample exit/quit,
> > then the socket file will be removed(by calling unlink), and thus make
> > vhost sample work correctly in second time startup.
> >
> > Signed-off-by: Changchun Ouyang <changchun.ouyang@intel.com>
> > ---
> >  examples/vhost/main.c | 18 ++++++++++++++++++
> >  1 file changed, 18 insertions(+)
> >
> > diff --git a/examples/vhost/main.c b/examples/vhost/main.c index
> > 72c4773..90666b3 100644
> > --- a/examples/vhost/main.c
> > +++ b/examples/vhost/main.c
> > @@ -2871,6 +2871,16 @@ setup_mempool_tbl(int socket, uint32_t index,
> char *pool_name,
> >  	}
> >  }
> >
> > +/* When we receive a HUP signal, unregister vhost driver */ static
> > +void sighup_handler(__rte_unused int signum) {
> > +	/* Unregister vhost driver. */
> > +	int ret = rte_vhost_driver_unregister((char *)&dev_basename);
> > +	if (ret != 0)
> > +		rte_exit(EXIT_FAILURE, "vhost driver unregister failure.\n");
> > +	exit(0);
> > +}
> >
> >  /*
> >   * Main function, does initialisation and calls the per-lcore
> > functions. The CUSE @@ -2887,6 +2897,8 @@ main(int argc, char *argv[])
> >  	uint16_t queue_id;
> >  	static pthread_t tid;
> >
> > +	signal(SIGINT, sighup_handler);
> > +
> 
> ignor if duplciated.
> sighup->sigint

Make sense, will update it in v2

> 
> >  	/* init EAL */
> >  	ret = rte_eal_init(argc, argv);
> >  	if (ret < 0)
> > @@ -3060,6 +3072,12 @@ main(int argc, char *argv[])
> >
> >  	/* Start CUSE session. */
> >  	rte_vhost_driver_session_start();
> > +
> > +	/* Unregister vhost driver. */
> > +	ret = rte_vhost_driver_unregister((char *)&dev_basename);
> > +	if (ret != 0)
> > +		rte_exit(EXIT_FAILURE,"vhost driver unregister failure.\n");
> > +
> >  	return 0;
> >
> >  }
  

Patch

diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index 72c4773..90666b3 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -2871,6 +2871,16 @@  setup_mempool_tbl(int socket, uint32_t index, char *pool_name,
 	}
 }
 
+/* When we receive a HUP signal, unregister vhost driver */
+static void
+sighup_handler(__rte_unused int signum)
+{
+	/* Unregister vhost driver. */
+	int ret = rte_vhost_driver_unregister((char *)&dev_basename);
+	if (ret != 0)
+		rte_exit(EXIT_FAILURE, "vhost driver unregister failure.\n");
+	exit(0);
+}
 
 /*
  * Main function, does initialisation and calls the per-lcore functions. The CUSE
@@ -2887,6 +2897,8 @@  main(int argc, char *argv[])
 	uint16_t queue_id;
 	static pthread_t tid;
 
+	signal(SIGINT, sighup_handler);
+
 	/* init EAL */
 	ret = rte_eal_init(argc, argv);
 	if (ret < 0)
@@ -3060,6 +3072,12 @@  main(int argc, char *argv[])
 
 	/* Start CUSE session. */
 	rte_vhost_driver_session_start();
+
+	/* Unregister vhost driver. */
+	ret = rte_vhost_driver_unregister((char *)&dev_basename);
+	if (ret != 0)
+		rte_exit(EXIT_FAILURE,"vhost driver unregister failure.\n");
+
 	return 0;
 
 }