• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
4  */
5 
6 /*\
7  * [Description]
8  *
9  * This test verifies that statmount() is correctly reading propagation from
10  * what mount in current namespace using STATMOUNT_PROPAGATE_FROM.
11  *
12  * [Algorithm]
13  *
14  * - create a mount point
15  * - propagate a mounted folder inside the mount point
16  * - run statmount() on the mount point using STATMOUNT_PROPAGATE_FROM
17  * - read results and check propagated_from parameter contains the propagated
18  *   folder ID
19  */
20 
21 #define _GNU_SOURCE
22 
23 #include "statmount.h"
24 #include "lapi/stat.h"
25 #include "lapi/sched.h"
26 
27 #define MNTPOINT "mntpoint"
28 #define DIR_A MNTPOINT "/LTP_DIR_A"
29 #define DIR_C_SUBFOLDER "/LTP_DIR_A/propagated"
30 #define DIR_C (MNTPOINT DIR_C_SUBFOLDER)
31 #define DIR_B MNTPOINT "/LTP_DIR_B"
32 #define DIR_D MNTPOINT "/LTP_DIR_B/propagated"
33 
34 static uint64_t peer_group_id;
35 static uint64_t dird_id;
36 static struct statmount *st_mount;
37 
run(void)38 static void run(void)
39 {
40 	memset(st_mount, 0, sizeof(struct statmount));
41 
42 	TST_EXP_PASS(statmount(dird_id, STATMOUNT_PROPAGATE_FROM, st_mount,
43 		sizeof(struct statmount), 0));
44 
45 	if (!TST_PASS)
46 		return;
47 
48 	TST_EXP_EQ_LI(st_mount->mask, STATMOUNT_PROPAGATE_FROM);
49 	TST_EXP_EQ_LI(st_mount->size, sizeof(struct statmount));
50 	TST_EXP_EQ_LI(st_mount->propagate_from, peer_group_id);
51 }
52 
setup(void)53 static void setup(void)
54 {
55 	struct ltp_statx sx;
56 
57 	/* create DIR_A / DIR_C structure with DIR_C mounted */
58 	SAFE_MKDIR(DIR_A, 0700);
59 	SAFE_MOUNT(DIR_A, DIR_A, "none", MS_BIND, NULL);
60 	SAFE_MOUNT("none", DIR_A, "none", MS_SHARED, NULL);
61 
62 	SAFE_MKDIR(DIR_C, 0700);
63 	SAFE_MOUNT(DIR_C, DIR_C, "none", MS_BIND, NULL);
64 	SAFE_MOUNT("none", DIR_C, "none", MS_SHARED, NULL);
65 
66 	/* DIR_A mounts into DIR_B. DIR_D is propagated */
67 	SAFE_MKDIR(DIR_B, 0700);
68 	SAFE_MOUNT(DIR_A, DIR_B, "none", MS_BIND, NULL);
69 	SAFE_MOUNT("none", DIR_B, "none", MS_SLAVE, NULL);
70 
71 	SAFE_STATX(AT_FDCWD, DIR_D, 0, STATX_MNT_ID_UNIQUE, &sx);
72 	dird_id = sx.data.stx_mnt_id;
73 
74 	peer_group_id = read_peer_group(DIR_A);
75 }
76 
cleanup(void)77 static void cleanup(void)
78 {
79 	if (tst_is_mounted(DIR_C))
80 		SAFE_UMOUNT(DIR_C);
81 
82 	if (tst_is_mounted(DIR_B))
83 		SAFE_UMOUNT(DIR_B);
84 
85 	if (tst_is_mounted(DIR_A))
86 		SAFE_UMOUNT(DIR_A);
87 }
88 
89 static struct tst_test test = {
90 	.test_all = run,
91 	.setup = setup,
92 	.cleanup = cleanup,
93 	.min_kver = "6.8",
94 	.mount_device = 1,
95 	.mntpoint = MNTPOINT,
96 	.all_filesystems = 1,
97 	.skip_filesystems = (const char *const []) {
98 		"fuse",
99 		NULL
100 	},
101 	.bufs = (struct tst_buffers []) {
102 		{&st_mount, .size = sizeof(struct statmount)},
103 		{}
104 	}
105 };
106