From 52a6224606e4a057b806225d93a2d0239a004723 Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Mon, 17 Aug 2020 09:48:09 -0400 Subject: [PATCH 1/6] lib/deploy: Clean up kargs override handling Tighten up how we handle kargs here so it's more clear. When we call `sysroot_finalize_deployment`, any karg overrides have already been set on the bootconfig object of the deployment. So re-setting it here is redundant and confusing. --- src/libostree/ostree-sysroot-deploy.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/libostree/ostree-sysroot-deploy.c b/src/libostree/ostree-sysroot-deploy.c index cb593020..89e3b8e8 100644 --- a/src/libostree/ostree-sysroot-deploy.c +++ b/src/libostree/ostree-sysroot-deploy.c @@ -2770,7 +2770,6 @@ get_var_dfd (OstreeSysroot *self, static gboolean sysroot_finalize_deployment (OstreeSysroot *self, OstreeDeployment *deployment, - char **override_kernel_argv, OstreeDeployment *merge_deployment, GCancellable *cancellable, GError **error) @@ -2780,15 +2779,18 @@ sysroot_finalize_deployment (OstreeSysroot *self, if (!glnx_opendirat (self->sysroot_fd, deployment_path, TRUE, &deployment_dfd, error)) return FALSE; - /* Only use the merge if we didn't get an override */ - if (!override_kernel_argv && merge_deployment) + OstreeBootconfigParser *bootconfig = ostree_deployment_get_bootconfig (deployment); + + /* If the kargs weren't set yet, then just pick it up from the merge deployment. In the + * deploy path, overrides are set as part of sysroot_initialize_deployment(). In the + * finalize-staged path, they're set by OstreeSysroot when reading the staged GVariant. */ + if (merge_deployment && ostree_bootconfig_parser_get (bootconfig, "options") == NULL) { - /* Override the bootloader arguments */ OstreeBootconfigParser *merge_bootconfig = ostree_deployment_get_bootconfig (merge_deployment); if (merge_bootconfig) { - const char *opts = ostree_bootconfig_parser_get (merge_bootconfig, "options"); - ostree_bootconfig_parser_set (ostree_deployment_get_bootconfig (deployment), "options", opts); + const char *kargs = ostree_bootconfig_parser_get (merge_bootconfig, "options"); + ostree_bootconfig_parser_set (bootconfig, "options", kargs); } } @@ -2882,8 +2884,7 @@ ostree_sysroot_deploy_tree (OstreeSysroot *self, &deployment, cancellable, error)) return FALSE; - if (!sysroot_finalize_deployment (self, deployment, override_kernel_argv, - provided_merge_deployment, + if (!sysroot_finalize_deployment (self, deployment, provided_merge_deployment, cancellable, error)) return FALSE; @@ -3149,8 +3150,6 @@ _ostree_sysroot_finalize_staged (OstreeSysroot *self, ostree_deployment_get_csum (merge_deployment_stub), ostree_deployment_get_deployserial (merge_deployment_stub)); } - g_autofree char **kargs = NULL; - g_variant_lookup (self->staged_deployment_data, "kargs", "^a&s", &kargs); /* Unlink the staged state now; if we're interrupted in the middle, * we don't want e.g. deal with the partially written /etc merge. @@ -3158,7 +3157,7 @@ _ostree_sysroot_finalize_staged (OstreeSysroot *self, if (!glnx_unlinkat (AT_FDCWD, _OSTREE_SYSROOT_RUNSTATE_STAGED, 0, error)) return FALSE; - if (!sysroot_finalize_deployment (self, self->staged_deployment, kargs, merge_deployment, + if (!sysroot_finalize_deployment (self, self->staged_deployment, merge_deployment, cancellable, error)) return FALSE; From 61c544df1bceeaa81e4ce98b587fad1e5198046d Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Mon, 17 Aug 2020 09:48:10 -0400 Subject: [PATCH 2/6] lib/deploy: Avoid shadowing variable There's already a `boot_relpath` variable in the outside scope. --- src/libostree/ostree-sysroot-deploy.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libostree/ostree-sysroot-deploy.c b/src/libostree/ostree-sysroot-deploy.c index 89e3b8e8..0179873b 100644 --- a/src/libostree/ostree-sysroot-deploy.c +++ b/src/libostree/ostree-sysroot-deploy.c @@ -1935,8 +1935,9 @@ install_deployment_kernel (OstreeSysroot *sysroot, if (kernel_layout->initramfs_namever) { - g_autofree char * boot_relpath = g_strconcat ("/", bootcsumdir, "/", kernel_layout->initramfs_namever, NULL); - ostree_bootconfig_parser_set (bootconfig, "initrd", boot_relpath); + g_autofree char * initrd_boot_relpath = + g_strconcat ("/", bootcsumdir, "/", kernel_layout->initramfs_namever, NULL); + ostree_bootconfig_parser_set (bootconfig, "initrd", initrd_boot_relpath); } else { From 74bd1362861ed66200094b469ef40d7a1f818c9f Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Mon, 17 Aug 2020 09:48:11 -0400 Subject: [PATCH 3/6] lib/deploy: Simplify deployment creation Minor cleanup; we were declaring a superfluous variable. --- src/libostree/ostree-sysroot-deploy.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/libostree/ostree-sysroot-deploy.c b/src/libostree/ostree-sysroot-deploy.c index 0179873b..4b678890 100644 --- a/src/libostree/ostree-sysroot-deploy.c +++ b/src/libostree/ostree-sysroot-deploy.c @@ -2699,10 +2699,8 @@ sysroot_initialize_deployment (OstreeSysroot *self, cancellable, error)) return FALSE; - g_autofree char *new_bootcsum = NULL; g_autoptr(OstreeDeployment) new_deployment = - ostree_deployment_new (0, osname, revision, new_deployserial, - new_bootcsum, -1); + ostree_deployment_new (0, osname, revision, new_deployserial, NULL, -1); ostree_deployment_set_origin (new_deployment, origin); /* Check out the userspace tree onto the filesystem */ From e4fb7d3bb152f70ec82c33bf19089e9ac0bcc9c4 Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Mon, 17 Aug 2020 09:48:12 -0400 Subject: [PATCH 4/6] lib/cleanup: Drop unnecessary GEqualFunc cast --- src/libostree/ostree-sysroot-cleanup.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libostree/ostree-sysroot-cleanup.c b/src/libostree/ostree-sysroot-cleanup.c index 71d978e0..ffad4130 100644 --- a/src/libostree/ostree-sysroot-cleanup.c +++ b/src/libostree/ostree-sysroot-cleanup.c @@ -295,9 +295,9 @@ cleanup_old_deployments (OstreeSysroot *self, /* Load all active deployments referenced by bootloader configuration. */ g_autoptr(GHashTable) active_deployment_dirs = - g_hash_table_new_full (g_str_hash, (GEqualFunc)g_str_equal, g_free, NULL); + g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); g_autoptr(GHashTable) active_boot_checksums = - g_hash_table_new_full (g_str_hash, (GEqualFunc)g_str_equal, g_free, NULL); + g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); for (guint i = 0; i < self->deployments->len; i++) { OstreeDeployment *deployment = self->deployments->pdata[i]; From 5de3a9759fc4a89c3c5ae6c4720bf984a2688374 Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Mon, 17 Aug 2020 09:48:13 -0400 Subject: [PATCH 5/6] lib/deploy: Drop unneccessary function arg --- src/libostree/ostree-sysroot-deploy.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/libostree/ostree-sysroot-deploy.c b/src/libostree/ostree-sysroot-deploy.c index 4b678890..c4a0ca92 100644 --- a/src/libostree/ostree-sysroot-deploy.c +++ b/src/libostree/ostree-sysroot-deploy.c @@ -111,7 +111,6 @@ install_into_boot (OstreeRepo *repo, const char *src_subpath, int dest_dfd, const char *dest_subpath, - OstreeSysrootDebugFlags flags, GCancellable *cancellable, GError **error) { @@ -1798,7 +1797,6 @@ install_deployment_kernel (OstreeSysroot *sysroot, { if (!install_into_boot (repo, sepolicy, kernel_layout->boot_dfd, kernel_layout->kernel_srcpath, bootcsum_dfd, kernel_layout->kernel_namever, - sysroot->debug_flags, cancellable, error)) return FALSE; } @@ -1815,7 +1813,6 @@ install_deployment_kernel (OstreeSysroot *sysroot, { if (!install_into_boot (repo, sepolicy, kernel_layout->boot_dfd, kernel_layout->initramfs_srcpath, bootcsum_dfd, kernel_layout->initramfs_namever, - sysroot->debug_flags, cancellable, error)) return FALSE; } @@ -1832,7 +1829,6 @@ install_deployment_kernel (OstreeSysroot *sysroot, { if (!install_into_boot (repo, sepolicy, kernel_layout->boot_dfd, kernel_layout->devicetree_srcpath, bootcsum_dfd, kernel_layout->devicetree_namever, - sysroot->debug_flags, cancellable, error)) return FALSE; } @@ -1853,7 +1849,6 @@ install_deployment_kernel (OstreeSysroot *sysroot, { if (!install_into_boot (repo, sepolicy, kernel_layout->boot_dfd, kernel_layout->kernel_hmac_srcpath, bootcsum_dfd, kernel_layout->kernel_hmac_namever, - sysroot->debug_flags, cancellable, error)) return FALSE; } From 10a68cd26b82489898d81cb5c6e5121e0de31222 Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Mon, 17 Aug 2020 09:48:15 -0400 Subject: [PATCH 6/6] lib/deploy: Clarify comment re. staging API Don't mention deprecation in the description for `ostree_sysroot_deploy_tree` since there are legitimate use cases for it (e.g. to create the first deployment via `ostree admin deploy`). Instead, make the comment clearly redirect to the staging API when booted into the sysroot. --- src/libostree/ostree-sysroot-deploy.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libostree/ostree-sysroot-deploy.c b/src/libostree/ostree-sysroot-deploy.c index c4a0ca92..8488111d 100644 --- a/src/libostree/ostree-sysroot-deploy.c +++ b/src/libostree/ostree-sysroot-deploy.c @@ -2856,8 +2856,8 @@ sysroot_finalize_deployment (OstreeSysroot *self, * Check out deployment tree with revision @revision, performing a 3 * way merge with @provided_merge_deployment for configuration. * - * While this API is not deprecated, you most likely want to use the - * ostree_sysroot_stage_tree() API. + * When booted into the sysroot, you should use the + * ostree_sysroot_stage_tree() API instead. */ gboolean ostree_sysroot_deploy_tree (OstreeSysroot *self,