-
Notifications
You must be signed in to change notification settings - Fork 168
Composefs changes #1915
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
base: main
Are you sure you want to change the base?
Composefs changes #1915
Changes from all commits
610bf2c
a276d75
7b4c009
364e600
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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"); | ||
| return Ok(()); | ||
| } | ||
|
|
||
| unmount(NEXTROOT, UnmountFlags::DETACH).context("Unmounting nextroot")?; | ||
|
|
||
| println!("Soft reboot state cleared successfully"); | ||
|
|
||
| Ok(()) | ||
|
Comment on lines
+31
to
+55
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. The logic to check for the existence and mount status of let nextroot = run_dir
.open_dir_optional("nextroot")
.context("Opening nextroot")?;
let mounted = match nextroot {
Some(nextroot) => {
let is_mounted = nextroot
.is_mountpoint(".")?
.ok_or_else(|| anyhow::anyhow!("Failed to get mount info"))?;
if !is_mounted {
tracing::debug!("Nextroot is not a mountpoint");
}
is_mounted
}
None => {
tracing::debug!("Nextroot is not a directory");
false
}
};
if mounted {
unmount(NEXTROOT, UnmountFlags::DETACH).context("Unmounting nextroot")?;
println!("Soft reboot state cleared successfully");
} else {
println!("No deployment staged for soft rebooting");
}
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()?; | ||
|
|
||
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.
Ideally we share these output messages between the two backends