Skip to content

lib: add support for soft-reboots #1392

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jmarrero
Copy link
Contributor

@jmarrero jmarrero commented Jun 30, 2025

depends on ostreedev/ostree#3455

  • new ostree release
  • new ostree rust bindings update
  • debug why centos stream 9 still has old ostree

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds support for soft-reboots. The implementation has code duplication in lib/src/cli.rs and lib/src/status.rs. An unnecessary backup file (lib/src/status.rs.orig) has been included and must be removed.

lib/src/cli.rs Outdated
Comment on lines 844 to 888
if can_soft_reboot {
println!("Staged deployment is soft-reboot capable, performing soft-reboot...");

// Find the index of the staged deployment
let deployments_list = sysroot.deployments();
let staged_index = deployments_list
.iter()
.position(|d| d.is_staged())
.ok_or_else(|| anyhow::anyhow!("Failed to find staged deployment index"))?;

// Prepare the soft-reboot using ostree admin prepare-soft-reboot
let mut cmd = std::process::Command::new("ostree");
cmd.args(["admin", "prepare-soft-reboot", &staged_index.to_string()]);
let status = cmd.status().context("Failed to run ostree admin prepare-soft-reboot")?;
if !status.success() {
anyhow::bail!("ostree admin prepare-soft-reboot failed");
}

// Perform the soft-reboot
crate::reboot::soft_reboot()?;
} else {
crate::reboot::reboot()?;
}

Choose a reason for hiding this comment

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

high

The if can_soft_reboot block is duplicated in the switch function. The logic for preparing and executing the soft reboot is also present in the rollback function. Extract this logic into helper functions to improve maintainability.

lib/src/cli.rs Outdated
Comment on lines 1019 to 1028
// Prepare the soft-reboot using ostree admin prepare-soft-reboot
let mut cmd = std::process::Command::new("ostree");
cmd.args(["admin", "prepare-soft-reboot", &target_index.to_string()]);
let status = cmd.status().context("Failed to run ostree admin prepare-soft-reboot")?;
if !status.success() {
anyhow::bail!("ostree admin prepare-soft-reboot failed");
}

// Perform the soft-reboot
crate::reboot::soft_reboot()?;

Choose a reason for hiding this comment

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

high

The logic to prepare and execute the soft reboot is duplicated from the upgrade and switch functions. Extract this into a shared helper function to reduce code duplication.

Comment on lines 459 to 458
if entry.soft_reboot_capable {
write_row_name(&mut out, "Soft-reboot", prefix_len)?;
writeln!(out, "capable")?;
}

Choose a reason for hiding this comment

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

medium

This logic to display the soft_reboot_capable status is duplicated in human_render_slot (lines 425-428). The pinned status and the tracing::debug! call are also duplicated. Consider extracting this common rendering logic into a helper function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed for now will be added with --verbose on #1399

@jmarrero jmarrero force-pushed the soft-reboots branch 4 times, most recently from f063416 to 825778d Compare July 8, 2025 13:51
@jmarrero jmarrero marked this pull request as ready for review July 8, 2025 13:51
@jmarrero jmarrero changed the title wip: add support for soft-reboots lib: add support for soft-reboots Jul 8, 2025
Copy link
Collaborator

@cgwalters cgwalters left a comment

Choose a reason for hiding this comment

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

Looking good in general!

lib/src/cli.rs Outdated
let deployments_list = sysroot.deployments();
let staged_deployment = deployments_list
.iter()
.find(|d| d.is_staged())
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is what we need to do at the moment, the code is fine.

However just looking at things overall, we should probably try to refactor in the future so that we have a clear staged state that has both the status object and the deployment and we shouldn't then need the unwrap_or and error checking here.

@jmarrero jmarrero force-pushed the soft-reboots branch 2 times, most recently from 521dd3a to 408dbd9 Compare July 9, 2025 16:42
Co-authored-by: Colin Walters <[email protected]>

Signed-off-by: Joseph Marrero Corchado <[email protected]>
crate::deploy::rollback(sysroot).await?;

if can_soft_reboot {
soft_reboot_rollback(sysroot)?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since this function is only called once so it could be inlined, but OK as is

@cgwalters cgwalters marked this pull request as draft July 16, 2025 18:00
@cgwalters
Copy link
Collaborator

Moving to draft since this is blocked until we either:

  • ship an updated ostree
  • switch to build/runtime conditionals

@cgwalters
Copy link
Collaborator

That said one thing that would be cool would be us keeping cached container images for PRs on ghcr.io/bootc-dev/bootc-pr-<PRNUMBER> or so.

In this PR (actually the dependency one) we could explicitly bump the ostree version even before it's shipped $everywhere.

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