From 457e84ef881d6dcd696171a3a0b8ab6a80e27075 Mon Sep 17 00:00:00 2001 From: Valentin David Date: Thu, 21 Nov 2024 12:47:34 +0100 Subject: [PATCH] fixup! overlord/fdestate/fdestate.go: fix path to data mount point on hybrid --- dirs/dirs.go | 10 ++++++++++ dirs/dirs_test.go | 14 ++++++++++++++ overlord/fdestate/fdemgr_test.go | 10 ++++++++-- overlord/fdestate/fdestate.go | 11 +---------- 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/dirs/dirs.go b/dirs/dirs.go index f1d441ee33f..7711b4b4951 100644 --- a/dirs/dirs.go +++ b/dirs/dirs.go @@ -141,6 +141,8 @@ var ( SysfsDir string FeaturesDir string + + RootDataDir string ) // User defined home directory variables @@ -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 diff --git a/dirs/dirs_test.go b/dirs/dirs_test.go index e0aa31489cf..9c0fa0a930c 100644 --- a/dirs/dirs_test.go +++ b/dirs/dirs_test.go @@ -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") +} diff --git a/overlord/fdestate/fdemgr_test.go b/overlord/fdestate/fdemgr_test.go index ca26a837f5b..860d385e4a7 100644 --- a/overlord/fdestate/fdemgr_test.go +++ b/overlord/fdestate/fdemgr_test.go @@ -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("") }) @@ -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 { @@ -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() @@ -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() @@ -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() diff --git a/overlord/fdestate/fdestate.go b/overlord/fdestate/fdestate.go index 4cd298ab812..6a5bc677e12 100644 --- a/overlord/fdestate/fdestate.go +++ b/overlord/fdestate/fdestate.go @@ -22,7 +22,6 @@ import ( "crypto" "errors" "fmt" - "path/filepath" "github.com/snapcore/snapd/asserts" "github.com/snapcore/snapd/dirs" @@ -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" ) @@ -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?