Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,6 @@ todo = "deny"
needless_borrow = "allow"
needless_borrows_for_generic_args = "allow"

[patch."https://github.com/composefs/composefs-rs"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we need this

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

cfsctl = { path = "/workspaces/composefs-rs/crates/cfsctl" }

5 changes: 3 additions & 2 deletions crates/lib/src/bootc_composefs/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ pub async fn export_repo_to_image(
let oci_dir = OciDir::ensure(tmpdir.try_clone()?).context("Opening OCI")?;

// Use composefs_oci::open_config to get the config and layer map
let (config, layer_map) =
open_config(&*booted_cfs.repo, &config_digest, None).context("Opening config")?;
let open = open_config(&*booted_cfs.repo, &config_digest, None).context("Opening config")?;
let config = open.config;
let layer_map = open.layer_refs;

// We can't guarantee that we'll get the same tar stream as the container image
// So we create new config and manifest
Expand Down
21 changes: 21 additions & 0 deletions crates/lib/src/bootc_composefs/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,27 @@ use crate::{
utils::path_relative_to,
};

/// Read and parse the `.origin` INI file for a deployment.
///
/// Returns `None` if the state directory or origin file doesn't exist
/// (e.g. the deployment was partially deleted).
#[context("Reading origin for deployment {deployment_id}")]
pub(crate) fn read_origin(sysroot: &Dir, deployment_id: &str) -> Result<Option<tini::Ini>> {
let depl_state_path = std::path::PathBuf::from(STATE_DIR_RELATIVE).join(deployment_id);

let Some(state_dir) = sysroot.open_dir_optional(&depl_state_path)? else {
return Ok(None);
};

let origin_filename = format!("{deployment_id}.origin");
let Some(origin_contents) = state_dir.read_to_string_optional(&origin_filename)? else {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The .origin file should always exist right?

return Ok(None);
};

let ini = tini::Ini::from_string(&origin_contents).context("Failed to parse origin file")?;
Ok(Some(ini))
}

pub(crate) fn get_booted_bls(boot_dir: &Dir) -> Result<BLSConfig> {
let cmdline = Cmdline::from_proc()?;
let booted = cmdline
Expand Down
18 changes: 3 additions & 15 deletions crates/lib/src/bootc_composefs/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
boot::BootType,
repo::get_imgref,
selinux::are_selinux_policies_compatible,
state::get_composefs_usr_overlay_status,
state::{get_composefs_usr_overlay_status, read_origin},
utils::{compute_store_boot_digest_for_uki, get_uki_cmdline},
},
composefs_consts::{
Expand Down Expand Up @@ -699,11 +699,6 @@ async fn composefs_deployment_status_from(
// This is our source of truth
let bootloader_entry_verity = list_bootloader_entries(storage)?;

let state_dir = storage
.physical_root
.open_dir(STATE_DIR_RELATIVE)
.with_context(|| format!("Opening {STATE_DIR_RELATIVE}"))?;

let host_spec = HostSpec {
image: None,
boot_order: BootOrder::Default,
Expand Down Expand Up @@ -732,15 +727,8 @@ async fn composefs_deployment_status_from(
let mut extra_deployment_boot_entries: Vec<BootEntry> = Vec::new();

for verity_digest in bootloader_entry_verity {
// read the origin file
let config = state_dir
.open_dir(&verity_digest)
.with_context(|| format!("Failed to open {verity_digest}"))?
.read_to_string(format!("{verity_digest}.origin"))
.with_context(|| format!("Reading file {verity_digest}.origin"))?;

let ini = tini::Ini::from_string(&config)
.with_context(|| format!("Failed to parse file {verity_digest}.origin as ini"))?;
let ini = read_origin(&storage.physical_root, &verity_digest)?
.ok_or_else(|| anyhow::anyhow!("No origin file for deployment {verity_digest}"))?;

let mut boot_entry =
boot_entry_from_composefs_deployment(storage, ini, &verity_digest).await?;
Expand Down