Refactor: Centralise choosing the appropriate bootloader
In preparation for enhancing `_ostree_sysroot_query_bootloader`
This commit is contained in:
parent
5e223f2962
commit
062df6ee81
|
|
@ -44,7 +44,6 @@
|
||||||
#include "ostree-repo-private.h"
|
#include "ostree-repo-private.h"
|
||||||
#include "ostree-sysroot-private.h"
|
#include "ostree-sysroot-private.h"
|
||||||
#include "ostree-sepolicy-private.h"
|
#include "ostree-sepolicy-private.h"
|
||||||
#include "ostree-bootloader-zipl.h"
|
|
||||||
#include "ostree-deployment-private.h"
|
#include "ostree-deployment-private.h"
|
||||||
#include "ostree-core-private.h"
|
#include "ostree-core-private.h"
|
||||||
#include "ostree-linuxfsutil.h"
|
#include "ostree-linuxfsutil.h"
|
||||||
|
|
@ -2561,7 +2560,6 @@ ostree_sysroot_write_deployments_with_options (OstreeSysroot *self,
|
||||||
gboolean bootloader_is_atomic = FALSE;
|
gboolean bootloader_is_atomic = FALSE;
|
||||||
SyncStats syncstats = { 0, };
|
SyncStats syncstats = { 0, };
|
||||||
g_autoptr(OstreeBootloader) bootloader = NULL;
|
g_autoptr(OstreeBootloader) bootloader = NULL;
|
||||||
const char *bootloader_config = NULL;
|
|
||||||
if (!requires_new_bootversion)
|
if (!requires_new_bootversion)
|
||||||
{
|
{
|
||||||
if (!create_new_bootlinks (self, self->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");
|
return glnx_throw_errno_prefix (error, "Remounting /boot read-write");
|
||||||
}
|
}
|
||||||
|
|
||||||
OstreeRepo *repo = ostree_sysroot_repo (self);
|
if (!_ostree_sysroot_query_bootloader (self, &bootloader, cancellable, error))
|
||||||
|
return FALSE;
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
bootloader_is_atomic = bootloader != NULL && _ostree_bootloader_is_atomic (bootloader);
|
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"),
|
(bootloader_is_atomic ? "Transaction complete" : "Bootloader updated"),
|
||||||
requires_new_bootversion ? "yes" : "no",
|
requires_new_bootversion ? "yes" : "no",
|
||||||
new_deployments->len - self->deployments->len);
|
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),
|
ot_journal_send ("MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(OSTREE_DEPLOYMENT_COMPLETE_ID),
|
||||||
"MESSAGE=%s", msg,
|
"MESSAGE=%s", msg,
|
||||||
"OSTREE_BOOTLOADER=%s", bootloader ? _ostree_bootloader_get_name (bootloader) : "none",
|
"OSTREE_BOOTLOADER=%s", bootloader ? _ostree_bootloader_get_name (bootloader) : "none",
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@
|
||||||
#include "ostree-bootloader-uboot.h"
|
#include "ostree-bootloader-uboot.h"
|
||||||
#include "ostree-bootloader-syslinux.h"
|
#include "ostree-bootloader-syslinux.h"
|
||||||
#include "ostree-bootloader-grub2.h"
|
#include "ostree-bootloader-grub2.h"
|
||||||
|
#include "ostree-bootloader-zipl.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SECTION:ostree-sysroot
|
* SECTION:ostree-sysroot
|
||||||
|
|
@ -1328,6 +1329,7 @@ ostree_sysroot_repo (OstreeSysroot *self)
|
||||||
* ostree_sysroot_query_bootloader:
|
* ostree_sysroot_query_bootloader:
|
||||||
* @sysroot: Sysroot
|
* @sysroot: Sysroot
|
||||||
* @out_bootloader: (out) (transfer full) (allow-none): Return location for bootloader, may be %NULL
|
* @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
|
* @cancellable: Cancellable
|
||||||
* @error: Error
|
* @error: Error
|
||||||
*/
|
*/
|
||||||
|
|
@ -1337,30 +1339,51 @@ _ostree_sysroot_query_bootloader (OstreeSysroot *sysroot,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
gboolean is_active;
|
OstreeRepo *repo = ostree_sysroot_repo (sysroot);
|
||||||
g_autoptr(OstreeBootloader) ret_loader =
|
g_autofree gchar *bootloader_config = ostree_repo_get_bootloader (repo);
|
||||||
(OstreeBootloader*)_ostree_bootloader_syslinux_new (sysroot);
|
|
||||||
if (!_ostree_bootloader_query (ret_loader, &is_active,
|
|
||||||
cancellable, error))
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
if (!is_active)
|
g_debug ("Using bootloader configuration: %s", bootloader_config);
|
||||||
|
|
||||||
|
g_autoptr(OstreeBootloader) ret_loader = NULL;
|
||||||
|
if (g_str_equal (bootloader_config, "none"))
|
||||||
{
|
{
|
||||||
g_object_unref (ret_loader);
|
/* No bootloader specified; do not query bootloaders to run. */
|
||||||
ret_loader = (OstreeBootloader*)_ostree_bootloader_grub2_new (sysroot);
|
ret_loader = NULL;
|
||||||
|
}
|
||||||
|
else if (g_str_equal (bootloader_config, "zipl"))
|
||||||
|
{
|
||||||
|
/* 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,
|
if (!_ostree_bootloader_query (ret_loader, &is_active,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
return FALSE;
|
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)
|
else
|
||||||
{
|
g_assert_not_reached ();
|
||||||
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);
|
|
||||||
|
|
||||||
ot_transfer_out_value(out_bootloader, &ret_loader);
|
ot_transfer_out_value(out_bootloader, &ret_loader);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue