1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) 2020 Viresh Kumar <[email protected]>
4 *
5 * Basic fsconfig() test which tries to configure and mount the filesystem as
6 * well.
7 */
8 #include "tst_test.h"
9 #include "lapi/fsmount.h"
10
11 #define MNTPOINT "mntpoint"
12
13 static int fd;
14
cleanup(void)15 static void cleanup(void)
16 {
17 if (fd != -1)
18 SAFE_CLOSE(fd);
19 }
20
run(void)21 static void run(void)
22 {
23 int fsmfd;
24
25 TEST(fd = fsopen(tst_device->fs_type, 0));
26 if (fd == -1)
27 tst_brk(TBROK | TTERRNO, "fsopen() failed");
28
29 TEST(fsconfig(fd, FSCONFIG_SET_FLAG, "rw", NULL, 0));
30 if (TST_RET == -1)
31 tst_brk(TFAIL | TTERRNO, "fsconfig(FSCONFIG_SET_FLAG) failed");
32
33 TEST(fsconfig(fd, FSCONFIG_SET_STRING, "source", tst_device->dev, 0));
34 if (TST_RET == -1)
35 tst_brk(TFAIL | TTERRNO, "fsconfig(FSCONFIG_SET_STRING) failed");
36
37 TEST(fsconfig(fd, FSCONFIG_SET_PATH, "sync", tst_device->dev, 0));
38 if (TST_RET == -1) {
39 if (TST_ERR == EOPNOTSUPP)
40 tst_res(TCONF, "fsconfig(FSCONFIG_SET_PATH) not supported");
41 else
42 tst_brk(TFAIL | TTERRNO, "fsconfig(FSCONFIG_SET_PATH) failed");
43 }
44
45 TEST(fsconfig(fd, FSCONFIG_SET_PATH_EMPTY, "sync", tst_device->dev, 0));
46 if (TST_RET == -1) {
47 if (TST_ERR == EOPNOTSUPP)
48 tst_res(TCONF, "fsconfig(FSCONFIG_SET_PATH_EMPTY) not supported");
49 else
50 tst_brk(TFAIL | TTERRNO, "fsconfig(FSCONFIG_SET_PATH_EMPTY) failed");
51 }
52
53 TEST(fsconfig(fd, FSCONFIG_SET_FD, "sync", NULL, 0));
54 if (TST_RET == -1) {
55 if (TST_ERR == EOPNOTSUPP)
56 tst_res(TCONF, "fsconfig(FSCONFIG_SET_FD) not supported");
57 else
58 tst_brk(TFAIL | TTERRNO, "fsconfig(FSCONFIG_SET_FD) failed");
59 }
60
61 TEST(fsconfig(fd, FSCONFIG_CMD_CREATE, NULL, NULL, 0));
62 if (TST_RET == -1)
63 tst_brk(TFAIL | TTERRNO, "fsconfig(FSCONFIG_CMD_CREATE) failed");
64
65 TEST(fsmfd = fsmount(fd, 0, 0));
66 if (fsmfd == -1)
67 tst_brk(TBROK | TTERRNO, "fsmount() failed");
68
69 TEST(move_mount(fsmfd, "", AT_FDCWD, MNTPOINT,
70 MOVE_MOUNT_F_EMPTY_PATH));
71 SAFE_CLOSE(fsmfd);
72
73 if (TST_RET == -1)
74 tst_brk(TBROK | TTERRNO, "move_mount() failed");
75
76 if (tst_is_mounted_at_tmpdir(MNTPOINT)) {
77 SAFE_UMOUNT(MNTPOINT);
78 tst_res(TPASS, "fsconfig() passed");
79 }
80
81 SAFE_CLOSE(fd);
82 }
83
84 static struct tst_test test = {
85 .test_all = run,
86 .setup = fsopen_supported_by_kernel,
87 .cleanup = cleanup,
88 .needs_root = 1,
89 .format_device = 1,
90 .mntpoint = MNTPOINT,
91 .all_filesystems = 1,
92 .skip_filesystems = (const char *const []){"fuse", NULL},
93 };
94