[sheepdog] [PATCH] sockfd_cache: close socket always when node is crashed

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Wed May 1 18:50:05 CEST 2013


When timeout happens, we cannot reuse the socket for other transfers
because data may remain in its send (or recv) buffer.  We have to
close the socket before making the sockfd_cache reusable.

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 sheep/sockfd_cache.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/sheep/sockfd_cache.c b/sheep/sockfd_cache.c
index 45d9d04..70d804c 100644
--- a/sheep/sockfd_cache.c
+++ b/sheep/sockfd_cache.c
@@ -410,7 +410,8 @@ out:
 	return sfd;
 }
 
-static void sockfd_cache_put(const struct node_id *nid, int idx)
+static void sockfd_cache_put(const struct node_id *nid, int idx,
+			     bool need_close)
 {
 	bool use_io = nid->io_port ? true : false;
 	const uint8_t *addr = use_io ? nid->io_addr : nid->addr;
@@ -423,8 +424,13 @@ static void sockfd_cache_put(const struct node_id *nid, int idx)
 
 	pthread_rwlock_rdlock(&sockfd_cache.lock);
 	entry = sockfd_cache_search(nid);
-	if (entry)
+	if (entry) {
+		if (need_close) {
+			close(entry->fds[idx].fd);
+			entry->fds[idx].fd = -1;
+		}
 		uatomic_set_false(&entry->fds[idx].in_use);
+	}
 	pthread_rwlock_unlock(&sockfd_cache.lock);
 }
 
@@ -478,7 +484,7 @@ void sheep_put_sockfd(const struct node_id *nid, struct sockfd *sfd)
 		return;
 	}
 
-	sockfd_cache_put(nid, sfd->idx);
+	sockfd_cache_put(nid, sfd->idx, false);
 	free(sfd);
 }
 
@@ -498,7 +504,7 @@ void sheep_del_sockfd(const struct node_id *nid, struct sockfd *sfd)
 		return;
 	}
 
-	sockfd_cache_put(nid, sfd->idx);
+	sockfd_cache_put(nid, sfd->idx, true);
 	sockfd_cache_del(nid);
 	free(sfd);
 }
-- 
1.8.1.3.566.gaa39828




More information about the sheepdog mailing list