Skip to content

Commit 7173995

Browse files
committed
composefs: Pass BootedComposefs data down instead of scraping global state
Update composefs command functions to accept and use Storage and BootedComposefs parameters instead of calling composefs_deployment_status() which scrapes global state. Changes: - Add get_composefs_status(storage, booted_cfs) helper in status.rs - Update upgrade_composefs() to use passed composefs.repo and get_composefs_status() - Update switch_composefs() to accept and use storage/booted_cfs parameters - Update composefs_rollback() to use storage.physical_root for opening directories - Update delete_composefs_deployment() to accept and pass through parameters - Update CLI dispatchers to pass storage and booted_cfs to all composefs functions This eliminates composefs_deployment_status() calls from command functions, completing the pattern established with BootedOstree for ostree commands. Assisted-by: Claude Code (Sonnet 4.5) Signed-off-by: Colin Walters <[email protected]>
1 parent 6adf1db commit 7173995

File tree

6 files changed

+61
-25
lines changed

6 files changed

+61
-25
lines changed

crates/lib/src/bootc_composefs/delete.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::{
1717
gc::composefs_gc,
1818
repo::open_composefs_repo,
1919
rollback::{composefs_rollback, rename_exchange_user_cfg},
20-
status::{composefs_deployment_status, get_sorted_grub_uki_boot_entries},
20+
status::{get_composefs_status, get_sorted_grub_uki_boot_entries},
2121
},
2222
composefs_consts::{
2323
COMPOSEFS_STAGED_DEPLOYMENT_FNAME, COMPOSEFS_TRANSIENT_STATE_DIR, STATE_DIR_RELATIVE,
@@ -26,6 +26,7 @@ use crate::{
2626
parsers::bls_config::{parse_bls_config, BLSConfigType},
2727
spec::{BootEntry, Bootloader, DeploymentEntry},
2828
status::Slot,
29+
store::{BootedComposefs, Storage},
2930
};
3031

3132
#[fn_error_context::context("Deleting Type1 Entry {}", depl.deployment.verity)]
@@ -316,8 +317,12 @@ pub(crate) fn delete_staged(staged: &Option<BootEntry>) -> Result<()> {
316317
}
317318

318319
#[fn_error_context::context("Deleting composefs deployment {}", deployment_id)]
319-
pub(crate) async fn delete_composefs_deployment(deployment_id: &str) -> Result<()> {
320-
let host = composefs_deployment_status().await?;
320+
pub(crate) async fn delete_composefs_deployment(
321+
deployment_id: &str,
322+
storage: &Storage,
323+
booted_cfs: &BootedComposefs,
324+
) -> Result<()> {
325+
let host = get_composefs_status(storage, booted_cfs).await?;
321326

322327
let booted = host.require_composefs_booted()?;
323328

@@ -344,7 +349,7 @@ pub(crate) async fn delete_composefs_deployment(deployment_id: &str) -> Result<(
344349

345350
// Unqueue rollback. This makes it easier to delete boot entries later on
346351
if matches!(depl_to_del.ty, Some(Slot::Rollback)) && host.status.rollback_queued {
347-
composefs_rollback().await?;
352+
composefs_rollback(storage, booted_cfs).await?;
348353
}
349354

350355
let kind = if depl_to_del.pinned {

crates/lib/src/bootc_composefs/rollback.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use std::io::Write;
22

33
use anyhow::{anyhow, Context, Result};
4-
use cap_std_ext::cap_std::ambient_authority;
54
use cap_std_ext::cap_std::fs::Dir;
65
use cap_std_ext::dirext::CapStdExtDirExt;
76
use fn_error_context::context;
@@ -10,9 +9,10 @@ use rustix::fs::{fsync, renameat_with, AtFlags, RenameFlags};
109
use crate::bootc_composefs::boot::{
1110
get_esp_partition, get_sysroot_parent_dev, mount_esp, type1_entry_conf_file_name, BootType,
1211
};
13-
use crate::bootc_composefs::status::{composefs_deployment_status, get_sorted_type1_boot_entries};
12+
use crate::bootc_composefs::status::{get_composefs_status, get_sorted_type1_boot_entries};
1413
use crate::composefs_consts::TYPE1_ENT_PATH_STAGED;
1514
use crate::spec::Bootloader;
15+
use crate::store::{BootedComposefs, Storage};
1616
use crate::{
1717
bootc_composefs::{boot::get_efi_uuid_source, status::get_sorted_grub_uki_boot_entries},
1818
composefs_consts::{
@@ -164,8 +164,11 @@ fn rollback_composefs_entries(boot_dir: &Dir, bootloader: Bootloader) -> Result<
164164
}
165165

166166
#[context("Rolling back composefs")]
167-
pub(crate) async fn composefs_rollback() -> Result<()> {
168-
let host = composefs_deployment_status().await?;
167+
pub(crate) async fn composefs_rollback(
168+
storage: &Storage,
169+
booted_cfs: &BootedComposefs,
170+
) -> Result<()> {
171+
let host = get_composefs_status(storage, booted_cfs).await?;
169172

170173
let new_spec = {
171174
let mut new_spec = host.spec.clone();
@@ -195,7 +198,9 @@ pub(crate) async fn composefs_rollback() -> Result<()> {
195198

196199
match &rollback_entry.bootloader {
197200
Bootloader::Grub => {
198-
let boot_dir = Dir::open_ambient_dir("/sysroot/boot", ambient_authority())
201+
let boot_dir = storage
202+
.physical_root
203+
.open_dir("boot")
199204
.context("Opening boot dir")?;
200205

201206
match rollback_entry.boot_type {

crates/lib/src/bootc_composefs/status.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,16 @@ pub(crate) async fn composefs_deployment_status() -> Result<Host> {
257257
composefs_deployment_status_from(&sysroot, composefs_state).await
258258
}
259259

260+
/// Get composefs status using provided storage and booted composefs data
261+
/// instead of scraping global state.
262+
#[context("Getting composefs deployment status")]
263+
pub(crate) async fn get_composefs_status(
264+
storage: &crate::store::Storage,
265+
booted_cfs: &crate::store::BootedComposefs,
266+
) -> Result<Host> {
267+
composefs_deployment_status_from(&storage.physical_root, booted_cfs.cmdline).await
268+
}
269+
260270
#[context("Getting composefs deployment status")]
261271
pub(crate) async fn composefs_deployment_status_from(
262272
sysroot: &Dir,

crates/lib/src/bootc_composefs/switch.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,22 @@ use crate::{
88
repo::pull_composefs_repo,
99
service::start_finalize_stated_svc,
1010
state::write_composefs_state,
11-
status::composefs_deployment_status,
11+
status::get_composefs_status,
1212
},
1313
cli::{imgref_for_switch, SwitchOpts},
14+
store::{BootedComposefs, Storage},
1415
};
1516

1617
#[context("Composefs Switching")]
17-
pub(crate) async fn switch_composefs(opts: SwitchOpts) -> Result<()> {
18+
pub(crate) async fn switch_composefs(
19+
opts: SwitchOpts,
20+
storage: &Storage,
21+
booted_cfs: &BootedComposefs,
22+
) -> Result<()> {
1823
let target = imgref_for_switch(&opts)?;
1924
// TODO: Handle in-place
2025

21-
let host = composefs_deployment_status()
26+
let host = get_composefs_status(storage, booted_cfs)
2227
.await
2328
.context("Getting composefs deployment status")?;
2429

@@ -63,6 +68,7 @@ pub(crate) async fn switch_composefs(opts: SwitchOpts) -> Result<()> {
6368
}
6469
};
6570

71+
// TODO: Remove this hardcoded path when write_composefs_state accepts a Dir
6672
write_composefs_state(
6773
&Utf8PathBuf::from("/sysroot"),
6874
id,

crates/lib/src/bootc_composefs/update.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,16 @@ use ostree_ext::oci_spec::image::{ImageConfiguration, ImageManifest};
77
use crate::{
88
bootc_composefs::{
99
boot::{setup_composefs_bls_boot, setup_composefs_uki_boot, BootSetupType, BootType},
10-
repo::{get_imgref, open_composefs_repo, pull_composefs_repo},
10+
repo::{get_imgref, pull_composefs_repo},
1111
service::start_finalize_stated_svc,
1212
state::write_composefs_state,
13-
status::{composefs_deployment_status, get_container_manifest_and_config},
13+
status::{get_composefs_status, get_container_manifest_and_config},
1414
},
1515
cli::UpgradeOpts,
1616
spec::ImageReference,
1717
store::{BootedComposefs, ComposefsRepository, Storage},
1818
};
1919

20-
use cap_std_ext::cap_std::{ambient_authority, fs::Dir};
21-
2220
#[context("Getting SHA256 Digest for {id}")]
2321
pub fn str_to_sha256digest(id: &str) -> Result<Sha256Digest> {
2422
let id = id.strip_prefix("sha256:").unwrap_or(id);
@@ -63,10 +61,10 @@ async fn is_image_pulled(
6361
#[context("Upgrading composefs")]
6462
pub(crate) async fn upgrade_composefs(
6563
opts: UpgradeOpts,
66-
_storage: &Storage,
67-
_composefs: &BootedComposefs,
64+
storage: &Storage,
65+
composefs: &BootedComposefs,
6866
) -> Result<()> {
69-
let host = composefs_deployment_status()
67+
let host = get_composefs_status(storage, composefs)
7068
.await
7169
.context("Getting composefs deployment status")?;
7270

@@ -76,9 +74,7 @@ pub(crate) async fn upgrade_composefs(
7674
.as_ref()
7775
.ok_or_else(|| anyhow::anyhow!("No image source specified"))?;
7876

79-
let sysroot =
80-
Dir::open_ambient_dir("/sysroot", ambient_authority()).context("Opening sysroot")?;
81-
let repo = open_composefs_repo(&sysroot)?;
77+
let repo = &*composefs.repo;
8278

8379
let (img_pulled, mut manifest, mut config) = is_image_pulled(&repo, imgref).await?;
8480
let booted_img_digest = manifest.config().digest().digest();

crates/lib/src/cli.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,7 +1108,9 @@ async fn switch(opts: SwitchOpts) -> Result<()> {
11081108
BootedStorageKind::Ostree(booted_ostree) => {
11091109
switch_ostree(opts, storage, &booted_ostree).await
11101110
}
1111-
BootedStorageKind::Composefs(_) => switch_composefs(opts).await,
1111+
BootedStorageKind::Composefs(booted_cfs) => {
1112+
switch_composefs(opts, storage, &booted_cfs).await
1113+
}
11121114
}
11131115
}
11141116

@@ -1144,7 +1146,9 @@ async fn rollback(opts: &RollbackOpts) -> Result<()> {
11441146
BootedStorageKind::Ostree(booted_ostree) => {
11451147
rollback_ostree(opts, storage, &booted_ostree).await
11461148
}
1147-
BootedStorageKind::Composefs(_) => composefs_rollback().await,
1149+
BootedStorageKind::Composefs(booted_cfs) => {
1150+
composefs_rollback(storage, &booted_cfs).await
1151+
}
11481152
}
11491153
}
11501154

@@ -1628,7 +1632,17 @@ async fn run_from_opt(opt: Opt) -> Result<()> {
16281632

16291633
Opt::ConfigDiff => get_etc_diff().await,
16301634

1631-
Opt::DeleteDeployment { depl_id } => delete_composefs_deployment(&depl_id).await,
1635+
Opt::DeleteDeployment { depl_id } => {
1636+
let storage = &get_storage().await?;
1637+
match storage.kind()? {
1638+
BootedStorageKind::Ostree(_) => {
1639+
anyhow::bail!("DeleteDeployment is only supported for composefs backend")
1640+
}
1641+
BootedStorageKind::Composefs(booted_cfs) => {
1642+
delete_composefs_deployment(&depl_id, storage, &booted_cfs).await
1643+
}
1644+
}
1645+
}
16321646
}
16331647
}
16341648

0 commit comments

Comments
 (0)