File tree Expand file tree Collapse file tree 3 files changed +30
-7
lines changed
Expand file tree Collapse file tree 3 files changed +30
-7
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ use nix::libc::dev_t;
1212use nix:: sys:: stat:: minor;
1313
1414use crate :: cmdline:: CmdlineOptions ;
15- use crate :: { read_file, Result } ;
15+ use crate :: { read_file, wait_for_device , Result } ;
1616
1717const DM_VERSION_MAJOR : u32 = 4 ;
1818
@@ -120,8 +120,9 @@ pub fn prepare_dmverity(options: &mut CmdlineOptions) -> Result<bool> {
120120 return Ok ( false ) ;
121121 }
122122 let root_device = options. root . as_ref ( ) . ok_or ( "No root device" ) ?;
123- if !Path :: new ( & root_device) . exists ( ) {
124- return Ok ( false ) ;
123+ match options. rootfstype . as_deref ( ) {
124+ Some ( "nfs" ) | Some ( "9p" ) => return Ok ( false ) ,
125+ _ => wait_for_device ( root_device) ?,
125126 }
126127
127128 let mut data_blocks = "" ;
Original file line number Diff line number Diff line change @@ -12,6 +12,8 @@ use std::os::fd::AsFd;
1212use std:: os:: unix:: ffi:: OsStrExt ;
1313use std:: panic:: set_hook;
1414use std:: path:: Path ;
15+ use std:: thread;
16+ use std:: time;
1517
1618use cmdline:: { parse_cmdline, CmdlineOptions } ;
1719#[ cfg( feature = "dmverity" ) ]
@@ -51,6 +53,21 @@ fn read_file(filename: &str) -> std::result::Result<String, String> {
5153 read_to_string ( filename) . map_err ( |e| format ! ( "Failed to read {filename}: {e}" ) )
5254}
5355
56+ fn wait_for_device ( root_device : & str ) -> Result < ( ) > {
57+ let duration = time:: Duration :: from_millis ( 5 ) ;
58+ let path = Path :: new ( & root_device) ;
59+
60+ for _ in 0 ..1000 {
61+ if path. exists ( ) {
62+ return Ok ( ( ) ) ;
63+ }
64+
65+ thread:: sleep ( duration) ;
66+ }
67+
68+ Err ( "timout reached while waiting for the device" . into ( ) )
69+ }
70+
5471/*
5572 * Setup stdout/stderr. The kernel will create /dev/console in the
5673 * initramfs, so we can use that.
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ use log::debug;
77use nix:: mount:: { mount, MsFlags } ;
88
99use crate :: cmdline:: CmdlineOptions ;
10- use crate :: { mkdir, Result } ;
10+ use crate :: { mkdir, wait_for_device , Result } ;
1111
1212pub fn do_mount (
1313 src : Option < & str > ,
@@ -45,10 +45,15 @@ pub fn mount_apivfs(dst: &str, fstype: &str) -> Result<()> {
4545}
4646
4747pub fn mount_root ( options : & CmdlineOptions ) -> Result < ( ) > {
48- if options. root . is_none ( ) {
49- return Err ( "root= not found in /proc/cmdline" . into ( ) ) ;
48+ let root = options
49+ . root
50+ . as_ref ( )
51+ . ok_or ( "root= not found in /proc/cmdline" ) ?;
52+
53+ match options. rootfstype . as_deref ( ) {
54+ Some ( "nfs" ) | Some ( "9p" ) => ( ) ,
55+ _ => wait_for_device ( root) ?,
5056 }
51-
5257 mkdir ( "/root" ) ?;
5358
5459 debug ! (
You can’t perform that action at this time.
0 commit comments