@@ -55,7 +55,9 @@ struct ContextConfig {
55
55
#[ cfg( not( feature = "tee" ) ) ]
56
56
fs_cfg : Option < FsDeviceConfig > ,
57
57
#[ cfg( feature = "tee" ) ]
58
- block_cfg : Option < BlockDeviceConfig > ,
58
+ root_block_cfg : Option < BlockDeviceConfig > ,
59
+ #[ cfg( feature = "tee" ) ]
60
+ data_block_cfg : Option < BlockDeviceConfig > ,
59
61
port_map : Option < HashMap < u16 , u16 > > ,
60
62
#[ cfg( feature = "tee" ) ]
61
63
tee_config_file : Option < PathBuf > ,
@@ -128,13 +130,23 @@ impl ContextConfig {
128
130
}
129
131
130
132
#[ cfg( feature = "tee" ) ]
131
- fn set_block_cfg ( & mut self , block_cfg : BlockDeviceConfig ) {
132
- self . block_cfg = Some ( block_cfg) ;
133
+ fn set_root_block_cfg ( & mut self , block_cfg : BlockDeviceConfig ) {
134
+ self . root_block_cfg = Some ( block_cfg) ;
135
+ }
136
+
137
+ #[ cfg( feature = "tee" ) ]
138
+ fn get_root_block_cfg ( & self ) -> Option < BlockDeviceConfig > {
139
+ self . root_block_cfg . clone ( )
140
+ }
141
+
142
+ #[ cfg( feature = "tee" ) ]
143
+ fn set_data_block_cfg ( & mut self , block_cfg : BlockDeviceConfig ) {
144
+ self . data_block_cfg = Some ( block_cfg) ;
133
145
}
134
146
135
147
#[ cfg( feature = "tee" ) ]
136
- fn get_block_cfg ( & self ) -> Option < BlockDeviceConfig > {
137
- self . block_cfg . clone ( )
148
+ fn get_data_block_cfg ( & self ) -> Option < BlockDeviceConfig > {
149
+ self . data_block_cfg . clone ( )
138
150
}
139
151
140
152
fn set_port_map ( & mut self , port_map : HashMap < u16 , u16 > ) {
@@ -397,7 +409,37 @@ pub unsafe extern "C" fn krun_set_root_disk(ctx_id: u32, c_disk_path: *const c_c
397
409
is_disk_read_only : false ,
398
410
is_disk_root : true ,
399
411
} ;
400
- cfg. set_block_cfg ( block_device_config) ;
412
+ cfg. set_root_block_cfg ( block_device_config) ;
413
+ }
414
+ Entry :: Vacant ( _) => return -libc:: ENOENT ,
415
+ }
416
+
417
+ KRUN_SUCCESS
418
+ }
419
+
420
+ #[ allow( clippy:: missing_safety_doc) ]
421
+ #[ no_mangle]
422
+ #[ cfg( feature = "tee" ) ]
423
+ pub unsafe extern "C" fn krun_set_data_disk ( ctx_id : u32 , c_disk_path : * const c_char ) -> i32 {
424
+ let disk_path = match CStr :: from_ptr ( c_disk_path) . to_str ( ) {
425
+ Ok ( disk) => disk,
426
+ Err ( _) => return -libc:: EINVAL ,
427
+ } ;
428
+
429
+ //let fs_id = "/dev/root".to_string();
430
+ //let shared_dir = root_path.to_string();
431
+
432
+ match CTX_MAP . lock ( ) . unwrap ( ) . entry ( ctx_id) {
433
+ Entry :: Occupied ( mut ctx_cfg) => {
434
+ let cfg = ctx_cfg. get_mut ( ) ;
435
+ let block_device_config = BlockDeviceConfig {
436
+ block_id : "data" . to_string ( ) ,
437
+ cache_type : CacheType :: Writeback ,
438
+ disk_image_path : disk_path. to_string ( ) ,
439
+ is_disk_read_only : false ,
440
+ is_disk_root : false ,
441
+ } ;
442
+ cfg. set_data_block_cfg ( block_device_config) ;
401
443
}
402
444
Entry :: Vacant ( _) => return -libc:: ENOENT ,
403
445
}
@@ -660,8 +702,16 @@ pub extern "C" fn krun_start_enter(ctx_id: u32) -> i32 {
660
702
}
661
703
662
704
#[ cfg( feature = "tee" ) ]
663
- if let Some ( block_cfg) = ctx_cfg. get_block_cfg ( ) {
664
- if ctx_cfg. vmr . set_block_device ( block_cfg) . is_err ( ) {
705
+ if let Some ( block_cfg) = ctx_cfg. get_root_block_cfg ( ) {
706
+ if ctx_cfg. vmr . add_block_device ( block_cfg) . is_err ( ) {
707
+ error ! ( "Error configuring virtio-blk" ) ;
708
+ return -libc:: EINVAL ;
709
+ }
710
+ }
711
+
712
+ #[ cfg( feature = "tee" ) ]
713
+ if let Some ( block_cfg) = ctx_cfg. get_data_block_cfg ( ) {
714
+ if ctx_cfg. vmr . add_block_device ( block_cfg) . is_err ( ) {
665
715
error ! ( "Error configuring virtio-blk" ) ;
666
716
return -libc:: EINVAL ;
667
717
}
0 commit comments