MCPcopy Create free account
hub / github.com/Dstack-TEE/dstack / start_vm

Method start_vm

vmm/src/app.rs:221–275  ·  view source on GitHub ↗
(&self, id: &str)

Source from the content-addressed store, hash-verified

219 }
220
221 pub async fn start_vm(&self, id: &str) -> Result<()> {
222 {
223 let state = self.lock();
224 if let Some(vm) = state.get(id) {
225 if vm.state.removing {
226 bail!("VM is being removed");
227 }
228 }
229 }
230 self.sync_dynamic_config(id)?;
231 let is_running = self
232 .supervisor
233 .info(id)
234 .await?
235 .is_some_and(|info| info.state.status.is_running());
236 self.set_started(id, true)?;
237 let vm_config = {
238 let mut state = self.lock();
239 let vm_state = state.get_mut(id).context("VM not found")?;
240 // Older images does not support for progress reporting
241 if vm_state.config.image.info.shared_ro {
242 vm_state.state.start(is_running);
243 } else {
244 vm_state.state.reset_na();
245 }
246 vm_state.config.clone()
247 };
248 if !is_running {
249 let work_dir = self.work_dir(id);
250 for path in [work_dir.serial_pty(), work_dir.qmp_socket()] {
251 if path.symlink_metadata().is_ok() {
252 fs::remove_file(path)?;
253 }
254 }
255 // Append current serial.log to serial.history.log before QEMU truncates it.
256 rotate_serial_log(&work_dir, self.config.cvm.serial_history_max_bytes);
257 // Add boot separator to stdout/stderr (they are opened in append mode).
258 append_boot_separator(&work_dir.stdout_file());
259 append_boot_separator(&work_dir.stderr_file());
260
261 let devices = self.try_allocate_gpus(&vm_config.manifest)?;
262 let processes = vm_config.config_qemu(&work_dir, &self.config.cvm, &devices)?;
263 for process in processes {
264 self.supervisor
265 .deploy(&process)
266 .await
267 .with_context(|| format!("Failed to start process {}", process.id))?;
268 }
269
270 let mut state = self.lock();
271 let vm_state = state.get_mut(id).context("VM not found")?;
272 vm_state.state.devices = devices;
273 }
274 Ok(())
275 }
276
277 fn set_started(&self, id: &str, started: bool) -> Result<()> {
278 let work_dir = self.work_dir(id);

Callers 3

load_vmMethod · 0.45
load_or_update_vmMethod · 0.45

Calls 15

rotate_serial_logFunction · 0.85
append_boot_separatorFunction · 0.85
sync_dynamic_configMethod · 0.80
is_runningMethod · 0.80
get_mutMethod · 0.80
reset_naMethod · 0.80
cloneMethod · 0.80
work_dirMethod · 0.80
serial_ptyMethod · 0.80
qmp_socketMethod · 0.80
stdout_fileMethod · 0.80
stderr_fileMethod · 0.80

Tested by

no test coverage detected