Skip to content

Commit

Permalink
Ensure container image layers are pruned
Browse files Browse the repository at this point in the history
I was debugging something else and stumbled into this; not
heavily tested yet but I think this was a regression from
2ed82ee
  • Loading branch information
cgwalters committed Dec 8, 2023
1 parent fc39c53 commit 9047b0c
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 9 deletions.
38 changes: 35 additions & 3 deletions rpmostree-cxxrs.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1294,6 +1294,7 @@ enum class BubblewrapMutability : ::std::uint8_t;
struct Bubblewrap;
struct ContainerImageState;
struct ExportedManifestDiff;
struct PrunedContainerInfo;
enum class RefspecType : ::std::uint8_t;
struct TempEtcGuard;
struct FilesystemScriptPrep;
Expand Down Expand Up @@ -1438,6 +1439,19 @@ struct ContainerImageState final
};
#endif // CXXBRIDGE1_STRUCT_rpmostreecxx$ContainerImageState

#ifndef CXXBRIDGE1_STRUCT_rpmostreecxx$PrunedContainerInfo
#define CXXBRIDGE1_STRUCT_rpmostreecxx$PrunedContainerInfo
struct PrunedContainerInfo final
{
::std::uint32_t images;
::std::uint32_t layers;

bool operator== (PrunedContainerInfo const &) const noexcept;
bool operator!= (PrunedContainerInfo const &) const noexcept;
using IsRelocatable = ::std::true_type;
};
#endif // CXXBRIDGE1_STRUCT_rpmostreecxx$PrunedContainerInfo

#ifndef CXXBRIDGE1_ENUM_rpmostreecxx$RefspecType
#define CXXBRIDGE1_ENUM_rpmostreecxx$RefspecType
enum class RefspecType : ::std::uint8_t
Expand Down Expand Up @@ -2084,13 +2098,17 @@ extern "C"

::rust::repr::PtrLen
rpmostreecxx$cxxbridge1$deploy_from_self_entrypoint (::rust::Vec< ::rust::String> *args) noexcept;
bool
rpmostreecxx$cxxbridge1$PrunedContainerInfo$operator$eq (PrunedContainerInfo const &,
PrunedContainerInfo const &) noexcept;

::rust::repr::PtrLen rpmostreecxx$cxxbridge1$pull_container (
::rpmostreecxx::OstreeRepo const &repo, ::rpmostreecxx::GCancellable const &cancellable,
::rust::Str imgref, ::rust::Box< ::rpmostreecxx::ContainerImageState> *return$) noexcept;

::rust::repr::PtrLen
rpmostreecxx$cxxbridge1$container_prune (::rpmostreecxx::OstreeSysroot const &sysroot) noexcept;
rpmostreecxx$cxxbridge1$container_prune (::rpmostreecxx::OstreeSysroot const &sysroot,
::rpmostreecxx::PrunedContainerInfo *return$) noexcept;

::rust::repr::PtrLen rpmostreecxx$cxxbridge1$query_container_image_commit (
::rpmostreecxx::OstreeRepo const &repo, ::rust::Str c,
Expand Down Expand Up @@ -3682,6 +3700,18 @@ deploy_from_self_entrypoint (::rust::Vec< ::rust::String> args)
}
}

bool
PrunedContainerInfo::operator== (PrunedContainerInfo const &rhs) const noexcept
{
return rpmostreecxx$cxxbridge1$PrunedContainerInfo$operator$eq (*this, rhs);
}

bool
PrunedContainerInfo::operator!= (PrunedContainerInfo const &rhs) const noexcept
{
return !(*this == rhs);
}

::rust::Box< ::rpmostreecxx::ContainerImageState>
pull_container (::rpmostreecxx::OstreeRepo const &repo,
::rpmostreecxx::GCancellable const &cancellable, ::rust::Str imgref)
Expand All @@ -3696,14 +3726,16 @@ pull_container (::rpmostreecxx::OstreeRepo const &repo,
return ::std::move (return$.value);
}

void
::rpmostreecxx::PrunedContainerInfo
container_prune (::rpmostreecxx::OstreeSysroot const &sysroot)
{
::rust::repr::PtrLen error$ = rpmostreecxx$cxxbridge1$container_prune (sysroot);
::rust::MaybeUninit< ::rpmostreecxx::PrunedContainerInfo> return$;
::rust::repr::PtrLen error$ = rpmostreecxx$cxxbridge1$container_prune (sysroot, &return$.value);
if (error$.ptr)
{
throw ::rust::impl< ::rust::Error>::error (error$);
}
return ::std::move (return$.value);
}

::rust::Box< ::rpmostreecxx::ContainerImageState>
Expand Down
16 changes: 15 additions & 1 deletion rpmostree-cxxrs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,7 @@ enum class BubblewrapMutability : ::std::uint8_t;
struct Bubblewrap;
struct ContainerImageState;
struct ExportedManifestDiff;
struct PrunedContainerInfo;
enum class RefspecType : ::std::uint8_t;
struct TempEtcGuard;
struct FilesystemScriptPrep;
Expand Down Expand Up @@ -1220,6 +1221,19 @@ struct ContainerImageState final
};
#endif // CXXBRIDGE1_STRUCT_rpmostreecxx$ContainerImageState

#ifndef CXXBRIDGE1_STRUCT_rpmostreecxx$PrunedContainerInfo
#define CXXBRIDGE1_STRUCT_rpmostreecxx$PrunedContainerInfo
struct PrunedContainerInfo final
{
::std::uint32_t images;
::std::uint32_t layers;

bool operator== (PrunedContainerInfo const &) const noexcept;
bool operator!= (PrunedContainerInfo const &) const noexcept;
using IsRelocatable = ::std::true_type;
};
#endif // CXXBRIDGE1_STRUCT_rpmostreecxx$PrunedContainerInfo

#ifndef CXXBRIDGE1_ENUM_rpmostreecxx$RefspecType
#define CXXBRIDGE1_ENUM_rpmostreecxx$RefspecType
enum class RefspecType : ::std::uint8_t
Expand Down Expand Up @@ -1793,7 +1807,7 @@ ::rust::Box< ::rpmostreecxx::ContainerImageState>
pull_container (::rpmostreecxx::OstreeRepo const &repo,
::rpmostreecxx::GCancellable const &cancellable, ::rust::Str imgref);

void container_prune (::rpmostreecxx::OstreeSysroot const &sysroot);
::rpmostreecxx::PrunedContainerInfo container_prune (::rpmostreecxx::OstreeSysroot const &sysroot);

::rust::Box< ::rpmostreecxx::ContainerImageState>
query_container_image_commit (::rpmostreecxx::OstreeRepo const &repo, ::rust::Str c);
Expand Down
8 changes: 7 additions & 1 deletion rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,20 @@ pub mod ffi {
pub added_size: u64,
}

#[derive(Debug, PartialEq, Eq)]
struct PrunedContainerInfo {
images: u32,
layers: u32,
}

// sysroot_upgrade.rs
extern "Rust" {
fn pull_container(
repo: &OstreeRepo,
cancellable: &GCancellable,
imgref: &str,
) -> Result<Box<ContainerImageState>>;
fn container_prune(sysroot: &OstreeSysroot) -> Result<()>;
fn container_prune(sysroot: &OstreeSysroot) -> Result<PrunedContainerInfo>;
fn query_container_image_commit(
repo: &OstreeRepo,
c: &str,
Expand Down
11 changes: 8 additions & 3 deletions rust/src/sysroot_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,18 @@ pub(crate) fn pull_container(
}

/// Run a prune of container images that are not referenced by a deployment.
pub(crate) fn container_prune(sysroot: &crate::FFIOstreeSysroot) -> CxxResult<()> {
pub(crate) fn container_prune(
sysroot: &crate::FFIOstreeSysroot,
) -> CxxResult<crate::ffi::PrunedContainerInfo> {
let sysroot = &sysroot.glib_reborrow();
tracing::debug!("Pruning container images");
crate::try_fail_point!("sysroot-upgrade::container-prune");
let sysroot = &ostree_ext::sysroot::SysrootLock::from_assumed_locked(sysroot);
ostree_container::deploy::remove_undeployed_images(sysroot).context("Pruning images")?;
Ok(())
let images = ostree_container::deploy::remove_undeployed_images(sysroot)
.context("Pruning images")?
.len() as u32;
let layers = ostree_container::store::gc_image_layers(&sysroot.repo())?;
Ok(crate::ffi::PrunedContainerInfo { images, layers })
}

/// C++ wrapper for querying image state; requires a pulled image
Expand Down
7 changes: 6 additions & 1 deletion src/daemon/rpmostree-sysroot-core.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,12 @@ rpmostree_syscore_cleanup (OstreeSysroot *sysroot, OstreeRepo *repo, GCancellabl
/* Refs for the live state */
ROSCXX_TRY (applylive_sync_ref (*sysroot), error);

CXX_TRY (rpmostreecxx::container_prune (*sysroot), error);
CXX_TRY_VAR (image_pruned, rpmostreecxx::container_prune (*sysroot), error);
if (image_pruned.images > 0 || image_pruned.layers > 0)
{
rpmostree_output_message ("Pruned images: %u (layers: %u)", image_pruned.images,
image_pruned.layers);
}

/* And do a prune */
guint64 freed_space;
Expand Down

0 comments on commit 9047b0c

Please sign in to comment.