From b248d1707e702d88baea0b241dedf162403dc743 Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Wed, 26 Feb 2020 11:14:53 -0500 Subject: [PATCH] initramfs: Use dracut args from commitmeta if available This is the second half of the previous commit. We check if the canonical dracut args are available in the commit metadata, and prefer those over using `--rebuild`. The latter is delegated as a backcompat fallback. --- src/daemon/rpmostree-sysroot-upgrader.c | 30 ++++++++++++++++++++++++- src/libpriv/rpmostree-kernel.c | 7 ++---- tests/vmcheck/test-override-kernel.sh | 4 ++++ 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/daemon/rpmostree-sysroot-upgrader.c b/src/daemon/rpmostree-sysroot-upgrader.c index f84e20c6c5..9908d53fdf 100644 --- a/src/daemon/rpmostree-sysroot-upgrader.c +++ b/src/daemon/rpmostree-sysroot-upgrader.c @@ -1060,6 +1060,7 @@ perform_local_assembly (RpmOstreeSysrootUpgrader *self, rpmostree_context_get_kernel_changed (self->ctx) || rpmostree_origin_get_regenerate_initramfs (self->origin); g_autoptr(GVariant) kernel_state = NULL; + g_autoptr(GPtrArray) initramfs_args = g_ptr_array_new_with_free_func (g_free); const char *bootdir = NULL; const char *kver = NULL; const char *kernel_path = NULL; @@ -1069,9 +1070,30 @@ perform_local_assembly (RpmOstreeSysrootUpgrader *self, kernel_state = rpmostree_find_kernel (self->tmprootfs_dfd, cancellable, error); if (!kernel_state) return FALSE; + + /* note we extract the initramfs path here but we only use it as a fallback to use + * with `--rebuild` if we're missing `initramfs-args` in the commit metadata -- in the + * future, we could remove this entirely */ g_variant_get (kernel_state, "(&s&s&sm&s)", &kver, &bootdir, &kernel_path, &initramfs_path); + + /* also try to extract initramfs args from the base commit */ + g_autoptr(GVariant) base_commit = NULL; + if (!ostree_repo_load_variant (self->repo, OSTREE_OBJECT_TYPE_COMMIT, + self->base_revision, &base_commit, error)) + return FALSE; + + g_autoptr(GVariant) metadata = g_variant_get_child_value (base_commit, 0); + g_autoptr(GVariantDict) metadata_dict = g_variant_dict_new (metadata); + + g_autofree char **args = NULL; + if (g_variant_dict_lookup (metadata_dict, "rpmostree.initramfs-args", "^a&s", &args)) + { + initramfs_path = NULL; + for (char **it = args; it && *it; it++) + g_ptr_array_add (initramfs_args, g_strdup (*it)); + } } /* If *just* the kernel changed, all we need to do is run depmod here. @@ -1087,9 +1109,13 @@ perform_local_assembly (RpmOstreeSysrootUpgrader *self, if (kernel_or_initramfs_changed) { + /* append the extra args */ const char *const* add_dracut_argv = NULL; if (rpmostree_origin_get_regenerate_initramfs (self->origin)) add_dracut_argv = rpmostree_origin_get_initramfs_args (self->origin); + for (char **it = (char**)add_dracut_argv; it && *it; it++) + g_ptr_array_add (initramfs_args, g_strdup (*it)); + g_ptr_array_add (initramfs_args, NULL); g_auto(RpmOstreeProgress) task = { 0, }; rpmostree_output_task_begin (&task, "Generating initramfs"); @@ -1100,7 +1126,9 @@ perform_local_assembly (RpmOstreeSysrootUpgrader *self, /* NB: We only use the real root's /etc if initramfs regeneration is explicitly * requested. IOW, just replacing the kernel still gets use stock settings, like the * server side. */ - if (!rpmostree_run_dracut (self->tmprootfs_dfd, add_dracut_argv, kver, initramfs_path, + if (!rpmostree_run_dracut (self->tmprootfs_dfd, + (const char* const*)initramfs_args->pdata, + kver, initramfs_path, rpmostree_origin_get_regenerate_initramfs (self->origin), NULL, &initramfs_tmpf, cancellable, error)) return FALSE; diff --git a/src/libpriv/rpmostree-kernel.c b/src/libpriv/rpmostree-kernel.c index adcb96a5d5..301da717e4 100644 --- a/src/libpriv/rpmostree-kernel.c +++ b/src/libpriv/rpmostree-kernel.c @@ -514,11 +514,8 @@ rpmostree_run_dracut (int rootfs_dfd, error)) return FALSE; - /* Previously we used to error out if argv or rebuild_from_initramfs were both - * not set; now we simply use the defaults (which in Fedora today also means - * implicitly hostonly). That case is for `rpm-ostree override replace - * kernel.*.x86_64.rpm`. - */ + /* Note rebuild_from_initramfs now is only used as a fallback in the client-side regen + * path when we can't fetch the canonical initramfs args to use. */ if (rebuild_from_initramfs) { diff --git a/tests/vmcheck/test-override-kernel.sh b/tests/vmcheck/test-override-kernel.sh index 4bde242a71..dc989ef4cc 100755 --- a/tests/vmcheck/test-override-kernel.sh +++ b/tests/vmcheck/test-override-kernel.sh @@ -69,3 +69,7 @@ vm_cmd lsinitrd ${newroot}/usr/lib/modules/${kernel_release}/initramfs.img > lsi assert_file_has_content_literal lsinitrd.txt etc/foobar.conf echo "ok override kernel with custom initramfs args" + +# FCOS omits lvm; check that we still omit lvm here too +assert_file_has_content_literal lsinitrd.txt "--omit 'lvm'" +echo "ok override kernel uses base initramfs args"