mirror of
https://github.com/agent-substrate/substrate.git
synced 2026-11-12 10:35:06 +08:00
Content-addressed pool of unpacked image layers, shared by every actor on the node; actor rootfs becomes an overlayfs mount (cached layers as read- only lowers, bundle-local upper) instead of a full re-untar per run. atelet (no capabilities) pulls and unpacks; the privileged ateoms finalize whiteouts and mount. Tag refs resolve via one HEAD and become cacheable; pull memory is O(stream buffers); the cache survives restarts. Phase 1 of #463. Fixes #437, #166, #228. Validated: kind + GKE counter demos (gvisor and microvm), suspend/resume (oci_unpack ~3ms vs ~15-20s), 411 SWE-bench-scale images pulled and unpacked with 0 failures, root-gated unit tests for the privileged paths. Known gaps: no GC yet (Phase 2, see internal/imagecache/README.md); upgrade ordering — deploy new ateoms before/with the new atelet.
41 lines
1.5 KiB
Go
41 lines
1.5 KiB
Go
// Copyright 2026 Google LLC
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package imagecache
|
|
|
|
import (
|
|
"io/fs"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
// RemoveAllWritable removes path and everything under it, first making every
|
|
// directory owner-writable so its children can be unlinked. Unpacked image
|
|
// trees keep the image's (possibly read-only) directory modes, which atelet
|
|
// cannot remove as plain root without CAP_DAC_OVERRIDE — os.RemoveAll alone
|
|
// fails there with EACCES. atelet owns these files, so chmod needs no
|
|
// capability.
|
|
func RemoveAllWritable(path string) error {
|
|
// Make dirs traversable/writable top-down (WalkDir visits a directory before
|
|
// reading it, so chmod here lets the walk descend into otherwise-unreadable
|
|
// dirs). Best-effort: ignore errors and let os.RemoveAll surface real ones.
|
|
_ = filepath.WalkDir(path, func(p string, d fs.DirEntry, err error) error {
|
|
if err == nil && d.IsDir() {
|
|
_ = os.Chmod(p, 0o700)
|
|
}
|
|
return nil
|
|
})
|
|
return os.RemoveAll(path)
|
|
}
|