mgmt-gateway: Add update status and update IDs#789
Conversation
There was a problem hiding this comment.
This may be a little clearer as a basic conditional with the matches! macro, i.e.
| match self.update_buf.in_progress_update_id() { | |
| Some(in_progress_id) if id != in_progress_id => { | |
| return Err(ResponseError::UpdateInProgress( | |
| self.update_buf.status(), | |
| )); | |
| } | |
| _ => (), | |
| } | |
| if matches!(self.update_buf.in_progress_update_id(), | |
| Some(in_progress_id) if id != in_progress_id) | |
| { | |
| return Err(ResponseError::UpdateInProgress( | |
| self.update_buf.status(), | |
| )); | |
| } |
There was a problem hiding this comment.
I can't bring myself to like matches!. How about
if let Some(in_progress_id) = self.update_buf.in_progress_update_id() {
if id != in_progress_id {
return Err(ResponseError::UpdateInProgress(
self.update_buf.status(),
));
}
}There was a problem hiding this comment.
Maybe replace with
| match self.update_task.abort_update() { | |
| // Aborting an update that hasn't started yet is fine; either way | |
| // our caller is clear to start a new update. | |
| Ok(()) | Err(UpdateError::UpdateNotStarted) => (), | |
| Err(other) => { | |
| return Err(ResponseError::UpdateFailed(other as u32)) | |
| } | |
| } | |
| // Aborting an update that hasn't started yet is fine; either way | |
| // our caller is clear to start a new update. | |
| if let Err(e) = self.update_task.abort_update() | |
| && !matches!(e, UpdateError::UpdateNotStarted) | |
| { | |
| return Err(ResponseError::UpdateFailed(e as u32)) | |
| } |
(you could avoid the awkward !matches! if ResponseError derived Eq, but that's in a separate crate)
There was a problem hiding this comment.
I'm not sure that syntax should work since let_chains are still unstable (?!). What if I rolled the rest of the method into the successful branch:
match self.update_task.abort_update() {
// Aborting an update that hasn't started yet is fine; either way
// our caller is clear to start a new update.
Ok(()) | Err(UpdateError::UpdateNotStarted) => {
self.update_buf.abort();
Ok(())
}
Err(other) => {
Err(ResponseError::UpdateFailed(other as u32))
}
}There was a problem hiding this comment.
Same suggestion as above (using a conditional + matches! instead of a match)
There was a problem hiding this comment.
Weakly-held opinion: since this function returns a Result, early-exiting may be cleaner than map, e.g.
| sector_erase.progress().map(|progress| { | |
| UpdateStatus::Preparing(UpdatePreparationStatus { | |
| id: sub_status.id, | |
| progress: Some(progress), | |
| }) | |
| }) | |
| let progress = sector_erase.progress()?; | |
| UpdateStatus::Preparing(UpdatePreparationStatus { | |
| id: sub_status.id, | |
| progress: Some(progress), | |
| }) |
There was a problem hiding this comment.
Yes, that's much better, thanks.
mkeeter
left a comment
There was a problem hiding this comment.
A few small suggestions for readability, but generally looks good.
This is the companion to the larger MGS change in oxidecomputer/omicron#1714. From the SP's side, the changes are relatively minor: 1. We removed "update prepare status" in favor of the more general "update status" 2. Update messages now always include an update ID, and for "update abort" we only abort if the ID matches our current in-progress update.
e988fea to
bf1b444
Compare
* mgmt-gateway: add update status and IDs This is the companion to the larger MGS change in oxidecomputer/omicron#1714. From the SP's side, the changes are relatively minor: 1. We removed "update prepare status" in favor of the more general "update status" 2. Update messages now always include an update ID, and for "update abort" we only abort if the ID matches our current in-progress update.
* mgmt-gateway: add update status and IDs This is the companion to the larger MGS change in oxidecomputer/omicron#1714. From the SP's side, the changes are relatively minor: 1. We removed "update prepare status" in favor of the more general "update status" 2. Update messages now always include an update ID, and for "update abort" we only abort if the ID matches our current in-progress update.
This is the companion to the larger MGS change in oxidecomputer/omicron#1714. From the SP's side,
the changes are relatively minor: