public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: libc-alpha@sourceware.org
Subject: [PATCH v2 14/15] linux: Add tst-mount to check for Linux new mount API
Date: Mon,  7 Feb 2022 14:44:30 -0300	[thread overview]
Message-ID: <20220207174431.360355-15-adhemerval.zanella@linaro.org> (raw)
In-Reply-To: <20220207174431.360355-1-adhemerval.zanella@linaro.org>

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 is far from extensive and only check for error path
and minimal funcionality to see if arguments are issued correctly.

Checked on x86_64-linux-gnu.
---
 sysdeps/unix/sysv/linux/Makefile    |  1 +
 sysdeps/unix/sysv/linux/tst-mount.c | 95 +++++++++++++++++++++++++++++
 2 files changed, 96 insertions(+)
 create mode 100644 sysdeps/unix/sysv/linux/tst-mount.c

diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
index f7440fd9f3..cdaabba358 100644
--- a/sysdeps/unix/sysv/linux/Makefile
+++ b/sysdeps/unix/sysv/linux/Makefile
@@ -129,6 +129,7 @@ tests += tst-clone tst-clone2 tst-clone3 tst-fanotify tst-personality \
   tst-epoll \
   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 <https://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <support/check.h>
+#include <support/xunistd.h>
+#include <support/namespace.h>
+#include <sys/wait.h>
+#include <sys/mount.h>
+
+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 <support/test-driver.c>
-- 
2.32.0


  parent reply	other threads:[~2022-02-07 17:44 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-07 17:44 [PATCH v2 00/15] linux: Add new syscalls Adhemerval Zanella
2022-02-07 17:44 ` [PATCH v2 01/15] linux: Add pidfd_open Adhemerval Zanella
2022-05-16 21:12   ` Carlos O'Donell
2022-06-01 18:02   ` Matheus Castanho
2022-06-01 18:49     ` Adhemerval Zanella
2022-06-01 20:53       ` Matheus Castanho
2022-06-01 22:22         ` Joseph Myers
2022-02-07 17:44 ` [PATCH v2 02/15] linux: Add pidfd_getfd Adhemerval Zanella
2022-05-16 21:12   ` Carlos O'Donell
2022-02-07 17:44 ` [PATCH v2 03/15] linux: Add pidfd_send_signal Adhemerval Zanella
2022-05-16 21:12   ` Carlos O'Donell
2022-02-07 17:44 ` [PATCH v2 04/15] linux: Add P_PIDFD Adhemerval Zanella
2022-05-16 21:12   ` Carlos O'Donell
2022-02-07 17:44 ` [PATCH v2 05/15] linux: Add tst-pidfd.c Adhemerval Zanella
2022-05-16 21:12   ` Carlos O'Donell
2022-02-07 17:44 ` [PATCH v2 06/15] linux: Add process_madvise Adhemerval Zanella
2022-05-31 22:03   ` Carlos O'Donell
2022-06-01 18:04     ` Adhemerval Zanella
2022-02-07 17:44 ` [PATCH v2 07/15] linux: Add process_mrelease Adhemerval Zanella
2022-05-31 22:12   ` Carlos O'Donell
2022-06-01 18:35     ` Adhemerval Zanella
2022-02-07 17:44 ` [PATCH v2 08/15] linux: Add fsopen Adhemerval Zanella
2022-02-07 17:44 ` [PATCH v2 09/15] linux: Add fsmount Adhemerval Zanella
2022-02-07 17:44 ` [PATCH v2 10/15] linux: Add move_mount Adhemerval Zanella
2022-02-07 17:44 ` [PATCH v2 11/15] linux: Add fsconfig Adhemerval Zanella
2022-02-07 17:44 ` [PATCH v2 12/15] linux: Add fspick Adhemerval Zanella
2022-02-07 17:44 ` [PATCH v2 13/15] linux: Add open_tree Adhemerval Zanella
2022-02-07 17:44 ` Adhemerval Zanella [this message]
2022-02-07 17:44 ` [PATCH v2 15/15] linux: Add mount_setattr Adhemerval Zanella
2022-05-16 21:12 ` [PATCH v2 00/15] linux: Add new syscalls Carlos O'Donell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220207174431.360355-15-adhemerval.zanella@linaro.org \
    --to=adhemerval.zanella@linaro.org \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 read-only IMAP folder(s) and NNTP newsgroup(s).