-
Notifications
You must be signed in to change notification settings - Fork 129
WIP: composefs branch #1444
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
cgwalters
wants to merge
19
commits into
main
Choose a base branch
from
composefs-backend
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: composefs branch #1444
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
5885686
WIP: composefs backend
Johan-Liebert1 d9b384d
Rework composefs_booted to use kernel cmdline
cgwalters 93a6d75
composefs/status: Read UKI entries to check for queued rollback
Johan-Liebert1 dc862a2
parser/grub: Use String instead of &str
Johan-Liebert1 7a10221
composefs/rollback: Handle UKI rollback
Johan-Liebert1 d3e8d36
composefs/state: Use atomic writes for origin and staged deployment f…
Johan-Liebert1 8e410f1
composefs/boot/bls: Handle duplicate VMLinuz + Initrd
Johan-Liebert1 805a42d
parser/bls: `impl Display` for BLSConfig
Johan-Liebert1 009ee03
lib/composefs: Centralize constants
Johan-Liebert1 1b99733
composefs/state: Name state directory `default`
Johan-Liebert1 a53ca13
parser/bls: Add tests for bls parser
Johan-Liebert1 08b1cad
install/composefs/uki: Write only staged + booted menuentry on upgrade
Johan-Liebert1 d425878
rollback/composefs: Print whether we are reverting the queued rollback
Johan-Liebert1 521a2ed
refactor: Pass boot dir to boot entry readers
Johan-Liebert1 2018de3
test: Add tests for reading boot entries
Johan-Liebert1 95bbfe6
Drop duplicate bls_config
cgwalters b091e0f
Merge pull request #1502 from cgwalters/composefs-add-lost-commits
cgwalters 06693d6
install: Use read_file from composefs-boot
cgwalters e2b19f9
Merge pull request #1507 from cgwalters/composefs-more-cleanups
cgwalters 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,11 +27,16 @@ use ostree_ext::ostree; | |
use schemars::schema_for; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use crate::deploy::RequiredHostSpec; | ||
use crate::deploy::{composefs_rollback, RequiredHostSpec}; | ||
use crate::install::{ | ||
pull_composefs_repo, setup_composefs_bls_boot, setup_composefs_uki_boot, write_composefs_state, | ||
BootSetupType, BootType, | ||
}; | ||
use crate::lints; | ||
use crate::progress_jsonl::{ProgressWriter, RawProgressFd}; | ||
use crate::spec::Host; | ||
use crate::spec::ImageReference; | ||
use crate::status::{composefs_booted, composefs_deployment_status}; | ||
use crate::utils::sigpolicy_from_opt; | ||
|
||
/// Shared progress options | ||
|
@@ -778,6 +783,69 @@ fn prepare_for_write() -> Result<()> { | |
Ok(()) | ||
} | ||
|
||
#[context("Upgrading composefs")] | ||
async fn upgrade_composefs(_opts: UpgradeOpts) -> Result<()> { | ||
// TODO: IMPORTANT Have all the checks here that `bootc upgrade` has for an ostree booted system | ||
|
||
let host = composefs_deployment_status() | ||
.await | ||
.context("Getting composefs deployment status")?; | ||
|
||
// TODO: IMPORTANT We need to check if any deployment is staged and get the image from that | ||
let imgref = host | ||
.spec | ||
.image | ||
.as_ref() | ||
.ok_or_else(|| anyhow::anyhow!("No image source specified"))?; | ||
|
||
// let booted_image = host | ||
// .status | ||
// .booted | ||
// .ok_or(anyhow::anyhow!("Could not find booted image"))? | ||
// .image | ||
// .ok_or(anyhow::anyhow!("Could not find booted image"))?; | ||
|
||
// tracing::debug!("booted_image: {booted_image:#?}"); | ||
// tracing::debug!("imgref: {imgref:#?}"); | ||
|
||
// let digest = booted_image | ||
// .digest() | ||
// .context("Getting digest for booted image")?; | ||
|
||
let (repo, entries, id) = pull_composefs_repo(&imgref.transport, &imgref.image).await?; | ||
|
||
let Some(entry) = entries.into_iter().next() else { | ||
anyhow::bail!("No boot entries!"); | ||
}; | ||
|
||
let boot_type = BootType::from(&entry); | ||
let mut boot_digest = None; | ||
|
||
match boot_type { | ||
BootType::Bls => { | ||
boot_digest = Some(setup_composefs_bls_boot( | ||
BootSetupType::Upgrade, | ||
repo, | ||
&id, | ||
entry, | ||
)?) | ||
} | ||
|
||
BootType::Uki => setup_composefs_uki_boot(BootSetupType::Upgrade, repo, &id, entry)?, | ||
}; | ||
|
||
write_composefs_state( | ||
&Utf8PathBuf::from("/sysroot"), | ||
id, | ||
imgref, | ||
true, | ||
boot_type, | ||
boot_digest, | ||
)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
/// Implementation of the `bootc upgrade` CLI command. | ||
#[context("Upgrading")] | ||
async fn upgrade(opts: UpgradeOpts) -> Result<()> { | ||
|
@@ -891,9 +959,7 @@ async fn upgrade(opts: UpgradeOpts) -> Result<()> { | |
Ok(()) | ||
} | ||
|
||
/// Implementation of the `bootc switch` CLI command. | ||
#[context("Switching")] | ||
async fn switch(opts: SwitchOpts) -> Result<()> { | ||
fn imgref_for_switch(opts: &SwitchOpts) -> Result<ImageReference> { | ||
let transport = ostree_container::Transport::try_from(opts.transport.as_str())?; | ||
let imgref = ostree_container::ImageReference { | ||
transport, | ||
|
@@ -902,6 +968,72 @@ async fn switch(opts: SwitchOpts) -> Result<()> { | |
let sigverify = sigpolicy_from_opt(opts.enforce_container_sigpolicy); | ||
let target = ostree_container::OstreeImageReference { sigverify, imgref }; | ||
let target = ImageReference::from(target); | ||
|
||
return Ok(target); | ||
} | ||
|
||
#[context("Composefs Switching")] | ||
async fn switch_composefs(opts: SwitchOpts) -> Result<()> { | ||
let target = imgref_for_switch(&opts)?; | ||
// TODO: Handle in-place | ||
|
||
let host = composefs_deployment_status() | ||
.await | ||
.context("Getting composefs deployment status")?; | ||
|
||
let new_spec = { | ||
let mut new_spec = host.spec.clone(); | ||
new_spec.image = Some(target.clone()); | ||
new_spec | ||
}; | ||
|
||
if new_spec == host.spec { | ||
println!("Image specification is unchanged."); | ||
return Ok(()); | ||
} | ||
|
||
let Some(target_imgref) = new_spec.image else { | ||
anyhow::bail!("Target image is undefined") | ||
}; | ||
|
||
let (repo, entries, id) = pull_composefs_repo(&"docker".into(), &target_imgref.image).await?; | ||
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 transport is hardcoded to let (repo, entries, id) = pull_composefs_repo(&target_imgref.transport, &target_imgref.image).await?; |
||
|
||
let Some(entry) = entries.into_iter().next() else { | ||
anyhow::bail!("No boot entries!"); | ||
}; | ||
|
||
let boot_type = BootType::from(&entry); | ||
let mut boot_digest = None; | ||
|
||
match boot_type { | ||
BootType::Bls => { | ||
boot_digest = Some(setup_composefs_bls_boot( | ||
BootSetupType::Upgrade, | ||
repo, | ||
&id, | ||
entry, | ||
)?) | ||
} | ||
BootType::Uki => setup_composefs_uki_boot(BootSetupType::Upgrade, repo, &id, entry)?, | ||
}; | ||
|
||
write_composefs_state( | ||
&Utf8PathBuf::from("/sysroot"), | ||
id, | ||
&target_imgref, | ||
true, | ||
boot_type, | ||
boot_digest, | ||
)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
/// Implementation of the `bootc switch` CLI command. | ||
#[context("Switching")] | ||
async fn switch(opts: SwitchOpts) -> Result<()> { | ||
let target = imgref_for_switch(&opts)?; | ||
|
||
let prog: ProgressWriter = opts.progress.try_into()?; | ||
|
||
// If we're doing an in-place mutation, we shortcut most of the rest of the work here | ||
|
@@ -966,8 +1098,12 @@ async fn switch(opts: SwitchOpts) -> Result<()> { | |
/// Implementation of the `bootc rollback` CLI command. | ||
#[context("Rollback")] | ||
async fn rollback(opts: RollbackOpts) -> Result<()> { | ||
let sysroot = &get_storage().await?; | ||
crate::deploy::rollback(sysroot).await?; | ||
if composefs_booted()?.is_some() { | ||
composefs_rollback().await? | ||
} else { | ||
let sysroot = &get_storage().await?; | ||
crate::deploy::rollback(sysroot).await?; | ||
}; | ||
|
||
if opts.apply { | ||
crate::reboot::reboot()?; | ||
|
@@ -1117,8 +1253,20 @@ impl Opt { | |
async fn run_from_opt(opt: Opt) -> Result<()> { | ||
let root = &Dir::open_ambient_dir("/", cap_std::ambient_authority())?; | ||
match opt { | ||
Opt::Upgrade(opts) => upgrade(opts).await, | ||
Opt::Switch(opts) => switch(opts).await, | ||
Opt::Upgrade(opts) => { | ||
if composefs_booted()?.is_some() { | ||
upgrade_composefs(opts).await | ||
} else { | ||
upgrade(opts).await | ||
} | ||
} | ||
Opt::Switch(opts) => { | ||
if composefs_booted()?.is_some() { | ||
switch_composefs(opts).await | ||
} else { | ||
switch(opts).await | ||
} | ||
} | ||
Opt::Rollback(opts) => rollback(opts).await, | ||
Opt::Edit(opts) => edit(opts).await, | ||
Opt::UsrOverlay => usroverlay().await, | ||
|
@@ -1259,8 +1407,7 @@ async fn run_from_opt(opt: Opt) -> Result<()> { | |
FsverityOpts::Enable { path } => { | ||
let fd = | ||
std::fs::File::open(&path).with_context(|| format!("Reading {path}"))?; | ||
// Note this is not robust to forks, we're not using the _maybe_copy variant | ||
fsverity::enable_verity_with_retry::<fsverity::Sha256HashValue>(&fd)?; | ||
fsverity::enable_verity_raw::<fsverity::Sha256HashValue>(&fd)?; | ||
Ok(()) | ||
} | ||
}, | ||
|
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/// composefs= paramter in kernel cmdline | ||
pub const COMPOSEFS_CMDLINE: &str = "composefs"; | ||
|
||
/// Directory to store transient state, such as staged deployemnts etc | ||
pub(crate) const COMPOSEFS_TRANSIENT_STATE_DIR: &str = "/run/composefs"; | ||
/// File created in /run/composefs to record a staged-deployment | ||
pub(crate) const COMPOSEFS_STAGED_DEPLOYMENT_FNAME: &str = "staged-deployment"; | ||
|
||
/// Absolute path to composefs-native state directory | ||
pub(crate) const STATE_DIR_ABS: &str = "/sysroot/state/deploy"; | ||
/// Relative path to composefs-native state directory. Relative to /sysroot | ||
pub(crate) const STATE_DIR_RELATIVE: &str = "state/deploy"; | ||
/// Relative path to the shared 'var' directory. Relative to /sysroot | ||
pub(crate) const SHARED_VAR_PATH: &str = "state/os/default/var"; | ||
|
||
/// Section in .origin file to store boot related metadata | ||
pub(crate) const ORIGIN_KEY_BOOT: &str = "boot"; | ||
/// Whether the deployment was booted with BLS or UKI | ||
pub(crate) const ORIGIN_KEY_BOOT_TYPE: &str = "boot_type"; | ||
/// Key to store the SHA256 sum of vmlinuz + initrd for a deployment | ||
pub(crate) const ORIGIN_KEY_BOOT_DIGEST: &str = "digest"; | ||
|
||
/// Filename for `loader/entries` | ||
pub(crate) const BOOT_LOADER_ENTRIES: &str = "entries"; | ||
/// Filename for staged boot loader entries | ||
pub(crate) const STAGED_BOOT_LOADER_ENTRIES: &str = "entries.staged"; | ||
/// Filename for rollback boot loader entries | ||
pub(crate) const ROLLBACK_BOOT_LOADER_ENTRIES: &str = STAGED_BOOT_LOADER_ENTRIES; | ||
|
||
/// Filename for grub user config | ||
pub(crate) const USER_CFG: &str = "user.cfg"; | ||
/// Filename for staged grub user config | ||
pub(crate) const USER_CFG_STAGED: &str = "user.cfg.staged"; | ||
/// Filename for rollback grub user config | ||
pub(crate) const USER_CFG_ROLLBACK: &str = USER_CFG_STAGED; |
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.
In Rust, it's more idiomatic to omit the
return
keyword for the final expression in a function.