blob: e9b9d3df4690c7594ce07430e1536ee076a4da99 [file] [log] [blame]
Brad Bishop64c979e2019-11-04 13:55:29 -05001From b42ab8e1aca951dd06c113159491b3fd5cf06f2e Mon Sep 17 00:00:00 2001
2From: Haiqing Bai <Haiqing.Bai@windriver.com>
3Date: Thu, 24 Oct 2019 09:39:04 +0800
4Subject: [PATCH] Add "listen" action for a tcp socket which does not call
5 'listen' after 'bind'
6
7It is found that /usr/bin/unfsd customus 100% cpu after starting qemu with 'nfs'
8option, and below lots of error messages shows when strace the process:
9
10poll([{fd=3, events=POLLIN|POLLPRI|POLLRDNORM|POLLRDBAND},{fd=4, events=POLLIN|POLLPRI|POLLRDNORM|POLLRDBAND},
11{fd=5, events=POLLIN|POLLPRI|POLLRDNORM|POLLRDBAND},{fd=6, events =POLLIN|POLLPRI|POLLRDNORM|POLLRDBAND}],
124, 2000) = 2 ([{fd=4, revents=POLLHUP},{fd=6, revents=POLLHUP}])
13accept(4, 0x7ffd5e6dddc0, [128]) = -1 EINVAL (Invalid argument)
14accept(6, 0x7ffd5e6dddc0, [128]) = -1 EINVAL (Invalid argument)
15
16% time seconds usecs/call calls errors syscall
17------ ----------- ----------- --------- --------- ----------------
18 70.87 0.005392 0 513886 513886 accept
19 29.13 0.002216 0 256943 poll
20 0.00 0.000000 0 4 read
21
22The root cause is that 'listen' is not called for the binded
23socket. The depended libtipc does not call 'listen' if found
24the incomming socket is binded, so 'accept' reports the error
25in the 'for' loop and cpu consumed.
26
27Upstream-Status: Pending
28
29Signed-off-by: Haiqing Bai <Haiqing.Bai@windriver.com>
30---
31 daemon.c | 7 +++++++
32 1 file changed, 7 insertions(+)
33
34diff --git a/daemon.c b/daemon.c
35index 028a181..4c85903 100644
36--- a/daemon.c
37+++ b/daemon.c
38@@ -814,6 +814,13 @@ static SVCXPRT *create_tcp_transport(unsigned int port)
39 fprintf(stderr, "Couldn't bind to tcp port %d\n", port);
40 exit(1);
41 }
42+
43+ if (listen(sock, SOMAXCONN) < 0) {
44+ perror("listen");
45+ fprintf(stderr, "Couldn't listen on the address \n");
46+ close(sock);
47+ exit(1);
48+ }
49 }
50
51 transp = svctcp_create(sock, 0, 0);
52--
531.9.1
54