Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compose: Include base dracut args in commitmeta #1997

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/app/rpmostree-compose-builtin-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,17 @@ impl_commit_tree (RpmOstreeTreeComposeContext *self,
if (!_rpmostree_jsonutil_object_get_optional_boolean_member (self->treefile, "selinux", &selinux, error))
return FALSE;

/* pick up any initramfs regeneration args to shove into the metadata */
JsonNode *initramfs_args = json_object_get_member (self->treefile, "initramfs-args");
if (initramfs_args)
{
GVariant *v = json_gvariant_deserialize (initramfs_args, "as", error);
if (!v)
return FALSE;
g_hash_table_insert (self->metadata, g_strdup ("rpmostree.initramfs-args"),
g_variant_ref_sink (v));
}

/* Convert metadata hash to GVariant */
g_autoptr(GVariant) metadata = rpmostree_composeutil_finalize_metadata (self->metadata, self->rootfs_dfd, error);
if (!metadata)
Expand Down
30 changes: 29 additions & 1 deletion src/daemon/rpmostree-sysroot-upgrader.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

g_assert (self->base_revision);
g_autoptr(GVariant) base_commit = NULL;
if (!ostree_repo_load_variant (self->repo, OSTREE_OBJECT_TYPE_COMMIT,
self->base_revision, &base_commit, error))
jlebon marked this conversation as resolved.
Show resolved Hide resolved
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; /* we got the canonical args, so don't use --rebuild */
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.
Expand All @@ -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");
Expand All @@ -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;
Expand Down
7 changes: 2 additions & 5 deletions src/libpriv/rpmostree-kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
4 changes: 4 additions & 0 deletions tests/vmcheck/test-override-kernel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"