@@ -160,7 +160,7 @@ impl<VirtBackend: VirtualizationBackend> UhyveVm<VirtBackend> {
160160 error ! ( "Hermit image doesn't contain configuration file" ) ;
161161 HypervisorError :: InvalidKernelPath ( kernel_path. clone ( ) )
162162 } ) ?;
163- let mut config = if let HermitImageThinTree :: File ( f) = config {
163+ let config = if let HermitImageThinTree :: File ( f) = config {
164164 hermit_image_reader:: config:: parse ( f) . map_err ( |e| {
165165 error ! ( "Hermit image configuration is invalid: {}" , e) ;
166166 HypervisorError :: ImageConfigParserError ( e)
@@ -170,65 +170,68 @@ impl<VirtBackend: VirtualizationBackend> UhyveVm<VirtBackend> {
170170 return Err ( HypervisorError :: InvalidKernelPath ( kernel_path. clone ( ) ) ) ;
171171 } ;
172172
173- // handle image configuration
173+ match config {
174+ hermit_image_reader:: config:: Config :: V1 { mut input, requirements : _, kernel, mount_point } => {
175+ // handle image configuration
176+
177+ // .input
178+ if params. kernel_args . is_empty ( ) {
179+ params. kernel_args . append ( & mut input. kernel_args ) ;
180+ if !input. app_args . is_empty ( ) {
181+ params. kernel_args . push ( "--" . to_string ( ) ) ;
182+ params. kernel_args . append ( & mut input. app_args ) ;
183+ }
184+ }
174185
175- // .input
176- if params. kernel_args . is_empty ( ) {
177- params. kernel_args . append ( & mut config. input . kernel_args ) ;
178- if !config. input . app_args . is_empty ( ) {
179- params. kernel_args . push ( "--" . to_string ( ) ) ;
180- params. kernel_args . append ( & mut config. input . app_args ) ;
181- }
182- }
186+ // don't pass privileged env-var commands through
187+ input. env_vars . retain ( |i| i. contains ( '=' ) ) ;
188+
189+ if let EnvVars :: Set ( env) = & mut params. env {
190+ if let Ok ( EnvVars :: Set ( prev_env_vars) ) =
191+ EnvVars :: try_from ( & input. env_vars [ ..] )
192+ {
193+ // env vars from params take precedence
194+ let new_env_vars = core:: mem:: take ( env) ;
195+ * env = prev_env_vars. into_iter ( ) . chain ( new_env_vars) . collect ( ) ;
196+ } else {
197+ warn ! ( "Unable to parse env vars from Hermit image configuration" ) ;
198+ }
199+ } else if !input. env_vars . is_empty ( ) {
200+ warn ! ( "Ignoring Hermit image env vars due to `-e host`" ) ;
201+ }
183202
184- // don't pass privileged env-var commands through
185- config. input . env_vars . retain ( |i| i. contains ( '=' ) ) ;
186-
187- if let EnvVars :: Set ( env) = & mut params. env {
188- if let Ok ( EnvVars :: Set ( prev_env_vars) ) =
189- EnvVars :: try_from ( & config. input . env_vars [ ..] )
190- {
191- // env vars from params take precedence
192- let new_env_vars = core:: mem:: take ( env) ;
193- * env = prev_env_vars. into_iter ( ) . chain ( new_env_vars) . collect ( ) ;
194- } else {
195- warn ! ( "Unable to parse env vars from Hermit image configuration" ) ;
203+ // .requirements
204+ // TODO: implement this part
205+
206+ // Limitation of current implementation:
207+ // because we need to put the image path into the file map,
208+ // it needs to be valid UTF-8
209+ let image_path_str = kernel_path
210+ . to_str ( )
211+ . expect ( "path to image must be valid UTF-8" ) ;
212+
213+ // .mount_point
214+ params
215+ . file_mapping
216+ . insert ( 0 , format ! ( "{}::{}" , image_path_str, mount_point) ) ;
217+
218+ // .kernel
219+ if let HermitImageThinTree :: File ( f) = image_tree
220+ . get ( )
221+ . resolve ( ( * kernel) . into ( ) )
222+ . ok_or_else ( || {
223+ HypervisorError :: InvalidKernelPath ( PathBuf :: from ( format ! (
224+ "{}:{}" ,
225+ image_path_str, & kernel
226+ ) ) )
227+ } ) ? {
228+ f. to_vec ( )
229+ } else {
230+ return Err ( HypervisorError :: InvalidKernelPath ( PathBuf :: from (
231+ format ! ( "{}:{}" , image_path_str, & kernel) ,
232+ ) ) ) ;
233+ }
196234 }
197- } else if !config. input . env_vars . is_empty ( ) {
198- warn ! ( "Ignoring Hermit image env vars due to `-e host`" ) ;
199- }
200-
201- // .requirements
202- // TODO: implement this part
203-
204- // Limitation of current implementation:
205- // because we need to put the image path into the file map,
206- // it needs to be valid UTF-8
207- let image_path_str = kernel_path
208- . to_str ( )
209- . expect ( "path to image must be valid UTF-8" ) ;
210-
211- // .mount_point
212- params
213- . file_mapping
214- . insert ( 0 , format ! ( "{}::{}" , image_path_str, config. mount_point) ) ;
215-
216- // .kernel
217- if let HermitImageThinTree :: File ( f) = image_tree
218- . get ( )
219- . resolve ( ( * config. kernel ) . into ( ) )
220- . ok_or_else ( || {
221- HypervisorError :: InvalidKernelPath ( PathBuf :: from ( format ! (
222- "{}:{}" ,
223- image_path_str, & config. kernel
224- ) ) )
225- } ) ? {
226- f. to_vec ( )
227- } else {
228- return Err ( HypervisorError :: InvalidKernelPath ( PathBuf :: from ( format ! (
229- "{}:{}" ,
230- image_path_str, & config. kernel
231- ) ) ) ) ;
232235 }
233236 }
234237 } ;
0 commit comments