This patch adds a pair of functions that aim to assist in implementation
of Change.Needed.
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
A comment for this section with an example would be nice telling how when searching for /foo/bar/baz if that isn't found, /foo/bar will be checked, onwards until the terminating condition of '/'.
+ }
+
+ // rfrag is reversed, let's correct that and re-construct the path.
+ frag = make([]string, 0, len(rfrag)+1)
+ frag = append(frag, foundEntry.Root)
+ fori:=len(rfrag) - 1; i >= 0; i-- {
+ frag = append(frag, rfrag[i])
+ }
+ foundDir:= path.Join(frag...)
+ return foundDir, foundEntry, nil
+}
+
+// AliasesOf finds aliases of a given directory in a given mountinfo table.
+//
+// When the kernel bind mounts something it produces another, indistinguishable
+// place where a given entry may be found. The algorithm works by looking at
+// MountSource (what is mounted) and MountOptions (how is it mounted).
The comment here is somewhat convoluted. Perhaps restructure it like:
// Search for equivalent mount points by matching their:
// - DevMajor:DevMinor against what the searched directory resolved to
// - Root (fragment mounted) against the fragment (relative to the root of the
// mounted filesystem) of the searched directory.
Saying something about how the kernel works here would be really helpful. Why are you looking at major:minor? What are you defining as an 'equivalent mountpoint'? What do you mean by 'fragement mounted'? What are you calling a 'fragment'? etc, etc
It seems you are trying say something about when have something like this (taken from /proc/self/mountinfo within snap on classic):
that because all of these have the same major:minor (ie, 7:14), they are all related to the root mount point in an important way (ie, 2001 1781 7:14 / / rw,relatime master:44 - squashfs /dev/loop14 ro). Stating that relationship would be very important here (with references if available).
I'm not sure introducing a new terminology ('mount alias') is wise. Perhaps bounds, err := BoundTogether(...)? That's a little awkward, but at least let's people understand that the function is for bind mounts.
Indeed, I was looking for a better word and I knew that alias clashes with other snapd terminology but I just ran with it because I failed to find anything sensible.
+ }
+}
+
+// Check that AliasesOf finds a trio of bind mounts.
A comment for this section with an example would be nice telling how when searching for /foo/bar/baz if that isn't found, /foo/bar will be checked, onwards until the terminating condition of '/'.