From c9d0850140b783daed8979d6a1d056d5483a693f Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Wed, 26 May 2021 15:07:52 -0400 Subject: [PATCH] Use new `ostree_commit_metadata_for_bootable()` API I planned to use this as part of doing live diffs, e.g. to notice the kernel changed between commits. But also, at some point I'd like to add `ostree.architecture` there to obsolete the cosa-specific `coreos-assembler.basearch` so that multiple buildsystems and consumers can use that. (That said, they can also just use `$(arch)` today) --- ci/composepost-checks.sh | 4 ++++ packaging/rpm-ostree.spec.in | 2 +- src/libpriv/rpmostree-core.cxx | 9 ++++++++- src/libpriv/rpmostree-postprocess.cxx | 8 +++++++- tests/kolainst/destructive/layering-local | 7 ++++++- 5 files changed, 26 insertions(+), 4 deletions(-) diff --git a/ci/composepost-checks.sh b/ci/composepost-checks.sh index a3cf6f99..e3ea0590 100755 --- a/ci/composepost-checks.sh +++ b/ci/composepost-checks.sh @@ -26,3 +26,7 @@ ostree --repo="${repo}" ls -R "${ref}" /usr/lib/modules > tmp/modules-lsr.txt assert_file_has_content tmp/modules-lsr.txt '/vmlinuz$' assert_file_has_content tmp/modules-lsr.txt '/initramfs.img$' echo "ok boot location modules" + +ostree --repo="${repo}" show --print-metadata-key=ostree.bootable "${ref}" >out.txt +assert_file_has_content_literal out.txt 'true' +echo "ok bootable metadata" diff --git a/packaging/rpm-ostree.spec.in b/packaging/rpm-ostree.spec.in index b75b6dd9..2b7cbfc0 100644 --- a/packaging/rpm-ostree.spec.in +++ b/packaging/rpm-ostree.spec.in @@ -49,7 +49,7 @@ BuildRequires: gnome-common BuildRequires: /usr/bin/g-ir-scanner # Core requirements # One way to check this: `objdump -p /path/to/rpm-ostree | grep LIBOSTREE` and pick the highest (though that might miss e.g. new struct members) -BuildRequires: pkgconfig(ostree-1) >= 2020.7 +BuildRequires: pkgconfig(ostree-1) >= 2021.1 BuildRequires: pkgconfig(polkit-gobject-1) BuildRequires: pkgconfig(json-glib-1.0) BuildRequires: pkgconfig(rpm) >= 4.16.0 diff --git a/src/libpriv/rpmostree-core.cxx b/src/libpriv/rpmostree-core.cxx index 0938cd35..bea40ca5 100644 --- a/src/libpriv/rpmostree-core.cxx +++ b/src/libpriv/rpmostree-core.cxx @@ -4604,7 +4604,14 @@ rpmostree_context_commit (RpmOstreeContext *self, if (!ostree_repo_write_mtree (self->ostreerepo, mtree, &root, cancellable, error)) return FALSE; - { g_autoptr(GVariant) metadata = g_variant_ref_sink (g_variant_builder_end (&metadata_builder)); + g_autoptr(GVariant) metadata_so_far = g_variant_ref_sink (g_variant_builder_end (&metadata_builder)); + // Unfortunately this API takes GVariantDict, not GVariantBuilder, so convert + g_autoptr(GVariantDict) metadata_dict = g_variant_dict_new (metadata_so_far); + if (!ostree_commit_metadata_for_bootable (root, metadata_dict, cancellable, error)) + return FALSE; + g_autoptr(GVariant) metadata = g_variant_dict_end (metadata_dict); + + { if (!ostree_repo_write_commit (self->ostreerepo, parent, "", "", metadata, OSTREE_REPO_FILE (root), diff --git a/src/libpriv/rpmostree-postprocess.cxx b/src/libpriv/rpmostree-postprocess.cxx index c2a471a3..42aa0b56 100644 --- a/src/libpriv/rpmostree-postprocess.cxx +++ b/src/libpriv/rpmostree-postprocess.cxx @@ -839,7 +839,7 @@ gboolean rpmostree_compose_commit (int rootfs_fd, OstreeRepo *repo, const char *parent_revision, - GVariant *metadata, + GVariant *src_metadata, const char *gpg_keyid, gboolean enable_selinux, OstreeRepoDevInoCache *devino_cache, @@ -918,6 +918,12 @@ rpmostree_compose_commit (int rootfs_fd, if (!ostree_repo_write_mtree (repo, mtree, &root_tree, cancellable, error)) return glnx_prefix_error (error, "While writing tree"); + // Unfortunately this API takes GVariantDict, not GVariantBuilder, so convert + g_autoptr(GVariantDict) metadata_dict = g_variant_dict_new (src_metadata); + if (!ostree_commit_metadata_for_bootable (root_tree, metadata_dict, cancellable, error)) + return FALSE; + g_autoptr(GVariant) metadata = g_variant_dict_end (metadata_dict); + g_autofree char *new_revision = NULL; if (!ostree_repo_write_commit (repo, parent_revision, "", "", metadata, (OstreeRepoFile*)root_tree, &new_revision, diff --git a/tests/kolainst/destructive/layering-local b/tests/kolainst/destructive/layering-local index 21b6a3b3..bdd4d366 100755 --- a/tests/kolainst/destructive/layering-local +++ b/tests/kolainst/destructive/layering-local @@ -55,6 +55,12 @@ rpmostree_assert_status '.deployments[0]["packages"]|length == 0' \ assert_streq $(rpm -q foo) foo-1.2-3.x86_64 echo "ok pkg foo added locally" +booted_commit=$(rpm-ostree status --json | jq -r '.deployments[0].checksum') + +ostree show --print-metadata-key=ostree.bootable ${booted_commit} >out.txt +assert_file_has_content_literal out.txt 'true' +echo "ok bootable metadata" + # check we could uninstall the package using either its NEVRA or name rpm-ostree uninstall foo-1.2-3.x86_64 rpmostree_assert_status '.deployments[0]["requested-local-packages"]|length == 0' @@ -81,7 +87,6 @@ rpmostree_assert_status '.deployments[0]["packages"]|length == 1' \ echo "ok layer foo back from repos" # check that trying to install a package already in the base errors out -booted_commit=$(rpm-ostree status --json | jq -r '.deployments[0].checksum') ostree refs ${booted_commit} --create vmcheck_tmp/with_foo ostree commit -b vmcheck --tree=ref=vmcheck_tmp/with_foo rpm-ostree uninstall foo