@@ -8,7 +8,10 @@ use std::sync::Arc;
88use futures:: lock:: Mutex ;
99use futures:: FutureExt ;
1010use tokio:: io:: AsyncBufReadExt ;
11- use tokio:: { io, process, spawn} ;
11+ use tokio:: {
12+ io, process, spawn,
13+ time:: { sleep, Duration } ,
14+ } ;
1215
1316use ya_client_model:: activity:: exe_script_command:: VolumeMount ;
1417use ya_runtime_sdk:: runtime_api:: server;
@@ -105,27 +108,43 @@ pub async fn start_vmrt(
105108 "virtserialport,chardev=manager_cdev,name=manager_port" ,
106109 ] ;
107110
108- let rootfs_devices: Vec < ( String , String ) > = deployment
109- . task_packages
110- . iter ( )
111- . enumerate ( )
112- . map ( |( i, path) | {
113- let drive = format ! (
114- "file={},cache=unsafe,readonly=on,format=raw,id=rootfs-{},if=none" ,
115- path. display( ) ,
116- i
117- ) ;
118- let device = format ! ( "virtio-blk-pci,drive=rootfs-{},serial=rootfs-{}" , i, i) ;
119- ( drive, device)
120- } )
121- . collect ( ) ;
122-
123- for ( drive, device) in rootfs_devices. iter ( ) {
124- args. push ( "-drive" ) ;
125- args. push ( drive) ;
126- args. push ( "-device" ) ;
127- args. push ( device) ;
111+ let mut additional_args = Vec :: new ( ) ;
112+ if cfg ! ( feature = "virtiofs" ) {
113+ // Reading the VIRTIOFS_SOCK_PATH environment variable isn't a robust or extensible solution.
114+ // A better approach would be to update the deployment logic to retrieve this information
115+ // from the image parameters. This would allow the image creator to specify whether a host
116+ // user virtiofs drive should be used, and if so, ensure the drive is set up and mounted
117+ // on the host before attaching it to the guest VM.
118+ let socket_path = std:: env:: var ( "VIRTIOFS_SOCK_PATH" )
119+ . expect ( "Environment variable VIRTIOFS_SOCK_PATH is not set" ) ;
120+ additional_args. extend ( [
121+ "-chardev" . to_string ( ) ,
122+ format ! ( "socket,id=char-0,path={socket_path}" ) ,
123+ "-device" . to_string ( ) ,
124+ format ! ( "vhost-user-fs-pci,queue-size=1024,chardev=char-0,tag=rootfs-0" ) ,
125+ ] ) ;
126+ } else {
127+ for ( i, path) in deployment. task_packages . iter ( ) . enumerate ( ) {
128+ additional_args. extend ( [
129+ "-drive" . to_string ( ) ,
130+ format ! (
131+ "file={},cache=unsafe,readonly=on,format=raw,id=rootfs-{i},if=none" ,
132+ path. display( )
133+ ) ,
134+ "-device" . to_string ( ) ,
135+ format ! ( "virtio-blk-pci,drive=rootfs-{i},serial=rootfs-{i}" ) ,
136+ ] ) ;
137+ }
138+ }
139+ if cfg ! ( feature = "numa" ) {
140+ additional_args. extend ( [
141+ "-object" . to_string ( ) ,
142+ format ! ( "memory-backend-file,id=mem,size={memory_size},mem-path=/dev/shm,share=on" ) ,
143+ "-numa" . to_string ( ) ,
144+ "node,memdev=mem" . to_string ( ) ,
145+ ] ) ;
128146 }
147+ args. extend ( additional_args. iter ( ) . map ( String :: as_str) ) ;
129148
130149 cmd. args ( args) ;
131150
0 commit comments