interfaces/mount: keep track of kept mount entries #3309

Merged
merged 2 commits into from May 13, 2017
Jump to file or symbol
Failed to load files and symbols.
+12 −2
Split
@@ -31,6 +31,8 @@ import (
type Action string
const (
+ // Keep indicates that a given mount entry should be kept as-is.
+ Keep Action = "keep"
@morphis

morphis May 12, 2017

Contributor

What actually uses this keyword?

@zyga

zyga May 12, 2017

Contributor

snap-update-ns does (in upcoming branch)

@morphis

morphis May 12, 2017

Contributor

Ah ok, that is why I didn't found it anywhere.

// Mount represents an action that results in mounting something somewhere.
Mount Action = "mount"
// Unmount represents an action that results in unmounting something from somewhere.
@@ -135,7 +137,9 @@ func NeededChanges(currentProfile, desiredProfile *Profile) []Change {
// Unmount entries not reused in reverse to handle children before their parent.
for i := len(current) - 1; i >= 0; i-- {
- if !reuse[current[i].Dir] {
+ if reuse[current[i].Dir] {
+ changes = append(changes, Change{Action: Keep, Entry: current[i]})
+ } else {
changes = append(changes, Change{Action: Unmount, Entry: current[i]})
}
}
@@ -50,7 +50,9 @@ func (s *changeSuite) TestNeededChangesNoChange(c *C) {
current := &mount.Profile{Entries: []mount.Entry{{Dir: "/common/stuf"}}}
desired := &mount.Profile{Entries: []mount.Entry{{Dir: "/common/stuf"}}}
changes := mount.NeededChanges(current, desired)
- c.Assert(changes, IsNil)
+ c.Assert(changes, DeepEquals, []mount.Change{
+ {Entry: mount.Entry{Dir: "/common/stuf"}, Action: mount.Keep},
+ })
}
// When the content interface is connected we should mount the new entry.
@@ -115,6 +117,7 @@ func (s *changeSuite) TestNeededChangesChangedParentSameChild(c *C) {
}}
changes := mount.NeededChanges(current, desired)
c.Assert(changes, DeepEquals, []mount.Change{
+ {Entry: mount.Entry{Dir: "/common/unrelated"}, Action: mount.Keep},
{Entry: mount.Entry{Dir: "/common/stuf/extra"}, Action: mount.Unmount},
{Entry: mount.Entry{Dir: "/common/stuf", Name: "/dev/sda1"}, Action: mount.Unmount},
{Entry: mount.Entry{Dir: "/common/stuf", Name: "/dev/sda2"}, Action: mount.Mount},
@@ -136,7 +139,9 @@ func (s *changeSuite) TestNeededChangesSameParentChangedChild(c *C) {
}}
changes := mount.NeededChanges(current, desired)
c.Assert(changes, DeepEquals, []mount.Change{
+ {Entry: mount.Entry{Dir: "/common/unrelated"}, Action: mount.Keep},
{Entry: mount.Entry{Dir: "/common/stuf/extra", Name: "/dev/sda1"}, Action: mount.Unmount},
+ {Entry: mount.Entry{Dir: "/common/stuf"}, Action: mount.Keep},
{Entry: mount.Entry{Dir: "/common/stuf/extra", Name: "/dev/sda2"}, Action: mount.Mount},
})
}
@@ -163,6 +168,7 @@ func (s *changeSuite) TestNeededChangesSmartEntryComparison(c *C) {
{Entry: mount.Entry{Dir: "/a/b/c"}, Action: mount.Unmount},
{Entry: mount.Entry{Dir: "/a/b", Name: "/dev/sda1"}, Action: mount.Unmount},
{Entry: mount.Entry{Dir: "/a/b-1/3"}, Action: mount.Unmount},
+ {Entry: mount.Entry{Dir: "/a/b-1"}, Action: mount.Keep},
{Entry: mount.Entry{Dir: "/a/b", Name: "/dev/sda2"}, Action: mount.Mount},
{Entry: mount.Entry{Dir: "/a/b/c"}, Action: mount.Mount},