Files
containerd/plugins/diff/erofs/dmverity_linux.go
Maksym Pavlenko 82a47efe92 Support dmverity
Add a --dmverity flag to `ctr images build-erofs-cache`. When set, each cached
erofs blob is dm-verity formatted (the hash tree is appended in place) and a
.dmverity sidecar is written alongside it. This is required when the erofs
snapshotter runs with dmverity_mode=on, which rejects cache hits that lack a
sidecar; without it such layers would have to be formatted out-of-band.

Extract the differ's dm-verity formatting into a shared dmverity.FormatLayer so
the differ and the cache builder share one implementation; the differ's
formatDmverityLayer now delegates to it.

Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2026-07-21 10:07:08 -07:00

53 lines
2.0 KiB
Go

//go:build linux
/*
Copyright The containerd Authors.
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 erofs
import (
"context"
"github.com/containerd/containerd/v2/internal/dmverity"
)
// getDmverityOptions returns dm-verity options configured for this differ instance.
// The block size is determined by the differ's mode:
// - Tar index mode requires 512-byte blocks to match EROFS and dm-verity constraints
// - Regular mode uses 4096-byte blocks (standard page size)
func (s *erofsDiff) getDmverityOptions() *dmverity.DmverityOptions {
opts := dmverity.DefaultDmverityOptions()
// Tar index mode requires 512-byte blocks because:
// 1. EROFS tar index mode uses 512-byte metadata blocks (mkfs.erofs --tar=i)
// 2. dm-verity sets the virtual block device logical_block_size to match the data block size
// 3. EROFS requires its block size (512) to be >= the underlying block device's logical_block_size
// Using 4096-byte dm-verity blocks would set logical_block_size=4096, causing EROFS sb_set_blocksize(512) to fail
if s.enableTarIndex {
opts.DataBlockSize = 512
opts.HashBlockSize = 512
}
// Regular mode uses the default 4096-byte blocks (standard page size)
return opts
}
// formatDmverityLayer formats an EROFS layer with a dm-verity hash tree using
// the differ's configured options.
func (s *erofsDiff) formatDmverityLayer(ctx context.Context, layerBlobPath string) error {
return dmverity.FormatLayer(ctx, layerBlobPath, s.getDmverityOptions())
}