Skip to content

Commit 0401db4

Browse files
Johan-Liebert1cgwalters
authored andcommitted
composefs/gc: Run GC for BLS/UKI binaries on finalize
On finalize, after we are done atomically exchanging staged bootloader entries with the current one, run GC for bootloader binaries that are no longer referenced We only GC the bootloader binaries and we do not touch the composefs repository as that can turn out to be quite expensive. The repo will be pruned in the next update/switch Signed-off-by: Pragyan Poudyal <pragyanpoudyal41999@gmail.com>
1 parent 056cf59 commit 0401db4

5 files changed

Lines changed: 18 additions & 4 deletions

File tree

crates/lib/src/bootc_composefs/delete.rs

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

262262
delete_depl_boot_entries(&depl_to_del, &storage, deleting_staged)?;
263263

264-
composefs_gc(storage, booted_cfs, true).await?;
264+
composefs_gc(storage, booted_cfs, false, true).await?;
265265

266266
Ok(())
267267
}

crates/lib/src/bootc_composefs/finalize.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::path::Path;
22

33
use crate::bootc_composefs::boot::BootType;
4+
use crate::bootc_composefs::gc::composefs_gc;
45
use crate::bootc_composefs::rollback::{rename_exchange_bls_entries, rename_exchange_user_cfg};
56
use crate::bootc_composefs::status::get_composefs_status;
67
use crate::composefs_consts::STATE_DIR_ABS;
@@ -123,7 +124,6 @@ pub(crate) async fn composefs_backend_finalize(
123124

124125
let boot_dir = storage.require_boot_dir()?;
125126

126-
// NOTE: Assuming here we won't have two bootloaders at the same time
127127
match booted_composefs.bootloader {
128128
Bootloader::Grub => match staged_composefs.boot_type {
129129
BootType::Bls => {
@@ -141,6 +141,10 @@ pub(crate) async fn composefs_backend_finalize(
141141
Bootloader::None => unreachable!("Checked at install time"),
142142
};
143143

144+
// Now that we have successfully updated bootloader entires, we can GC the unreferenced ones
145+
// We do not prune the composefs repository here though
146+
composefs_gc(storage, booted_cfs, false, false).await?;
147+
144148
Ok(())
145149
}
146150

crates/lib/src/bootc_composefs/gc.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ pub(crate) async fn composefs_gc(
213213
storage: &Storage,
214214
booted_cfs: &BootedComposefs,
215215
dry_run: bool,
216+
prune_repo: bool,
216217
) -> Result<GcResult> {
217218
const COMPOSEFS_GC_JOURNAL_ID: &str = "3b2a1f0e9d8c7b6a5f4e3d2c1b0a9f8e7";
218219

@@ -288,6 +289,10 @@ pub(crate) async fn composefs_gc(
288289
}
289290
}
290291

292+
if !prune_repo {
293+
return Ok(GcResult::default());
294+
}
295+
291296
// Identify orphaned deployments: state dirs or bootloader entries
292297
// that don't correspond to a live deployment. EROFS images in
293298
// composefs/images/ are NOT managed here — repo.gc() handles those

crates/lib/src/bootc_composefs/update.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ pub(crate) async fn do_upgrade(
324324

325325
// We take into account the staged bootloader entries so this won't remove
326326
// the currently staged entry
327-
composefs_gc(storage, booted_cfs, false).await?;
327+
composefs_gc(storage, booted_cfs, false, true).await?;
328328

329329
apply_upgrade(storage, booted_cfs, &id.to_hex(), opts).await
330330
}

crates/lib/src/cli.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,9 @@ pub(crate) enum InternalsOpts {
725725
/// Implies `--dry-run`. Intended for use in tests and health-checks.
726726
#[clap(long)]
727727
assert_no_op: bool,
728+
/// Prune the composefs repository in addition to boot binaries
729+
#[clap(long)]
730+
prune_repo: bool,
728731
},
729732
/// Block device inspection tools.
730733
#[clap(subcommand)]
@@ -2214,6 +2217,7 @@ async fn run_from_opt(opt: Opt) -> Result<()> {
22142217
InternalsOpts::ComposefsGC {
22152218
dry_run,
22162219
assert_no_op,
2220+
prune_repo,
22172221
} => {
22182222
let storage = &get_storage().await?;
22192223

@@ -2225,7 +2229,8 @@ async fn run_from_opt(opt: Opt) -> Result<()> {
22252229
BootedStorageKind::Composefs(booted_cfs) => {
22262230
let effective_dry_run = dry_run || assert_no_op;
22272231
let gc_result =
2228-
composefs_gc(storage, &booted_cfs, effective_dry_run).await?;
2232+
composefs_gc(storage, &booted_cfs, effective_dry_run, prune_repo)
2233+
.await?;
22292234

22302235
if effective_dry_run {
22312236
println!("Dry run (no files deleted)");

0 commit comments

Comments
 (0)