From 6ee6e1b960e252f5d7774430f55f39e7539b45cc Mon Sep 17 00:00:00 2001 From: Huijing Hei Date: Fri, 19 Aug 2022 11:31:46 +0800 Subject: [PATCH] Fix `ostree admin kargs edit-in-place` assertion when deployments are pending This is to support pending deployments instead of rasing assertion. For example: ``` $ sudo rpm-ostree kargs --append=foo=bar $ sudo ostree admin kargs edit-in-place --append-if-missing=rw ``` After reboot we get both `foo=bar rw`. Fix https://github.com/ostreedev/ostree/issues/2679 --- src/libostree/ostree-sysroot-deploy.c | 51 +++++++++++++------ .../destructive/kargs-edit-in-place.sh | 20 +++++++- 2 files changed, 55 insertions(+), 16 deletions(-) diff --git a/src/libostree/ostree-sysroot-deploy.c b/src/libostree/ostree-sysroot-deploy.c index d86de7dc7b..29b55e286b 100644 --- a/src/libostree/ostree-sysroot-deploy.c +++ b/src/libostree/ostree-sysroot-deploy.c @@ -3614,25 +3614,46 @@ ostree_sysroot_deployment_set_kargs_in_place (OstreeSysroot *self, if (!_ostree_sysroot_ensure_writable (self, error)) return FALSE; - g_assert (!ostree_deployment_is_staged (deployment)); + //g_assert (!ostree_deployment_is_staged (deployment)); + if (ostree_deployment_is_staged (deployment)) + { + if (!_ostree_sysroot_reload_staged (self, error)) + return FALSE; - OstreeBootconfigParser *new_bootconfig = ostree_deployment_get_bootconfig (deployment); - ostree_bootconfig_parser_set (new_bootconfig, "options", kargs_str); + g_autoptr(OstreeKernelArgs) kargs = ostree_kernel_args_from_string (kargs_str); + g_auto(GStrv) kargs_strv = ostree_kernel_args_to_strv (kargs); + + OstreeSysrootDeployTreeOpts opts = { + .override_kernel_argv = kargs_strv, + }; + g_autoptr(OstreeDeployment) new_deployment = NULL; + const char *osname = ostree_deployment_get_osname (self->staged_deployment); + g_autoptr(OstreeDeployment) merge_deployment = ostree_sysroot_get_merge_deployment (self, osname); + if (!ostree_sysroot_stage_tree_with_options(self, osname, ostree_deployment_get_csum (self->staged_deployment), + NULL, merge_deployment, &opts, &new_deployment, + cancellable, error)) + return FALSE; + } + else + { + OstreeBootconfigParser *new_bootconfig = ostree_deployment_get_bootconfig (deployment); + ostree_bootconfig_parser_set (new_bootconfig, "options", kargs_str); - g_autofree char *bootconf_name = - g_strdup_printf ("ostree-%d-%s.conf", - self->deployments->len - ostree_deployment_get_index (deployment), - ostree_deployment_get_osname (deployment)); + g_autofree char *bootconf_name = + g_strdup_printf ("ostree-%d-%s.conf", + self->deployments->len - ostree_deployment_get_index (deployment), + ostree_deployment_get_osname (deployment)); - g_autofree char *bootconfdir = g_strdup_printf ("loader.%d/entries", self->bootversion); - glnx_autofd int bootconf_dfd = -1; - if (!glnx_opendirat (self->boot_fd, bootconfdir, TRUE, &bootconf_dfd, error)) - return FALSE; + g_autofree char *bootconfdir = g_strdup_printf ("loader.%d/entries", self->bootversion); + glnx_autofd int bootconf_dfd = -1; + if (!glnx_opendirat (self->boot_fd, bootconfdir, TRUE, &bootconf_dfd, error)) + return FALSE; - if (!ostree_bootconfig_parser_write_at (new_bootconfig, - bootconf_dfd, bootconf_name, - cancellable, error)) - return FALSE; + if (!ostree_bootconfig_parser_write_at (new_bootconfig, + bootconf_dfd, bootconf_name, + cancellable, error)) + return FALSE; + } return TRUE; } diff --git a/tests/kolainst/destructive/kargs-edit-in-place.sh b/tests/kolainst/destructive/kargs-edit-in-place.sh index 6380ff3340..b8bbe30ca4 100755 --- a/tests/kolainst/destructive/kargs-edit-in-place.sh +++ b/tests/kolainst/destructive/kargs-edit-in-place.sh @@ -9,4 +9,22 @@ set -xeuo pipefail sudo ostree admin kargs edit-in-place --append-if-missing=testarg assert_file_has_content /boot/loader/entries/ostree-* testarg -echo "ok test `kargs edit-in-place --append-if-missing`" +echo "ok basic test: kargs edit-in-place --append-if-missing" + +case "${AUTOPKGTEST_REBOOT_MARK:-}" in +"") + sudo rpm-ostree kargs --append=somedummykarg=1 + sudo ostree admin kargs edit-in-place --append-if-missing=testarg1 + assert_file_has_content /boot/loader/entries/ostree-* testarg1 + /tmp/autopkgtest-reboot 2 + ;; +"2") + assert_file_has_content_literal /proc/cmdline somedummykarg=1 + assert_file_has_content_literal /proc/cmdline testarg1 + ;; +*) + fatal "Unexpected AUTOPKGTEST_REBOOT_MARK=${AUTOPKGTEST_REBOOT_MARK}" + ;; +esac + +echo "ok test with stage: kargs edit-in-place --append-if-missing"