Skip to contentSkip to conversation

syscalls/sendfile: Delete unnecessary loop logic in do_child()

PATCH New Xie Ziyao 2 participants 5 messages Apr 20, 2021 – Apr 23, 2021

lore
Share & tools
lore

Xie Ziyao

author
#0 lore raw

PATCH 1/1 syscalls/sendfile: Delete unnecessary loop logic in do_child()

We don't need do_child() loop 'TEST_LOOPING(lc)' times to invoke the recvfrom() function, whitch makes no sense. If we run with "-i large number", this will slow down the program.

---
 testcases/kernel/syscalls/sendfile/sendfile02.c | 14 ++++++++------
 testcases/kernel/syscalls/sendfile/sendfile04.c | 14 ++++++++------
 testcases/kernel/syscalls/sendfile/sendfile05.c | 14 ++++++++------
 3 files changed, 24 insertions(+), 18 deletions(-)
testcases/kernel/syscalls/sendfile/sendfile02.c +8 -6
index e5f115146..acd7a5a50 100644
@@ -156,15 +156,17 @@ void do_sendfile(OFF_T offset, int i)
  */
 void do_child(void)
 {
-	int lc;
-	socklen_t length;
 	char rbuf[4096];
+	ssize_t ret = 0;
+	socklen_t length = sizeof(sin1);
 
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		length = sizeof(sin1);
-		recvfrom(sockfd, rbuf, 4096, 0, (struct sockaddr *)&sin1,
-			 &length);
+	ret = recvfrom(sockfd, rbuf, 4096, 0, (struct sockaddr *)&sin1, &length);
+	if (ret < 0) {
+		tst_resm(TFAIL, "child process recvfrom failed: %s\n",
+			 strerror(errno));
+		exit(1);
 	}
+
 	exit(0);
 }
 
testcases/kernel/syscalls/sendfile/sendfile04.c +8 -6
index 0f315abb0..322e2b58e 100644
@@ -153,15 +153,17 @@ void do_sendfile(int prot, int pass_unmapped_buffer)
  */
 void do_child(void)
 {
-	int lc;
-	socklen_t length;
 	char rbuf[4096];
+	ssize_t ret = 0;
+	socklen_t length = sizeof(sin1);
 
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		length = sizeof(sin1);
-		recvfrom(sockfd, rbuf, 4096, 0, (struct sockaddr *)&sin1,
-			 &length);
+	ret = recvfrom(sockfd, rbuf, 4096, 0, (struct sockaddr *)&sin1, &length);
+	if (ret < 0) {
+		tst_resm(TFAIL, "child process recvfrom failed: %s\n",
+			 strerror(errno));
+		exit(1);
 	}
+
 	exit(0);
 }
 
testcases/kernel/syscalls/sendfile/sendfile05.c +8 -6
index 0f268ceb3..a8e76d91d 100644
@@ -118,15 +118,17 @@ void do_sendfile(void)
  */
 void do_child(void)
 {
-	int lc;
-	socklen_t length;
 	char rbuf[4096];
+	ssize_t ret = 0;
+	socklen_t length = sizeof(sin1);
 
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		length = sizeof(sin1);
-		recvfrom(sockfd, rbuf, 4096, 0, (struct sockaddr *)&sin1,
-			 &length);
+	ret = recvfrom(sockfd, rbuf, 4096, 0, (struct sockaddr *)&sin1, &length);
+	if (ret < 0) {
+		tst_resm(TFAIL, "child process recvfrom failed: %s\n",
+			 strerror(errno));
+		exit(1);
 	}
+
 	exit(0);
 }
 

--
2.17.1

#1 lore raw

PATCH 1/1 syscalls/sendfile: Delete unnecessary loop logic in do_child()

Hi!
Looking at the code the sendfile04 and sendfile05 does not need 99% of the code in the tests, as a matter of fact it even breaks the tests with sufficiently large -i parameter.

Can we please instead remove all the server and socket code from sendfile04 and sendfile05? We can just easily pass in_fd and out_fd pointing to a regular files to the sendfile() syscall instead.

Signature · 2 lines
Cyril Hrubis
[email protected]
author
#2 lore raw

PATCH 1/1 syscalls/sendfile: Delete unnecessary loop logic in do_child()

Of course, I'm interested in modifying the testcases that way, and I'll submit another version to fix the problem.

Thanks for your review, Cyril.

Best Regards,
Ziyao

-----Original Message-----
From: Cyril Hrubis [mailto:[email protected]]
Sent: Wednesday, April 21, 2021 8:35 PM
To: xieziyao <[email protected]>
Cc: [email protected]
Subject: Re: [LTP] [PATCH] syscalls/sendfile: Delete unnecessary loop logic in do_child()

Hi!
Looking at the code the sendfile04 and sendfile05 does not need 99% of the code in the tests, as a matter of fact it even breaks the tests with sufficiently large -i parameter.

Can we please instead remove all the server and socket code from
sendfile04 and sendfile05? We can just easily pass in_fd and out_fd pointing to a regular files to the sendfile() syscall instead.

--
Cyril Hrubis
[email protected]

author
#3 lore raw

PATCH 1/1 syscalls/sendfile: Delete unnecessary loop logic in do_child()

In reply to Cyril Hrubis

Hi, Cyril,

I just made changes to sendfile04 and sendfile05 on your suggestions:
1. Convert sendfile04 to the new API;
2. Remove the socket code of server/client and use SAFE_SOCKETPAIR() instead, which can simplify the code logic.

And I think the other testcases of the sendfile testsuite have the same problem. Can we please modify other testcases in the same way?

Please see: https://patchwork.ozlabs.org/project/ltp/list/?series=240489

Best Regards,
Ziyao

-----Original Message-----
From: xieziyao
Sent: Thursday, April 22, 2021 3:13 PM
To: 'Cyril Hrubis' <[email protected]>
Cc: [email protected]
Subject: RE: [LTP] [PATCH] syscalls/sendfile: Delete unnecessary loop logic in do_child()

Of course, I'm interested in modifying the testcases that way, and I'll submit another version to fix the problem.

Thanks for your review, Cyril.

Best Regards,
Ziyao

-----Original Message-----
From: Cyril Hrubis [mailto:[email protected]]
Sent: Wednesday, April 21, 2021 8:35 PM
To: xieziyao <[email protected]>
Cc: [email protected]
Subject: Re: [LTP] [PATCH] syscalls/sendfile: Delete unnecessary loop logic in do_child()

Hi!
Looking at the code the sendfile04 and sendfile05 does not need 99% of the code in the tests, as a matter of fact it even breaks the tests with sufficiently large -i parameter.

Can we please instead remove all the server and socket code from
sendfile04 and sendfile05? We can just easily pass in_fd and out_fd pointing to a regular files to the sendfile() syscall instead.

--
Cyril Hrubis
[email protected]

#4 lore raw

PATCH 1/1 syscalls/sendfile: Delete unnecessary loop logic in do_child()

Hi!

Quoted 2 lines

And I think the other testcases of the sendfile testsuite have the same problem. Can we please modify other testcases in the same way?

Yes please, at least sendfile03, sendfile07 should be cleand up the same way as the sendfile04 and sendfile05 were.

The rest of the tests seems to actually transfer data, but the code is really messy so they should be cleaned up and converted to new library as well.

Signature · 2 lines
Cyril Hrubis
[email protected]