Skip to content

Commit

Permalink
boot: lock the modeenv while reading revisions
Browse files Browse the repository at this point in the history
`ubuntu-core-20-64:tests/core/system-snap-refresh` fails because
of this.
  • Loading branch information
valentindavid authored and MiguelPires committed Oct 26, 2023
1 parent 8a80f03 commit 7e3b1bb
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
3 changes: 3 additions & 0 deletions boot/boot.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,9 @@ func fixedInUse(inUse bool) InUseFunc {
// InUse returns a checker for whether a given name/revision is used in the
// boot environment for snaps of the relevant snap type.
func InUse(typ snap.Type, dev snap.Device) (InUseFunc, error) {
modeenvLock()
defer modeenvUnlock()

if !dev.RunMode() {
// ephemeral mode, block manipulations for now
return fixedInUse(true), nil
Expand Down
41 changes: 41 additions & 0 deletions boot/boot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,47 @@ func (s *bootenvSuite) TestInUse(c *C) {
}
}

func (s *bootenv20Suite) TestInUseCore20(c *C) {
coreDev := boottest.MockUC20Device("", nil)
c.Assert(coreDev.HasModeenv(), Equals, true)
c.Assert(coreDev.IsCoreBoot(), Equals, true)

r := setupUC20Bootenv(
c,
s.bootloader,
&bootenv20Setup{
modeenv: &boot.Modeenv{
// base is base1
Base: s.base1.Filename(),
// no try base
TryBase: "",
// gadget is gadget1
Gadget: s.gadget1.Filename(),
// current kernels is just kern1
CurrentKernels: []string{s.kern1.Filename()},
// operating mode is run
Mode: "run",
// RecoverySystem is unset, as it should be during run mode
RecoverySystem: "",
},
// enabled kernel is kern1
kern: s.kern1,
// no try kernel enabled
tryKern: nil,
// kernel status is default
kernStatus: boot.DefaultStatus,
})
defer r()

inUse, err := boot.InUse(snap.TypeKernel, coreDev)
c.Check(err, IsNil)
c.Check(inUse(s.kern1.SnapName(), s.kern1.SnapRevision()), Equals, true)
c.Check(inUse(s.kern2.SnapName(), s.kern2.SnapRevision()), Equals, false)

_, err = boot.InUse(snap.TypeBase, coreDev)
c.Check(err, IsNil)
}

func (s *bootenvSuite) TestInUseEphemeral(c *C) {
coreDev := boottest.MockDevice("some-snap@install")

Expand Down

0 comments on commit 7e3b1bb

Please sign in to comment.