Blame SOURCES/quota-4.04-Listen-on-a-TCP-socket.patch

30c500
From 31ecd29b3b3f51145fd78f63087c10e9fcadf999 Mon Sep 17 00:00:00 2001
30c500
From: Steve Dickson <steved@redhat.com>
30c500
Date: Tue, 22 May 2018 12:41:59 +0200
30c500
Subject: [PATCH] Listen on a TCP socket
30c500
MIME-Version: 1.0
30c500
Content-Type: text/plain; charset=UTF-8
30c500
Content-Transfer-Encoding: 8bit
30c500
30c500
rpc.rquotad spins in libtirpc's rendezvous_request() on accepting TCP
30c500
connections because the polled TCP socket is not listening:
30c500
30c500
poll([{fd=4, events=POLLIN|POLLPRI|POLLRDNORM|POLLRDBAND}, {fd=5,
30c500
  events=POLLIN|POLLPRI|POLLRDNORM|POLLRDBAND}, {fd=6,
30c500
  events=POLLIN|POLLPRI|POLLRDNORM|POLLRDBAND}, {fd=7,
30c500
  events=POLLIN|POLLPRI|POLLRDNORM|POLLRDBAND}], 4, -1) = 2 ([{fd=5,
30c500
  revents=POLLHUP}, {fd=7, revents=POLLHUP}])
30c500
accept(5, 0x7ffe61698700, [128])        = -1 EINVAL (Invalid argument)
30c500
accept(7, 0x7ffe61698700, [128])        = -1 EINVAL (Invalid argument)
30c500
30c500
The polled descriptors are:
30c500
30c500
rpc.rquot 21981 root    4u  IPv4 80449159      0t0      UDP *:rquotad
30c500
rpc.rquot 21981 root    5u  sock      0,9      0t0 80449162 protocol: TCP
30c500
rpc.rquot 21981 root    6u  IPv6 80449165      0t0      UDP *:rquotad
30c500
rpc.rquot 21981 root    7u  sock      0,9      0t0 80449168 protocol: TCPv6
30c500
30c500
That results into a high CPU usage just after staring rpc.rquotad
30c500
process.
30c500
30c500
This patch adds a listen() call to svc_create_sock()
30c500
routine which is needed with libtirpc version of svc_tli_create()
30c500
as well as a needed IPv6 setsockopt().
30c500
30c500
Signed-off-by: Petr Písař <ppisar@redhat.com>
30c500
---
30c500
 svc_socket.c | 18 ++++++++++++++++++
30c500
 1 file changed, 18 insertions(+)
30c500
30c500
diff --git a/svc_socket.c b/svc_socket.c
30c500
index 8a44604..d2e3abf 100644
30c500
--- a/svc_socket.c
30c500
+++ b/svc_socket.c
30c500
@@ -118,6 +118,15 @@ static int svc_create_sock(struct addrinfo *ai)
30c500
 		return -1;
30c500
 	}
30c500
 
30c500
+	if (ai->ai_family == AF_INET6) {
30c500
+		if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY,
30c500
+				&optval, sizeof(optval)) < 0) {
30c500
+			errstr(_("Cannot set IPv6 socket options: %s\n"), strerror(errno));
30c500
+			close(fd);
30c500
+			return -1;
30c500
+		}
30c500
+	}
30c500
+
30c500
 	if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)) < 0) {
30c500
 		errstr(_("Cannot set socket options: %s\n"), strerror(errno));
30c500
 		close(fd);
30c500
@@ -129,6 +138,15 @@ static int svc_create_sock(struct addrinfo *ai)
30c500
 		close(fd);
30c500
 		return -1;
30c500
 	}
30c500
+
30c500
+	if (ai->ai_protocol == IPPROTO_TCP) {
30c500
+		if (listen(fd, SOMAXCONN) < 0) {
30c500
+			errstr(_("Cannot listen to address: %s\n"), strerror(errno));
30c500
+			close(fd);
30c500
+			return -1;
30c500
+		}
30c500
+	}
30c500
+
30c500
 	return fd;
30c500
 }
30c500
 
30c500
-- 
30c500
2.14.3
30c500