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

Prep patches for ex initramfs-etc #2171

Merged
merged 5 commits into from
Aug 4, 2020
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
3 changes: 0 additions & 3 deletions src/app/rpmostree-builtin-ex.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ static RpmOstreeCommand ex_subcommands[] = {
"Convert an rpm-ostree rojig into an OSTree commit", rpmostree_ex_builtin_rojig2commit },
{ "history", RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD,
"Inspect rpm-ostree history of the system", rpmostree_ex_builtin_history },
/* temporary aliases; nuke in next version */
{ "reset", RPM_OSTREE_BUILTIN_FLAG_SUPPORTS_PKG_INSTALLS | RPM_OSTREE_BUILTIN_FLAG_HIDDEN,
NULL, rpmostree_builtin_reset },
{ NULL, 0, NULL, NULL }
};

Expand Down
4 changes: 2 additions & 2 deletions src/daemon/rpmostree-sysroot-upgrader.c
Original file line number Diff line number Diff line change
Expand Up @@ -1147,13 +1147,13 @@ perform_local_assembly (RpmOstreeSysrootUpgrader *self,
if (!rpmostree_finalize_kernel (self->tmprootfs_dfd, bootdir, kver, kernel_path,
&initramfs_tmpf, RPMOSTREE_FINALIZE_KERNEL_AUTO,
cancellable, error))
return FALSE;
return glnx_prefix_error (error, "Finalizing kernel");
}

if (!rpmostree_context_commit (self->ctx, self->base_revision,
RPMOSTREE_ASSEMBLE_TYPE_CLIENT_LAYERING,
&self->final_revision, cancellable, error))
return FALSE;
return glnx_prefix_error (error, "Committing");

/* Ensure we aren't holding any references to the tmpdir now that we're done;
* rpmostree_sysroot_upgrader_deploy() eventually calls
Expand Down
50 changes: 32 additions & 18 deletions src/libpriv/rpmostree-kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,12 +366,38 @@ rpmostree_finalize_kernel (int rootfs_dfd,
if (!_rpmostree_util_update_checksum_from_file (boot_checksum, rootfs_dfd, kernel_path,
cancellable, error))
return FALSE;
{ g_autoptr(GMappedFile) mfile = g_mapped_file_new_from_fd (initramfs_tmpf->fd, FALSE, error);
if (!mfile)
return FALSE;
g_checksum_update (boot_checksum, (guint8*)g_mapped_file_get_contents (mfile),
g_mapped_file_get_length (mfile));
}

g_autofree char *initramfs_modules_path =
g_build_filename (modules_bootdir, "initramfs.img", NULL);

if (initramfs_tmpf && initramfs_tmpf->initialized)
{
g_autoptr(GMappedFile) mfile = g_mapped_file_new_from_fd (initramfs_tmpf->fd, FALSE, error);
if (!mfile)
return glnx_prefix_error (error, "mmap(initramfs)");
g_checksum_update (boot_checksum, (guint8*)g_mapped_file_get_contents (mfile),
g_mapped_file_get_length (mfile));

/* Replace the initramfs */
if (unlinkat (rootfs_dfd, initramfs_modules_path, 0) < 0)
{
if (errno != ENOENT)
return glnx_throw_errno_prefix (error, "unlinkat(%s)", initramfs_modules_path);
}
if (!glnx_link_tmpfile_at (initramfs_tmpf, GLNX_LINK_TMPFILE_NOREPLACE,
rootfs_dfd, initramfs_modules_path,
error))
return glnx_prefix_error (error, "Linking initramfs");
}
else
{
/* we're not replacing the initramfs; use built-in one */
if (!_rpmostree_util_update_checksum_from_file (boot_checksum, rootfs_dfd,
initramfs_modules_path, cancellable,
error))
return FALSE;
}

const char *boot_checksum_str = g_checksum_get_string (boot_checksum);

g_autofree char *kernel_modules_path = g_build_filename (modules_bootdir, "vmlinuz", NULL);
Expand Down Expand Up @@ -428,18 +454,6 @@ rpmostree_finalize_kernel (int rootfs_dfd,
return FALSE;
}

/* Replace the initramfs */
g_autofree char *initramfs_modules_path = g_build_filename (modules_bootdir, "initramfs.img", NULL);
if (unlinkat (rootfs_dfd, initramfs_modules_path, 0) < 0)
{
if (errno != ENOENT)
return glnx_throw_errno_prefix (error, "unlinkat(%s)", initramfs_modules_path);
}
if (!glnx_link_tmpfile_at (initramfs_tmpf, GLNX_LINK_TMPFILE_NOREPLACE,
rootfs_dfd, initramfs_modules_path,
error))
return FALSE;

/* Update /usr/lib/ostree-boot and /boot (if desired) */
const gboolean only_if_found = (dest == RPMOSTREE_FINALIZE_KERNEL_AUTO);
if (only_if_found || dest >= RPMOSTREE_FINALIZE_KERNEL_USRLIB_OSTREEBOOT)
Expand Down
16 changes: 11 additions & 5 deletions src/libpriv/rpmostree-origin.c
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,16 @@ rpmostree_origin_unref (RpmOstreeOrigin *origin)
g_free (origin);
}

static void
update_string_list_from_hash_table (GKeyFile *kf,
const char *group,
const char *key,
GHashTable *values)
{
g_autofree char **strv = (char**)g_hash_table_get_keys_as_array (values, NULL);
g_key_file_set_string_list (kf, group, key, (const char *const*)strv, g_strv_length (strv));
}

void
rpmostree_origin_set_regenerate_initramfs (RpmOstreeOrigin *origin,
gboolean regenerate,
Expand Down Expand Up @@ -623,11 +633,7 @@ update_keyfile_pkgs_from_cache (RpmOstreeOrigin *origin,
}
else
{
g_autofree char **pkgv =
(char**)g_hash_table_get_keys_as_array (pkgs, NULL);
g_key_file_set_string_list (origin->kf, group, key,
(const char *const*)pkgv,
g_strv_length (pkgv));
update_string_list_from_hash_table (origin->kf, group, key, pkgs);
}

if (g_hash_table_size (pkgs) > 0)
Expand Down