Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server: add a first-class error type to machine init #777

Merged
merged 1 commit into from
Oct 2, 2024

Conversation

gjcolombo
Copy link
Contributor

Add a MachineInitError type and make MachineInitializer functions return it. This makes it more convenient to handle new logic errors in initializer functions. To handle the (many) cases where the initializer calls bhyve ioctls or filesystem functions that return std::io:Error, MachineInitError has a catchall anyhow::Error variant; this encourages calls that produce I/O errors to call context or with_context to better describe those errors.

Tested by running propolis-server ad hoc in a couple of invalid configurations (file backend not pointing to an actual file; too many vCPUs; more guest memory than the host has available) and verified that the error chains (and contexts, if applicable) show up in the Propolis logs.

Add a `MachineInitError` type and make `MachineInitializer` functions
return it. This makes it more convenient to handle new logic errors in
initializer functions. To handle the (many) cases where the initializer
calls bhyve ioctls or filesystem functions that return `std::io:Error`,
`MachineInitError` has a catchall `anyhow::Error` variant; this
encourages calls that produce I/O errors to call `context` or
`with_context` to better describe those errors.

Tested by running propolis-server ad hoc in a couple of invalid
configurations (file backend not pointing to an actual file; too many
vCPUs; more guest memory than the host has available) and verified that
the error chains (and contexts, if applicable) show up in the Propolis
logs.
@gjcolombo gjcolombo requested review from hawkw and iximeow October 2, 2024 18:20
Copy link
Member

@iximeow iximeow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 thanks!

let fwcfg = fwcfg::FwCfg::new();
fwcfg
.insert_legacy(
fwcfg::LegacyId::SmpCpuCount,
fwcfg::Entry::fixed_u32(u32::from(cpus)),
)
.unwrap();
.map_err(|e| MachineInitError::FwcfgInsertFailed("cpu count", e))?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh that's nice along the way.

@gjcolombo
Copy link
Contributor Author

Thanks for the reviews!

@gjcolombo gjcolombo merged commit 3c4be43 into master Oct 2, 2024
11 checks passed
@gjcolombo gjcolombo deleted the gjcolombo/machine-init-errors branch October 2, 2024 22:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants