Skip to content

mgmt-gateway: Add update status and update IDs#789

Merged
jgallagher merged 3 commits into
masterfrom
mgmt-gateway-add-update-status
Sep 19, 2022
Merged

mgmt-gateway: Add update status and update IDs#789
jgallagher merged 3 commits into
masterfrom
mgmt-gateway-add-update-status

Conversation

@jgallagher

Copy link
Copy Markdown
Contributor

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.

@jgallagher jgallagher requested a review from mkeeter September 16, 2022 21:19
Comment thread task/mgmt-gateway/src/mgs_common.rs Outdated
Comment on lines 127 to 133

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This may be a little clearer as a basic conditional with the matches! macro, i.e.

Suggested change
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(),
));
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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(),
                ));
            }
        }

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Totally fine by me!

Comment thread task/mgmt-gateway/src/mgs_common.rs Outdated
Comment on lines 136 to 143

@mkeeter mkeeter Sep 19, 2022

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Maybe replace with

Suggested change
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)

@jgallagher jgallagher Sep 19, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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))
            }
        }

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

👍🏻

Comment thread task/mgmt-gateway/src/mgs_gimlet.rs Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Same suggestion as above (using a conditional + matches! instead of a match)

Comment thread task/mgmt-gateway/src/mgs_gimlet.rs Outdated
Comment on lines 689 to 694

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Weakly-held opinion: since this function returns a Result, early-exiting may be cleaner than map, e.g.

Suggested change
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),
})

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, that's much better, thanks.

@mkeeter mkeeter left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.
@jgallagher jgallagher force-pushed the mgmt-gateway-add-update-status branch from e988fea to bf1b444 Compare September 19, 2022 17:28
@jgallagher jgallagher merged commit ec36cbf into master Sep 19, 2022
@jgallagher jgallagher deleted the mgmt-gateway-add-update-status branch September 19, 2022 17:49
FawazTirmizi pushed a commit to rivosinc/hubris that referenced this pull request Oct 3, 2022
* 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.
FawazTirmizi pushed a commit to rivosinc/hubris that referenced this pull request Oct 3, 2022
* 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.
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.

2 participants