Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

overlord/fdestate/fdestate.go: fix path to data mount point on hybrid #14734

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions dirs/dirs.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ var (
SysfsDir string

FeaturesDir string

// WritableMountPath is a path where writable root data is
// mounted. For Classic it is /, but Ubuntu Core it is
// /writable.
WritableMountPath string
)

// User defined home directory variables
Expand Down Expand Up @@ -635,6 +640,14 @@ func SetRootDir(rootdir string) {
c(rootdir)
}

if release.OnClassic {
// On Classic, the data disk is mounted as /
WritableMountPath = rootdir
} else {
// If on Core /writable is a bind mount from data dir
WritableMountPath = filepath.Join(rootdir, "writable")
}

}

// what inside a (non-classic) snap is /usr/lib/snapd, outside can come from different places
Expand Down
14 changes: 14 additions & 0 deletions dirs/dirs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,17 @@ func (s *DirsTestSuite) TestLibexecdirOpenSUSEFlavors(c *C) {
dirs.SetRootDir("/")
c.Check(dirs.DistroLibExecDir, Equals, "/usr/libexec/snapd")
}

func (s *DirsTestSuite) TestWritableMountPath(c *C) {
release.MockOnClassic(true)
dirs.SetRootDir("/")

c.Check(dirs.WritableMountPath, Equals, "/")
}

func (s *DirsTestSuite) TestWritableMountPathCore(c *C) {
release.MockOnClassic(false)
dirs.SetRootDir("/")

c.Check(dirs.WritableMountPath, Equals, "/writable")
}
43 changes: 36 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 All @@ -56,6 +58,8 @@ var _ = Suite(&fdeMgrSuite{})
func (s *fdeMgrSuite) SetUpTest(c *C) {
s.BaseTest.SetUpTest(c)

s.AddCleanup(release.MockOnClassic(true))

s.rootdir = c.MkDir()
dirs.SetRootDir(s.rootdir)
s.AddCleanup(func() { dirs.SetRootDir("") })
Expand Down Expand Up @@ -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,12 @@ 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))
dirs.SetRootDir(s.rootdir)

manager := s.startedManager(c, onClassic)

st.Lock()
defer st.Unlock()
Expand All @@ -151,6 +162,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 +201,11 @@ 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))
dirs.SetRootDir(s.rootdir)

manager := s.startedManager(c, onClassic)

st.Lock()
defer st.Unlock()
Expand Down Expand Up @@ -209,7 +234,11 @@ 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))
dirs.SetRootDir(s.rootdir)

manager := s.startedManager(c, onClassic)

st.Lock()
defer st.Unlock()
Expand Down Expand Up @@ -261,7 +290,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
2 changes: 1 addition & 1 deletion overlord/fdestate/fdestate.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ 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))
dataUUID, dataErr := disksDMCryptUUIDFromMountPoint(dirs.WritableMountPath)
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
Loading