Commit Graph

354 Commits

Author SHA1 Message Date
Derek McGowan
36c22f45c8 Update referrers fallback logic to always have a fallback
Always attempt the fallback on hosts configured with the referrers
capability. Fallback for any non-404 error.

Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-10-07 15:38:26 -07:00
Fu Wei
61ddcd5372 Merge pull request #12063 from dmcgowan/mount-manager
Add mount manager
2025-10-03 14:01:38 +00:00
Derek McGowan
c7b3114ebb Update mount manager code documentation
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-09-30 13:37:11 -07:00
Derek McGowan
f3af360f6d Update runtime to read allowed custom mounts from runtime
Let the runtime specify which custom mounts it will support

Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-09-30 13:37:11 -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
efc9950114 Add runtimes option to task manager
Allow task manager to fetch info on runtimes at startup.
Use this info to configure whether the runtime allows formatted mounts.
This info could also be used in the future to enforce policy such as
requiring a pre-known set of runtimes or specific runtime properties.

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
9c21e867ed Handle flaky case for loop autoclear
The autoclear may take a bit of time to clear out the file, check
multiple times for the file to get removed before returning an error.

Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-09-29 17:08:37 -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
93070961b7 Update snapshotter tests to use mount manager
Create separate package for snapshotter test in metadata package to
prevent circular dependency.

Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-09-29 17:08:36 -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
39f128b994 fix invalid deactivate error
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-09-29 17:08:35 -07:00
Derek McGowan
76a877bb5c Add mount activation support to task service
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-09-29 17:08:35 -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
Fu Wei
1b613badfa Merge pull request #12309 from dmcgowan/remote-referrers
Add referrers fetcher to remotes
2025-09-26 19:06:24 +00:00
Henry Wang
748cd9f037 Prevent goroutine hangs during ProgressTracker shutdown
Signed-off-by: Henry Wang <henwang@amazon.com>
2025-09-25 18:50:14 +00:00
Derek McGowan
a7537cb8a5 Add referrers to default registries
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-09-24 17:59:19 -07:00
Derek McGowan
b668614b55 Add referrers to host config
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-09-24 17:59:19 -07:00
Tonis Tiigi
c1b1297c6c Update capabilities for referrers
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-09-24 17:59:18 -07:00
Derek McGowan
09b4ac136d Add referrers fetcher to remotes
Adds an implementation of the referrers API from
OCI distribution-spec 1.1.

Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-09-24 17:59:18 -07:00
Aadhar Agarwal
3df2b5d981 TestErofs/Rename fails with EROFS snapshotter
Signed-off-by: Aadhar Agarwal <aadagarwal@microsoft.com>
2025-09-23 21:50:38 +00:00
Akihiro Suda
cef8ce2ecb Merge pull request #12291 from henry118/fix-range-igore
Ensure errContentRangeIgnored error when range-get request is ignored
2025-09-19 20:10:55 +00: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
55ff117377 Add loopback mount handler
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
Derek McGowan
78ca11c1c7 Add mount garbage collection resource
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-09-18 17:08:42 -07:00
Derek McGowan
c715986227 Add mount manager interface to mount package
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-09-18 17:08:42 -07:00
Derek McGowan
1809f3ef1e Update metadata gc to run context finishes in parallel
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-09-18 17:08:42 -07:00
Derek McGowan
37cec68004 Move transaction context to boltutil
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-09-18 17:08:42 -07:00
Henry Wang
635907e63a Ensure errContentRangeIgnored error when range-get request is ignored by registry
Signed-off-by: Henry Wang <henwang@amazon.com>
2025-09-16 19:47:28 -07:00
Derek McGowan
479cf42ca2 Add extraction progress to transfer service
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-09-10 20:07:40 -07:00
Derek McGowan
09e531b88e Add progress to apply options
Allows the apply process to return progress on the tar apply operation.

Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-09-10 20:07:40 -07:00
Enji Cooper
f45716efed Clean up issues cited by usetesting package with golangci
This commit makes all of the recommended changes to use the `testing`
package helper functions instead of doing the equivalent longhand
versions of the same thing.

This change was needed in order to properly detect errors, as the code
would previously skip running `tenv` stating that it had been deprecated
in favor of `usetesting`.

Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
2025-09-07 14:07:40 -07:00
Rodrigo Campos
41953f7ac1 cri: Fix userns with Dockerfile VOLUME mounts that need copy
If a Dockerfile is using a `VOLUME` directive and the directory exists
in the rootfs, like in this example:

	FROM docker.io/library/alpine:latest
	VOLUME [ "/run" ]

The alpine container image already contains a "/run" directory. This
will force the code in WithVolumes() to copy its  content to the new
volume created for the VOLUME directive. This copies the content as well
as the ownership.

However, as we perform the mounts from the host POV without being inside
a userns, the idmap option will just shift the IDs in ways that will
screw up the ownerships when copied. We should only use the idmap option
when running the container inside a userns, so the ownerships are fine
(the userns will do a shift and the idmap another, to make it all seem
as if there was no UID/GID shift in the first place).

This PR does just that, remove the idmap option from mounts so we copy
the files without any ID transformations. It's simpler and easier to
reason about if we just don't mount with the idmap option here: all
files are copied just fine without ID transformations and ID
transformation is applied via the idmap option at mount time when
running the pod.

Also, note that `VOLUME` directives that refer to directories that don't
exist on the rootfs work fine (`VOLUME [ "/rata" ]` for example), as
there is no copy done in that case so the permissions weren't changed.

Signed-off-by: Rodrigo Campos <rodrigoca@microsoft.com>
2025-08-26 11:15:55 +02:00
Akihiro Suda
1321cbc7b6 Merge pull request #12025 from dmcgowan/gc-reverse-ref
Add support for back references in the garbage collector
2025-08-22 04:45:55 +00:00
Rodrigo Campos
da3dc1ef6c core/mount: Retry unmounting idmapped directories
When a lot of pods are created all at the same time, the umount fails
with EBUSY sometimes. This causes some mounts to be leaked. A way to
repro this issue is here:
	https://github.com/containerd/containerd/issues/12139#issuecomment-3165305904

While using lsof/fuser it was not possible to get the culprits on time
(the mount is busy for a few ms), @fuwei has found what is causing the
mount to be busy:
	https://github.com/containerd/containerd/issues/12139#issuecomment-3184544534

When we fork in `GetUsernsFD()`, if a call to prepareIDMappedOverlay()
is ongoing and has an open fd to the path to idmap, then the unmount
callback will fail as the forked process still has an open fd to it.

Let's handle the idmap unmounts in the same way other temp mounts are
done, using the Unmount() helper, that retries the unmount.

This retry fixes it 100% of the times on my system and in the systems
of @halaney that reported the issue too.

This was originally fixed by #10721 by using a detached mount, but the
mount was switched to non-detached again in #10955 and we started to
leak mounts. As @fuwei mentioned, using a detached mount is quite
invisible for the admin and, therefore, a retry is a better alternative.

It seems these umounts are a great candidate for #11303, which will
manage the life-cycle of mounts and can handle these retries whenever
needed.

[1]: To do it, I just run as root "unshare -m", that creates a mntns
with private propagation, and then run the containerd daemon.

Signed-off-by: Rodrigo Campos <rodrigoca@microsoft.com>
2025-08-19 17:38:00 +02:00
Rodrigo Campos
27ba690a1e core/mount: Test cleanup of DoPrepareIDMappedOverlay()
Signed-off-by: Rodrigo Campos <rodrigoca@microsoft.com>
2025-08-19 14:58:09 +02:00
Rodrigo Campos
dd7fe0b76f core/mount: Properly cleanup on doPrepareIDMappedOverlay errors
Before this patch, the cleanup was unconditionally trying an unmount,
which is not needed if the mount never succeeded in the first place.
This causes logs of failed stuff, that should never be there.
Also, one function was creating the tmpDir and the nested one removing
it (in the cleanup function), which complicates the reasoning about
not leaking resources.

This patch on one hand moves the creation of the tmpDir into the
function that will remove it later and renames the parameter. On the
other hand, it also separates the cleanup function in two functions:
cleanDir() and cleanMount(). Each one will clean the directory or the
mount, only if needed, and a new cleanup function that just calls
cleanDir() and cleanMount() is returned as the cleanup function handler.

Because we now create the tmp directory inside the function, we need to
adjust the test: the directory passed as param now will exist, but it
shoild be empty. Therefore, we change the os.Stat() to an os.Remove().
If it's not empty (the cleanup didn't work), the remove will fail.

Signed-off-by: Rodrigo Campos <rodrigoca@microsoft.com>
2025-08-19 14:58:09 +02:00
Rodrigo Campos
7a19c94d6c core/mount: Don't call nil function on errors
doPrepareIDMappedOverlay() can return nil as the cleanup function. As
the function mandates for the callback to be called, even when errors
are returned, we end-up calling the nil function that of course causes:

        panic: runtime error: invalid memory address or nil pointer dereference

The containerd daemon continues to run fine, though.

With the current structure of always calling the cleanup function, we
would either need to check which error it is, to call it only on
specific errors (ugly) or return a "stub function" that doesn't do
anything on those cases (so the call works). None of these options seem
very nice.

Let's just switch the logic to a pattern more common on go: only need to
cleanup if it returned fine. This makes it easier for callers to not do
the wrong thing.

For this change we need to do the cleanup when returning errors on the
function itself, so the user doesn't need to do it for us.

Signed-off-by: Rodrigo Campos <rodrigoca@microsoft.com>
2025-08-18 07:01:16 -03:00
Akihiro Suda
0649e9b280 Merge pull request #12092 from halaney/ahalaney/use-one-idmap-per-overlayfs
Only idmap once per overlayfs, not per layer
2025-08-17 05:07:34 +00:00
Phil Estes
cbe833eb4d Merge pull request #12181 from fuweid/reorder-checker
pkg/sys: check SupportsPidFD first
2025-08-13 14:24:48 +00:00