Skip to content

Commit 6945318

Browse files
pevikmetan-ucw
authored andcommitted
syscalls/copy_file_range02: skip if cross-fs isn't supported
copy_file_range02 was written to verify copy_file_range() v5.3 changes. Detect it via cross-filesystem copy_file_range() functionality, so that we cover also backports to stable/enterprise distro kernels (if backported, it should be with all those API fixes). Missing these API fixes is detected by errno changes introduced by This fixes errors caused by commits from v5.3-rc1: 5dae222a5ff0 ("vfs: allow copy_file_range to copy across devices") 96e6e8f4a68d ("vfs: add missing checks to copy_file_range") This check requires to put back into copy_file_range02 .mount_device = 1 and .mntpoint = MNTPOINT (but .all_filesystems = 1 is obviously not needed). + Remove few unused imports. Suggested-by: Amir Goldstein <amir73il@gmail.com> Signed-off-by: Petr Vorel <pvorel@suse.cz> Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
1 parent bd355b9 commit 6945318

File tree

3 files changed

+32
-24
lines changed

3 files changed

+32
-24
lines changed

testcases/kernel/syscalls/copy_file_range/copy_file_range.h

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
#ifndef __COPY_FILE_RANGE_H__
88
#define __COPY_FILE_RANGE_H__
99

10-
#include <stdbool.h>
11-
#include <unistd.h>
12-
#include <sys/sysmacros.h>
10+
#include <stdio.h>
1311
#include "lapi/syscalls.h"
1412
#include "lapi/fs.h"
1513

@@ -62,4 +60,23 @@ static int sys_copy_file_range(int fd_in, loff_t *off_in,
6260
return -1;
6361
}
6462

63+
static inline int verify_cross_fs_copy_support(const char *path_in, const char *path_out)
64+
{
65+
int i, fd, fd_test;
66+
67+
fd = SAFE_OPEN(path_in, O_RDWR | O_CREAT, 0664);
68+
/* Writing page_size * 4 of data into test file */
69+
for (i = 0; i < (int)(getpagesize() * 4); i++)
70+
SAFE_WRITE(1, fd, CONTENT, CONTSIZE);
71+
72+
fd_test = SAFE_OPEN(path_out, O_RDWR | O_CREAT, 0664);
73+
TEST(sys_copy_file_range(fd, 0, fd_test, 0, CONTSIZE, 0));
74+
75+
SAFE_CLOSE(fd_test);
76+
remove(FILE_MNTED_PATH);
77+
SAFE_CLOSE(fd);
78+
79+
return TST_ERR == EXDEV ? 0 : 1;
80+
}
81+
6582
#endif /* __COPY_FILE_RANGE_H__ */

testcases/kernel/syscalls/copy_file_range/copy_file_range01.c

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
#define _GNU_SOURCE
1818

19-
#include <stdio.h>
20-
#include <stdlib.h>
2119
#include "tst_test.h"
2220
#include "tst_safe_stdio.h"
2321
#include "copy_file_range.h"
@@ -179,7 +177,7 @@ static void copy_file_range_verify(unsigned int n)
179177

180178
if (tc->flags && !cross_sup) {
181179
tst_res(TCONF,
182-
"copy_file_range doesn't support cross-device, skip it");
180+
"copy_file_range() doesn't support cross-device, skip it");
183181
return;
184182
}
185183

@@ -215,25 +213,9 @@ static void copy_file_range_verify(unsigned int n)
215213

216214
static void setup(void)
217215
{
218-
int i, fd, fd_test;
219-
220216
syscall_info();
221-
222217
page_size = getpagesize();
223-
cross_sup = 1;
224-
fd = SAFE_OPEN(FILE_SRC_PATH, O_RDWR | O_CREAT, 0664);
225-
/* Writing page_size * 4 of data into test file */
226-
for (i = 0; i < (int)(page_size * 4); i++)
227-
SAFE_WRITE(1, fd, CONTENT, CONTSIZE);
228-
229-
fd_test = SAFE_OPEN(FILE_MNTED_PATH, O_RDWR | O_CREAT, 0664);
230-
TEST(sys_copy_file_range(fd, 0, fd_test, 0, CONTSIZE, 0));
231-
if (TST_ERR == EXDEV)
232-
cross_sup = 0;
233-
234-
SAFE_CLOSE(fd_test);
235-
remove(FILE_MNTED_PATH);
236-
SAFE_CLOSE(fd);
218+
cross_sup = verify_cross_fs_copy_support(FILE_SRC_PATH, FILE_MNTED_PATH);
237219
}
238220

239221
static void cleanup(void)

testcases/kernel/syscalls/copy_file_range/copy_file_range02.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ static int fd_blkdev;
4949
static int fd_chrdev;
5050
static int fd_fifo;
5151
static int fd_copy;
52+
static int need_unlink;
5253

5354
static int chattr_i_nsup;
5455
static int swap_nsup;
@@ -160,14 +161,19 @@ static void cleanup(void)
160161
SAFE_CLOSE(fd_dup);
161162
if (fd_copy > 0)
162163
SAFE_CLOSE(fd_copy);
163-
SAFE_UNLINK(FILE_FIFO);
164+
if (need_unlink > 0)
165+
SAFE_UNLINK(FILE_FIFO);
164166
}
165167

166168
static void setup(void)
167169
{
168170
syscall_info();
169171
char dev_path[1024];
170172

173+
if (!verify_cross_fs_copy_support(FILE_SRC_PATH, FILE_MNTED_PATH))
174+
tst_brk(TCONF,
175+
"copy_file_range() doesn't support cross-device, skip it");
176+
171177
if (access(FILE_DIR_PATH, F_OK) == -1)
172178
SAFE_MKDIR(FILE_DIR_PATH, 0777);
173179
/*
@@ -177,6 +183,7 @@ static void setup(void)
177183
loop_devn = tst_find_free_loopdev(dev_path, sizeof(dev_path));
178184

179185
SAFE_MKNOD(FILE_FIFO, S_IFIFO | 0777, 0);
186+
need_unlink = 1;
180187

181188
fd_src = SAFE_OPEN(FILE_SRC_PATH, O_RDWR | O_CREAT, 0664);
182189
fd_dest = SAFE_OPEN(FILE_DEST_PATH, O_RDWR | O_CREAT, 0664);
@@ -223,6 +230,8 @@ static struct tst_test test = {
223230
.tcnt = ARRAY_SIZE(tcases),
224231
.setup = setup,
225232
.cleanup = cleanup,
233+
.mount_device = 1,
234+
.mntpoint = MNTPOINT,
226235
.needs_root = 1,
227236
.needs_tmpdir = 1,
228237
.test_variants = TEST_VARIANTS,

0 commit comments

Comments
 (0)