Skip to content

Commit eebb1fe

Browse files
shi2wei3Johan-Liebert1
authored andcommitted
composefs: add pre-flight disk space check for native backend
The previous commit (7196079) added a pre-flight disk space check for the ostree and ostree+unified-storage backend paths. This commit extends the same protection to the native composefs backend. - Rename check_disk_space_composefs -> check_disk_space_unified for the ostree unified-storage path (uses PreparedImportMeta), to clarify that this variant is not used by the native composefs backend. - Add check_disk_space_composefs for the native composefs backend: sums layer sizes from the raw ImageManifest and calls fstatvfs on the composefs objects directory to verify available space before pulling. - Call check_disk_space_composefs in do_upgrade() (covers bootc upgrade and bootc switch on the native composefs backend), reusing the already-opened composefs repo from booted_cfs.repo. - Call check_disk_space_composefs in install_to_filesystem_impl() before initialize_composefs_repository() (covers bootc install --composefs-backend). Note: ensure_composefs_dir() is called first to create the objects directory if it does not yet exist on the fresh install target. - Enable the existing pre-flight disk check tmt test for the composefs backend (remove fixme_skip_if_composefs). Note: the check uses compressed layer sizes from the manifest, which is a lower bound of actual disk usage (composefs stores decompressed content). This is consistent with the ostree path and the broader container ecosystem, as uncompressed sizes are not available in the OCI manifest without downloading layers. Assisted-by: AI Signed-off-by: Wei Shi <wshi@redhat.com>
1 parent 42e2db3 commit eebb1fe

File tree

5 files changed

+48
-9
lines changed

5 files changed

+48
-9
lines changed

crates/lib/src/bootc_composefs/update.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,13 @@ pub(crate) async fn do_upgrade(
255255
) -> Result<()> {
256256
start_finalize_stated_svc()?;
257257

258+
// Pre-flight disk space check before pulling any data.
259+
crate::deploy::check_disk_space_composefs(
260+
&booted_cfs.repo,
261+
&img_manifest_config.manifest,
262+
imgref,
263+
)?;
264+
258265
let (repo, entries, id, fs) = pull_composefs_repo(
259266
&imgref.transport,
260267
&imgref.image,

crates/lib/src/deploy.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,15 +411,31 @@ pub(crate) fn check_disk_space_ostree(
411411
)
412412
}
413413

414-
/// Verify there is sufficient disk space to pull an image into the composefs store.
415-
pub(crate) fn check_disk_space_composefs(
414+
/// Verify there is sufficient disk space to pull an image into the composefs store
415+
/// via the ostree unified-storage path (uses `PreparedImportMeta`).
416+
pub(crate) fn check_disk_space_unified(
416417
cfs: &crate::store::ComposefsRepository,
417418
image_meta: &PreparedImportMeta,
418419
imgref: &ImageReference,
419420
) -> Result<()> {
420421
check_disk_space_inner(cfs.objects_dir()?, image_meta.bytes_to_fetch, 0, imgref)
421422
}
422423

424+
/// Verify there is sufficient disk space to pull an image into the composefs store
425+
/// for the native composefs backend (uses a raw `ImageManifest`).
426+
pub(crate) fn check_disk_space_composefs(
427+
cfs: &crate::store::ComposefsRepository,
428+
manifest: &ostree_ext::oci_spec::image::ImageManifest,
429+
imgref: &ImageReference,
430+
) -> Result<()> {
431+
let bytes_to_fetch: u64 = manifest
432+
.layers()
433+
.iter()
434+
.map(|l: &ostree_ext::oci_spec::image::Descriptor| l.size())
435+
.sum();
436+
check_disk_space_inner(cfs.objects_dir()?, bytes_to_fetch, 0, imgref)
437+
}
438+
423439
pub(crate) struct PreparedImportMeta {
424440
pub imp: ImageImporter,
425441
pub prep: Box<PreparedImport>,
@@ -609,7 +625,7 @@ pub(crate) async fn pull_unified(
609625
Ok(existing)
610626
}
611627
PreparedPullResult::Ready(prepared_image_meta) => {
612-
check_disk_space_composefs(
628+
check_disk_space_unified(
613629
store.get_ensure_composefs()?.as_ref(),
614630
&prepared_image_meta,
615631
imgref,

crates/lib/src/install.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,11 @@ use serde::{Deserialize, Serialize};
188188
#[cfg(feature = "install-to-disk")]
189189
use self::baseline::InstallBlockDeviceOpts;
190190
use crate::bootc_composefs::status::ComposefsCmdline;
191-
use crate::bootc_composefs::{boot::setup_composefs_boot, repo::initialize_composefs_repository};
191+
use crate::bootc_composefs::{
192+
boot::setup_composefs_boot,
193+
repo::{get_imgref, initialize_composefs_repository, open_composefs_repo},
194+
status::get_container_manifest_and_config,
195+
};
192196
use crate::boundimage::{BoundImage, ResolvedBoundImage};
193197
use crate::containerenv::ContainerExecutionInfo;
194198
use crate::deploy::{MergeState, PreparedPullResult, prepare_for_pull, pull_from_prepared};
@@ -1951,8 +1955,23 @@ async fn install_to_filesystem_impl(
19511955
}
19521956

19531957
if state.composefs_options.composefs_backend {
1954-
// Load a fd for the mounted target physical root
1955-
1958+
// Pre-flight disk space check for native composefs install path.
1959+
{
1960+
let imgref = &state.source.imageref;
1961+
let imgref_repr = get_imgref(&imgref.transport.to_string(), &imgref.name);
1962+
let img_manifest_config = get_container_manifest_and_config(&imgref_repr).await?;
1963+
crate::store::ensure_composefs_dir(&rootfs.physical_root)?;
1964+
let cfs_repo = open_composefs_repo(&rootfs.physical_root)?;
1965+
crate::deploy::check_disk_space_composefs(
1966+
&cfs_repo,
1967+
&img_manifest_config.manifest,
1968+
&crate::spec::ImageReference {
1969+
image: imgref.name.clone(),
1970+
transport: imgref.transport.to_string(),
1971+
signature: None,
1972+
},
1973+
)?;
1974+
}
19561975
let pull_result = initialize_composefs_repository(
19571976
state,
19581977
rootfs,

tmt/plans/integration.fmf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@ execute:
201201
how: fmf
202202
test:
203203
- /tmt/tests/tests/test-35-upgrade-preflight-disk-check
204-
extra-fixme_skip_if_composefs: true
205204

206205
/plan-36-rollback:
207206
summary: Test bootc rollback functionality

tmt/tests/booted/test-upgrade-preflight-disk-check.nu

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
# tmt:
33
# summary: Verify pre-flight disk space check rejects images with inflated layer sizes
44
# duration: 10m
5-
# extra:
6-
# fixme_skip_if_composefs: true
75
#
86
# This test does NOT require a reboot.
97
# It constructs a minimal fake OCI image directory that claims to have an

0 commit comments

Comments
 (0)