Skip to content

Commit bcbe7bc

Browse files
committed
Update composefs
And the code reworks to make it work. Signed-off-by: Dallas Strouse <dallas.strouse2007@gmail.com>
1 parent e8953d1 commit bcbe7bc

13 files changed

Lines changed: 295 additions & 55 deletions

File tree

Cargo.lock

Lines changed: 233 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ clap_mangen = { version = "0.3.0" }
4444
# [patch."https://github.com/composefs/composefs-rs"]
4545
# composefs-ctl = { path = "/path/to/composefs-rs/crates/composefs-ctl" }
4646
# The Justfile will auto-detect these and bind-mount them into container builds.
47-
composefs-ctl = { git = "https://github.com/composefs/composefs-rs", rev = "e2770757762ec5091bb183bf0e778fe97c8d5694" }
47+
composefs-ctl = { git = "https://github.com/composefs/composefs-rs", rev = "a4c1ca7a7a5e8cc5b87bec3ca212c2b77f48f4f5" }
4848
fn-error-context = "0.2.1"
4949
futures-util = "0.3"
5050
hex = "0.4.3"

crates/etc-merge/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ impl From<(&cap_std::fs::Metadata, Xattrs)> for MyStat {
5252
st_uid: value.0.uid(),
5353
st_gid: value.0.gid(),
5454
st_mtim_sec: value.0.mtime(),
55+
st_mtim_nsec: value.0.mtime_nsec() as u32,
5556
xattrs: value.1,
5657
})
5758
}

crates/initramfs/src/lib.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use composefs::{
2828
mountcompat::{overlayfs_set_fd, overlayfs_set_lower_and_data_fds, prepare_mount},
2929
repository::Repository,
3030
};
31-
use composefs_boot::cmdline::get_cmdline_composefs;
31+
use composefs_boot::cmdline::ComposefsCmdline;
3232
use composefs_ctl::composefs;
3333
use composefs_ctl::composefs_boot;
3434

@@ -463,11 +463,17 @@ pub fn setup_root(args: Args) -> Result<()> {
463463
config
464464
};
465465

466-
let (image, insecure) = get_cmdline_composefs::<Sha512HashValue>(&cmdline)?;
466+
let composefs_info = ComposefsCmdline::<Sha512HashValue>::from_cmdline(&cmdline)
467+
.context("Failed to parse composefs cmdline")?
468+
.ok_or_else(|| anyhow::anyhow!("No composefs image in cmdline"))?;
467469

468470
let new_root = match &args.root_fs {
469471
Some(path) => open_root_fs(path).context("Failed to clone specified root fs")?,
470-
None => mount_composefs_image(&sysroot, &image.to_hex(), insecure)?,
472+
None => mount_composefs_image(
473+
&sysroot,
474+
&composefs_info.digest().to_hex(),
475+
composefs_info.is_insecure(),
476+
)?,
471477
};
472478

473479
// we need to clone this before the next step to make sure we get the old one
@@ -497,7 +503,7 @@ pub fn setup_root(args: Args) -> Result<()> {
497503
let transient_overlay_fd: Option<OwnedFd> = if config.root.transient {
498504
let overlay_fd = overlay_transient(
499505
&new_root,
500-
&format!("transient:composefs={}", image.to_hex()),
506+
&format!("transient:composefs={}", composefs_info.digest().to_hex()),
501507
None,
502508
)?;
503509

@@ -533,7 +539,10 @@ pub fn setup_root(args: Args) -> Result<()> {
533539
}
534540

535541
// etc + var
536-
let state = open_dir(open_dir(&sysroot, "state/deploy")?, image.to_hex())?;
542+
let state = open_dir(
543+
open_dir(&sysroot, "state/deploy")?,
544+
composefs_info.digest().to_hex(),
545+
)?;
537546
mount_subdir(visible_root, &state, "etc", config.etc, MountType::Bind)?;
538547
// /var is bind-mounted from the deployment state directory by default.
539548
// The systemd.volatile=state cmdline detection above (or an explicit

crates/lib/src/bootc_composefs/boot.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ use composefs_boot::bootloader::{
8282
BootEntry as ComposefsBootEntry, EFI_ADDON_DIR_EXT, EFI_ADDON_FILE_EXT, EFI_EXT, PEType,
8383
UsrLibModulesVmlinuz, get_boot_resources,
8484
};
85-
use composefs_boot::{cmdline::get_cmdline_composefs, os_release::OsReleaseInfo, uki};
85+
use composefs_boot::{
86+
cmdline::ComposefsCmdline as ComposefsBootCmdline, os_release::OsReleaseInfo, uki,
87+
};
8688
use composefs_ctl::composefs;
8789
use composefs_ctl::composefs_boot;
8890
use composefs_ctl::composefs_oci;
@@ -811,8 +813,11 @@ fn write_pe_to_esp(
811813
if matches!(pe_type, PEType::Uki) {
812814
let cmdline = uki::get_cmdline_buffered(&mut uki_reader).context("Getting UKI cmdline")?;
813815

814-
let (composefs_cmdline, missing_verity_allowed_cmdline) =
815-
get_cmdline_composefs::<Sha512HashValue>(&cmdline).context("Parsing composefs=")?;
816+
let composefs_info = ComposefsBootCmdline::<Sha512HashValue>::from_cmdline(&cmdline)
817+
.context("Parsing composefs=")?
818+
.ok_or_else(|| anyhow::anyhow!("No composefs image in UKI cmdline"))?;
819+
let composefs_cmdline = composefs_info.digest();
820+
let missing_verity_allowed_cmdline = composefs_info.is_insecure();
816821

817822
// If the UKI cmdline does not match what the user has passed as cmdline option
818823
// NOTE: This will only be checked for new installs and now upgrades/switches
@@ -830,7 +835,7 @@ fn write_pe_to_esp(
830835
_ => { /* no-op */ }
831836
}
832837

833-
if composefs_cmdline != *uki_id {
838+
if *composefs_cmdline != *uki_id {
834839
anyhow::bail!(
835840
"The UKI has the wrong composefs= parameter (is '{composefs_cmdline:?}', should be {uki_id:?})"
836841
);

crates/lib/src/bootc_composefs/digest.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use cap_std_ext::cap_std;
1111
use cap_std_ext::cap_std::fs::Dir;
1212
use composefs::dumpfile;
1313
use composefs::fsverity::{Algorithm, FsVerityHashValue};
14+
use composefs::repository::RepositoryConfig;
1415
use composefs_boot::BootOps as _;
1516
use composefs_ctl::composefs;
1617
use composefs_ctl::composefs_boot;
@@ -30,11 +31,10 @@ pub(crate) fn new_temp_composefs_repo() -> Result<(TempDir, Arc<ComposefsReposit
3031

3132
td_dir.create_dir("repo")?;
3233
let repo_dir = td_dir.open_dir("repo")?;
33-
let (mut repo, _created) =
34-
ComposefsRepository::init_path(&repo_dir, ".", Algorithm::SHA512, false)
35-
.context("Init cfs repo")?;
3634
// We don't need to hard require verity on the *host* system, we're just computing a checksum here
37-
repo.set_insecure();
35+
let config = RepositoryConfig::new(Algorithm::SHA512).set_insecure();
36+
let (repo, _created) =
37+
ComposefsRepository::init_path(&repo_dir, ".", config).context("Init cfs repo")?;
3838
Ok((td_guard, Arc::new(repo)))
3939
}
4040

@@ -81,7 +81,7 @@ pub(crate) async fn compute_composefs_digest(
8181
.await
8282
.context("Reading container root")?;
8383
fs.transform_for_boot(&repo).context("Preparing for boot")?;
84-
let id = fs.compute_image_id();
84+
let id = fs.compute_image_id(repo.erofs_version());
8585
let digest = id.to_hex();
8686

8787
if let Some(dumpfile_path) = write_dumpfile_to {

crates/lib/src/bootc_composefs/gc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ pub(crate) async fn composefs_gc(
402402
ref_digest,
403403
None,
404404
) {
405-
if let Some(img_ref) = img.image_ref() {
405+
if let Some(img_ref) = img.image_ref(booted_cfs.repo.erofs_version()) {
406406
if img_ref.to_hex() == *verity {
407407
tracing::info!(
408408
"Deployment {verity} has no manifest_digest in origin; \

crates/lib/src/bootc_composefs/repo.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ use std::sync::Arc;
4141
use anyhow::{Context, Result};
4242

4343
use composefs::fsverity::{FsVerityHashValue, Sha512HashValue};
44+
use composefs::repository::RepositoryConfig;
4445
use composefs_boot::bootloader::{BootEntry as ComposefsBootEntry, get_boot_resources};
4546
use composefs_ctl::composefs;
4647
use composefs_ctl::composefs_boot;
@@ -99,16 +100,15 @@ pub(crate) async fn initialize_composefs_repository(
99100

100101
crate::store::ensure_composefs_dir(rootfs_dir)?;
101102

102-
let (mut repo, _created) = crate::store::ComposefsRepository::init_path(
103-
rootfs_dir,
104-
"composefs",
105-
composefs::fsverity::Algorithm::SHA512,
106-
!allow_missing_fsverity,
107-
)
108-
.context("Failed to initialize composefs repository")?;
109-
if allow_missing_fsverity {
110-
repo.set_insecure();
111-
}
103+
let config = RepositoryConfig::new(composefs::fsverity::Algorithm::SHA512);
104+
let config = if allow_missing_fsverity {
105+
config.set_insecure()
106+
} else {
107+
config
108+
};
109+
let (repo, _created) =
110+
crate::store::ComposefsRepository::init_path(rootfs_dir, "composefs", config)
111+
.context("Failed to initialize composefs repository")?;
112112

113113
let imgref: containers_image_proxy::ImageReference = state
114114
.source

crates/lib/src/bootc_composefs/update.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ pub(crate) fn validate_update(
141141
let mut fs = create_filesystem(repo, &oci_digest, Some(config_verity))?;
142142
fs.transform_for_boot(&repo)?;
143143

144-
let image_id = fs.compute_image_id();
144+
let image_id = fs.compute_image_id(repo.erofs_version());
145145

146146
let all_deployments = host.all_composefs_deployments()?;
147147

crates/lib/src/cli.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1892,7 +1892,7 @@ async fn run_from_opt(opt: Opt) -> Result<()> {
18921892
)
18931893
.context("Populating fs")?;
18941894
fs.transform_for_boot(&repo).context("Preparing for boot")?;
1895-
let id = fs.compute_image_id();
1895+
let id = fs.compute_image_id(repo.erofs_version());
18961896
println!("{}", id.to_hex());
18971897

18981898
if let Some(path) = write_dumpfile_to.as_deref() {

0 commit comments

Comments
 (0)