Skip to content

Commit 834c9ca

Browse files
committed
refactor: generify "these features are incompatible" error variants
There's be a lot more things that are incompatible going forward (mostly related to secret freedom), so instead of adding a ton of error variants for each pair of incompatible features, let's just have a single one where we can insert arbitrary features via a string argument. Signed-off-by: Patrick Roy <roypat@amazon.co.uk>
1 parent c6e17b9 commit 834c9ca

File tree

4 files changed

+15
-12
lines changed

4 files changed

+15
-12
lines changed

src/vmm/src/resources.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,9 @@ impl VmResources {
227227
self.balloon.set_device(balloon);
228228

229229
if self.machine_config.huge_pages != HugePageConfig::None {
230-
return Err(ResourcesError::BalloonDevice(BalloonConfigError::HugePages));
230+
return Err(ResourcesError::BalloonDevice(
231+
BalloonConfigError::IncompatibleWith("huge pages"),
232+
));
231233
}
232234
}
233235

@@ -269,7 +271,10 @@ impl VmResources {
269271
}
270272

271273
if self.balloon.get().is_some() && updated.huge_pages != HugePageConfig::None {
272-
return Err(MachineConfigError::BalloonAndHugePages);
274+
return Err(MachineConfigError::Incompatible(
275+
"balloon device",
276+
"huge pages",
277+
));
273278
}
274279
self.machine_config = updated;
275280

@@ -326,7 +331,7 @@ impl VmResources {
326331
}
327332

328333
if self.machine_config.huge_pages != HugePageConfig::None {
329-
return Err(BalloonConfigError::HugePages);
334+
return Err(BalloonConfigError::IncompatibleWith("huge pages"));
330335
}
331336

332337
self.balloon.set(config)
@@ -1446,7 +1451,7 @@ mod tests {
14461451
assert!(
14471452
matches!(
14481453
err,
1449-
ResourcesError::BalloonDevice(BalloonConfigError::HugePages)
1454+
ResourcesError::BalloonDevice(BalloonConfigError::IncompatibleWith("huge pages"))
14501455
),
14511456
"{:?}",
14521457
err

src/vmm/src/vmm_config/balloon.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ pub enum BalloonConfigError {
2828
CreateFailure(crate::devices::virtio::balloon::BalloonError),
2929
/// Error updating the balloon device configuration: {0}
3030
UpdateFailure(std::io::Error),
31-
/// Firecracker's huge pages support is incompatible with memory ballooning.
32-
HugePages,
31+
/// Memory ballooning is incompatible with {0}.
32+
IncompatibleWith(&'static str),
3333
}
3434

3535
/// This struct represents the strongly typed equivalent of the json body

src/vmm/src/vmm_config/machine_config.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,8 @@ pub enum MachineConfigError {
2727
/// Enabling simultaneous multithreading is not supported on aarch64.
2828
#[cfg(target_arch = "aarch64")]
2929
SmtNotSupported,
30-
/// Could not determine host kernel version when checking hugetlbfs compatibility
31-
KernelVersion,
32-
/// Firecracker's huge pages support is incompatible with memory ballooning.
33-
BalloonAndHugePages,
30+
/// '{0}' and '{1}' are mutually exclusive and cannot be used together.
31+
Incompatible(&'static str, &'static str)
3432
}
3533

3634
/// Describes the possible (huge)page configurations for a microVM's memory.

tests/integration_tests/performance/test_huge_pages.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ def test_negative_huge_pages_plus_balloon(uvm_plain):
255255
uvm_plain.basic_config(huge_pages=HugePagesConfig.HUGETLBFS_2MB)
256256
with pytest.raises(
257257
RuntimeError,
258-
match="Firecracker's huge pages support is incompatible with memory ballooning.",
258+
match="Memory ballooning is incompatible with huge pages.",
259259
):
260260
uvm_plain.api.balloon.put(amount_mib=0, deflate_on_oom=False)
261261

@@ -264,6 +264,6 @@ def test_negative_huge_pages_plus_balloon(uvm_plain):
264264
uvm_plain.api.balloon.put(amount_mib=0, deflate_on_oom=False)
265265
with pytest.raises(
266266
RuntimeError,
267-
match="Machine config error: Firecracker's huge pages support is incompatible with memory ballooning.",
267+
match="Machine config error: 'balloon device' and 'huge pages' are mutually exclusive and cannot be used together.",
268268
):
269269
uvm_plain.basic_config(huge_pages=HugePagesConfig.HUGETLBFS_2MB)

0 commit comments

Comments
 (0)