Skip to content

Conversation

@hawkw
Copy link
Member

@hawkw hawkw commented May 9, 2025

PR #57 updated idol to generate code using zerocopy v0.8.x rather than v0.6.x. With the addition of the TryFromBytes trait, the new zerocopy release now has support for data-bearing enums (with some limitations due to padding bytes). Therefore, we can now support zerocopy as an encoding for Complex error types provided they satisfy the requirements to derive IntoBytes and TryFromBytes. This branch changes encoding: Zerocopy IPC responses to support the Complex error type provided that the error derives the appropriate error traits, rather than failing.

Fixes #58

@hawkw hawkw requested a review from cbiffle May 9, 2025 22:44
hawkw added a commit to oxidecomputer/hubris that referenced this pull request May 11, 2025
Currently, the `cpu-seq` API has the sequencer return an
`IllegalTransition` error in the case where the requested power state is
the same as the current power state. This is also the error variant
returned when the requested state differs from the current state, but a
transition between those two states cannot be performed. This is
unfortunate, as the caller cannot distinguish between cases where the
system *is* in the requested state and everything is basically fine, and
cases where the caller asked the sequencer to do something that will
never succeed.

This commit changes the `cpu-seq` Idol API to return a `Transition` type
from the `set_power_state` and `set_power_state_with_reason` IPCs that
indicates whether or not a power state change occurred. Sequencer
implementations are changed to return `Ok(Transition::NoChange)` instead
of `Err(IllegalTransition)` when no state change occurred because the
current and requested states are the same.

I considered alternatively having the `IllegalTransition` error return
the current state so that the caller can distinguish between illegal
transitions that are totally disallowed and cases where no transition
occurs. However, this requires changing the entire IPC from using
`zerocopy` to `hubpack`, or adding an empty byte of padding to every
*other* `SeqError` variant so that we can use the support for returning
`Complex` error types with `zerocopy` I added in
oxidecomputer/idolatry#59. That gets a bit trickier, as we also convert
the `SeqError` code into a `u32` to send it upstack, so I figured
keeping it as a C-like enum was better than adding logic to convert the
error into a `u32` error code rather than just `as` casting it. Also,
it felt a bit wrong for this to be an "error", in my opinion. Doing
nothing because we were already in the requested state feels more like a
different type of "success" to me...

This is a first step towards fixing
oxidecomputer/management-gateway-service#270. Fully fixing that will
also require adding a way to indicate to MGS whether a state transition
occurred or not, which also requires a change to the
`gateway-sp-messages` crate.
hawkw added a commit to oxidecomputer/hubris that referenced this pull request May 12, 2025
Currently, the `cpu-seq` API has the sequencer return an
`IllegalTransition` error in the case where the requested power state is
the same as the current power state. This is also the error variant
returned when the requested state differs from the current state, but a
transition between those two states cannot be performed. This is
unfortunate, as the caller cannot distinguish between cases where the
system *is* in the requested state and everything is basically fine, and
cases where the caller asked the sequencer to do something that will
never succeed.

This commit changes the `cpu-seq` Idol API to return a `Transition` type
from the `set_power_state` and `set_power_state_with_reason` IPCs that
indicates whether or not a power state change occurred. Sequencer
implementations are changed to return `Ok(Transition::NoChange)` instead
of `Err(IllegalTransition)` when no state change occurred because the
current and requested states are the same.

I considered alternatively having the `IllegalTransition` error return
the current state so that the caller can distinguish between illegal
transitions that are totally disallowed and cases where no transition
occurs. However, this requires changing the entire IPC from using
`zerocopy` to `hubpack`, or adding an empty byte of padding to every
*other* `SeqError` variant so that we can use the support for returning
`Complex` error types with `zerocopy` I added in
oxidecomputer/idolatry#59. That gets a bit trickier, as we also convert
the `SeqError` code into a `u32` to send it upstack, so I figured
keeping it as a C-like enum was better than adding logic to convert the
error into a `u32` error code rather than just `as` casting it. Also,
it felt a bit wrong for this to be an "error", in my opinion. Doing
nothing because we were already in the requested state feels more like a
different type of "success" to me...

This is a first step towards fixing
oxidecomputer/management-gateway-service#270. Fully fixing that will
also require adding a way to indicate to MGS whether a state transition
occurred or not, which also requires a change to the
`gateway-sp-messages` crate.
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.

add support for Complex error types with zerocopy

2 participants