Commit Graph
32 Commits
Author SHA1 Message Date
Derek McGowan 0b641f0099 mount: honor a claimed transform as a chain suffix
A claimed transform was recorded but never actually left unapplied:
every parsed transformer in a mount's chain was applied in full
regardless of what the caller had claimed, so a shim advertising it
performs "mkdir" in "format/mkdir/overlay" never got the chance to,
since the manager silently applied it anyway. This predates the shim
capability protocol — it was reachable before through the "format/*"
annotation convention — but this series turns it into a documented,
supported way for a shim to claim a transform, so a shim relying on it
(at least one is: Kata's EROFS snapshotter shim, per its annotation
usage) would find its claim silently ignored.

A claimed transform can only be honored as a suffix of the chain: each
transform's input is the previous one's output, so an outer, unclaimed
transform must still be applied even when an inner one is claimed,
since the inner one cannot run without it. planActivation now tracks,
per mount, how much of its chain — starting from the beginning — the
manager must apply itself: through the last unclaimed transform, which
by construction covers every transform before it too. Applying only
that prefix and returning the true, contiguous claimed suffix to the
caller is what actually makes the claim meaningful. This is only
observable for mounts[firstSystemMount], the one mount partially
transformed by the manager and returned to the caller to finish; every
earlier mount is fully internal to the manager and was, and remains,
always fully transformed regardless of any claim.

While changing this expression, also guard it against the case where
firstSystemMount reaches len(mounts) — every mount consumed inside the
manager, with no system mount left to transform — which indexes out of
range today. This is a distinct, pre-existing latent panic (for
example, reachable via WithTemporary combined with a transformed mount
type), tracked separately from the claim-handling fix above; guarding
it here only prevents a crash newly reachable by touching this line,
it does not address the mount.ActivationInfo.System non-empty
invariant that scenario also violates.

Signed-off-by: Derek McGowan <derek@mcg.dev>
2026-08-26 10:49:00 -07:00
Derek McGowan 8ba69faf06 mount: extract activation planning
Activate's planning phase — deciding, for each mount, which transforms
the manager must apply and whether the manager or the caller performs
the mount itself — was inline in a bolt transaction spanning hundreds
of lines, and every existing test of it goes through the full Activate
path, which needs root to mount anything for real.

Extract it into planActivation, a pure function of the mount list,
activation options, and registered transforms/handlers. No behavior
change; this is what makes the next commit's fix testable without
root.

Signed-off-by: Derek McGowan <derek@mcg.dev>
2026-08-26 10:49:00 -07:00
Derek McGowan 00967ecf03 mount: add WithAllowTransform activate option
A caller that applies a mount transform itself had to say so by naming the
mount type "format/*", a sentinel the mount manager constructs internally
by concatenating a transform name with "/*". Both sides had to
independently know and agree on that convention, and the resulting string
is neither a mount type nor a transform name.

Add AllowTransforms, and WithAllowTransform to set it, so a transform can
be claimed by its own name instead. The "/*" convention is removed rather
than kept as a second accepted spelling: it existed only to be produced by
the runtime-allow-mounts annotation, which is removed in an earlier commit
in this series, and there is no other producer of it in this tree.

Signed-off-by: Derek McGowan <derek@mcg.dev>
2026-08-26 10:49:00 -07:00
SaloniRathi 807fbc13dc core/mount/manager: improve TestMkdirHandler failure messages
Signed-off-by: SaloniRathi <45892093+SaloniRathi@users.noreply.github.com>
2026-07-16 17:43:32 -05:00
Austin VazquezandRob Murray 3bc019ea3d fix: close boltdb on metadata and mount plugin close
Co-authored-by: Rob Murray <rob.murray@docker.com>
Signed-off-by: Austin Vazquez <austin.vazquez@docker.com>
2026-05-05 17:20:26 -05:00
Derek McGowan 80ec03fe7e core/mount: Fix mount manager activation error when already exists
Correctly handle cases where the mount activation still exists:
- If activation is fully activate, then just return already exists and
  allow the caller to return error or call Info to continue.
- If activation is stale or incomplete due to crash during activation,
  overwrite the identifier and cleanup the incomplete activation during
  activate.

Signed-off-by: Derek McGowan <derek@mcg.dev>
2026-04-20 18:04:16 -07:00
Akihiro Suda 317286ac00 Merge pull request #12581 from ticpu/fix-12549-ctr-image-mount-fails-no-such-device
Fix ctr image mount failing with no such device
2026-01-28 02:50:36 +00:00
Jérôme Poulin 776e50aa21 core/mount/manager: fix bind mount missing rbind option
The bind mount created for temporary activations was missing the
Options field, causing mount to fail with "no such device" because
the MS_BIND flag wasn't being set.

Fixes #12549

Signed-off-by: Jérôme Poulin <jeromepoulin@gmail.com>
2025-11-26 18:42:38 -05:00
Jérôme Poulin d2593b6477 core/mount/manager: add tests for WithTemporary option
Add tests for the WithTemporary mount activation used by `ctr images mount`.
Covers bind mount and overlay scenarios to catch regressions like #12549.

Signed-off-by: Jérôme Poulin <jeromepoulin@gmail.com>
2025-11-26 18:42:38 -05:00
Gao Xiang 190ed6b677 Avoid using redundant loop devices to run mkfs for mount manager tests.
mkfs.ext4 supports creating filesystems from regular files.

Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
2025-11-19 11:50:01 +08:00
Gao Xiang 8a6e6263f8 Support arbitary mkfs size (not only in MiB)
Rename `default_size_mb` to `default_size` so that it's similar to
Docker's `--storage-opt size=30G` flag.  For example,

``` toml
[plugins."io.containerd.snapshotter.v1.erofs"]
  default_size = "5GB"
```

Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
2025-10-21 15:35:05 +08:00
Gao Xiang 3cc411c8b2 Fix backreference support for mount manager
The mount manager GC seems to be broken on my local setup.

According to commit df87a8f71b ("Add support for backreferences
in gc"), the interface name should be "ActiveWithBackRefs" instead.

After this patch, erofs and ext4 mounts won't be GCed in advance.

Fixes: 184fae60fc ("Add backreference support to mount manager")
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
2025-10-21 15:06:20 +08:00
Derek McGowan 0d62c71885 Update loopback test to make initialization more robust
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-10-19 13:38:40 -07:00
Derek McGowan 25c3871baa Switch mount manager tests to ext4
Reduce the size of the test files. Even using sparse files, the reported
large size may cause issues in some test environments.

Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-10-16 16:58:37 -07:00
Derek McGowan 55d5d5b500 Add Close method to mount manager
Adding a close method allows the mount manager to close any open file
descriptors. The method will also be called automatically by containerd
on shutdown.

Ensure the tests call Close to avoid leaking file descriptors or errors
on Windows cleaning up directories that are in use.

Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-10-16 16:01:29 -07:00
Derek McGowan be9f183f45 Add mount transformers to mount manager
Extend the mount manager to support more transformers than format. The
transformers allow altering the mount before it is passed to the mount
handlers. These could be one-time actions which are needed to perform
the mount.

Adds mkdir and mkfs actions which can be used to prepare the arguments
for a mount. The actions can be limited to actions within the target
mount directory or plugin directories.

Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-10-14 16:35:53 -07:00
Derek McGowan 94e6bcea50 Add support for allowing custom types through mount manager
Allow the mount manager to skip handling of custom types. Ensure that
custom types are still working with formatted mounts.

Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-09-29 17:08:38 -07:00
Derek McGowan dd9c43150a Add option to allow formatted mounts
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-09-29 17:08:38 -07:00
Derek McGowan f7b77e649c Update mount manager cleanup logic
Avoid keeping file descriptor open to directory which is getting
removed. Update error handling and wrapping to provide more clarity
around failures.

Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-09-29 17:08:37 -07:00
Derek McGowan fa327566bb Fix mount manager deactivate errors
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-09-29 17:08:36 -07:00
Derek McGowan 9c0cc4a424 Add mount manager format test
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-09-29 17:08:36 -07:00
Derek McGowan 5b4de2c34f Add implementation of list and get mount activation
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-09-29 17:08:34 -07:00
Derek McGowan 184fae60fc Add backreference support to mount manager
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-09-29 17:08:34 -07:00
Derek McGowan 9794addcea Add mount formatting test
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-09-29 17:08:34 -07:00
Derek McGowan d8e5cdd76a Fix gc cleanup and add unit tests for gc
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-09-29 17:08:34 -07:00
Derek McGowan c8e7674cc9 Add temporary mount support to manager
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-09-29 17:08:33 -07:00
Derek McGowan 75ed5e0037 Fix mount manager gc
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-09-29 17:08:32 -07:00
Derek McGowan 8db3010865 Add mounts api service
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-09-29 17:08:31 -07:00
Derek McGowan 4d34b01ce0 Add loopback and overlay mount manager tests
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-09-29 17:08:31 -07:00
Derek McGowan 6243cf5627 Add mount manager tests
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-09-18 17:08:43 -07:00
Derek McGowan f4b7b9344c Improve formatting and support for deactivate
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-09-18 17:08:43 -07:00
Derek McGowan ed03f3a710 Add mount manager plugin and types
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-09-18 17:08:43 -07:00