* [PATCH bpf-next] selftests/bpf: copy file using read/write in local storage test
@ 2020-12-02 17:49 Stanislav Fomichev
2020-12-03 18:33 ` Alexei Starovoitov
0 siblings, 1 reply; 2+ messages in thread
From: Stanislav Fomichev @ 2020-12-02 17:49 UTC (permalink / raw)
To: netdev, bpf; +Cc: davem, ast, daniel, Stanislav Fomichev
Splice (copy_file_range) doesn't work on all filesystems. I'm running
test kernels on top of my read-only disk image and it uses plan9 under the
hood. This prevents test_local_storage from successfully passing.
There is really no technical reason to use splice, so lets do
old-school read/write to copy file; this should work in all
environments.
Signed-off-by: Stanislav Fomichev <sdf@google.com>
---
.../bpf/prog_tests/test_local_storage.c | 28 ++++++++++++-------
1 file changed, 18 insertions(+), 10 deletions(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/test_local_storage.c b/tools/testing/selftests/bpf/prog_tests/test_local_storage.c
index fcca7ba1f368..c0fe73a17ed1 100644
--- a/tools/testing/selftests/bpf/prog_tests/test_local_storage.c
+++ b/tools/testing/selftests/bpf/prog_tests/test_local_storage.c
@@ -21,14 +21,6 @@ static inline int sys_pidfd_open(pid_t pid, unsigned int flags)
return syscall(__NR_pidfd_open, pid, flags);
}
-static inline ssize_t copy_file_range(int fd_in, loff_t *off_in, int fd_out,
- loff_t *off_out, size_t len,
- unsigned int flags)
-{
- return syscall(__NR_copy_file_range, fd_in, off_in, fd_out, off_out,
- len, flags);
-}
-
static unsigned int duration;
#define TEST_STORAGE_VALUE 0xbeefdead
@@ -47,6 +39,7 @@ static int copy_rm(char *dest)
{
int fd_in, fd_out = -1, ret = 0;
struct stat stat;
+ char *buf = NULL;
fd_in = open("/bin/rm", O_RDONLY);
if (fd_in < 0)
@@ -64,18 +57,33 @@ static int copy_rm(char *dest)
goto out;
}
- ret = copy_file_range(fd_in, NULL, fd_out, NULL, stat.st_size, 0);
- if (ret == -1) {
+ buf = malloc(stat.st_blksize);
+ if (!buf) {
ret = -errno;
goto out;
}
+ while (ret = read(fd_in, buf, stat.st_blksize), ret > 0) {
+ ret = write(fd_out, buf, ret);
+ if (ret < 0) {
+ ret = -errno;
+ goto out;
+
+ }
+ }
+ if (ret < 0) {
+ ret = -errno;
+ goto out;
+
+ }
+
/* Set executable permission on the copied file */
ret = chmod(dest, 0100);
if (ret == -1)
ret = -errno;
out:
+ free(buf);
close(fd_in);
close(fd_out);
return ret;
--
2.29.2.454.gaff20da3a2-goog
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH bpf-next] selftests/bpf: copy file using read/write in local storage test
2020-12-02 17:49 [PATCH bpf-next] selftests/bpf: copy file using read/write in local storage test Stanislav Fomichev
@ 2020-12-03 18:33 ` Alexei Starovoitov
0 siblings, 0 replies; 2+ messages in thread
From: Alexei Starovoitov @ 2020-12-03 18:33 UTC (permalink / raw)
To: Stanislav Fomichev; +Cc: netdev, bpf, davem, ast, daniel
On Wed, Dec 02, 2020 at 09:49:47AM -0800, Stanislav Fomichev wrote:
> Splice (copy_file_range) doesn't work on all filesystems. I'm running
> test kernels on top of my read-only disk image and it uses plan9 under the
> hood. This prevents test_local_storage from successfully passing.
>
> There is really no technical reason to use splice, so lets do
> old-school read/write to copy file; this should work in all
> environments.
>
> Signed-off-by: Stanislav Fomichev <sdf@google.com>
Applied, Thanks
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-12-03 18:34 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-02 17:49 [PATCH bpf-next] selftests/bpf: copy file using read/write in local storage test Stanislav Fomichev
2020-12-03 18:33 ` Alexei Starovoitov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).