Skip to content

Commit 3e749bb

Browse files
Geliang Tangintel-lab-lkp
authored andcommitted
selftests: mptcp: add splice io mode
This patch adds a new 'splice' io mode for mptcp_connect to test the newly added read_sock() and splice() functions of MPTCP. ./mptcp_connect.sh -m splice Signed-off-by: Geliang Tang <[email protected]>
1 parent 56700ca commit 3e749bb

File tree

2 files changed

+68
-2
lines changed

2 files changed

+68
-2
lines changed

tools/testing/selftests/net/mptcp/mptcp_connect.c

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ enum cfg_mode {
5151
CFG_MODE_POLL,
5252
CFG_MODE_MMAP,
5353
CFG_MODE_SENDFILE,
54+
CFG_MODE_SPLICE,
5455
};
5556

5657
enum cfg_peek {
@@ -123,7 +124,7 @@ static void die_usage(void)
123124
fprintf(stderr, "\t-j -- add additional sleep at connection start and tear down "
124125
"-- for MPJ tests\n");
125126
fprintf(stderr, "\t-l -- listens mode, accepts incoming connection\n");
126-
fprintf(stderr, "\t-m [poll|mmap|sendfile] -- use poll(default)/mmap+write/sendfile\n");
127+
fprintf(stderr, "\t-m [poll|mmap|sendfile|splice] -- use poll(default)/mmap+write/sendfile/splice\n");
127128
fprintf(stderr, "\t-M mark -- set socket packet mark\n");
128129
fprintf(stderr, "\t-o option -- test sockopt <option>\n");
129130
fprintf(stderr, "\t-p num -- use port num\n");
@@ -925,6 +926,53 @@ static int copyfd_io_sendfile(int infd, int peerfd, int outfd,
925926
return err;
926927
}
927928

929+
static int do_splice(const int infd, const int outfd, const size_t len)
930+
{
931+
int pipefd[2];
932+
ssize_t bytes;
933+
int err;
934+
935+
err = pipe(pipefd);
936+
if (err)
937+
return err;
938+
939+
while ((bytes = splice(infd, NULL, pipefd[1], NULL, len,
940+
SPLICE_F_MOVE | SPLICE_F_MORE)) > 0) {
941+
splice(pipefd[0], NULL, outfd, NULL, bytes,
942+
SPLICE_F_MOVE | SPLICE_F_MORE);
943+
}
944+
945+
close(pipefd[0]);
946+
close(pipefd[1]);
947+
948+
return 0;
949+
}
950+
951+
static int copyfd_io_splice(int infd, int peerfd, int outfd, unsigned int size,
952+
bool *in_closed_after_out, struct wstate *winfo)
953+
{
954+
int err;
955+
956+
if (listen_mode) {
957+
err = do_splice(peerfd, outfd, size);
958+
if (err)
959+
return err;
960+
961+
err = do_splice(infd, peerfd, size);
962+
} else {
963+
err = do_splice(infd, peerfd, size);
964+
if (err)
965+
return err;
966+
967+
shut_wr(peerfd);
968+
969+
err = do_splice(peerfd, outfd, size);
970+
*in_closed_after_out = true;
971+
}
972+
973+
return err;
974+
}
975+
928976
static int copyfd_io(int infd, int peerfd, int outfd, bool close_peerfd, struct wstate *winfo)
929977
{
930978
bool in_closed_after_out = false;
@@ -957,6 +1005,14 @@ static int copyfd_io(int infd, int peerfd, int outfd, bool close_peerfd, struct
9571005
&in_closed_after_out, winfo);
9581006
break;
9591007

1008+
case CFG_MODE_SPLICE:
1009+
file_size = get_infd_size(infd);
1010+
if (file_size < 0)
1011+
return file_size;
1012+
ret = copyfd_io_splice(infd, peerfd, outfd, file_size,
1013+
&in_closed_after_out, winfo);
1014+
break;
1015+
9601016
default:
9611017
fprintf(stderr, "Invalid mode %d\n", cfg_mode);
9621018

@@ -1361,12 +1417,15 @@ int parse_mode(const char *mode)
13611417
return CFG_MODE_MMAP;
13621418
if (!strcasecmp(mode, "sendfile"))
13631419
return CFG_MODE_SENDFILE;
1420+
if (!strcasecmp(mode, "splice"))
1421+
return CFG_MODE_SPLICE;
13641422

13651423
fprintf(stderr, "Unknown test mode: %s\n", mode);
13661424
fprintf(stderr, "Supported modes are:\n");
13671425
fprintf(stderr, "\t\t\"poll\" - interleaved read/write using poll()\n");
13681426
fprintf(stderr, "\t\t\"mmap\" - send entire input file (mmap+write), then read response (-l will read input first)\n");
13691427
fprintf(stderr, "\t\t\"sendfile\" - send entire input file (sendfile), then read response (-l will read input first)\n");
1428+
fprintf(stderr, "\t\t\"splice\" - send entire input file (splice), then read response (-l will read input first)\n");
13701429

13711430
die_usage();
13721431

tools/testing/selftests/net/mptcp/mptcp_connect.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,14 @@ do_transfer()
339339
fi
340340

341341
if [ -n "$testmode" ]; then
342-
extra_args+=" -m $testmode"
342+
if [ ${testmode} = "splice" ]; then
343+
# only use 'splice' mode for MPTCP tests
344+
if [ ${cl_proto} = "MPTCP" ] && [ ${srv_proto} = "MPTCP" ]; then
345+
extra_args+=" -m splice"
346+
fi
347+
else
348+
extra_args+=" -m $testmode"
349+
fi
343350
fi
344351

345352
if [ -n "$extra_args" ] && $options_log; then

0 commit comments

Comments
 (0)