diff options
| author | Michael Vogt <mvo@ubuntu.com> | 2018-12-12 22:03:12 +0100 |
|---|---|---|
| committer | Michael Vogt <mvo@ubuntu.com> | 2018-12-12 22:03:12 +0100 |
| commit | 093e99a0f6f6cf2b461bcdeb667776a86f040ee0 (patch) | |
| tree | fa8e3ee2897a452f38bd27f866d3a667bf00c301 | |
| parent | 916ac42cd30a52159cf5d6369306d63cc52504ab (diff) | |
snapstate/backend: make {add,remove}MountUnit part of the backendsnapd-gil
| -rw-r--r-- | overlord/snapstate/backend/export_test.go | 14 | ||||
| -rw-r--r-- | overlord/snapstate/backend/mountunit.go | 13 | ||||
| -rw-r--r-- | overlord/snapstate/backend/mountunit_test.go | 10 | ||||
| -rw-r--r-- | overlord/snapstate/backend/setup.go | 4 |
4 files changed, 25 insertions, 16 deletions
diff --git a/overlord/snapstate/backend/export_test.go b/overlord/snapstate/backend/export_test.go index 2ff5ecf906..98aebe0de1 100644 --- a/overlord/snapstate/backend/export_test.go +++ b/overlord/snapstate/backend/export_test.go @@ -19,11 +19,19 @@ package backend -var ( - AddMountUnit = addMountUnit - RemoveMountUnit = removeMountUnit +import ( + "github.com/snapcore/snapd/progress" + "github.com/snapcore/snapd/snap" ) +func (b *Backend) AddMountUnit(s *snap.Info, meter progress.Meter) error { + return b.addMountUnit(s, meter) +} + +func (b *Backend) RemoveMountUnit(baseDir string, meter progress.Meter) error { + return b.removeMountUnit(baseDir, meter) +} + func MockUpdateFontconfigCaches(f func() error) (restore func()) { oldUpdateFontconfigCaches := updateFontconfigCaches updateFontconfigCaches = f diff --git a/overlord/snapstate/backend/mountunit.go b/overlord/snapstate/backend/mountunit.go index 1cd6cdf55b..634d1b850a 100644 --- a/overlord/snapstate/backend/mountunit.go +++ b/overlord/snapstate/backend/mountunit.go @@ -23,7 +23,6 @@ import ( "os" "os/exec" "path/filepath" - "sync" "time" "github.com/snapcore/snapd/dirs" @@ -36,9 +35,9 @@ import ( // addMountUnit adds a new mount unit for the given snap "s". It requires // a lock that ensures there is only a single concurrent operation that // manipulates mount units (see https://github.com/systemd/systemd/issues/10872) -func addMountUnit(s *snap.Info, meter progress.Meter, lock *sync.Mutex) error { - lock.Lock() - defer lock.Unlock() +func (b *Backend) addMountUnit(s *snap.Info, meter progress.Meter) error { + b.mountLock.Lock() + defer b.mountLock.Unlock() squashfsPath := dirs.StripRootDir(s.MountFile()) whereDir := dirs.StripRootDir(s.MountDir()) @@ -65,9 +64,9 @@ func addMountUnit(s *snap.Info, meter progress.Meter, lock *sync.Mutex) error { // removeMountUnit removes the mount unit for the given baseDir. It requires // a lock that ensures there is only a single concurrent operation that // manipulates mount units (see https://github.com/systemd/systemd/issues/10872) -func removeMountUnit(baseDir string, meter progress.Meter, lock *sync.Mutex) error { - lock.Lock() - defer lock.Unlock() +func (b *Backend) removeMountUnit(baseDir string, meter progress.Meter) error { + b.mountLock.Lock() + defer b.mountLock.Unlock() sysd := systemd.New(dirs.GlobalRootDir, meter) unit := systemd.MountUnitPath(dirs.StripRootDir(baseDir)) diff --git a/overlord/snapstate/backend/mountunit_test.go b/overlord/snapstate/backend/mountunit_test.go index a2afb029ea..acfd5bf885 100644 --- a/overlord/snapstate/backend/mountunit_test.go +++ b/overlord/snapstate/backend/mountunit_test.go @@ -23,7 +23,6 @@ import ( "fmt" "os" "path/filepath" - "sync" . "gopkg.in/check.v1" @@ -39,6 +38,7 @@ import ( type mountunitSuite struct { umount *testutil.MockCmd + be *backend.Backend systemctlRestorer func() } @@ -55,6 +55,8 @@ func (s *mountunitSuite) SetUpTest(c *C) { return []byte("ActiveState=inactive\n"), nil }) s.umount = testutil.MockCommand(c, "umount", "") + + s.be = &backend.Backend{} } func (s *mountunitSuite) TearDownTest(c *C) { @@ -75,7 +77,7 @@ func (s *mountunitSuite) TestAddMountUnit(c *C) { Version: "1.1", Architectures: []string{"all"}, } - err := backend.AddMountUnit(info, progress.Null, &sync.Mutex{}) + err := s.be.AddMountUnit(info, progress.Null) c.Assert(err, IsNil) // ensure correct mount unit @@ -106,7 +108,7 @@ func (s *mountunitSuite) TestRemoveMountUnit(c *C) { Architectures: []string{"all"}, } - err := backend.AddMountUnit(info, progress.Null, &sync.Mutex{}) + err := s.be.AddMountUnit(info, progress.Null) c.Assert(err, IsNil) // ensure we have the files @@ -115,7 +117,7 @@ func (s *mountunitSuite) TestRemoveMountUnit(c *C) { c.Assert(osutil.FileExists(p), Equals, true) // now call remove and ensure they are gone - err = backend.RemoveMountUnit(info.MountDir(), progress.Null, &sync.Mutex{}) + err = s.be.RemoveMountUnit(info.MountDir(), progress.Null) c.Assert(err, IsNil) p = filepath.Join(dirs.SnapServicesDir, un) c.Assert(osutil.FileExists(p), Equals, false) diff --git a/overlord/snapstate/backend/setup.go b/overlord/snapstate/backend/setup.go index eddfb4e795..87dd8960a0 100644 --- a/overlord/snapstate/backend/setup.go +++ b/overlord/snapstate/backend/setup.go @@ -69,7 +69,7 @@ func (b *Backend) SetupSnap(snapFilePath, instanceName string, sideInfo *snap.Si } // generate the mount unit for the squashfs - if err := addMountUnit(s, meter, &b.mountLock); err != nil { + if err := b.addMountUnit(s, meter); err != nil { return snapType, err } @@ -87,7 +87,7 @@ func (b *Backend) RemoveSnapFiles(s snap.PlaceInfo, typ snap.Type, meter progres mountDir := s.MountDir() // this also ensures that the mount unit stops - if err := removeMountUnit(mountDir, meter, &b.mountLock); err != nil { + if err := b.removeMountUnit(mountDir, meter); err != nil { return err } |
