64 Commits

Author SHA1 Message Date
Samuele Pedroni
d0cfb81163 boot,o/devicestate: protect with a mutex modifying modeeenv and sealing/releasing (#13185)
this should allow to release the global state lock while doing resealing/sealing proper as those are slow operations in fact

* boot: use loadModeenv a bit more consistently and some XXXs

* boot: take a lock around read modeenv/modify(/reaseal) etc

* boot: do not seal without the modeenv associated lock

* boot: do not reseal without the modeenv associated lock

* boot,o/devicestate: introduce Unlocker to unlock global state

have boot.DeviceChange make use of it for a start

* boot: explain a bit more modeenvMu

* overlord: introduce state.Unlocker convenience method

* boot: check that the lock is taken also in bootStateUpdate20.commit
2023-09-20 18:26:12 +02:00
alfonsosanchezbeato
91622c094b many: introduce IsUndo flag in LinkContext
* many: introduce IsUndo flag in LinkContext

Some times LinkSnap is called in an undo task when we want to revert
to a previous snap revision. Introduce a flag to make LinkSnap and
boot code aware of when this happen, as some of the logic for snap
installations should not be applied when doing a revert. Specifically,
avoid the "try" logic that applies to kernels and bases: we are
reverting to a known snap that is expected to work, and making the
current snap the fallback provokes failures as we are removing it (and
also probably we are removing it because it has failed).

* tests: check that kernel with failing post-refresh is reverted

Check that a kernel with failing post-refresh hook is reverted
properly. In this case a second reboot to go back to the previous
kernel is needed.

* tests: check that base with failing post-refresh is reverted

Check that a base with failing post-refresh hook is reverted
properly. In this case a second reboot to go back to the previous
base is needed.

* boot,overlord: replace isUndo flags with NextBootContext

Replace isUndo flags with the NextBootContext struct, so we have
further information in the type and we can add flags in the future.

* boot: some style changes as suggested by review

* overlord: SetNextBoot call in maybeUndoRemodelBootChanges as undo type

* boot: add tests for the IsUndoingInstall true case

* overlord: fix remodel test for undos

* boot,overlord: implement the undo install for core16/18

* tests: added method to repack kernel snap also for core16/18

* tests: run revert after boot tests for UC16/18 too

* tests/nested/core/base-revert-after-boot: fix var usage

* tests: consider right channel/snap for uc16 in revert tests

* boot: minor stylistic changes

* boot: add tests for the undoing install case for core16/18

* boot,overlord: rename IsUndoingInstall to BootWithoutTry

* boot: use constant instead of literal for status
2022-07-11 17:49:06 +02:00
Alfonso Sánchez-Beato
08b0a7262b boot: address review comments 2022-02-08 13:44:01 +01:00
Alfonso Sánchez-Beato
5d8a45a87f boot: return error in getRebootBootloader() 2022-02-04 10:42:13 +01:00
Alfonso Sánchez-Beato
9374574af5 boot: introduce RebootInfo type
Now SetNextBoot() will return a RebootInfo struct that will include a
bootloader.RebootBootloader interface, instead of just a bool
indicating if rebooting is required. This allows to obtain additional
information from the bootloader while rebooting.
2022-02-02 18:13:57 +01:00
Maciej Borzecki
d6e9d828e4 boot: pass bootloader options by pointer rather than by value
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2020-01-30 11:16:11 +01:00
Maciej Borzecki
6c4c6b9faa boot: core kernel should not keep the device but rather relevant bootloader options
Currently there is no need for coreKernel{} to keep track of the device. Getting
hold of bootloader options is sufficient to set up the right bootloader
implementation.

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2020-01-30 10:36:26 +01:00
Ian Johnson
c3767adb5e boot: add Device iface to coreKernel
This allows us to ask the device if we are on UC20 essentially, and figure out
what options we should use when searching for a bootloader to extract/remove
kernel assets from.

Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2020-01-29 09:12:03 +01:00
Samuele Pedroni
2fbacd360e boot: fix comments and generalize setNext signature 2020-01-08 20:52:28 +01:00
Samuele Pedroni
0e7ebb34c0 boot: implement SetNextBoot in terms of bootState.setNext 2020-01-08 17:35:53 +01:00
Samuele Pedroni
93cd0956cf reorg: move bootState16 to bootstate16.go for clarity 2020-01-07 19:23:35 +01:00
Samuele Pedroni
cece0b428a boot: drop Participant.ChangeRequiresReboot, it's unused now 2020-01-07 13:29:05 +01:00
Samuele Pedroni
d5604eba63 boot,o/snapstate: SetNextBoot/LinkSnap return whether to reboot, use the info
SetNextBoot knows already whether a reboot is needed or not, just
propagate the info
2020-01-07 13:29:05 +01:00
Samuele Pedroni
51700352b8 boot,o/snapstate: use bootState in GetCurrentBoot, adjust InUse
now bootState.revisions fails if the current snap revision is not
set, that's the behavior GetCurrentBoot needs but this required
some tweaks to InUse again

added some TODOs for later consideration as well
2019-12-18 17:47:37 +01:00
Samuele Pedroni
2b838b241a boot: introduce internal abstraction bootState and use it in InUse 2019-12-18 17:47:37 +01:00
Samuele Pedroni
9621752ff7 many: pass the rootdir and options to bootloader.Find
the only option for now is for knowing whether
ths bootloader is being used in prepare-image

this should help cleaning up the LittleKernel work

this is only an intermediate step toward refactoring image
vs boot/bootloader interaction
2019-09-05 19:32:04 +02:00
John R. Lenton
1d7ea10ff0 boot, etc: misc renames and cleanups
Thanks @zyga and @pedronis for the reviews.

This makes things a lot tidier: instead of interfaces
`boot.BootParticipant` and `boot.Kernel`, and functions `boot.Lookup()`
and `boot.LookupKernel()`, we now have interfaces `boot.BootParticipant`
and `boot.BootKernel`, and `boot.Participant()` and `boot.Kernel()`.
2019-09-03 15:27:17 +01:00
John R. Lenton
ee2b9963b9 boot, etc: simplify BootParticipant (etc) usage
This change simplifies using the recently introduced
boot.BootParticipant and boot.Kernel interfaces. Two changes:

1. `boot.Lookup` is split into `boot.Lookup` and `boot.LookupKernel`,
    and a `boot.Kernel` is no longer a `boot.BootParticipant`, and

2. `boot.Lookup` (and `LookupKernel`) return a single element that's
    always non-nil but might be a trivial implementation of the
    interface. A caller can always call the associated methods, and
    they'll do nothing when not 'applicable'. Optionally the caller
    can check whether it's the trivial implementation by using the new
    `IsTrivial()` helper.
2019-09-03 11:17:02 +01:00
John R. Lenton
6192a39d51 added comments to make things more readable 2019-09-02 15:39:01 +01:00
John R. Lenton
23998c4430 boot, snapstate: finally found the bug, fixed, refactored a little in passing 2019-08-22 10:06:32 +01:00
John R. Lenton
f2d7f30858 boot, snapstate: one last coat of polish
tweaking comments and moving code around for it to be clearer
2019-08-14 16:40:07 +01:00
John R. Lenton
0e68374ce1 boot, image: addressed review comments from @pedronis
Small tweaks and a minor structure change.
2019-08-14 13:36:16 +01:00
John R. Lenton
1f1398f10a boot, etc: much back-and-forthing ensued 2019-08-02 10:45:05 +01:00
John R. Lenton
5061d2aa6d boot, etc.: refactor boot to have a lookup with different imps
Currently the logic of boot has a lot of per-snap-type cheks in the
exported functions. Going forwards into core20 we know these checks
are going to get more involved, so now is a good time to switch things
around so that different implementations exist for each of the
situations, and thus the checks can be done while looking up which
implementation to use, instead of in each of the functions.
2019-07-29 10:14:08 +01:00
John R. Lenton
45e26bf16f boot: updated the doc of GetCurrentBoot to not mention ErrUnsupportedSnapType 2019-07-23 12:16:29 +01:00