From: Zhihong Wang <zhihong.wang@intel.com>
To: dev@dpdk.org
Cc: s.dyasly@samsung.com, i.maximets@samsung.com
Subject: [dpdk-dev] [PATCH] Unlink existing unused sockets at start up
Date: Wed, 16 Dec 2015 23:21:02 -0500 [thread overview]
Message-ID: <1450326062-105574-1-git-send-email-zhihong.wang@intel.com> (raw)
This patch unlinks existing unused sockets (which cause new bindings to fail, e.g. vHost PMD) to ensure smooth startup.
In a lot of cases DPDK applications are terminated abnormally without proper resource release. Therefore, DPDK libs should be able to deal with unclean boot environment.
Signed-off-by: Zhihong Wang <zhihong.wang@intel.com>
---
lib/librte_vhost/vhost_user/vhost-net-user.c | 28 ++++++++++++++++++++++++----
1 file changed, 24 insertions(+), 4 deletions(-)
diff --git a/lib/librte_vhost/vhost_user/vhost-net-user.c b/lib/librte_vhost/vhost_user/vhost-net-user.c
index 8b7a448..eac0721 100644
--- a/lib/librte_vhost/vhost_user/vhost-net-user.c
+++ b/lib/librte_vhost/vhost_user/vhost-net-user.c
@@ -120,18 +120,38 @@ uds_socket(const char *path)
sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
if (sockfd < 0)
return -1;
- RTE_LOG(INFO, VHOST_CONFIG, "socket created, fd:%d\n", sockfd);
+ RTE_LOG(INFO, VHOST_CONFIG, "socket created, fd: %d\n", sockfd);
memset(&un, 0, sizeof(un));
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) {
- RTE_LOG(ERR, VHOST_CONFIG, "fail to bind fd:%d, remove file:%s and try again.\n",
+ RTE_LOG(ERR, VHOST_CONFIG,
+ "bind fd: %d to file: %s failed, checking socket...\n",
sockfd, path);
- goto err;
+ ret = connect(sockfd, (struct sockaddr *)&un, sizeof(un));
+ if (ret == -1) {
+ RTE_LOG(INFO, VHOST_CONFIG,
+ "socket: %s is inactive, rebinding after unlink...\n", path);
+ unlink(path);
+ ret = bind(sockfd, (struct sockaddr *)&un, sizeof(un));
+ if (ret == -1) {
+ RTE_LOG(ERR, VHOST_CONFIG,
+ "bind fd: %d to file: %s failed even after unlink\n",
+ sockfd, path);
+ goto err;
+ }
+ } else {
+ RTE_LOG(INFO, VHOST_CONFIG,
+ "socket: %s is alive, remove it and try again\n", path);
+ RTE_LOG(ERR, VHOST_CONFIG,
+ "bind fd: %d to file: %s failed\n", sockfd, path);
+ goto err;
+ }
}
- RTE_LOG(INFO, VHOST_CONFIG, "bind to %s\n", path);
+ RTE_LOG(INFO, VHOST_CONFIG,
+ "bind fd: %d to file: %s successful\n", sockfd, path);
ret = listen(sockfd, MAX_VIRTIO_BACKLOG);
if (ret == -1)
--
2.5.0
next reply other threads:[~2015-12-17 11:24 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-17 4:21 Zhihong Wang [this message]
2015-12-17 11:47 ` Ilya Maximets
2015-12-18 2:39 ` Wang, Zhihong
2015-12-18 6:17 ` Ilya Maximets
2015-12-21 3:31 ` Wang, Zhihong
2015-12-17 11:59 ` Yuanhan Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1450326062-105574-1-git-send-email-zhihong.wang@intel.com \
--to=zhihong.wang@intel.com \
--cc=dev@dpdk.org \
--cc=i.maximets@samsung.com \
--cc=s.dyasly@samsung.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).