-
Notifications
You must be signed in to change notification settings - Fork 168
WIP: Cfs tests #1913
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
Johan-Liebert1
wants to merge
5
commits into
bootc-dev:main
Choose a base branch
from
Johan-Liebert1:cfs-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
WIP: Cfs tests #1913
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9d260fa
composefs: Add option to reset soft reboot state
Johan-Liebert1 266ef39
composefs: Don't soft-reboot automatically
Johan-Liebert1 272e5cd
composefs/export: Update image digest query format
Johan-Liebert1 7b4f32b
composefs/update: Handle --download-only flag
Johan-Liebert1 dc68b62
Add composefs tests
Johan-Liebert1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ use crate::{ | |
| bootc_composefs::{ | ||
| service::start_finalize_stated_svc, status::composefs_deployment_status_from, | ||
| }, | ||
| cli::SoftRebootMode, | ||
| composefs_consts::COMPOSEFS_CMDLINE, | ||
| store::{BootedComposefs, Storage}, | ||
| }; | ||
|
|
@@ -10,25 +11,66 @@ use bootc_initramfs_setup::setup_root; | |
| use bootc_kernel_cmdline::utf8::Cmdline; | ||
| use bootc_mount::{PID1, bind_mount_from_pidns}; | ||
| use camino::Utf8Path; | ||
| use cap_std_ext::cap_std::ambient_authority; | ||
| use cap_std_ext::cap_std::fs::Dir; | ||
| use cap_std_ext::dirext::CapStdExtDirExt; | ||
| use fn_error_context::context; | ||
| use ostree_ext::systemd_has_soft_reboot; | ||
| use rustix::mount::{UnmountFlags, unmount}; | ||
| use std::{fs::create_dir_all, os::unix::process::CommandExt, path::PathBuf, process::Command}; | ||
|
|
||
| const NEXTROOT: &str = "/run/nextroot"; | ||
|
|
||
| #[context("Resetting soft reboot state")] | ||
| pub(crate) fn reset_soft_reboot() -> Result<()> { | ||
| let run = Utf8Path::new("/run"); | ||
| bind_mount_from_pidns(PID1, &run, &run, true).context("Bind mounting /run")?; | ||
|
|
||
| let run_dir = Dir::open_ambient_dir("/run", ambient_authority()).context("Opening run")?; | ||
|
|
||
| let nextroot = run_dir | ||
| .open_dir_optional("nextroot") | ||
| .context("Opening nextroot")?; | ||
|
|
||
| let Some(nextroot) = nextroot else { | ||
| tracing::debug!("Nextroot is not a directory"); | ||
| println!("No deployment staged for soft rebooting"); | ||
| return Ok(()); | ||
| }; | ||
|
|
||
| let nextroot_mounted = nextroot | ||
| .is_mountpoint(".")? | ||
| .ok_or_else(|| anyhow::anyhow!("Failed to get mount info"))?; | ||
|
|
||
| if !nextroot_mounted { | ||
| tracing::debug!("Nextroot is not a mountpoint"); | ||
| println!("No deployment staged for soft rebooting"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| return Ok(()); | ||
| } | ||
|
|
||
| unmount(NEXTROOT, UnmountFlags::DETACH).context("Unmounting nextroot")?; | ||
|
|
||
| println!("Soft reboot state cleared successfully"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| /// Checks if the provided deployment is soft reboot capable, and soft reboots the system if | ||
| /// argument `reboot` is true | ||
| #[context("Soft rebooting")] | ||
| pub(crate) async fn prepare_soft_reboot_composefs( | ||
| storage: &Storage, | ||
| booted_cfs: &BootedComposefs, | ||
| deployment_id: &String, | ||
| deployment_id: Option<&String>, | ||
| soft_reboot_mode: SoftRebootMode, | ||
| reboot: bool, | ||
| ) -> Result<()> { | ||
| if !systemd_has_soft_reboot() { | ||
| anyhow::bail!("System does not support soft reboots") | ||
| } | ||
|
|
||
| let deployment_id = deployment_id.ok_or_else(|| anyhow::anyhow!("Expected deployment id"))?; | ||
|
|
||
| if *deployment_id == *booted_cfs.cmdline.digest { | ||
| anyhow::bail!("Cannot soft-reboot to currently booted deployment"); | ||
| } | ||
|
|
@@ -44,7 +86,13 @@ pub(crate) async fn prepare_soft_reboot_composefs( | |
| .ok_or_else(|| anyhow::anyhow!("Deployment '{deployment_id}' not found"))?; | ||
|
|
||
| if !requred_deployment.soft_reboot_capable { | ||
| anyhow::bail!("Cannot soft-reboot to deployment with a different kernel state"); | ||
| match soft_reboot_mode { | ||
| SoftRebootMode::Required => { | ||
| anyhow::bail!("Cannot soft-reboot to deployment with a different kernel state") | ||
| } | ||
|
|
||
| SoftRebootMode::Auto => return Ok(()), | ||
| } | ||
| } | ||
|
|
||
| start_finalize_stated_svc()?; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The messages printed to the console for user feedback should ideally be directed to
stderrinstead ofstdout. This is a common practice for diagnostic messages, allowing users to separate program output from informational messages. For example,eprintln!("No deployment staged for soft rebooting");.