@@ -31,6 +31,8 @@ use composefs_boot::cmdline::get_cmdline_composefs;
3131
3232use fn_error_context:: context;
3333
34+ use bootc_kernel_cmdline:: utf8:: Cmdline ;
35+
3436// mount_setattr syscall support
3537const MOUNT_ATTR_RDONLY : u64 = 0x00000001 ;
3638
@@ -74,13 +76,17 @@ fn set_mount_readonly(fd: impl AsFd) -> Result<()> {
7476 mount_setattr ( fd, libc:: AT_EMPTY_PATH , & attr)
7577}
7678
77- // Config file
79+ /// Types of mounts supported by the configuration
7880#[ derive( Clone , Copy , Debug , Deserialize ) ]
7981#[ serde( rename_all = "lowercase" ) ]
80- enum MountType {
82+ pub enum MountType {
83+ /// No mount
8184 None ,
85+ /// Bind mount
8286 Bind ,
87+ /// Overlay mount
8388 Overlay ,
89+ /// Transient mount
8490 Transient ,
8591}
8692
@@ -90,11 +96,14 @@ struct RootConfig {
9096 transient : bool ,
9197}
9298
99+ /// Configuration for mount operations
93100#[ derive( Debug , Default , Deserialize ) ]
94- struct MountConfig {
95- mount : Option < MountType > ,
101+ pub struct MountConfig {
102+ /// The type of mount to use
103+ pub mount : Option < MountType > ,
96104 #[ serde( default ) ]
97- transient : bool ,
105+ /// Whether this mount should be transient (temporary)
106+ pub transient : bool ,
98107}
99108
100109#[ derive( Deserialize , Default ) ]
@@ -138,7 +147,7 @@ pub struct Args {
138147
139148 #[ arg( long, help = "Kernel commandline args (for testing)" ) ]
140149 /// Kernel commandline args (for testing)
141- pub cmdline : Option < String > ,
150+ pub cmdline : Option < Cmdline < ' static > > ,
142151
143152 #[ arg( long, help = "Mountpoint (don't replace sysroot, for testing)" ) ]
144153 /// Mountpoint (don't replace sysroot, for testing)
@@ -265,8 +274,9 @@ pub fn mount_composefs_image(sysroot: &OwnedFd, name: &str, insecure: bool) -> R
265274 Ok ( rootfs)
266275}
267276
277+ /// Mounts a subdirectory with the specified configuration
268278#[ context( "Mounting subdirectory" ) ]
269- fn mount_subdir (
279+ pub fn mount_subdir (
270280 new_root : impl AsFd ,
271281 state : impl AsFd ,
272282 subdir : & str ,
@@ -331,12 +341,11 @@ pub fn setup_root(args: Args) -> Result<()> {
331341 let sysroot = open_dir ( CWD , & args. sysroot )
332342 . with_context ( || format ! ( "Failed to open sysroot {:?}" , args. sysroot) ) ?;
333343
334- let cmdline = match & args. cmdline {
335- Some ( cmdline) => cmdline,
336- // TODO: Deduplicate this with composefs branch karg parser
337- None => & std:: fs:: read_to_string ( "/proc/cmdline" ) ?,
338- } ;
339- let ( image, insecure) = get_cmdline_composefs :: < Sha512HashValue > ( cmdline) ?;
344+ let cmdline = args
345+ . cmdline
346+ . unwrap_or ( Cmdline :: from_proc ( ) . context ( "Failed to read cmdline" ) ?) ;
347+
348+ let ( image, insecure) = get_cmdline_composefs :: < Sha512HashValue > ( & cmdline) ?;
340349
341350 let new_root = match args. root_fs {
342351 Some ( path) => open_root_fs ( & path) . context ( "Failed to clone specified root fs" ) ?,
@@ -348,11 +357,13 @@ pub fn setup_root(args: Args) -> Result<()> {
348357
349358 set_mount_readonly ( & sysroot_clone) ?;
350359
360+ let mount_target = args. target . unwrap_or ( args. sysroot . clone ( ) ) ;
361+
351362 // Ideally we build the new root filesystem together before we mount it, but that only works on
352363 // 6.15 and later. Before 6.15 we can't mount into a floating tree, so mount it first. This
353364 // will leave an abandoned clone of the sysroot mounted under it, but that's OK for now.
354365 if cfg ! ( feature = "pre-6.15" ) {
355- mount_at_wrapper ( & new_root, CWD , & args . sysroot ) ?;
366+ mount_at_wrapper ( & new_root, CWD , & mount_target ) ?;
356367 }
357368
358369 if config. root . transient {
@@ -372,7 +383,7 @@ pub fn setup_root(args: Args) -> Result<()> {
372383 if cfg ! ( not( feature = "pre-6.15" ) ) {
373384 // Replace the /sysroot with the new composed root filesystem
374385 unmount ( & args. sysroot , UnmountFlags :: DETACH ) ?;
375- mount_at_wrapper ( & new_root, CWD , & args . sysroot ) ?;
386+ mount_at_wrapper ( & new_root, CWD , & mount_target ) ?;
376387 }
377388
378389 Ok ( ( ) )
0 commit comments