4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 /* Test that open(O_TMPFILE), linkat() doesn't screw accounting. */
20 #include <sys/types.h>
23 #include <sys/mount.h>
26 #include "../kselftest.h"
32 // Setting up kselftest framework
36 // Check if test is run as root
38 ksft_exit_skip("This test needs root to run!\n");
42 if (unshare(CLONE_NEWNS) == -1) {
43 if (errno == ENOSYS || errno == EPERM) {
44 ksft_exit_skip("unshare() error: unshare, errno %d\n", errno);
46 ksft_exit_fail_msg("unshare() error: unshare, errno %d\n", errno);
50 if (mount(NULL, "/", NULL, MS_PRIVATE|MS_REC, NULL) == -1) {
51 ksft_exit_fail_msg("mount() error: Root filesystem private mount: Fail %d\n", errno);
54 /* Our heroes: 1 root inode, 1 O_TMPFILE inode, 1 permanent inode. */
55 if (mount(NULL, "/tmp", "tmpfs", 0, "nr_inodes=3") == -1) {
56 ksft_exit_fail_msg("mount() error: Mounting tmpfs on /tmp: Fail %d\n", errno);
59 fd = openat(AT_FDCWD, "/tmp", O_WRONLY|O_TMPFILE, 0600);
61 ksft_exit_fail_msg("openat() error: Open first temporary file: Fail %d\n", errno);
64 if (linkat(fd, "", AT_FDCWD, "/tmp/1", AT_EMPTY_PATH) == -1) {
65 ksft_exit_fail_msg("linkat() error: Linking the temporary file: Fail %d\n", errno);
66 /* Ensure fd is closed on failure */
71 fd = openat(AT_FDCWD, "/tmp", O_WRONLY|O_TMPFILE, 0600);
73 ksft_exit_fail_msg("openat() error: Opening the second temporary file: Fail %d\n", errno);
75 ksft_test_result_pass(" ");