Skip to content

Keep a directory mount when a file from the same folder is also mounted - #990

Open
guanchzhou wants to merge 1 commit into
apple:mainfrom
guanchzhou:fix/file-mount-shared-parent
Open

guanchzhou wants to merge 1 commit into
apple:mainfrom
guanchzhou:fix/file-mount-shared-parent

Conversation

@guanchzhou

Copy link
Copy Markdown

Fixes apple/container#2148.

Problem

A single-file mount is served by sharing the file's parent directory and bind mounting the file out of it. Shares are tagged by hashFilePath(source), so when the file's parent is also a directory mount, the holding share and the user's share have the same tag. LinuxContainer and LinuxPod drop every mount whose tag is in holdingDirectoryTags when they build the OCI spec, so the user's directory mount is dropped too. The directory disappears from the container without an error.

This matches the cases reported in apple/container#2148 (comment) (C below is the failing one):

Case Mounts Before After
A the same folder at two paths both present both present
B two files from the same folder both present both present
C a folder at /x, one of its files at /z/f /x missing both present
D a folder at /x, a file from another folder at /x/g both present both present
E a folder at /x, a file from its subfolder at /x/a/f both present both present

Change

FileMountContext.prepare now collects the tags of directory mounts first. A file whose parent directory is already a directory mount reuses that share: no holding share is added and its tag is not recorded in holdingDirectoryTags. The file's bind mount still comes from /run/virtiofs/<tag>, which the directory mount provides.

Testing

  • New FileMountTests cover cases A–E, with the file listed both before and after the directory in case C. They check which destinations survive the holding-tag filter and that every file mount has a share with its tag. Without the change, only case C fails.
  • swift test passes.
  • make check passes.

A single-file mount is served by sharing the file's parent directory.
Shares are tagged by a hash of their host path, so when that parent is
also a directory mount, both use the same tag. The holding-tag filter
applied when building the OCI spec then removed the user's directory
mount along with the holding share, and the directory disappeared from
the container without an error.

When a file's parent directory is already a directory mount, reuse that
share for the file and do not record its tag as a holding tag.

Fixes apple/container#2148.

This branch has not been deployed

No deployments
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.

[Bug]: A file mount nested inside a directory mount replaces the parent share (directory mounts unaffected)

1 participant