From: William Manley Date: Mon, 6 Jul 2020 13:54:31 +0000 (+0100) Subject: Refactor: Centralise choosing the appropriate bootloader X-Git-Tag: archive/raspbian/2022.1-3+rpi1~1^2~4^2~6^2~12^2~6 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=062df6ee8111be538321ee624e219f5d61d5e7dc;p=ostree.git Refactor: Centralise choosing the appropriate bootloader In preparation for enhancing `_ostree_sysroot_query_bootloader` --- diff --git a/src/libostree/ostree-sysroot-deploy.c b/src/libostree/ostree-sysroot-deploy.c index 1a4a6369..900efe49 100644 --- a/src/libostree/ostree-sysroot-deploy.c +++ b/src/libostree/ostree-sysroot-deploy.c @@ -44,7 +44,6 @@ #include "ostree-repo-private.h" #include "ostree-sysroot-private.h" #include "ostree-sepolicy-private.h" -#include "ostree-bootloader-zipl.h" #include "ostree-deployment-private.h" #include "ostree-core-private.h" #include "ostree-linuxfsutil.h" @@ -2561,7 +2560,6 @@ ostree_sysroot_write_deployments_with_options (OstreeSysroot *self, gboolean bootloader_is_atomic = FALSE; SyncStats syncstats = { 0, }; g_autoptr(OstreeBootloader) bootloader = NULL; - const char *bootloader_config = NULL; if (!requires_new_bootversion) { if (!create_new_bootlinks (self, self->bootversion, @@ -2593,29 +2591,8 @@ ostree_sysroot_write_deployments_with_options (OstreeSysroot *self, return glnx_throw_errno_prefix (error, "Remounting /boot read-write"); } - OstreeRepo *repo = ostree_sysroot_repo (self); - - bootloader_config = ostree_repo_get_bootloader (repo); - - g_debug ("Using bootloader configuration: %s", bootloader_config); - - if (g_str_equal (bootloader_config, "auto")) - { - if (!_ostree_sysroot_query_bootloader (self, &bootloader, cancellable, error)) - return FALSE; - } - else if (g_str_equal (bootloader_config, "none")) - { - /* No bootloader specified; do not query bootloaders to run. */ - } - else if (g_str_equal (bootloader_config, "zipl")) - { - /* Because we do not mark zipl as active by default, lets creating one here, - * which is basically the same what _ostree_sysroot_query_bootloader() does - * for other bootloaders if being activated. - * */ - bootloader = (OstreeBootloader*) _ostree_bootloader_zipl_new (self); - } + if (!_ostree_sysroot_query_bootloader (self, &bootloader, cancellable, error)) + return FALSE; bootloader_is_atomic = bootloader != NULL && _ostree_bootloader_is_atomic (bootloader); @@ -2646,6 +2623,7 @@ ostree_sysroot_write_deployments_with_options (OstreeSysroot *self, (bootloader_is_atomic ? "Transaction complete" : "Bootloader updated"), requires_new_bootversion ? "yes" : "no", new_deployments->len - self->deployments->len); + const gchar *bootloader_config = ostree_repo_get_bootloader (ostree_sysroot_repo (self)); ot_journal_send ("MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(OSTREE_DEPLOYMENT_COMPLETE_ID), "MESSAGE=%s", msg, "OSTREE_BOOTLOADER=%s", bootloader ? _ostree_bootloader_get_name (bootloader) : "none", diff --git a/src/libostree/ostree-sysroot.c b/src/libostree/ostree-sysroot.c index e0813b55..f183edd1 100644 --- a/src/libostree/ostree-sysroot.c +++ b/src/libostree/ostree-sysroot.c @@ -36,6 +36,7 @@ #include "ostree-bootloader-uboot.h" #include "ostree-bootloader-syslinux.h" #include "ostree-bootloader-grub2.h" +#include "ostree-bootloader-zipl.h" /** * SECTION:ostree-sysroot @@ -1328,6 +1329,7 @@ ostree_sysroot_repo (OstreeSysroot *self) * ostree_sysroot_query_bootloader: * @sysroot: Sysroot * @out_bootloader: (out) (transfer full) (allow-none): Return location for bootloader, may be %NULL + * @out_bootloader_config: (out) (transfer none) (allow-none): Return location for value of ostree repo config variable sysroot.bootloader, may be %NULL * @cancellable: Cancellable * @error: Error */ @@ -1337,30 +1339,51 @@ _ostree_sysroot_query_bootloader (OstreeSysroot *sysroot, GCancellable *cancellable, GError **error) { - gboolean is_active; - g_autoptr(OstreeBootloader) ret_loader = - (OstreeBootloader*)_ostree_bootloader_syslinux_new (sysroot); - if (!_ostree_bootloader_query (ret_loader, &is_active, - cancellable, error)) - return FALSE; + OstreeRepo *repo = ostree_sysroot_repo (sysroot); + g_autofree gchar *bootloader_config = ostree_repo_get_bootloader (repo); + + g_debug ("Using bootloader configuration: %s", bootloader_config); - if (!is_active) + g_autoptr(OstreeBootloader) ret_loader = NULL; + if (g_str_equal (bootloader_config, "none")) { - g_object_unref (ret_loader); - ret_loader = (OstreeBootloader*)_ostree_bootloader_grub2_new (sysroot); - if (!_ostree_bootloader_query (ret_loader, &is_active, - cancellable, error)) - return FALSE; + /* No bootloader specified; do not query bootloaders to run. */ + ret_loader = NULL; } - if (!is_active) + else if (g_str_equal (bootloader_config, "zipl")) { - g_object_unref (ret_loader); - ret_loader = (OstreeBootloader*)_ostree_bootloader_uboot_new (sysroot); - if (!_ostree_bootloader_query (ret_loader, &is_active, cancellable, error)) + /* We never consider zipl as active by default, so it can only be created + * if it's explicitly requested in the config */ + ret_loader = (OstreeBootloader*) _ostree_bootloader_zipl_new (sysroot); + } + else if (g_str_equal (bootloader_config, "auto")) + { + gboolean is_active; + ret_loader = (OstreeBootloader*)_ostree_bootloader_syslinux_new (sysroot); + if (!_ostree_bootloader_query (ret_loader, &is_active, + cancellable, error)) return FALSE; + + if (!is_active) + { + g_object_unref (ret_loader); + ret_loader = (OstreeBootloader*)_ostree_bootloader_grub2_new (sysroot); + if (!_ostree_bootloader_query (ret_loader, &is_active, + cancellable, error)) + return FALSE; + } + if (!is_active) + { + g_object_unref (ret_loader); + ret_loader = (OstreeBootloader*)_ostree_bootloader_uboot_new (sysroot); + if (!_ostree_bootloader_query (ret_loader, &is_active, cancellable, error)) + return FALSE; + } + if (!is_active) + g_clear_object (&ret_loader); } - if (!is_active) - g_clear_object (&ret_loader); + else + g_assert_not_reached (); ot_transfer_out_value(out_bootloader, &ret_loader); return TRUE;