From e2aee762c0a63d8c6630c3b0a8f761002376dfa3 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Thu, 10 Nov 2022 08:33:52 -0500 Subject: [PATCH] daemon: Query container image commit If a container image reference is pruned, we must not error out when computing the status. The deployment roots will hold a strong reference to the deployed commit, so query via the commit digest to find metadata about the pulled container image. --- rpmostree-cxxrs.cxx | 8 ++++---- rpmostree-cxxrs.h | 2 +- rust/src/lib.rs | 4 ++-- rust/src/sysroot_upgrade.rs | 8 +++----- src/daemon/rpmostreed-deployment-utils.cxx | 2 +- 5 files changed, 11 insertions(+), 13 deletions(-) diff --git a/rpmostree-cxxrs.cxx b/rpmostree-cxxrs.cxx index 3e1d64a1a4..9277eb0d16 100644 --- a/rpmostree-cxxrs.cxx +++ b/rpmostree-cxxrs.cxx @@ -2056,8 +2056,8 @@ extern "C" const ::rpmostreecxx::OstreeRepo &repo, const ::rpmostreecxx::GCancellable &cancellable, ::rust::Str imgref, ::rust::Box< ::rpmostreecxx::ContainerImageState> *return$) noexcept; - ::rust::repr::PtrLen rpmostreecxx$cxxbridge1$query_container_image ( - const ::rpmostreecxx::OstreeRepo &repo, ::rust::Str imgref, + ::rust::repr::PtrLen rpmostreecxx$cxxbridge1$query_container_image_commit ( + const ::rpmostreecxx::OstreeRepo &repo, ::rust::Str c, ::rust::Box< ::rpmostreecxx::ContainerImageState> *return$) noexcept; ::std::size_t rpmostreecxx$cxxbridge1$TempEtcGuard$operator$sizeof () noexcept; ::std::size_t rpmostreecxx$cxxbridge1$TempEtcGuard$operator$alignof () noexcept; @@ -3606,11 +3606,11 @@ pull_container (const ::rpmostreecxx::OstreeRepo &repo, } ::rust::Box< ::rpmostreecxx::ContainerImageState> -query_container_image (const ::rpmostreecxx::OstreeRepo &repo, ::rust::Str imgref) +query_container_image_commit (const ::rpmostreecxx::OstreeRepo &repo, ::rust::Str c) { ::rust::MaybeUninit< ::rust::Box< ::rpmostreecxx::ContainerImageState> > return$; ::rust::repr::PtrLen error$ - = rpmostreecxx$cxxbridge1$query_container_image (repo, imgref, &return$.value); + = rpmostreecxx$cxxbridge1$query_container_image_commit (repo, c, &return$.value); if (error$.ptr) { throw ::rust::impl< ::rust::Error>::error (error$); diff --git a/rpmostree-cxxrs.h b/rpmostree-cxxrs.h index 019af084da..8279b4e39b 100644 --- a/rpmostree-cxxrs.h +++ b/rpmostree-cxxrs.h @@ -1762,7 +1762,7 @@ pull_container (const ::rpmostreecxx::OstreeRepo &repo, const ::rpmostreecxx::GCancellable &cancellable, ::rust::Str imgref); ::rust::Box< ::rpmostreecxx::ContainerImageState> -query_container_image (const ::rpmostreecxx::OstreeRepo &repo, ::rust::Str imgref); +query_container_image_commit (const ::rpmostreecxx::OstreeRepo &repo, ::rust::Str c); ::rust::Box< ::rpmostreecxx::TempEtcGuard> prepare_tempetc_guard (::std::int32_t rootfs); diff --git a/rust/src/lib.rs b/rust/src/lib.rs index dcee55cb02..7dad68260d 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -195,9 +195,9 @@ pub mod ffi { cancellable: &GCancellable, imgref: &str, ) -> Result>; - fn query_container_image( + fn query_container_image_commit( repo: &OstreeRepo, - imgref: &str, + c: &str, ) -> Result>; } diff --git a/rust/src/sysroot_upgrade.rs b/rust/src/sysroot_upgrade.rs index 4d6e517522..790bdd1e10 100644 --- a/rust/src/sysroot_upgrade.rs +++ b/rust/src/sysroot_upgrade.rs @@ -146,13 +146,11 @@ pub(crate) fn pull_container( } /// C++ wrapper for querying image state; requires a pulled image -pub(crate) fn query_container_image( +pub(crate) fn query_container_image_commit( repo: &crate::FFIOstreeRepo, - imgref: &str, + imgcommit: &str, ) -> CxxResult> { let repo = &repo.glib_reborrow(); - let imgref = &OstreeImageReference::try_from(imgref)?; - let state = ostree_container::store::query_image(repo, imgref)? - .ok_or_else(|| anyhow::anyhow!("Failed to find image {}", imgref))?; + let state = ostree_container::store::query_image_commit(repo, imgcommit)?; Ok(Box::new(state.into())) } diff --git a/src/daemon/rpmostreed-deployment-utils.cxx b/src/daemon/rpmostreed-deployment-utils.cxx index 119546dbb1..a04c72a9f7 100644 --- a/src/daemon/rpmostreed-deployment-utils.cxx +++ b/src/daemon/rpmostreed-deployment-utils.cxx @@ -214,7 +214,7 @@ rpmostreed_deployment_generate_variant (OstreeSysroot *sysroot, OstreeDeployment case rpmostreecxx::RefspecType::Container: { g_variant_dict_insert (dict, "container-image-reference", "s", refspec); - CXX_TRY_VAR (state, rpmostreecxx::query_container_image (*repo, refspec), error); + CXX_TRY_VAR (state, rpmostreecxx::query_container_image_commit (*repo, base_checksum), error); g_variant_dict_insert (dict, "container-image-reference-digest", "s", state->image_digest.c_str ()); if (state->version.size () > 0)