interfaces/mount: add partial implementation of Change.Needed #3209

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
2 participants
Contributor

zyga commented Apr 19, 2017

This patch adds a partial implementation of Change.Needed that works for
things that aren't bind mounted. Bind mounting requires some additional
detection because the fstab entry doesn't contain the whole information
and that needs to be reconstructed by looking at mountinfo.

To be precise, the source of the bind mount is only defined indirectly.
In a simple bind mount /src -> /dst the /src is a "pointer" to whatever
is mounted there (cound be something mounted directly at /src or could
be a fragment of the bigger mount at /).

Signed-off-by: Zygmunt Krynicki zygmunt.krynicki@canonical.com

interfaces/mount: add partial implementation of Change.Needed
This patch adds a partial implementation of Change.Needed that works for
things that aren't bind mounted. Bind mounting requires some additional
detection because the fstab entry doesn't contain the whole information
and that needs to be reconstructed by looking at mountinfo.

To be precise, the source of the bind mount is only defined indirectly.
In a simple bind mount /src -> /dst the /src is a "pointer" to whatever
is mounted there (cound be something mounted directly at /src or could
be a fragment of the bigger mount at /).

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
+ //
+ // NOTE: This disregards mount options and and any optional fields that
+ // indicate sharing. Snapd doesn't use those properties yet, except for
+ // read-only bind mounts but those are special anyway.
@niemeyer

niemeyer Apr 25, 2017

Contributor

Why is it ignored, though? I mean, why would we support flags, yet ignore them? Sounds like Needed should report whether it's needed based on whether the information changed.

@zyga

zyga Apr 27, 2017

Contributor

On second thought I think we do need to look at flags. This is also made a little bit more complicated because there are two sets of flags (superblock and mount) and they mean different things.

+ switch c.Action {
+ case Mount:
+ for _, mie := range mounted {
+ if fe.Dir == mie.MountDir && fe.Type == mie.FsType && fe.Name == mie.MountSource && mie.Root == "/" {
@niemeyer

niemeyer Apr 25, 2017

Contributor

What's the root test about?

@zyga

zyga Apr 27, 2017

Contributor

Root is the part of the mounted device that is really mounted at MountDir. Since this branch is not trying to support bind mounts that part is always "/" for normal mounts.

@niemeyer

niemeyer Apr 27, 2017

Contributor

I still don't understand why this is relevant. This logic shouldn't really care whether it's a bind mount or not. If it changed, it's not the same anymore, and it ought to say so.

+ return true
+ case Unmount:
+ for _, mie := range mounted {
+ if fe.Dir == mie.MountDir && fe.Type == mie.FsType && fe.Name == mie.MountSource && mie.Root == "/" {
@niemeyer

niemeyer Apr 25, 2017

Contributor

These are both exactly the same algorithm, so we can pull it out of the switch and perform the comparison ahead of time, and then inside the switch simply take the decision of whether to return true/false or not.

@zyga

zyga Apr 27, 2017

Contributor

I think you are right now but as the bind mount logic is added those won't look the same (I think). If it is still the same later we can optimize this part.

@niemeyer

niemeyer Apr 27, 2017

Contributor

The best practice is actually the opposite: do it tersely while you can, and then expand as necessary. Having that sort of trivially duplicated logic anticipating potential needs makes it harder to have better code later, because your mind is always looking at more logic than it ought to.

Contributor

niemeyer commented Apr 27, 2017

This PR needs some love still.

Contributor

zyga commented May 12, 2017

I'm closing this as I think we don't really need it anymore.

@zyga zyga closed this May 12, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment