From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1791) id E3D323858036; Tue, 5 Jul 2022 13:13:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E3D323858036 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Adhemerval Zanella To: glibc-cvs@sourceware.org Subject: [glibc] linux: Add tst-mount to check for Linux new mount API X-Act-Checkin: glibc X-Git-Author: Adhemerval Zanella X-Git-Refname: refs/heads/master X-Git-Oldrev: 78a408ee7ba041fc8d5dbd5f67065b4a982c11e5 X-Git-Newrev: c3b02b6567e5709614eb24c85c3c0b69ae5c58a6 Message-Id: <20220705131341.E3D323858036@sourceware.org> Date: Tue, 5 Jul 2022 13:13:41 +0000 (GMT) X-BeenThere: glibc-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Glibc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 05 Jul 2022 13:13:42 -0000 https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=c3b02b6567e5709614eb24c85c3c0b69ae5c58a6 commit c3b02b6567e5709614eb24c85c3c0b69ae5c58a6 Author: Adhemerval Zanella Date: Fri Jun 24 16:59:18 2022 -0300 linux: Add tst-mount to check for Linux new mount API The new mount API was added on Linux 5.2 with six new syscalls: fsopen, fsconfig, fsmount, move_mount, fspick, and open_tree. The new test verifies minimal functionality along with error paths for specific arguments and their corner cases. Checked on x86_64-linux-gnu. Reviewed-by: Carlos O'Donell Diff: --- sysdeps/unix/sysv/linux/Makefile | 1 + sysdeps/unix/sysv/linux/tst-mount.c | 95 +++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index 7ffcf7ed83..2ccc92b6b8 100644 --- a/sysdeps/unix/sysv/linux/Makefile +++ b/sysdeps/unix/sysv/linux/Makefile @@ -130,6 +130,7 @@ tests += tst-clone tst-clone2 tst-clone3 tst-fanotify tst-personality \ tst-getauxval \ tst-pidfd \ tst-process_mrelease \ + tst-mount \ # tests # process_madvise requires CAP_SYS_ADMIN. diff --git a/sysdeps/unix/sysv/linux/tst-mount.c b/sysdeps/unix/sysv/linux/tst-mount.c new file mode 100644 index 0000000000..12a665f950 --- /dev/null +++ b/sysdeps/unix/sysv/linux/tst-mount.c @@ -0,0 +1,95 @@ +/* Basic tests for the new Linux API added on Linux 5.2. + Copyright (C) 2022 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2.1 of the + License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; see the file COPYING.LIB. If + not, see . */ + +#include +#include +#include +#include +#include +#include + +static void +subprocess (void) +{ + int r = fsopen ("it_should_be_not_a_valid_mount", 0); + TEST_VERIFY_EXIT (r == -1); + if (errno == ENOSYS) + FAIL_UNSUPPORTED ("kernel does not support new mount API, skipping test"); + TEST_COMPARE (errno, ENODEV); + + int fd = fsopen ("tmpfs", FSOPEN_CLOEXEC); + TEST_VERIFY (fd != -1); + + TEST_COMPARE (fsconfig (-1, FSCONFIG_SET_STRING, "size", "2048", 0), -1); + TEST_COMPARE (errno, EINVAL); + + { + int r = fsconfig (fd, FSCONFIG_SET_STRING, "size", "2048", 0); + TEST_VERIFY (r != -1); + r = fsconfig (fd, FSCONFIG_CMD_CREATE, NULL, NULL, 0); + TEST_VERIFY (r != -1); + } + + TEST_COMPARE (fsmount (-1, FSMOUNT_CLOEXEC, MOUNT_ATTR_NODEV), -1); + TEST_COMPARE (errno, EBADF); + + int mfd = fsmount (fd, FSMOUNT_CLOEXEC, MOUNT_ATTR_NODEV); + TEST_VERIFY (mfd != -1); + + TEST_COMPARE (move_mount (-1, "", AT_FDCWD, "/tmp", 0), -1); + TEST_COMPARE (errno, ENOENT); + { + int r = move_mount (mfd, "", AT_FDCWD, "/tmp", MOVE_MOUNT_F_EMPTY_PATH); + TEST_VERIFY (r != -1); + } + + TEST_COMPARE (fspick (AT_FDCWD, "", 0), -1); + TEST_COMPARE (errno, ENOENT); + { + int pfd = fspick (AT_FDCWD, "/tmp", FSPICK_CLOEXEC); + TEST_VERIFY (pfd != -1); + } + + TEST_COMPARE (open_tree (AT_FDCWD, "", 0), -1); + TEST_COMPARE (errno, ENOENT); + { + int fd_tree = open_tree (AT_FDCWD, "/tmp", + OPEN_TREE_CLONE | OPEN_TREE_CLOEXEC); + TEST_VERIFY (fd_tree != -1); + } + + _exit (0); +} + +static int +do_test (void) +{ + support_become_root (); + + pid_t pid = xfork (); + if (pid == 0) + subprocess (); + + int status; + xwaitpid (pid, &status, 0); + TEST_VERIFY (WIFEXITED (status)); + + return 0; +} + +#include