Skip to content

Commit

Permalink
fixup! overlord/fdestate/fdestate.go: fix path to data mount point on…
Browse files Browse the repository at this point in the history
… hybrid
  • Loading branch information
valentindavid committed Nov 21, 2024
1 parent a80d97c commit 457e84e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
10 changes: 10 additions & 0 deletions dirs/dirs.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ var (
SysfsDir string

FeaturesDir string

RootDataDir string
)

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

if release.OnClassic {
// On Classic, the data disk is mounted as /
RootDataDir = rootdir
} else {
// If on Core /writable is a bind mount from data dir
RootDataDir = 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) TestRootDataDir(c *C) {
release.MockOnClassic(true)
dirs.SetRootDir("/")

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

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

c.Check(dirs.RootDataDir, Equals, "/writable")
}
10 changes: 8 additions & 2 deletions overlord/fdestate/fdemgr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,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 All @@ -84,8 +86,6 @@ func (s *fdeMgrSuite) SetUpTest(c *C) {
}
err := m.WriteTo(dirs.GlobalRootDir)
c.Assert(err, IsNil)

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

type instrumentedUnlocker struct {
Expand Down Expand Up @@ -143,6 +143,8 @@ func (s *fdeMgrSuite) startedManager(c *C, onClassic bool) *fdestate.FDEManager
func (s *fdeMgrSuite) testGetManagerFromState(c *C, onClassic bool) {
st := s.st
s.AddCleanup(release.MockOnClassic(onClassic))
dirs.SetRootDir(s.rootdir)

manager := s.startedManager(c, onClassic)

st.Lock()
Expand Down Expand Up @@ -201,6 +203,8 @@ func (s *fdeMgrSuite) TestUpdateState(c *C) {
st := s.st
const onClassic = true
s.AddCleanup(release.MockOnClassic(onClassic))
dirs.SetRootDir(s.rootdir)

manager := s.startedManager(c, onClassic)

st.Lock()
Expand Down Expand Up @@ -232,6 +236,8 @@ func (s *fdeMgrSuite) TestUpdateReseal(c *C) {
st := s.st
const onClassic = true
s.AddCleanup(release.MockOnClassic(onClassic))
dirs.SetRootDir(s.rootdir)

manager := s.startedManager(c, onClassic)

st.Lock()
Expand Down
11 changes: 1 addition & 10 deletions overlord/fdestate/fdestate.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"crypto"
"errors"
"fmt"
"path/filepath"

"github.com/snapcore/snapd/asserts"
"github.com/snapcore/snapd/dirs"
Expand All @@ -31,7 +30,6 @@ 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 @@ -220,14 +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()

// 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)
dataUUID, dataErr := disksDMCryptUUIDFromMountPoint(dirs.RootDataDir)
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

0 comments on commit 457e84e

Please sign in to comment.