Skip to content

Commit ef3900f

Browse files
committed
feat: Dump with CPU template
Previously we needed to provide a custom CPU template path indirectly via config file. Since we went through the trouble of enabling it to dump without config file, allows users to specify a CPU template path directly without config file when dumping. Signed-off-by: Takahiro Itazuri <[email protected]>
1 parent 67435f8 commit ef3900f

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

docs/cpu_templates/cpu-template-helper.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ format.
1818
```
1919
cpu-template-helper template dump \
2020
--output <cpu-config> \
21+
[--template <cpu-template>] \
2122
[--config <firecracker-config>]
2223
```
2324

@@ -70,7 +71,7 @@ This command verifies that the given custom CPU template is applied correctly.
7071

7172
```
7273
cpu-template-helper template verify \
73-
--template <cpu-template>
74+
--template <cpu-template> \
7475
[--config <firecracker-config>]
7576
```
7677

@@ -98,6 +99,7 @@ information that could affect the validity of custom CPU templates.
9899
```
99100
cpu-template-helper fingerprint dump \
100101
--output <output-path> \
102+
[--template <cpu-template>] \
101103
[--config <firecracker-config>]
102104
```
103105

src/cpu-template-helper/src/main.rs

+26-4
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ enum TemplateOperation {
5757
/// Path of firecracker config file.
5858
#[arg(short, long, value_name = "PATH")]
5959
config: Option<PathBuf>,
60+
/// Path of CPU template to apply.
61+
#[arg(short, long, value_name = "PATH")]
62+
template: Option<PathBuf>,
6063
/// Path of output file.
6164
#[arg(short, long, value_name = "PATH", default_value = "cpu_config.json")]
6265
output: PathBuf,
@@ -88,6 +91,9 @@ enum FingerprintOperation {
8891
/// Path of firecracker config file.
8992
#[arg(short, long, value_name = "PATH")]
9093
config: Option<PathBuf>,
94+
/// Path of CPU template to apply.
95+
#[arg(short, long, value_name = "PATH")]
96+
template: Option<PathBuf>,
9197
/// Path of output file.
9298
#[arg(short, long, value_name = "PATH", default_value = "fingerprint.json")]
9399
output: PathBuf,
@@ -115,9 +121,17 @@ enum FingerprintOperation {
115121
fn run(cli: Cli) -> Result<(), HelperError> {
116122
match cli.command {
117123
Command::Template(op) => match op {
118-
TemplateOperation::Dump { config, output } => {
124+
TemplateOperation::Dump {
125+
config,
126+
template,
127+
output,
128+
} => {
119129
let config = config.map(read_to_string).transpose()?;
120-
let (vmm, _) = utils::build_microvm_from_config(config, None)?;
130+
let template = template
131+
.as_ref()
132+
.map(utils::load_cpu_template)
133+
.transpose()?;
134+
let (vmm, _) = utils::build_microvm_from_config(config, template)?;
121135

122136
let cpu_config = template::dump::dump(vmm)?;
123137

@@ -157,9 +171,17 @@ fn run(cli: Cli) -> Result<(), HelperError> {
157171
}
158172
},
159173
Command::Fingerprint(op) => match op {
160-
FingerprintOperation::Dump { config, output } => {
174+
FingerprintOperation::Dump {
175+
config,
176+
template,
177+
output,
178+
} => {
161179
let config = config.map(read_to_string).transpose()?;
162-
let (vmm, _) = utils::build_microvm_from_config(config, None)?;
180+
let template = template
181+
.as_ref()
182+
.map(utils::load_cpu_template)
183+
.transpose()?;
184+
let (vmm, _) = utils::build_microvm_from_config(config, template)?;
163185

164186
let fingerprint = fingerprint::dump::dump(vmm)?;
165187

0 commit comments

Comments
 (0)