Skip to content

RUN: only use an overlay for --mount=type=bind,rw on overlay #6126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

nalind
Copy link
Member

@nalind nalind commented Apr 15, 2025

What type of PR is this?

/kind bug

What this PR does / why we need it:

Only use an overlay for --mounts of type=bind,rw, where changes should be discarded, if the storage driver is overlay. Otherwise, make a temporary copy.

How to verify it

Updated CI to test {vfs|overlay} over {vfs|overlay}, which would have caught this.

Which issue(s) this PR fixes:

Should fix #5988.

Special notes for your reviewer:

Basically what #5988 (comment) suggested.

Does this PR introduce a user-facing change?

When not using overlay for storage, running `buildah run` or executing a `buildah build` RUN instruction with the `--mount=type=bind,rw` flag will now use a temporary copy to ensure that writes are discarded, instead of attempting to mount an overlay filesystem using the source location as a "lower".

@openshift-ci openshift-ci bot added do-not-merge/work-in-progress kind/bug Categorizes issue or PR as related to a bug. approved labels Apr 15, 2025
@nalind nalind force-pushed the overlay-copy branch 7 times, most recently from 6084d5f to b81b006 Compare April 17, 2025 18:20
Copy link

Ephemeral COPR build failed. @containers/packit-build please check.

@nalind nalind force-pushed the overlay-copy branch 2 times, most recently from 86b6879 to f0e6488 Compare April 23, 2025 21:57
@nalind nalind force-pushed the overlay-copy branch 6 times, most recently from 04b80e1 to e62f77c Compare April 25, 2025 20:55
Copy link

@cgwalters cgwalters left a comment

Choose a reason for hiding this comment

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

I only gave this a quick skim and I don't know the code really, but FWIW looks sane to me.

@@ -118,6 +120,87 @@ func convertToOverlay(m specs.Mount, store storage.Store, mountLabel, tmpDir str
return mountThisInstead, overlayDir, nil
}

func makeTempCopy(m specs.Mount, tmpDir string, uid, gid int) (specs.Mount, string, error) {

Choose a reason for hiding this comment

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

This function seems like it could use a doc comment.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added one.

@TomSweeneyRedHat
Copy link
Member

@nalind looks lke you need an update here.

tests/run.bats Outdated
@@ -420,23 +420,23 @@ function configure_and_check_user() {
cid=$output
mkdir -p ${TEST_SCRATCH_DIR}/was:empty
# As a baseline, this should succeed.
run_buildah run --mount type=tmpfs,dst=/var/tmpfs-not-empty $cid touch /var/tmpfs-not-empty/testfile
run_buildah run --mount type=tmpfs,dst=/var/tmpfs-not-empty $cid touch /var/tmpfs-not-empty/testfile
Copy link
Member

@Honny1 Honny1 Jun 5, 2025

Choose a reason for hiding this comment

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

Not blocking: I'm not sure if the spaces are intentional, but if they are to improve readability. It might be better to move the value of the --mount argument to a separate variable.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, that does help. Thanks!

Copy link
Member

@Honny1 Honny1 left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM. I haven't noticed any problems. I think a rebase will be necessary.

/approve

Copy link
Contributor

openshift-ci bot commented Jun 5, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Honny1, nalind

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

nalind added 10 commits June 5, 2025 10:01
Expand our task that runs the integration tests inside of a container
from running buildah-using-vfs-inside-podman-using-vfs and
buildah-using-overlay-inside-podman-using-overlay to also test vfs over
overlay, and overlay over vfs.

Signed-off-by: Nalin Dahyabhai <[email protected]>
Only use an overlay for --mounts of type=bind,rw, where changes should
be discarded, if the storage driver is overlay.  Otherwise, make a
temporary copy and use a bind mount to the copy.

Signed-off-by: Nalin Dahyabhai <[email protected]>
If we're forcing a mount using overlay, but we fail, and our chosen
upper directory is on overlay, try using fuse-overlayfs.

Signed-off-by: Nalin Dahyabhai <[email protected]>
Force the mount of the overlay in runSetupVolumeMounts() so that we can
take advantage of logic that tries to use fuse-overlayfs if we happen to
be on top of overlay, which would otherwise fail.

Signed-off-by: Nalin Dahyabhai <[email protected]>
Force the mount of the overlay in volumeCacheSaveOverlay(), and clean it
up in volumeCacheRestoreOverlay(), so that we can take advantage of
logic that tries to use fuse-overlayfs if we happen to be on top of
overlay, which would otherwise fail.

Signed-off-by: Nalin Dahyabhai <[email protected]>
Drop the conditional ,z that we were trying to add when testing the -v
flag with the "O" option, the combination of which is not allowed by
github.com/containers/common/pkg/parse.ValidateVolumeOpts().

Signed-off-by: Nalin Dahyabhai <[email protected]>
When grepping the mounts list for the root mount, also accept the entry
if "rw" is the only flag.

Signed-off-by: Nalin Dahyabhai <[email protected]>
If we're on overlayfs, we can't use the directory name that we'd like to
use as part of the test and expect things to succeed, even if we try to
work around it using fuse-overlayfs.

Signed-off-by: Nalin Dahyabhai <[email protected]>
If we're on overlayfs, we can't use the directory name that we'd like to
use as part of the test and expect things to succeed, even if we try to
work around it using fuse-overlayfs.

Signed-off-by: Nalin Dahyabhai <[email protected]>
When setting up a chroot using overlay, if the intended upper directory
is already on an overlayfs, mount a tmpfs onto it so that we can finish
setting up the chroot that's an overlayfs that we'll actually test in,
and copy the base image into the storage that it'll use.

Signed-off-by: Nalin Dahyabhai <[email protected]>
Copy link
Contributor

@mtrmac mtrmac left a comment

Choose a reason for hiding this comment

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

I don’t know enough to judge the volumeCache… part.

Overall, I suppose the added test coverage should be decisive.

if newMount, overlayDir, err = convertToOverlay(newMount, store, mountLabel, tmpDir, 0, 0); err != nil {
return newMount, "", "", "", err
switch store.GraphDriverName() {
case "overlay":
Copy link
Contributor

Choose a reason for hiding this comment

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

(There is precedent for hard-coding a condition like this … but maybe the checks could all be consolidated into a single function.)

Comment on lines +1204 to +1205
ForceMount: true,
MountLabel: b.MountLabel,
Copy link
Contributor

@mtrmac mtrmac Jun 6, 2025

Choose a reason for hiding this comment

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

Force the mount of the overlay in runSetupVolumeMounts() so that we can
take advantage of logic that tries to use fuse-overlayfs if we happen to
be on top of overlay, which would otherwise fail.

I read that as potentially unclean… if using fuse-overlay this way is expected for an “overlay” mount, shouldn’t the consumer of the created specs.Mount be able to handle that universally, instead of us special-casing it and adding an extra mount operation every time?

*shrug* I suppose changing all relevant OCI runtimes is unpalatable?

With this, every single caller in Buildah except for run_freebsd.go (but not the callers in podman/libpod) sets ForceMount. Is that correct, or should the option be removed entirely?

Copy link

github-actions bot commented Jul 7, 2025

A friendly reminder that this PR had no activity for 30 days.

@TomSweeneyRedHat
Copy link
Member

@nalind merge conflict here that needs some massaging.

@github-actions github-actions bot removed the stale-pr label Jul 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved kind/bug Categorizes issue or PR as related to a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ERRO[0025] unlinkat /var/tmp/buildah2410054376/mounts3022885724/bind626918239: device or resource busy
7 participants