@@ -213,7 +213,26 @@ static int remove_path(const char *const path)
213213 return err ;
214214}
215215
216- static void prepare_layout (struct __test_metadata * const _metadata )
216+ struct mnt_opt {
217+ const char * const source ;
218+ const char * const type ;
219+ const unsigned long flags ;
220+ const char * const data ;
221+ };
222+
223+ const struct mnt_opt mnt_tmp = {
224+ .type = "tmpfs" ,
225+ .data = "size=4m,mode=700" ,
226+ };
227+
228+ static int mount_opt (const struct mnt_opt * const mnt , const char * const target )
229+ {
230+ return mount (mnt -> source ?: mnt -> type , target , mnt -> type , mnt -> flags ,
231+ mnt -> data );
232+ }
233+
234+ static void prepare_layout_opt (struct __test_metadata * const _metadata ,
235+ const struct mnt_opt * const mnt )
217236{
218237 disable_caps (_metadata );
219238 umask (0077 );
@@ -225,11 +244,27 @@ static void prepare_layout(struct __test_metadata *const _metadata)
225244 */
226245 set_cap (_metadata , CAP_SYS_ADMIN );
227246 ASSERT_EQ (0 , unshare (CLONE_NEWNS ));
228- ASSERT_EQ (0 , mount ("tmp" , TMP_DIR , "tmpfs" , 0 , "size=4m,mode=700" ));
247+ ASSERT_EQ (0 , mount_opt (mnt , TMP_DIR ))
248+ {
249+ TH_LOG ("Failed to mount the %s filesystem: %s" , mnt -> type ,
250+ strerror (errno ));
251+ /*
252+ * FIXTURE_TEARDOWN() is not called when FIXTURE_SETUP()
253+ * failed, so we need to explicitly do a minimal cleanup to
254+ * avoid cascading errors with other tests that don't depend on
255+ * the same filesystem.
256+ */
257+ remove_path (TMP_DIR );
258+ }
229259 ASSERT_EQ (0 , mount (NULL , TMP_DIR , NULL , MS_PRIVATE | MS_REC , NULL ));
230260 clear_cap (_metadata , CAP_SYS_ADMIN );
231261}
232262
263+ static void prepare_layout (struct __test_metadata * const _metadata )
264+ {
265+ prepare_layout_opt (_metadata , & mnt_tmp );
266+ }
267+
233268static void cleanup_layout (struct __test_metadata * const _metadata )
234269{
235270 set_cap (_metadata , CAP_SYS_ADMIN );
@@ -269,7 +304,7 @@ static void create_layout1(struct __test_metadata *const _metadata)
269304 create_file (_metadata , file1_s3d1 );
270305 create_directory (_metadata , dir_s3d2 );
271306 set_cap (_metadata , CAP_SYS_ADMIN );
272- ASSERT_EQ (0 , mount ( "tmp" , dir_s3d2 , "tmpfs" , 0 , "size=4m,mode=700" ));
307+ ASSERT_EQ (0 , mount_opt ( & mnt_tmp , dir_s3d2 ));
273308 clear_cap (_metadata , CAP_SYS_ADMIN );
274309
275310 ASSERT_EQ (0 , mkdir (dir_s3d3 , 0700 ));
@@ -4068,7 +4103,7 @@ FIXTURE_SETUP(layout2_overlay)
40684103 create_directory (_metadata , LOWER_BASE );
40694104 set_cap (_metadata , CAP_SYS_ADMIN );
40704105 /* Creates tmpfs mount points to get deterministic overlayfs. */
4071- ASSERT_EQ (0 , mount ( "tmp" , LOWER_BASE , "tmpfs" , 0 , "size=4m,mode=700" ));
4106+ ASSERT_EQ (0 , mount_opt ( & mnt_tmp , LOWER_BASE ));
40724107 clear_cap (_metadata , CAP_SYS_ADMIN );
40734108 create_file (_metadata , lower_fl1 );
40744109 create_file (_metadata , lower_dl1_fl2 );
@@ -4078,7 +4113,7 @@ FIXTURE_SETUP(layout2_overlay)
40784113
40794114 create_directory (_metadata , UPPER_BASE );
40804115 set_cap (_metadata , CAP_SYS_ADMIN );
4081- ASSERT_EQ (0 , mount ( "tmp" , UPPER_BASE , "tmpfs" , 0 , "size=4m,mode=700" ));
4116+ ASSERT_EQ (0 , mount_opt ( & mnt_tmp , UPPER_BASE ));
40824117 clear_cap (_metadata , CAP_SYS_ADMIN );
40834118 create_file (_metadata , upper_fu1 );
40844119 create_file (_metadata , upper_du1_fu2 );
0 commit comments