Skip to content

Commit fd3ab21

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 1f3bef0 commit fd3ab21

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
@@ -213,7 +213,9 @@ impl VmResources {
213213
self.balloon.set_device(balloon);
214214

215215
if self.machine_config.huge_pages != HugePageConfig::None {
216-
return Err(ResourcesError::BalloonDevice(BalloonConfigError::HugePages));
216+
return Err(ResourcesError::BalloonDevice(
217+
BalloonConfigError::IncompatibleWith("huge pages"),
218+
));
217219
}
218220
}
219221

@@ -255,7 +257,10 @@ impl VmResources {
255257
}
256258

257259
if self.balloon.get().is_some() && updated.huge_pages != HugePageConfig::None {
258-
return Err(MachineConfigError::BalloonAndHugePages);
260+
return Err(MachineConfigError::Incompatible(
261+
"balloon device",
262+
"huge pages",
263+
));
259264
}
260265
self.machine_config = updated;
261266

@@ -312,7 +317,7 @@ impl VmResources {
312317
}
313318

314319
if self.machine_config.huge_pages != HugePageConfig::None {
315-
return Err(BalloonConfigError::HugePages);
320+
return Err(BalloonConfigError::IncompatibleWith("huge pages"));
316321
}
317322

318323
self.balloon.set(config)
@@ -1452,7 +1457,7 @@ mod tests {
14521457
assert!(
14531458
matches!(
14541459
err,
1455-
ResourcesError::BalloonDevice(BalloonConfigError::HugePages)
1460+
ResourcesError::BalloonDevice(BalloonConfigError::IncompatibleWith("huge pages"))
14561461
),
14571462
"{:?}",
14581463
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
@@ -30,10 +30,8 @@ pub enum MachineConfigError {
3030
/// Enabling simultaneous multithreading is not supported on aarch64.
3131
#[cfg(target_arch = "aarch64")]
3232
SmtNotSupported,
33-
/// Could not determine host kernel version when checking hugetlbfs compatibility
34-
KernelVersion,
35-
/// Firecracker's huge pages support is incompatible with memory ballooning.
36-
BalloonAndHugePages,
33+
/// '{0}' and '{1}' are mutually exclusive and cannot be used together.
34+
Incompatible(&'static str, &'static str)
3735
}
3836

3937
/// 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)