From patchwork Wed Jun 22 12:52:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 1646530 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=Tw4YI+ZX; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LSk1K4rsPz9s5V for ; Wed, 22 Jun 2022 22:57:09 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 36FAD3857B9C for ; Wed, 22 Jun 2022 12:57:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 36FAD3857B9C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1655902627; bh=v7xAgQ4vWGiky2tSjKs0mf7w0/twPsBIeRZvCCIZB8Q=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Tw4YI+ZX5PM5BODpnl/GIUHmYzHg3I7Vm2HpR0rgubYZRVaJ4YS9AelC8JA5kSW0M iak4sDuBE5fwmZzEzyTYJTzu6YRkRf899271NRMPNmw6r9z9HXOFGdEidOBqFpb1Qs O0gQj9t15y4sxxenTh68XUAoFD1fGgRuYnHM8TbA= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x230.google.com (mail-oi1-x230.google.com [IPv6:2607:f8b0:4864:20::230]) by sourceware.org (Postfix) with ESMTPS id 83C783856DCA for ; Wed, 22 Jun 2022 12:52:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 83C783856DCA Received: by mail-oi1-x230.google.com with SMTP id bd16so21015986oib.6 for ; Wed, 22 Jun 2022 05:52:42 -0700 (PDT) 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=v7xAgQ4vWGiky2tSjKs0mf7w0/twPsBIeRZvCCIZB8Q=; b=4bG5dSIupb/G+NQG4HdUmakQXjawZnWMAcrqx8sQSe2GctanlhqsNs7NYy4DUZecdo YEnzyyW+P/3sdymDIKhUtUfC/rXnDhWDGKv7qX6ZJTzungETmvf918pj0SP0jFWT+bMF zO6iBNaentVC+Fx9hGBFeIFVCNTaCpAoFPf0eodtFT0hwCGOYx8yyx6UqCB91rlC1TuG U5qgoSM5/Mxt4uEDrV1XejjAy+tp63vKtbbvfVdUU9XDr3dlaL9s+W7kQLq8Ga6ZMqjD 5coYIeYW5miNg2nJXcIknL9W02E4EFAjXMp/ql0/X2kjWF5SFfUKyXiGOLXtsX6I2LPY jGUg== X-Gm-Message-State: AJIora8UKtS5m9GKXJY9czBY1ZmnWGr0233i0JNvPunWXAW/giJ2pMzL kk+9gU8w3hGQh69YW9IvmREx7X7+qnFxA4eX X-Google-Smtp-Source: AGRyM1sbeQdg+Y1XTYMoZc5OC2cecxVDb3XBT048V7Hy+XGRGKeG/wJVo6/zeoCE5wOP3zxu8CA1IA== X-Received: by 2002:a05:6808:2385:b0:32f:5b48:af5a with SMTP id bp5-20020a056808238500b0032f5b48af5amr1845713oib.58.1655902361656; Wed, 22 Jun 2022 05:52:41 -0700 (PDT) Received: from birita.. ([2804:431:c7ca:6d95:46aa:7388:40f0:ce5a]) by smtp.gmail.com with ESMTPSA id l7-20020a05683016c700b006168af9b625sm694664otr.65.2022.06.22.05.52.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jun 2022 05:52:41 -0700 (PDT) To: libc-alpha@sourceware.org, Carlos O'Donell Subject: [PATCH v6 7/8] linux: Add tst-mount to check for Linux new mount API Date: Wed, 22 Jun 2022 09:52:22 -0300 Message-Id: <20220622125223.14336-8-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220622125223.14336-1-adhemerval.zanella@linaro.org> References: <20220622125223.14336-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.7 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.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" 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 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