• 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 move_mount() test.
6  */
7 #include "tst_test.h"
8 #include "lapi/fsmount.h"
9 
10 #define MNTPOINT	"mntpoint"
11 
12 #define TCASE_ENTRY(_flags)	{.name = "Flag " #_flags, .flags = _flags}
13 
14 static struct tcase {
15 	char *name;
16 	unsigned int flags;
17 } tcases[] = {
18 	TCASE_ENTRY(MOVE_MOUNT_F_SYMLINKS),
19 	TCASE_ENTRY(MOVE_MOUNT_F_AUTOMOUNTS),
20 	TCASE_ENTRY(MOVE_MOUNT_F_EMPTY_PATH),
21 	TCASE_ENTRY(MOVE_MOUNT_T_SYMLINKS),
22 	TCASE_ENTRY(MOVE_MOUNT_T_AUTOMOUNTS),
23 	TCASE_ENTRY(MOVE_MOUNT_T_EMPTY_PATH),
24 };
25 
run(unsigned int n)26 static void run(unsigned int n)
27 {
28 	struct tcase *tc = &tcases[n];
29 	int fsmfd, fd;
30 
31 	TEST(fd = fsopen(tst_device->fs_type, 0));
32 	if (fd == -1) {
33 		tst_res(TFAIL | TTERRNO, "fsopen() failed");
34 		return;
35 	}
36 
37 	TEST(fsconfig(fd, FSCONFIG_SET_STRING, "source", tst_device->dev, 0));
38 	if (TST_RET == -1) {
39 		SAFE_CLOSE(fd);
40 		tst_res(TFAIL | TTERRNO, "fsconfig(FSCONFIG_SET_STRING) failed");
41 		return;
42 	}
43 
44 	TEST(fsconfig(fd, FSCONFIG_CMD_CREATE, NULL, NULL, 0));
45 	if (TST_RET == -1) {
46 		SAFE_CLOSE(fd);
47 		tst_res(TFAIL | TTERRNO, "fsconfig(FSCONFIG_CMD_CREATE) failed");
48 		return;
49 	}
50 
51 	TEST(fsmfd = fsmount(fd, 0, 0));
52 	SAFE_CLOSE(fd);
53 
54 	if (fsmfd == -1) {
55 		tst_res(TFAIL | TTERRNO, "fsmount() failed");
56 		return;
57 	}
58 
59 	TEST(move_mount(fsmfd, "", AT_FDCWD, MNTPOINT,
60 			tc->flags | MOVE_MOUNT_F_EMPTY_PATH));
61 	SAFE_CLOSE(fsmfd);
62 
63 	if (TST_RET == -1) {
64 		tst_res(TFAIL | TTERRNO, "move_mount() failed");
65 		return;
66 	}
67 
68 	if (tst_is_mounted_at_tmpdir(MNTPOINT)) {
69 		SAFE_UMOUNT(MNTPOINT);
70 		tst_res(TPASS, "%s: move_mount() passed", tc->name);
71 	}
72 }
73 
74 static struct tst_test test = {
75 	.tcnt = ARRAY_SIZE(tcases),
76 	.test = run,
77 	.setup = fsopen_supported_by_kernel,
78 	.needs_root = 1,
79 	.format_device = 1,
80 	.mntpoint = MNTPOINT,
81 	.all_filesystems = 1,
82 	.skip_filesystems = (const char *const []){"fuse", NULL},
83 };
84