From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi1-x22d.google.com (mail-oi1-x22d.google.com [IPv6:2607:f8b0:4864:20::22d]) by sourceware.org (Postfix) with ESMTPS id 74D2F385842C for ; Mon, 7 Feb 2022 17:44:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 74D2F385842C Received: by mail-oi1-x22d.google.com with SMTP id ay7so3870022oib.8 for ; Mon, 07 Feb 2022 09:44:52 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IshmM0AC66Qns4MrDemSq0pWadEcJYXF+udAuwvd42E=; b=Lwsxh/HaJ/EppuRcQ05vf7ZCdKEeOcjnwTFOJDIQxA5oH9g5RAP2TR6sR5p26F7+8b YQtWVyKv3uGZGVnDi/Ti6peoZ4usyLfvIb5Y3HSnUP+psAUeBL3yzK29JDmCuns5MVu9 QB5pK8PdCoEX/1XIFuMROj87wfU+Sev5ZAZxpDOwCXq33J8CGRUNXciRzuJ4wUmtrlxn N+ruBymM7/PWBMAKOz3i1JD1X4p6t7o1OltPZTp+FEbq6sKG4AWd+c8sjXaT3UZiWCMm jpjUZCtb7xJrQhoymCpO5v2P4rBj1LIBUpUcQbfBJt88AAbPA0nKm9UGjYU3H+l2bB91 Cl7g== X-Gm-Message-State: AOAM532XmZXC16TE6YvGKVL9F4vD+E0NuLLUlyvgWNABahlDlQsTqVfN to21TMMf6FTlaBApYCatJt/BQuvB69C+4g== X-Google-Smtp-Source: ABdhPJxJ5Su7KK5UStEhQNrbbkKsoOvHu205B00LSkRux/Jg1uQ4ggmweFACwkOHtDrmSvn7TgrcOg== X-Received: by 2002:a05:6808:3021:: with SMTP id ay33mr19058oib.256.1644255891658; Mon, 07 Feb 2022 09:44:51 -0800 (PST) Received: from birita.. ([2804:431:c7ca:733:4cdc:e08a:54c6:5108]) by smtp.gmail.com with ESMTPSA id l22sm4270334otj.44.2022.02.07.09.44.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Feb 2022 09:44:51 -0800 (PST) From: Adhemerval Zanella 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 Message-Id: <20220207174431.360355-15-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220207174431.360355-1-adhemerval.zanella@linaro.org> References: <20220207174431.360355-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 07 Feb 2022 17:44:54 -0000 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 . */ + +#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 -- 2.32.0