Skip to content

Commit 441ccf9

Browse files
committed
composefs: Update gc and finalize functions to use passed Storage/BootedComposefs
Update composefs_gc(), composefs_backend_finalize(), and get_etc_diff() to accept Storage and BootedComposefs parameters instead of calling composefs_deployment_status() and opening hardcoded paths. Changes: - composefs_gc() now accepts storage and booted_cfs parameters - composefs_backend_finalize() uses storage.physical_root instead of hardcoded "/sysroot" - get_etc_diff() uses storage.physical_root instead of hardcoded "/sysroot" - Update CLI dispatchers to use BootedStorageKind pattern for finalize and config-diff - Remove unused imports from finalize.rs (open_dir, CWD) This eliminates remaining composefs_deployment_status() calls from gc.rs and finalize.rs, and removes several hardcoded "/sysroot" paths. Assisted-by: Claude Code (Sonnet 4.5) Signed-off-by: Colin Walters <[email protected]>
1 parent 7173995 commit 441ccf9

File tree

6 files changed

+55
-42
lines changed

6 files changed

+55
-42
lines changed

crates/lib/src/bootc_composefs/delete.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ pub(crate) async fn delete_composefs_deployment(
364364

365365
delete_depl_boot_entries(&depl_to_del, deleting_staged)?;
366366

367-
composefs_gc().await?;
367+
composefs_gc(storage, booted_cfs).await?;
368368

369369
Ok(())
370370
}

crates/lib/src/bootc_composefs/finalize.rs

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,28 @@ use crate::bootc_composefs::boot::{
44
get_esp_partition, get_sysroot_parent_dev, mount_esp, BootType,
55
};
66
use crate::bootc_composefs::rollback::{rename_exchange_bls_entries, rename_exchange_user_cfg};
7+
use crate::bootc_composefs::status::get_composefs_status;
8+
use crate::composefs_consts::STATE_DIR_ABS;
79
use crate::spec::Bootloader;
8-
use crate::{
9-
bootc_composefs::status::composefs_deployment_status, composefs_consts::STATE_DIR_ABS,
10-
};
10+
use crate::store::{BootedComposefs, Storage};
1111
use anyhow::{Context, Result};
12-
use bootc_initramfs_setup::{mount_composefs_image, open_dir};
12+
use bootc_initramfs_setup::mount_composefs_image;
1313
use bootc_mount::tempmount::TempMount;
1414
use cap_std_ext::cap_std::{ambient_authority, fs::Dir};
1515
use cap_std_ext::dirext::CapStdExtDirExt;
1616
use etc_merge::{compute_diff, merge, print_diff, traverse_etc};
17-
use rustix::fs::{fsync, renameat, CWD};
17+
use rustix::fs::{fsync, renameat};
1818
use rustix::path::Arg;
1919

2020
use fn_error_context::context;
2121

22-
pub(crate) async fn get_etc_diff() -> Result<()> {
23-
let host = composefs_deployment_status().await?;
22+
pub(crate) async fn get_etc_diff(storage: &Storage, booted_cfs: &BootedComposefs) -> Result<()> {
23+
let host = get_composefs_status(storage, booted_cfs).await?;
2424
let booted_composefs = host.require_composefs_booted()?;
2525

2626
// Mount the booted EROFS image to get pristine etc
27-
let sysroot = open_dir(CWD, "/sysroot").context("Opening /sysroot")?;
28-
let composefs_fd = mount_composefs_image(&sysroot, &booted_composefs.verity, false)?;
27+
let sysroot_fd = storage.physical_root.reopen_as_ownedfd()?;
28+
let composefs_fd = mount_composefs_image(&sysroot_fd, &booted_composefs.verity, false)?;
2929

3030
let erofs_tmp_mnt = TempMount::mount_fd(&composefs_fd)?;
3131

@@ -41,8 +41,11 @@ pub(crate) async fn get_etc_diff() -> Result<()> {
4141
Ok(())
4242
}
4343

44-
pub(crate) async fn composefs_backend_finalize() -> Result<()> {
45-
let host = composefs_deployment_status().await?;
44+
pub(crate) async fn composefs_backend_finalize(
45+
storage: &Storage,
46+
booted_cfs: &BootedComposefs,
47+
) -> Result<()> {
48+
let host = get_composefs_status(storage, booted_cfs).await?;
4649

4750
let booted_composefs = host.require_composefs_booted()?;
4851

@@ -56,8 +59,8 @@ pub(crate) async fn composefs_backend_finalize() -> Result<()> {
5659
))?;
5760

5861
// Mount the booted EROFS image to get pristine etc
59-
let sysroot = open_dir(CWD, "/sysroot")?;
60-
let composefs_fd = mount_composefs_image(&sysroot, &booted_composefs.verity, false)?;
62+
let sysroot_fd = storage.physical_root.reopen_as_ownedfd()?;
63+
let composefs_fd = mount_composefs_image(&sysroot_fd, &booted_composefs.verity, false)?;
6164

6265
let erofs_tmp_mnt = TempMount::mount_fd(&composefs_fd)?;
6366

@@ -88,8 +91,10 @@ pub(crate) async fn composefs_backend_finalize() -> Result<()> {
8891
let (esp_part, ..) = get_esp_partition(&sysroot_parent)?;
8992

9093
let esp_mount = mount_esp(&esp_part)?;
91-
let boot_dir = Dir::open_ambient_dir("/sysroot/boot", ambient_authority())
92-
.context("Opening sysroot/boot")?;
94+
let boot_dir = storage
95+
.physical_root
96+
.open_dir("boot")
97+
.context("Opening boot")?;
9398

9499
// NOTE: Assuming here we won't have two bootloaders at the same time
95100
match booted_composefs.bootloader {

crates/lib/src/bootc_composefs/gc.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ use crate::{
1616
boot::{get_esp_partition, get_sysroot_parent_dev, mount_esp},
1717
delete::{delete_image, delete_staged, delete_state_dir, get_image_objects},
1818
status::{
19-
composefs_deployment_status, get_bootloader, get_sorted_grub_uki_boot_entries,
19+
get_bootloader, get_composefs_status, get_sorted_grub_uki_boot_entries,
2020
get_sorted_type1_boot_entries,
2121
},
2222
},
2323
composefs_consts::{STATE_DIR_RELATIVE, USER_CFG},
2424
spec::Bootloader,
25+
store::{BootedComposefs, Storage},
2526
};
2627

2728
#[fn_error_context::context("Listing EROFS images")]
@@ -172,12 +173,11 @@ pub(crate) fn gc_objects(sysroot: &Dir) -> Result<()> {
172173
/// Similarly if EROFS image B1 doesn't exist, but state dir does, then delete the state dir and
173174
/// perform GC
174175
#[fn_error_context::context("Running composefs garbage collection")]
175-
pub(crate) async fn composefs_gc() -> Result<()> {
176-
let host = composefs_deployment_status().await?;
177-
let booted_cfs = host.require_composefs_booted()?;
176+
pub(crate) async fn composefs_gc(storage: &Storage, booted_cfs: &BootedComposefs) -> Result<()> {
177+
let host = get_composefs_status(storage, booted_cfs).await?;
178+
let booted_cfs_status = host.require_composefs_booted()?;
178179

179-
let sysroot =
180-
Dir::open_ambient_dir("/sysroot", ambient_authority()).context("Opening sysroot")?;
180+
let sysroot = &storage.physical_root;
181181

182182
let bootloader_entries = list_bootloader_entries()?;
183183
let images = list_erofs_images(&sysroot)?;
@@ -190,10 +190,10 @@ pub(crate) async fn composefs_gc() -> Result<()> {
190190

191191
let staged = &host.status.staged;
192192

193-
if img_bootloader_diff.contains(&&booted_cfs.verity) {
193+
if img_bootloader_diff.contains(&&booted_cfs_status.verity) {
194194
anyhow::bail!(
195195
"Inconsistent state. Booted entry '{}' found for cleanup",
196-
booted_cfs.verity
196+
booted_cfs_status.verity
197197
)
198198
}
199199

crates/lib/src/bootc_composefs/status.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use crate::{
1919
use std::str::FromStr;
2020

2121
use bootc_utils::try_deserialize_timestamp;
22-
use cap_std_ext::cap_std::ambient_authority;
2322
use cap_std_ext::cap_std::fs::Dir;
2423
use ostree_container::OstreeImageReference;
2524
use ostree_ext::container::deploy::ORIGIN_CONTAINER;
@@ -247,16 +246,6 @@ async fn boot_entry_from_composefs_deployment(
247246
return Ok(e);
248247
}
249248

250-
pub(crate) async fn composefs_deployment_status() -> Result<Host> {
251-
let composefs_state = composefs_booted()?
252-
.ok_or_else(|| anyhow::anyhow!("Failed to find composefs parameter in kernel cmdline"))?;
253-
254-
let sysroot =
255-
Dir::open_ambient_dir("/sysroot", ambient_authority()).context("Opening sysroot")?;
256-
257-
composefs_deployment_status_from(&sysroot, composefs_state).await
258-
}
259-
260249
/// Get composefs status using provided storage and booted composefs data
261250
/// instead of scraping global state.
262251
#[context("Getting composefs deployment status")]

crates/lib/src/cli.rs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,9 +1146,7 @@ async fn rollback(opts: &RollbackOpts) -> Result<()> {
11461146
BootedStorageKind::Ostree(booted_ostree) => {
11471147
rollback_ostree(opts, storage, &booted_ostree).await
11481148
}
1149-
BootedStorageKind::Composefs(booted_cfs) => {
1150-
composefs_rollback(storage, &booted_cfs).await
1151-
}
1149+
BootedStorageKind::Composefs(booted_cfs) => composefs_rollback(storage, &booted_cfs).await,
11521150
}
11531151
}
11541152

@@ -1628,9 +1626,29 @@ async fn run_from_opt(opt: Opt) -> Result<()> {
16281626
}
16291627
},
16301628

1631-
Opt::ComposefsFinalizeStaged => composefs_backend_finalize().await,
1629+
Opt::ComposefsFinalizeStaged => {
1630+
let storage = &get_storage().await?;
1631+
match storage.kind()? {
1632+
BootedStorageKind::Ostree(_) => {
1633+
anyhow::bail!("ComposefsFinalizeStaged is only supported for composefs backend")
1634+
}
1635+
BootedStorageKind::Composefs(booted_cfs) => {
1636+
composefs_backend_finalize(storage, &booted_cfs).await
1637+
}
1638+
}
1639+
}
16321640

1633-
Opt::ConfigDiff => get_etc_diff().await,
1641+
Opt::ConfigDiff => {
1642+
let storage = &get_storage().await?;
1643+
match storage.kind()? {
1644+
BootedStorageKind::Ostree(_) => {
1645+
anyhow::bail!("ConfigDiff is only supported for composefs backend")
1646+
}
1647+
BootedStorageKind::Composefs(booted_cfs) => {
1648+
get_etc_diff(storage, &booted_cfs).await
1649+
}
1650+
}
1651+
}
16341652

16351653
Opt::DeleteDeployment { depl_id } => {
16361654
let storage = &get_storage().await?;

crates/lib/src/status.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use ostree_ext::sysroot::SysrootLock;
1919

2020
use ostree_ext::ostree;
2121

22-
use crate::bootc_composefs::status::composefs_deployment_status;
2322
use crate::cli::OutputFormat;
2423
use crate::spec::BootEntryComposefs;
2524
use crate::spec::ImageStatus;
@@ -376,7 +375,9 @@ async fn get_host() -> Result<Host> {
376375
let (_deployments, host) = get_status(&booted_ostree)?;
377376
host
378377
}
379-
crate::store::BootedStorageKind::Composefs(_) => composefs_deployment_status().await?,
378+
crate::store::BootedStorageKind::Composefs(booted_cfs) => {
379+
crate::bootc_composefs::status::get_composefs_status(&storage, &booted_cfs).await?
380+
}
380381
}
381382
} else {
382383
Default::default()

0 commit comments

Comments
 (0)