Skip to content

Commit

Permalink
overlord/fdestate/fdestate.go: fix path to data mount point on hybrid
Browse files Browse the repository at this point in the history
We used a path that is not a mount point on hybrid to discover the
data disk. Instead we now use / for hybrid, and /writable on core.
  • Loading branch information
valentindavid committed Nov 20, 2024
1 parent dd0f4ad commit a80d97c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 9 deletions.
37 changes: 30 additions & 7 deletions overlord/fdestate/fdemgr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"crypto"
"fmt"
"os"
"path/filepath"
"testing"

. "gopkg.in/check.v1"
Expand All @@ -36,6 +37,7 @@ import (
"github.com/snapcore/snapd/overlord/fdestate"
"github.com/snapcore/snapd/overlord/fdestate/backend"
"github.com/snapcore/snapd/overlord/state"
"github.com/snapcore/snapd/release"
"github.com/snapcore/snapd/secboot"
"github.com/snapcore/snapd/snapdenv"
"github.com/snapcore/snapd/testutil"
Expand Down Expand Up @@ -82,6 +84,8 @@ func (s *fdeMgrSuite) SetUpTest(c *C) {
}
err := m.WriteTo(dirs.GlobalRootDir)
c.Assert(err, IsNil)

s.AddCleanup(release.MockOnClassic(true))
}

type instrumentedUnlocker struct {
Expand All @@ -101,10 +105,14 @@ func (u *instrumentedUnlocker) Relock() {
u.relocked += 1
}

func (s *fdeMgrSuite) startedManager(c *C) *fdestate.FDEManager {
func (s *fdeMgrSuite) startedManager(c *C, onClassic bool) *fdestate.FDEManager {
defer fdestate.MockDMCryptUUIDFromMountPoint(func(mountpoint string) (string, error) {
switch mountpoint {
case dirs.SnapdStateDir(dirs.GlobalRootDir):
case dirs.GlobalRootDir:
c.Check(onClassic, Equals, true)
return "aaa", nil
case filepath.Join(dirs.GlobalRootDir, "writable"):
c.Check(onClassic, Equals, false)
return "aaa", nil
case dirs.SnapSaveDir:
return "bbb", nil
Expand Down Expand Up @@ -132,9 +140,10 @@ func (s *fdeMgrSuite) startedManager(c *C) *fdestate.FDEManager {
return manager
}

func (s *fdeMgrSuite) TestGetManagerFromState(c *C) {
func (s *fdeMgrSuite) testGetManagerFromState(c *C, onClassic bool) {
st := s.st
manager := s.startedManager(c)
s.AddCleanup(release.MockOnClassic(onClassic))
manager := s.startedManager(c, onClassic)

st.Lock()
defer st.Unlock()
Expand All @@ -151,6 +160,16 @@ func (s *fdeMgrSuite) TestGetManagerFromState(c *C) {
c.Check(primaryKey.Digest.Digest, DeepEquals, []byte{5, 6, 7, 8})
}

func (s *fdeMgrSuite) TestGetManagerFromStateClassic(c *C) {
const onClassic = true
s.testGetManagerFromState(c, onClassic)
}

func (s *fdeMgrSuite) TestGetManagerFromStateCore(c *C) {
const onClassic = false
s.testGetManagerFromState(c, onClassic)
}

type mockModel struct {
}

Expand Down Expand Up @@ -180,7 +199,9 @@ func (m *mockModel) SignKeyID() string {

func (s *fdeMgrSuite) TestUpdateState(c *C) {
st := s.st
manager := s.startedManager(c)
const onClassic = true
s.AddCleanup(release.MockOnClassic(onClassic))
manager := s.startedManager(c, onClassic)

st.Lock()
defer st.Unlock()
Expand Down Expand Up @@ -209,7 +230,9 @@ func (s *fdeMgrSuite) TestUpdateState(c *C) {

func (s *fdeMgrSuite) TestUpdateReseal(c *C) {
st := s.st
manager := s.startedManager(c)
const onClassic = true
s.AddCleanup(release.MockOnClassic(onClassic))
manager := s.startedManager(c, onClassic)

st.Lock()
defer st.Unlock()
Expand Down Expand Up @@ -261,7 +284,7 @@ type mountResolveTestCase struct {
func (s *fdeMgrSuite) testMountResolveError(c *C, tc mountResolveTestCase) {
defer fdestate.MockDMCryptUUIDFromMountPoint(func(mountpoint string) (string, error) {
switch mountpoint {
case dirs.SnapdStateDir(dirs.GlobalRootDir):
case dirs.GlobalRootDir:
// ubuntu-data
if tc.dataResolveErr != nil {
return "", tc.dataResolveErr
Expand Down
11 changes: 10 additions & 1 deletion overlord/fdestate/fdestate.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"crypto"
"errors"
"fmt"
"path/filepath"

"github.com/snapcore/snapd/asserts"
"github.com/snapcore/snapd/dirs"
Expand All @@ -30,6 +31,7 @@ import (
"github.com/snapcore/snapd/osutil"
"github.com/snapcore/snapd/osutil/disks"
"github.com/snapcore/snapd/overlord/state"
"github.com/snapcore/snapd/release"
"github.com/snapcore/snapd/secboot"
)

Expand Down Expand Up @@ -218,7 +220,14 @@ func initializeState(st *state.State) error {

// FIXME mount points will be different in recovery or factory-reset modes
// either inspect degraded.json, or use boot.HostUbuntuDataForMode()
dataUUID, dataErr := disksDMCryptUUIDFromMountPoint(dirs.SnapdStateDir(dirs.GlobalRootDir))

// On Classic, the data disk is mounted as /
dataDir := dirs.GlobalRootDir
if !release.OnClassic {
// If on Core /writable is a bind mount from data dir
dataDir = filepath.Join(dirs.GlobalRootDir, "writable")
}
dataUUID, dataErr := disksDMCryptUUIDFromMountPoint(dataDir)
saveUUID, saveErr := disksDMCryptUUIDFromMountPoint(dirs.SnapSaveDir)
if errors.Is(saveErr, disks.ErrMountPointNotFound) {
// TODO: do we need to care about old cases where there is no save partition?
Expand Down
4 changes: 3 additions & 1 deletion overlord/managers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7461,7 +7461,9 @@ func (s *mgrsSuiteCore) testRemodelUC20WithRecoverySystem(c *C, encrypted bool)

restore = fdestate.MockDMCryptUUIDFromMountPoint(func(mountpoint string) (string, error) {
switch mountpoint {
case dirs.SnapdStateDir(dirs.GlobalRootDir):
case filepath.Join(dirs.GlobalRootDir, "writable"):
return "root-uuid", nil
case dirs.GlobalRootDir:
return "root-uuid", nil
case dirs.SnapSaveDir:
return "save-uuid", nil
Expand Down

0 comments on commit a80d97c

Please sign in to comment.