Skip to content

fix mount propagation causing repeated runs - #3602

Merged
vito merged 3 commits into
dagger:mainfrom
vito:fix-mount-propagation
Oct 31, 2022
Merged

vito merged 3 commits into
dagger:mainfrom
vito:fix-mount-propagation

Conversation

@vito

@vito vito commented Oct 30, 2022 •

Copy link
Copy Markdown
Contributor

fixes #3551

  • propagate mounts from the result of running the command with every mount, rather than one at a time as we iterate, which meant each mount technically had a different llb state.
  • remove stacking semantics as Buildkit currently assumes mount targets are unique (see second commit message)

fixes dagger#3551

propagate mounts from the result of running the command with every
mount, rather than one at a time as we iterate, which meant each mount
technically had a different llb state.

Signed-off-by: Alex Suraci <[email protected]>
"Stacking" in this commit means mounting over a path rather than
replacing it. On Linux this is allowed and unmounting the upper mount
will reveal the lower one.

Buildkit however currently assumes mounts have unique paths:

* GetMount returns the first one listed, rather than the last, which is
  what you'd want for stacked mounts as it's the mount that was actually
  visible to the process.
* Many APIs (e.g. Marshal) internally sort the mounts by the target
  name, implying that they don't expect collisions and marshaling may
  become nondeterministic without stable sorting.

So instead we'll just replace any mounts at the exact same target path.
It is no longer possible to unmount it to reveal the prior mount.

We could change Buildkit to not do this sorting and to have GetMount
return the upper mount, but for now this seems like the safest step
assuming this is not a common use case. We can always re-introduce
stacking if/when Buildkit supports it.

Signed-off-by: Alex Suraci <[email protected]>
@vito
vito requested review from aluzzardi, shykes and sipsma October 31, 2022 16:02
Comment thread core/container.go Outdated
var replaced bool
for i, mnt := range mntsCp {
if mnt.Target == newMnt.Target {
mntsCp[i] = newMnt

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be better to remove from the found index and append to the end instead to match stacking semantics, i.e. so later mounts to subpaths of the target don't mount "over" it. Not sure if that's what'll actually happen though.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICT this is handled on our behalf by the sorting of mount targets in the LLB code, so I think we're fine? Could add a test case that does something like:

  1. Mount A at /foo/bar
  2. Mount B at /foo (blocks out previous mount)
  3. Mount C at /foo/bar

Where the expected behavior should be that C is actually visible.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right, so it doesn't really matter where we insert.

Added a test that checks that when adding mount B above, mount A is removed and we can still add mount C after. I think this is more correct than the current behavior which allows it to stick around. But we're really splitting hairs, I'd be equally happy to remove this and leave the behavior undefined until someone has a use case. 🤷

@sipsma sipsma left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, one comment about a possible test to add to verify behavior.

It seems like if we modified upstream client/llb to instead call sort.SliceStable on exec state mounts then we could probably retain the stacking behavior (?), but this case of stacked vs. non-stacked is obscure enough that I don't think it matters right now.

Comment thread core/container.go Outdated
var replaced bool
for i, mnt := range mntsCp {
if mnt.Target == newMnt.Target {
mntsCp[i] = newMnt

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICT this is handled on our behalf by the sorting of mount targets in the LLB code, so I think we're fine? Could add a test case that does something like:

  1. Mount A at /foo/bar
  2. Mount B at /foo (blocks out previous mount)
  3. Mount C at /foo/bar

Where the expected behavior should be that C is actually visible.

clobbering in this PR means mounting in this order:

* /mnt/foo
* /mnt
* /mnt/bar

In this case we should expect /mnt/foo to disappear when /mnt is
mounted, and for /mnt/bar to be visible with new content since it was
mounted over the clobberer. (/mnt/bar could also be /mnt/foo but it's
easier to explain this way.)

Signed-off-by: Alex Suraci <[email protected]>
@vito

vito commented Oct 31, 2022

Copy link
Copy Markdown
Contributor Author

It seems like if we modified upstream client/llb to instead call sort.SliceStable on exec state mounts then we could probably retain the stacking behavior (?), but this case of stacked vs. non-stacked is obscure enough that I don't think it matters right now.

@sipsma Yeah, I think so, but at this point I'm a little worried about any other areas in Buildkit that assume mounts are unique. Agree that it seems sufficiently edge-casey to not worry about going above and beyond.

This is ready for another look, I tweaked the replacing semantics to simulate more aspects of stacking (basically remove /mnt/foo when mounting over /mnt).

@vito vito added this to the Go SDK 0.4.0 milestone Oct 31, 2022
@vito
vito merged commit b4bb0b9 into dagger:main Oct 31, 2022
@vito
vito deleted the fix-mount-propagation branch October 31, 2022 22:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐞 Odd container behavior with exec / multiple withMountedDirectory

2 participants