[dpdk-dev,1/3] vhost: add log if fails to bind a socket

Message ID 1435807983-20383-2-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
  It adds more readable log info if a socket fails to bind to local device file name.

Signed-off-by: Changchun Ouyang <changchun.ouyang@intel.com>
---
 lib/librte_vhost/vhost_user/vhost-net-user.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
  

Comments

Huawei Xie July 2, 2015, 9:29 a.m. UTC | #1
On 7/2/2015 11:33 AM, Ouyang, Changchun wrote:
> It adds more readable log info if a socket fails to bind to local device file name.
local socket file, not device file. :).
>
> Signed-off-by: Changchun Ouyang <changchun.ouyang@intel.com>
> ---
>  lib/librte_vhost/vhost_user/vhost-net-user.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/lib/librte_vhost/vhost_user/vhost-net-user.c b/lib/librte_vhost/vhost_user/vhost-net-user.c
> index 87a4711..f406a94 100644
> --- a/lib/librte_vhost/vhost_user/vhost-net-user.c
> +++ b/lib/librte_vhost/vhost_user/vhost-net-user.c
> @@ -122,8 +122,11 @@ uds_socket(const char *path)
>  	un.sun_family = AF_UNIX;
>  	snprintf(un.sun_path, sizeof(un.sun_path), "%s", path);
>  	ret = bind(sockfd, (struct sockaddr *)&un, sizeof(un));
> -	if (ret == -1)
> +	if (ret == -1) {
> +		RTE_LOG(ERR, VHOST_CONFIG, "fail to bind fd:%d, remove file:%s and try again.\n",
> +			sockfd, path);
>  		goto err;
> +	}
>  	RTE_LOG(INFO, VHOST_CONFIG, "bind to %s\n", path);
>  
>  	ret = listen(sockfd, MAX_VIRTIO_BACKLOG);
  
Huawei Xie July 2, 2015, 9:31 a.m. UTC | #2
On 7/2/2015 11:33 AM, Ouyang, Changchun wrote:
> It adds more readable log info if a socket fails to bind to local device file name.

fails in binding, not fail to bind, :).

>
  
Ouyang Changchun July 3, 2015, 1:57 a.m. UTC | #3
> -----Original Message-----
> From: Xie, Huawei
> Sent: Thursday, July 2, 2015 5:29 PM
> To: Ouyang, Changchun; dev@dpdk.org
> Cc: Cao, Waterman; Xu, Qian Q
> Subject: Re: [PATCH 1/3] vhost: add log if fails to bind a socket
> 
> On 7/2/2015 11:33 AM, Ouyang, Changchun wrote:
> > It adds more readable log info if a socket fails to bind to local device file
> name.
> local socket file, not device file. :).

Make sense, will update it, thanks

> >
> > Signed-off-by: Changchun Ouyang <changchun.ouyang@intel.com>
> > ---
> >  lib/librte_vhost/vhost_user/vhost-net-user.c | 5 ++++-
> >  1 file changed, 4 insertions(+), 1 deletion(-)
> >
> > diff --git a/lib/librte_vhost/vhost_user/vhost-net-user.c
> b/lib/librte_vhost/vhost_user/vhost-net-user.c
> > index 87a4711..f406a94 100644
> > --- a/lib/librte_vhost/vhost_user/vhost-net-user.c
> > +++ b/lib/librte_vhost/vhost_user/vhost-net-user.c
> > @@ -122,8 +122,11 @@ uds_socket(const char *path)
> >  	un.sun_family = AF_UNIX;
> >  	snprintf(un.sun_path, sizeof(un.sun_path), "%s", path);
> >  	ret = bind(sockfd, (struct sockaddr *)&un, sizeof(un));
> > -	if (ret == -1)
> > +	if (ret == -1) {
> > +		RTE_LOG(ERR, VHOST_CONFIG, "fail to bind fd:%d, remove
> file:%s and try again.\n",
> > +			sockfd, path);
> >  		goto err;
> > +	}
> >  	RTE_LOG(INFO, VHOST_CONFIG, "bind to %s\n", path);
> >
> >  	ret = listen(sockfd, MAX_VIRTIO_BACKLOG);
  

Patch

diff --git a/lib/librte_vhost/vhost_user/vhost-net-user.c b/lib/librte_vhost/vhost_user/vhost-net-user.c
index 87a4711..f406a94 100644
--- a/lib/librte_vhost/vhost_user/vhost-net-user.c
+++ b/lib/librte_vhost/vhost_user/vhost-net-user.c
@@ -122,8 +122,11 @@  uds_socket(const char *path)
 	un.sun_family = AF_UNIX;
 	snprintf(un.sun_path, sizeof(un.sun_path), "%s", path);
 	ret = bind(sockfd, (struct sockaddr *)&un, sizeof(un));
-	if (ret == -1)
+	if (ret == -1) {
+		RTE_LOG(ERR, VHOST_CONFIG, "fail to bind fd:%d, remove file:%s and try again.\n",
+			sockfd, path);
 		goto err;
+	}
 	RTE_LOG(INFO, VHOST_CONFIG, "bind to %s\n", path);
 
 	ret = listen(sockfd, MAX_VIRTIO_BACKLOG);