• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) 2020 Viresh Kumar <viresh.kumar@linaro.org>
4  *
5  * Basic open_tree() test.
6  */
7 #include "tst_test.h"
8 #include "lapi/fsmount.h"
9 
10 #define MNTPOINT	"mntpoint"
11 #define OT_MNTPOINT	"ot_mntpoint"
12 
13 #define TCASE_ENTRY(_flags)	{.name = "Flag " #_flags, .flags = _flags}
14 
15 static struct tcase {
16 	char *name;
17 	unsigned int flags;
18 } tcases[] = {
19 	TCASE_ENTRY(OPEN_TREE_CLONE),
20 	TCASE_ENTRY(OPEN_TREE_CLOEXEC)
21 };
22 
23 static int dir_created;
24 
cleanup(void)25 static void cleanup(void)
26 {
27 	if (dir_created)
28 		SAFE_RMDIR(OT_MNTPOINT);
29 }
30 
setup(void)31 static void setup(void)
32 {
33 	fsopen_supported_by_kernel();
34 	SAFE_MKDIR(OT_MNTPOINT, 0777);
35 	dir_created = 1;
36 }
37 
run(unsigned int n)38 static void run(unsigned int n)
39 {
40 	struct tcase *tc = &tcases[n];
41 	int otfd;
42 
43 	TEST(otfd = open_tree(AT_FDCWD, MNTPOINT, tc->flags | OPEN_TREE_CLONE));
44 	if (otfd == -1) {
45 		tst_res(TFAIL | TTERRNO, "open_tree() failed");
46 		return;
47 	}
48 
49 	TEST(move_mount(otfd, "", AT_FDCWD, OT_MNTPOINT,
50 			MOVE_MOUNT_F_EMPTY_PATH));
51 	SAFE_CLOSE(otfd);
52 
53 	if (TST_RET == -1) {
54 		tst_res(TFAIL | TTERRNO, "move_mount() failed");
55 		return;
56 	}
57 
58 	if (tst_is_mounted_at_tmpdir(OT_MNTPOINT)) {
59 		SAFE_UMOUNT(OT_MNTPOINT);
60 		tst_res(TPASS, "%s: open_tree() passed", tc->name);
61 	}
62 }
63 
64 static struct tst_test test = {
65 	.tcnt = ARRAY_SIZE(tcases),
66 	.test = run,
67 	.setup = setup,
68 	.cleanup = cleanup,
69 	.needs_root = 1,
70 	.mount_device = 1,
71 	.mntpoint = MNTPOINT,
72 	.all_filesystems = 1,
73 	.skip_filesystems = (const char *const []){"fuse", NULL},
74 };
75