lkml.org 
[lkml]   [2021]   [Oct]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH bpf-next 2/2] selftests: bpf: test RENAME_EXCHANGE and RENAME_NOREPLACE on bpffs
Date
Add tests to exercise the behaviour of RENAME_EXCHANGE and RENAME_NOREPLACE
on bpffs. The former checks that after an exchange the inode of two
directories has changed. The latter checks that the source still exists
after a failed rename.

Signed-off-by: Lorenz Bauer <lmb@cloudflare.com>
---
.../selftests/bpf/prog_tests/test_bpffs.c | 39 +++++++++++++++++++
1 file changed, 39 insertions(+)

diff --git a/tools/testing/selftests/bpf/prog_tests/test_bpffs.c b/tools/testing/selftests/bpf/prog_tests/test_bpffs.c
index 172c999e523c..9c28ae9589bf 100644
--- a/tools/testing/selftests/bpf/prog_tests/test_bpffs.c
+++ b/tools/testing/selftests/bpf/prog_tests/test_bpffs.c
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2020 Facebook */
#define _GNU_SOURCE
+#include <stdio.h>
#include <sched.h>
#include <sys/mount.h>
#include <sys/stat.h>
@@ -29,6 +30,7 @@ static int read_iter(char *file)

static int fn(void)
{
+ struct stat a, b;
int err, duration = 0;

err = unshare(CLONE_NEWNS);
@@ -67,6 +69,43 @@ static int fn(void)
err = read_iter(TDIR "/fs2/progs.debug");
if (CHECK(err, "reading " TDIR "/fs2/progs.debug", "failed\n"))
goto out;
+
+ err = mkdir(TDIR "/fs1/a", 0777);
+ if (CHECK(err, "creating " TDIR "/fs1/a", "failed\n"))
+ goto out;
+ err = mkdir(TDIR "/fs1/a/1", 0777);
+ if (CHECK(err, "creating " TDIR "/fs1/a/1", "failed\n"))
+ goto out;
+ err = mkdir(TDIR "/fs1/b", 0777);
+ if (CHECK(err, "creating " TDIR "/fs1/b", "failed\n"))
+ goto out;
+
+ /* Check that RENAME_EXCHANGE works. */
+ err = stat(TDIR "/fs1/a", &a);
+ if (CHECK(err, "stat(" TDIR "/fs1/a)", "failed\n"))
+ goto out;
+ err = renameat2(0, TDIR "/fs1/a", 0, TDIR "/fs1/b", RENAME_EXCHANGE);
+ if (CHECK(err, "renameat2(RENAME_EXCHANGE)", "failed\n"))
+ goto out;
+ err = stat(TDIR "/fs1/b", &b);
+ if (CHECK(err, "stat(" TDIR "/fs1/b)", "failed\n"))
+ goto out;
+ if (CHECK(a.st_ino != b.st_ino, "b should have a's inode", "failed\n"))
+ goto out;
+ err = access(TDIR "/fs1/b/1", F_OK);
+ if (CHECK(err, "access(" TDIR "/fs1/b/1)", "failed\n"))
+ goto out;
+
+ /* Check that RENAME_NOREPLACE works. */
+ err = renameat2(0, TDIR "/fs1/b", 0, TDIR "/fs1/a", RENAME_NOREPLACE);
+ if (CHECK(!err, "renameat2(RENAME_NOREPLACE)", "succeeded\n")) {
+ err = -EINVAL;
+ goto out;
+ }
+ err = access(TDIR "/fs1/b", F_OK);
+ if (CHECK(err, "access(" TDIR "/fs1/b)", "failed\n"))
+ goto out;
+
out:
umount(TDIR "/fs1");
umount(TDIR "/fs2");
--
2.30.2
\
 
 \ /
  Last update: 2021-10-20 10:31    [W:0.063 / U:2.388 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site