Skip to contentSkip to conversation

syscalls/splice04,05: fix max limit for pipe

PATCH Superseded Xiao Yang 2 participants 9 messages Jun 8, 2017 – Jun 20, 2017

lore
Share & tools
lore

Xiao Yang

author
#0 lore raw

PATCH 1/2 syscalls/splice04,05: fix max limit for pipe

These cases fail on some older kernel(e.g, 2.6.32 and 2.6.35-rc1) because the pipe-max-size file does not exist.

The pipe-max-pages is introduced in kernel:
'b492e95be0ae(pipe: set lower and upper limit on max pages in the pipe page array)'

The pipe-max-pages is renamed to pipe-max-size in kernel:
'ff9da691c049(pipe: change /proc/sys/fs/pipe-max-pages to byte sized interface)'

We add get_max_limit function to check whether pipe-max-pages or pipe-max-size exists. If both pipe-max-pages and pipe-max-size don't exist, the max limit is set to default PIPE_MAX.

---
 testcases/kernel/syscalls/splice/splice.h   | 45 +++++++++++++++++++++++++++++
 testcases/kernel/syscalls/splice/splice04.c |  6 ++--
 testcases/kernel/syscalls/splice/splice05.c |  6 ++--
 3 files changed, 51 insertions(+), 6 deletions(-)
 create mode 100644 testcases/kernel/syscalls/splice/splice.h
testcases/kernel/syscalls/splice/splice.h new file +45 -0
new file mode 100644
index 0000000..681f657
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2017 Xiao Yang <[email protected]>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef SPLICE_H__
+#define SPLICE_H__
+
+#include <unistd.h>
+#include "tst_safe_file_ops.h"
+#include "tst_minmax.h"
+
+static inline int get_max_limit(int default_len_data)
+{
+	int pipe_max_unpriv;
+	int pipe_max_limit;
+
+	if (!access("/proc/sys/fs/pipe-max-size", F_OK)) {
+		SAFE_FILE_SCANF("/proc/sys/fs/pipe-max-size", "%d", &pipe_max_unpriv);
+		pipe_max_limit = MIN(pipe_max_unpriv, default_len_data);
+		return pipe_max_limit;
+	}
+
+	if (!access("/proc/sys/fs/pipe-max-pages", F_OK)) {
+		SAFE_FILE_SCANF("/proc/sys/fs/pipe-max-pages", "%d", &pipe_max_unpriv);
+		pipe_max_limit = MIN(pipe_max_unpriv * getpagesize(), default_len_data);
+		return pipe_max_limit;
+	}
+
+	return default_len_data;
+}
+
+#endif  /* SPLICE_H__ */
testcases/kernel/syscalls/splice/splice04.c +3 -3
index da0d3e1..2c94a29 100644
@@ -27,6 +27,7 @@
 #include <fcntl.h>
 #include <stdlib.h>
 #include "tst_test.h"
+#include "splice.h"
 
 #define PIPE_MAX (64*1024)
 
@@ -41,10 +42,9 @@ static struct tst_option options[] = {
 
 static void setup(void)
 {
-	int i, pipe_max_unpriv, pipe_limit;
+	int i, pipe_limit;
 
-	SAFE_FILE_SCANF("/proc/sys/fs/pipe-max-size", "%d", &pipe_max_unpriv);
-	pipe_limit = MIN(pipe_max_unpriv, num_len_data);
+	pipe_limit = get_max_limit(num_len_data);
 	num_len_data = pipe_limit;
 
 	if (tst_parse_int(str_len_data, &num_len_data, 1, pipe_limit)) {
testcases/kernel/syscalls/splice/splice05.c +3 -3
index 7f312e7..d7edf8d 100644
@@ -32,6 +32,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include "tst_test.h"
+#include "splice.h"
 
 #define PIPE_MAX (64*1024)
 
@@ -46,10 +47,9 @@ static struct tst_option options[] = {
 
 static void setup(void)
 {
-	int i, pipe_max_unpriv, pipe_limit;
+	int i, pipe_limit;
 
-	SAFE_FILE_SCANF("/proc/sys/fs/pipe-max-size", "%d", &pipe_max_unpriv);
-	pipe_limit = MIN(pipe_max_unpriv, num_len_data);
+	pipe_limit = get_max_limit(num_len_data);
 	num_len_data = pipe_limit;
 
 	if (tst_parse_int(str_len_data, &num_len_data, 1, pipe_limit)) {
Signature · 1 line
1.8.3.1
author
#1 lore raw

PATCH 2/2 syscalls/splice05: check if splice supports stream af_unix sockets

On some older kernel(e.g, 3.10.0), test result should be TCONF instead of TFAIL when splice does not support stream af_unix sockets as input.

This implement is introduced in kernel:
'2b514574f7e8(net: af_unix: implement splice for stream af_unix sockets)'

---
 testcases/kernel/syscalls/splice/splice05.c | 6 ++++++
 1 file changed, 6 insertions(+)
testcases/kernel/syscalls/splice/splice05.c +6 -0
index d7edf8d..b65df4b 100644
@@ -24,6 +24,7 @@
  */
 
 #define _GNU_SOURCE
+#include <errno.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/stat.h>
@@ -90,6 +91,11 @@ static void pipe_socket(void)
 	for (i = num_len_data; i > 0; i = i - ret) {
 		ret = splice(sv[1], 0, pp2[1], NULL, i, 0);
 		if (ret == -1) {
+			if (errno == EINVAL) {
+				tst_res(TCONF | TERRNO, "splice doesn't "
+					"support stream af_unix sockets");
+				goto exit;
+			}
 			tst_res(TFAIL | TERRNO, "splice error");
 			goto exit;
 		}
Signature · 1 line
1.8.3.1
author
#2 lore raw

PATCH 2/2 syscalls/splice05: check if splice supports stream af_unix sockets

Hi,

I have modified it and will send the v2 patch.

Thanks,
Xiao Yang

Quoted 35 lines · Xiao Yang

On some older kernel(e.g, 3.10.0), test result should be TCONF instead of TFAIL when splice does not support stream af_unix sockets as input.

This implement is introduced in kernel:
'2b514574f7e8(net: af_unix: implement splice for stream af_unix sockets)'

---
 testcases/kernel/syscalls/splice/splice05.c | 6 ++++++
 1 file changed, 6 insertions(+)
testcases/kernel/syscalls/splice/splice05.c +6 -0
index d7edf8d..b65df4b 100644
@@ -24,6 +24,7 @@
  */
 
 #define _GNU_SOURCE
+#include <errno.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/stat.h>
@@ -90,6 +91,11 @@ static void pipe_socket(void)
 	for (i = num_len_data; i > 0; i = i - ret) {
 		ret = splice(sv[1], 0, pp2[1], NULL, i, 0);
 		if (ret == -1) {
+			if (errno == EINVAL) {
+				tst_res(TCONF | TERRNO, "splice doesn't "
+					"support stream af_unix sockets");
+				goto exit;
+			}
 			tst_res(TFAIL | TERRNO, "splice error");
 			goto exit;
 		}
author
#3 lore raw

PATCH v2 1/1 syscalls/splice05: check if splice supports stream af_unix sockets

In reply to Xiao Yang

On some older kernel(e.g, 3.10.0), test result should be TCONF instead of TFAIL when splice does not support stream af_unix sockets as input.

This implement is introduced in kernel:
'2b514574f7e8(net: af_unix: implement splice for stream af_unix sockets)'

---
 testcases/kernel/syscalls/splice/splice05.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/splice/splice05.c +7 -1
index d7edf8d..01e2145 100644
@@ -24,6 +24,7 @@
  */
 
 #define _GNU_SOURCE
+#include <errno.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/stat.h>
@@ -90,7 +91,12 @@ static void pipe_socket(void)
 	for (i = num_len_data; i > 0; i = i - ret) {
 		ret = splice(sv[1], 0, pp2[1], NULL, i, 0);
 		if (ret == -1) {
-			tst_res(TFAIL | TERRNO, "splice error");
+			if (errno == EINVAL) {
+				tst_res(TCONF, "splice doesn't support "
+					"stream af_unix sockets as input");
+			} else {
+				tst_res(TFAIL | TERRNO, "splice error");
+			}
 			goto exit;
 		}
 		SAFE_READ(1, pp2[0], arr_out + num_len_data - i, ret);
Signature · 1 line
1.8.3.1
#4 lore raw

PATCH v2 1/1 syscalls/splice05: check if splice supports stream af_unix sockets

Hi!

testcases/kernel/syscalls/splice/splice05.c static void pipe_socket(void) · line 96

Quoted 3 lines
testcases/kernel/syscalls/splice/splice05.c +3 -0
+			if (errno == EINVAL) {
+				tst_res(TCONF, "splice doesn't support "
+					"stream af_unix sockets as input");

Maybe just shorter:

	tst_res(TCONF, "splice() does not support af_unix sockets");

Otherwise it looks fine.

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

PATCH v3 1/2 syscalls/splice04,05: fix max limit for pipe

These cases fail on some older kernel(e.g, 2.6.32 and 2.6.35-rc1) because the pipe-max-size file does not exist.

The pipe-max-pages is introduced in kernel:
'b492e95be0ae(pipe: set lower and upper limit on max pages in the pipe page array)'

The pipe-max-pages is renamed to pipe-max-size in kernel:
'ff9da691c049(pipe: change /proc/sys/fs/pipe-max-pages to byte sized interface)'

We add get_max_limit function to check whether pipe-max-pages or pipe-max-size exists. If both pipe-max-pages and pipe-max-size don't exist, the max limit is set to default PIPE_MAX.

---
 testcases/kernel/syscalls/splice/splice.h   | 42 +++++++++++++++++++++++++++++
 testcases/kernel/syscalls/splice/splice04.c |  6 ++---
 testcases/kernel/syscalls/splice/splice05.c |  6 ++---
 3 files changed, 48 insertions(+), 6 deletions(-)
 create mode 100644 testcases/kernel/syscalls/splice/splice.h
testcases/kernel/syscalls/splice/splice.h new file +42 -0
new file mode 100644
index 0000000..16e4c98
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2017 Xiao Yang <[email protected]>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef SPLICE_H__
+#define SPLICE_H__
+
+#include <unistd.h>
+#include "tst_safe_file_ops.h"
+#include "tst_minmax.h"
+
+static inline int get_max_limit(int default_len_data)
+{
+	int pipe_max_unpriv;
+
+	if (!access("/proc/sys/fs/pipe-max-size", F_OK)) {
+		SAFE_FILE_SCANF("/proc/sys/fs/pipe-max-size", "%d", &pipe_max_unpriv);
+		return MIN(pipe_max_unpriv, default_len_data);
+	}
+
+	if (!access("/proc/sys/fs/pipe-max-pages", F_OK)) {
+		SAFE_FILE_SCANF("/proc/sys/fs/pipe-max-pages", "%d", &pipe_max_unpriv);
+		return MIN(pipe_max_unpriv * getpagesize(), default_len_data);
+	}
+
+	return default_len_data;
+}
+
+#endif  /* SPLICE_H__ */
testcases/kernel/syscalls/splice/splice04.c +3 -3
index 91f5425..dbdc104 100644
@@ -27,6 +27,7 @@
 #include <fcntl.h>
 #include <stdlib.h>
 #include "tst_test.h"
+#include "splice.h"
 
 #define PIPE_MAX (64*1024)
 
@@ -41,10 +42,9 @@ static struct tst_option options[] = {
 
 static void setup(void)
 {
-	int i, pipe_max_unpriv, pipe_limit;
+	int i, pipe_limit;
 
-	SAFE_FILE_SCANF("/proc/sys/fs/pipe-max-size", "%d", &pipe_max_unpriv);
-	pipe_limit = MIN(pipe_max_unpriv, num_len_data);
+	pipe_limit = get_max_limit(num_len_data);
 	num_len_data = pipe_limit;
 
 	if (tst_parse_int(str_len_data, &num_len_data, 1, pipe_limit)) {
testcases/kernel/syscalls/splice/splice05.c +3 -3
index b8a21b9..decf7ae 100644
@@ -32,6 +32,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include "tst_test.h"
+#include "splice.h"
 
 #define PIPE_MAX (64*1024)
 
@@ -46,10 +47,9 @@ static struct tst_option options[] = {
 
 static void setup(void)
 {
-	int i, pipe_max_unpriv, pipe_limit;
+	int i, pipe_limit;
 
-	SAFE_FILE_SCANF("/proc/sys/fs/pipe-max-size", "%d", &pipe_max_unpriv);
-	pipe_limit = MIN(pipe_max_unpriv, num_len_data);
+	pipe_limit = get_max_limit(num_len_data);
 	num_len_data = pipe_limit;
 
 	if (tst_parse_int(str_len_data, &num_len_data, 1, pipe_limit)) {
Signature · 1 line
1.8.3.1
author
#6 lore raw

PATCH v3 2/2 syscalls/splice05: check if splice supports af_unix sockets

On some older kernel(e.g, 3.10.0), test result should be TCONF instead of TFAIL when splice does not support stream af_unix sockets as input.

This implement is introduced in kernel:
'2b514574f7e8(net: af_unix: implement splice for stream af_unix sockets)'

---
 testcases/kernel/syscalls/splice/splice05.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/splice/splice05.c +7 -1
index decf7ae..4cd1c5f 100644
@@ -24,6 +24,7 @@
  */
 
 #define _GNU_SOURCE
+#include <errno.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/stat.h>
@@ -90,7 +91,12 @@ static void pipe_socket(void)
 	for (i = num_len_data; i > 0; i = i - ret) {
 		ret = splice(sv[1], 0, pp2[1], NULL, i, 0);
 		if (ret == -1) {
-			tst_res(TFAIL | TERRNO, "splice error");
+			if (errno == EINVAL) {
+				tst_res(TCONF, "splice does not support "
+					"af_unix sockets");
+			} else {
+				tst_res(TFAIL | TERRNO, "splice error");
+			}
 			goto exit;
 		}
 		SAFE_READ(1, pp2[0], arr_out + num_len_data - i, ret);
Signature · 1 line
1.8.3.1
#8 lore raw

PATCH 1/2 syscalls/splice04,05: fix max limit for pipe

In reply to Xiao Yang

Hi!

Quoted 6 lines
testcases/kernel/syscalls/splice/splice.h new file +6 -0
+#ifndef SPLICE_H__
+#define SPLICE_H__
+
+#include <unistd.h>
+#include "tst_safe_file_ops.h"
+#include "tst_minmax.h"

testcases/kernel/syscalls/splice/splice.h line 33

Quoted 10 lines
testcases/kernel/syscalls/splice/splice.h new file +10 -0
+
+static inline int get_max_limit(int default_len_data)
+{
+	int pipe_max_unpriv;
+	int pipe_max_limit;
+
+	if (!access("/proc/sys/fs/pipe-max-size", F_OK)) {
+		SAFE_FILE_SCANF("/proc/sys/fs/pipe-max-size", "%d", &pipe_max_unpriv);
+		pipe_max_limit = MIN(pipe_max_unpriv, default_len_data);
+		return pipe_max_limit;

Just do return MIN(pipe_max_unpriv, default_len_data); there is no point in storing the result into the variable here.

testcases/kernel/syscalls/splice/splice.h line 39

Quoted 6 lines
testcases/kernel/syscalls/splice/splice.h new file +6 -0
+	}
+
+	if (!access("/proc/sys/fs/pipe-max-pages", F_OK)) {
+		SAFE_FILE_SCANF("/proc/sys/fs/pipe-max-pages", "%d", &pipe_max_unpriv);
+		pipe_max_limit = MIN(pipe_max_unpriv * getpagesize(), default_len_data);
+		return pipe_max_limit;

And here as well.

testcases/kernel/syscalls/splice/splice.h line 43

Quoted 4 lines
testcases/kernel/syscalls/splice/splice.h new file +4 -0
+	}
+
+	return default_len_data;
+}

Otherwise it looks obviously OK.

Signature · 2 lines
Cyril Hrubis
[email protected]