@@ -267,6 +267,54 @@ criu_check_mem_track (char *work_path, libcrun_error_t *err)
267
267
268
268
# endif
269
269
270
+ static int
271
+ register_masked_paths_mounts (runtime_spec_schema_config_schema * def , libcrun_container_t * container ,
272
+ struct libcriu_wrapper_s * libcriu_wrapper , bool is_restore , libcrun_error_t * err )
273
+ {
274
+ cleanup_free char * empty_dir_path = NULL ;
275
+ bool shared_dir_registered = false;
276
+ size_t i ;
277
+ int ret ;
278
+
279
+ for (i = 0 ; i < def -> linux -> masked_paths_len ; i ++ )
280
+ {
281
+ struct stat statbuf ;
282
+ ret = stat (def -> linux -> masked_paths [i ], & statbuf );
283
+ if (ret != 0 )
284
+ continue ;
285
+
286
+ if (S_ISDIR (statbuf .st_mode ))
287
+ {
288
+ if (! shared_dir_registered )
289
+ {
290
+ ret = get_shared_empty_directory_path (& empty_dir_path ,
291
+ (container -> context ? container -> context -> state_root : NULL ), err );
292
+ if (UNLIKELY (ret < 0 ))
293
+ return ret ;
294
+
295
+ ret = libcriu_wrapper -> criu_add_ext_mount (empty_dir_path , empty_dir_path );
296
+ if (UNLIKELY (ret < 0 ))
297
+ return crun_make_error (err , - ret , "CRIU: failed adding external mount for shared empty directory `%s`" , empty_dir_path );
298
+
299
+ shared_dir_registered = true;
300
+ }
301
+
302
+ ret = libcriu_wrapper -> criu_add_ext_mount (def -> linux -> masked_paths [i ], empty_dir_path );
303
+ if (UNLIKELY (ret < 0 ))
304
+ return crun_make_error (err , - ret , "CRIU: failed adding external mount for masked directory `%s`" , def -> linux -> masked_paths [i ]);
305
+ }
306
+ else if (S_ISREG (statbuf .st_mode ))
307
+ {
308
+ const char * bind_target = is_restore ? "/dev/null" : def -> linux -> masked_paths [i ];
309
+ ret = libcriu_wrapper -> criu_add_ext_mount (def -> linux -> masked_paths [i ], bind_target );
310
+ if (UNLIKELY (ret < 0 ))
311
+ return crun_make_error (err , - ret , "CRIU: failed adding external mount to `%s`" , bind_target );
312
+ }
313
+ }
314
+
315
+ return 0 ;
316
+ }
317
+
270
318
static int
271
319
restore_cgroup_v1_mount (runtime_spec_schema_config_schema * def , libcrun_error_t * err )
272
320
{
@@ -609,17 +657,9 @@ libcrun_container_checkpoint_linux_criu (libcrun_container_status_t *status, lib
609
657
}
610
658
}
611
659
612
- for (i = 0 ; i < def -> linux -> masked_paths_len ; i ++ )
613
- {
614
- struct stat statbuf ;
615
- ret = stat (def -> linux -> masked_paths [i ], & statbuf );
616
- if (ret == 0 && S_ISREG (statbuf .st_mode ))
617
- {
618
- ret = libcriu_wrapper -> criu_add_ext_mount (def -> linux -> masked_paths [i ], def -> linux -> masked_paths [i ]);
619
- if (UNLIKELY (ret < 0 ))
620
- return crun_make_error (err , - ret , "CRIU: failed adding external mount to `%s`" , def -> linux -> masked_paths [i ]);
621
- }
622
- }
660
+ ret = register_masked_paths_mounts (def , container , libcriu_wrapper , false, err );
661
+ if (UNLIKELY (ret < 0 ))
662
+ return ret ;
623
663
624
664
/* CRIU tries to checkpoint and restore all namespaces. However,
625
665
* namespaces could be shared between containers in a pod.
@@ -947,17 +987,9 @@ libcrun_container_restore_linux_criu (libcrun_container_status_t *status, libcru
947
987
}
948
988
}
949
989
950
- for (i = 0 ; i < def -> linux -> masked_paths_len ; i ++ )
951
- {
952
- struct stat statbuf ;
953
- ret = stat (def -> linux -> masked_paths [i ], & statbuf );
954
- if (ret == 0 && S_ISREG (statbuf .st_mode ))
955
- {
956
- ret = libcriu_wrapper -> criu_add_ext_mount (def -> linux -> masked_paths [i ], "/dev/null" );
957
- if (UNLIKELY (ret < 0 ))
958
- return crun_make_error (err , - ret , "CRIU: failed adding external mount to `%s`" , "/dev/null" );
959
- }
960
- }
990
+ ret = register_masked_paths_mounts (def , container , libcriu_wrapper , true, err );
991
+ if (UNLIKELY (ret < 0 ))
992
+ return ret ;
961
993
962
994
/* do realpath on root */
963
995
bundle_cleanup = realpath (status -> bundle , NULL );
0 commit comments