Repository navigation
Conversation
There was a problem hiding this comment.
Pull request overview
Enables the EROFS layer content cache fast-path for both sequential and parallel unpacking by serving cached (staged) layer blobs even when Prepare is parented, while preventing accidental writes into shared cache-backed blobs.
Changes:
- Serve staged (cache-backed) layers read-only even when
Prepareincludes a parent, enabling cache hits beyond layer 0 in sequential mode. - Add protections to prevent writing into snapshots backed by cache-staged symlinked
layer.erofsblobs. - Expand test coverage across snapshotter behavior, differ safeguards, and unpacker staged-layer handling in both unpack modes.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| plugins/snapshots/erofs/plugin/plugin.go | Updates config documentation to reflect cache behavior in sequential + parallel modes. |
| plugins/snapshots/erofs/erofs.go | Adds staged-layer mount detection and returns RO mounts for staged parented prepares. |
| plugins/snapshots/erofs/erofs_linux_test.go | Refactors staging assertions and adds tests for parented staging + stale staged blobs. |
| internal/erofsutils/mount.go | Refuses to treat symlinked layer.erofs as writable conversion targets. |
| internal/erofsutils/mount_test.go | Adds unit test ensuring staged symlinked blobs are rejected by MountsToLayer. |
| core/unpack/unpacker_test.go | Adds helper + tests ensuring staged layers skip fetch/apply in both parallel and sequential modes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ccd9f66 to
c2ddd31
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.
Suppressed comments (1)
plugins/snapshots/erofs/erofs.go:653
- The createSnapshot doc comment says a staged cache hit lets the unpacker "skip the layer download", but unpacker fetch starts at the first cache miss and downloads the tail range (which can include later staged layers). So staged layers above the first miss may still be downloaded even though they are not applied/converted. Updating the comment would avoid misleading future maintainers.
// On an image-layer extraction whose diffID blob is in the layer content cache,
// it stages the cached blob into the active snapshot (without committing) and
// returns it as a read-only mount, so the unpacker can detect the fast path
// (skip the layer download and conversion) while still committing the
// snapshot normally. The parent is applied either at Prepare (sequential
c2ddd31 to
895e602
Compare
895e602 to
bbc885f
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.
Suppressed comments (3)
plugins/snapshots/erofs/erofs.go:446
- The comment reads "restart with caching since disabled", which is grammatically incorrect and a bit confusing in a safety-sensitive explanation.
// configured. So a staged snapshot left behind by a restart with caching since
// disabled is still safe, and this stays a cache-only fast path rather than an
plugins/snapshots/erofs/erofs.go:556
- When layer_content_caches is enabled, mounts() now calls stagedLayerMounts() for every parented active snapshot, which adds an extra Lstat/Stat on each Mounts call even for normal container-rootfs snapshots (no extraction labels). Since staging is keyed on the extraction labels, you can avoid this overhead by checking those labels before probing for a staged symlink.
if snap.Kind == snapshots.KindActive {
// A staged cache blob already holds this layer, so return it read-only
// instead of a writable overlay, the same way the parentless case above
// returns a layer blob it finds. Handing out the overlay would invite
// the differ to write the layer through the staged symlink and into the
plugins/snapshots/erofs/plugin/plugin.go:64
- The config comment says the first cache hit is "committed" without conversion, but the implementation stages the blob during Prepare and the unpacker commits it later. Using the same "staged" terminology here would better match the actual behavior and avoid confusing operators reading the config.
// LayerContentCaches lists directories of pre-converted, diffID-keyed erofs
// layer blobs. Each is checked one by one and the first hit is committed
// without being converted, in both sequential and parallel unpack modes; a
// directory that doesn't exist is treated as a cache miss. Layers missing
// from all of them are converted normally.
bbc885f to
0d54eb2
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.
Suppressed comments (3)
plugins/snapshots/erofs/erofs.go:654
- This doc comment claims the staged fast-path lets the unpacker "skip the layer download". With range-based fetching, cached layers above the first miss may still be downloaded even though they skip apply/conversion. Consider tightening the wording to avoid implying download-skip is guaranteed.
// returns it as a read-only mount, so the unpacker can detect the fast path
// (skip the layer download and conversion) while still committing the
// snapshot normally. The parent is applied either at Prepare (sequential
plugins/snapshots/erofs/erofs.go:59
- The config doc comment says cached layers are served "instead of downloading and converting". With the current unpacker behavior (range-based fetch after the first miss), a cached layer may still be downloaded even though it skips apply/conversion. Consider rewording to avoid promising download-skip in all cases.
This issue also appears on line 652 of the same file.
// layerContentCaches lists directories of pre-converted, diffID-keyed erofs
// layer blobs. Each is checked one by one; the first hit is staged into the
// snapshot (symlinked) instead of downloading and converting the layer. A
// directory that doesn't exist is treated as a cache miss. Layers missing
// from all of them are converted normally.
plugins/snapshots/erofs/plugin/plugin.go:64
- The LayerContentCaches comment says the first cache hit is "committed" without conversion. The cache hit is actually staged (symlinked) during Prepare and only committed later, so "committed" here is misleading about when the commit happens.
// LayerContentCaches lists directories of pre-converted, diffID-keyed erofs
// layer blobs. Each is checked one by one and the first hit is committed
// without being converted, in both sequential and parallel unpack modes; a
// directory that doesn't exist is treated as a cache miss. Layers missing
// from all of them are converted normally.
0d54eb2 to
2849c59
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.
Suppressed comments (3)
plugins/snapshots/erofs/erofs.go:439
- Returning early when
layerContentCachesis empty can misclassify an already-staged snapshot (existinglayer.erofssymlink, e.g., after a config change/restart) as non-staged, causingPrepare/Mountsto expose a writable overlay. The unpacker may then try to apply/diff and hitErrFailedPreconditionfromMountsToLayer, turning a usable staged snapshot into an avoidable runtime failure. Consider detecting staged blobs based on the on-disk symlink regardless of currentlayerContentCachesconfiguration (and only gate on cache config for creating new staged blobs).
func (s *snapshotter) stagedLayerMounts(id string) ([]mount.Mount, error) {
// Just a fast path: erofsutils.MountsToLayer refuses a symlinked layer blob
// whatever the config, so a blob staged before caching was turned off stays
// safe from the differ.
if len(s.layerContentCaches) == 0 {
return nil, nil
}
plugins/snapshots/erofs/plugin/plugin.go:64
- The comment says the first hit is "committed" without conversion, but the behavior described elsewhere (and in tests) is that the blob is staged at
Preparetime and later committed by the unpacker. Rewording to reflect staging (and eventual commit) would avoid misleading operators about when the commit actually occurs.
// layer blobs. Each is checked one by one and the first hit is committed
// without being converted, in both sequential and parallel unpack modes; a
// directory that doesn't exist is treated as a cache miss. Layers missing
// from all of them are converted normally.
internal/erofsutils/mount.go:224
- This error message indicates the layer is populated from the cache, but it omits the concrete reason it's unsafe (writing through a symlinked
layer.erofs) and doesn’t include the problematic path, which makes debugging harder. Consider mentioning thatlayer.erofsis a symlink and includinglayerBlobin the message (e.g., "refusing to write through symlinked layer blob ").
} else if fi.Mode()&os.ModeSymlink != 0 {
return "", fmt.Errorf("layer %q is already populated from the layer content cache: %w", layer, errdefs.ErrFailedPrecondition)
}
fuweid
left a comment
There was a problem hiding this comment.
Found one issue about the change on MountsToLayer
The current approach works, but it adds quite a few cache-specific branches to mounts(). Since the parent is already known for a parented cache hit, I’d prefer committing the cached snapshot in Prepare and returning ErrAlreadyExists via LabelSnapshotRef. The parentless (parallel) path can't use this protocol — but it doesn't need to, it already returns a read-only mount today.
I’ll defer to @dmcgowan @hsiangkao .
| if _, err := os.Stat(filepath.Join(layer, ".erofslayer")); err != nil { | ||
| return "", fmt.Errorf("mount layer type must be erofs-layer: %w", errdefs.ErrNotImplemented) | ||
| } | ||
| // A symlinked layer blob is served from the snapshotter's layer content |
There was a problem hiding this comment.
The function MountsToLayer is called by Compare/Diff. If the snapshot is committed with cache, Diff probably returns error
There was a problem hiding this comment.
Moved the check to where the write actually happens: MountsToLayer is back to what it was, and Apply now calls a small erofsutils.StagedLayerBlob() helper and refuses there. Compare should not be affected.
Staging a cached layer blob was gated on the Prepare having no parent, which sequential unpacking only does for the first layer, so a warm cache missed on every layer but layer 0 and a pull ended up slower than with no cache at all. Serve any image-layer extraction instead, and mount a staged blob read-only whatever its parents, so the differ is never handed a writable view of a blob shared with every other snapshot of that layer. Since read-only mounts are only advisory, the erofs differ now also refuses a layer whose blob is a symlink rather than truncating the cache entry through it. Signed-off-by: Maksym Pavlenko <[email protected]>
2849c59 to
fa14224
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.
Suppressed comments (2)
plugins/snapshots/erofs/erofs.go:436
- This comment claims erofsutils.MountsToLayer “refuses a symlinked layer blob,” but MountsToLayer currently just derives the layer dir from the mount source and does not check for symlinks. The actual write-through protection is enforced by the differ’s staged-blob check (erofsutils.StagedLayerBlob). Updating the comment avoids misleading future readers.
// Just a fast path: erofsutils.MountsToLayer refuses a symlinked layer blob
// whatever the config, so a blob staged before caching was turned off stays
// safe from the differ.
plugins/snapshots/erofs/erofs.go:59
- The config comment says a cache hit is staged “instead of downloading and converting the layer,” but (as noted later in createSnapshot’s TODO) cached layers above the first miss may still be downloaded due to the unpacker’s range-based fetch. This comment should avoid promising download skipping and focus on conversion skipping / staging behavior.
// layerContentCaches lists directories of pre-converted, diffID-keyed erofs
// layer blobs. Each is checked one by one; the first hit is staged into the
// snapshot (symlinked) instead of downloading and converting the layer. A
// directory that doesn't exist is treated as a cache miss. Layers missing
// from all of them are converted normally.
|
PR needs rebase. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
This PR was superseded by #14107 so I'm going to close it. |
This is a follow up to #13813 (where we had the cache working for sequential mode, but disabled in parallel) and #13826 (where we got it enabled for parallel mode, but only layer 0 in sequential mode).
This PR enables both with minimal changes in the erofs snapshotter: a cached layer is now served whether or not the Prepare carries a parent, and since such a layer is shared with every snapshot that uses it, it's handed out read-only and the differ refuses to write into one.
The cache now serves every cached layer for conversion-skip in both modes. Only the download remains range-limited from the first miss.
Context: #13826 (comment) — at that point parented layers were still writable, so the shared cache entry really could be overwritten. This adds the protection that was missing, which is what lets the restriction go.
The unpacker downloads layers in one run starting at the first cache miss, so cached layers above a miss are still transferred (they skip conversion, not the download). A fully cached image downloads nothing.
I don't want to mess too much with unpacker since 2.4 is coming soon — there's a TODO to come back to this once 2.4 is out.