Refactor `ostree_sysroot_query_bootloader`
This is more regular, so will make it easier to add more bootloader types in the future.
This commit is contained in:
parent
31acd2ef99
commit
a8dce46b5f
|
|
@ -1325,6 +1325,31 @@ ostree_sysroot_repo (OstreeSysroot *self)
|
||||||
return self->repo;
|
return self->repo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static OstreeBootloader*
|
||||||
|
_ostree_sysroot_new_bootloader_by_type (
|
||||||
|
OstreeSysroot *sysroot,
|
||||||
|
OstreeCfgSysrootBootloaderOpt bl_type)
|
||||||
|
{
|
||||||
|
switch (bl_type)
|
||||||
|
{
|
||||||
|
case CFG_SYSROOT_BOOTLOADER_OPT_NONE:
|
||||||
|
/* No bootloader specified; do not query bootloaders to run. */
|
||||||
|
return NULL;
|
||||||
|
case CFG_SYSROOT_BOOTLOADER_OPT_GRUB2:
|
||||||
|
return (OstreeBootloader*) _ostree_bootloader_grub2_new (sysroot);
|
||||||
|
case CFG_SYSROOT_BOOTLOADER_OPT_SYSLINUX:
|
||||||
|
return (OstreeBootloader*) _ostree_bootloader_syslinux_new (sysroot);
|
||||||
|
case CFG_SYSROOT_BOOTLOADER_OPT_UBOOT:
|
||||||
|
return (OstreeBootloader*) _ostree_bootloader_uboot_new (sysroot);
|
||||||
|
case CFG_SYSROOT_BOOTLOADER_OPT_ZIPL:
|
||||||
|
/* We never consider zipl as active by default, so it can only be created
|
||||||
|
* if it's explicitly requested in the config */
|
||||||
|
return (OstreeBootloader*) _ostree_bootloader_zipl_new (sysroot);
|
||||||
|
default:
|
||||||
|
g_assert_not_reached ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ostree_sysroot_query_bootloader:
|
* ostree_sysroot_query_bootloader:
|
||||||
* @sysroot: Sysroot
|
* @sysroot: Sysroot
|
||||||
|
|
@ -1346,58 +1371,31 @@ _ostree_sysroot_query_bootloader (OstreeSysroot *sysroot,
|
||||||
CFG_SYSROOT_BOOTLOADER_OPTS_STR[bootloader_config]);
|
CFG_SYSROOT_BOOTLOADER_OPTS_STR[bootloader_config]);
|
||||||
|
|
||||||
g_autoptr(OstreeBootloader) ret_loader = NULL;
|
g_autoptr(OstreeBootloader) ret_loader = NULL;
|
||||||
switch (repo->bootloader)
|
if (bootloader_config == CFG_SYSROOT_BOOTLOADER_OPT_AUTO)
|
||||||
{
|
{
|
||||||
case CFG_SYSROOT_BOOTLOADER_OPT_NONE:
|
OstreeCfgSysrootBootloaderOpt probe[] = {
|
||||||
/* No bootloader specified; do not query bootloaders to run. */
|
CFG_SYSROOT_BOOTLOADER_OPT_SYSLINUX,
|
||||||
ret_loader = NULL;
|
CFG_SYSROOT_BOOTLOADER_OPT_GRUB2,
|
||||||
break;
|
CFG_SYSROOT_BOOTLOADER_OPT_UBOOT,
|
||||||
case CFG_SYSROOT_BOOTLOADER_OPT_GRUB2:
|
};
|
||||||
ret_loader = (OstreeBootloader*) _ostree_bootloader_grub2_new (sysroot);
|
for (int i = 0; i < G_N_ELEMENTS (probe); i++)
|
||||||
break;
|
|
||||||
case CFG_SYSROOT_BOOTLOADER_OPT_SYSLINUX:
|
|
||||||
ret_loader = (OstreeBootloader*) _ostree_bootloader_syslinux_new (sysroot);
|
|
||||||
break;
|
|
||||||
case CFG_SYSROOT_BOOTLOADER_OPT_UBOOT:
|
|
||||||
ret_loader = (OstreeBootloader*) _ostree_bootloader_uboot_new (sysroot);
|
|
||||||
break;
|
|
||||||
case CFG_SYSROOT_BOOTLOADER_OPT_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);
|
|
||||||
break;
|
|
||||||
case CFG_SYSROOT_BOOTLOADER_OPT_AUTO:
|
|
||||||
{
|
{
|
||||||
gboolean is_active;
|
g_autoptr(OstreeBootloader) bl = _ostree_sysroot_new_bootloader_by_type (
|
||||||
ret_loader = (OstreeBootloader*)_ostree_bootloader_syslinux_new (sysroot);
|
sysroot, probe[i]);
|
||||||
if (!_ostree_bootloader_query (ret_loader, &is_active,
|
gboolean is_active = FALSE;
|
||||||
cancellable, error))
|
if (!_ostree_bootloader_query (bl, &is_active, cancellable, error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
if (is_active)
|
||||||
|
{
|
||||||
|
ret_loader = g_steal_pointer (&bl);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
ret_loader = _ostree_sysroot_new_bootloader_by_type (sysroot, bootloader_config);
|
||||||
|
|
||||||
if (!is_active)
|
ot_transfer_out_value (out_bootloader, &ret_loader)
|
||||||
{
|
|
||||||
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);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
g_assert_not_reached ();
|
|
||||||
}
|
|
||||||
|
|
||||||
ot_transfer_out_value(out_bootloader, &ret_loader);
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue