1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//! Explicit resident pause and resume.
use clap::Args;
use microsandbox::Sandbox;
use crate::ui;
//--------------------------------------------------------------------------------------------------
// Types
//--------------------------------------------------------------------------------------------------
/// Arguments for resident pause.
#[derive(Debug, Args)]
pub struct PauseArgs {
/// Optional guest writeback: auto, required, or skip. Required establishes a flushed pause.
#[arg(long)]
pub guest_flush: Option<microsandbox::snapshot::GuestFlush>,
/// Sandbox name.
pub name: String,
/// Suppress progress output.
#[arg(short, long)]
pub quiet: bool,
}
/// Resume has no writeback option: it cannot improve an already captured disk boundary.
#[derive(Debug, Args)]
pub struct ResumeArgs {
/// Sandbox name.
pub name: String,
/// Suppress progress output.
#[arg(short, long)]
pub quiet: bool,
}
//--------------------------------------------------------------------------------------------------
// Functions
//--------------------------------------------------------------------------------------------------
/// Change resident execution state through host control, without opening the guest agent.
pub async fn run(args: PauseArgs, resume: bool) -> anyhow::Result<()> {
let sandbox = Sandbox::get_for_control(&args.name).await?;
if resume {
sandbox.resume().await?;
} else if let Some(policy) = args.guest_flush {
sandbox.pause_with_guest_flush(policy).await?;
} else {
sandbox.pause().await?;
}
if !args.quiet {
ui::success(if resume { "Resumed" } else { "Paused" }, &args.name);
}
Ok(())
}