diff --git a/cmd/containerd-shim-runhcs-v1/rootfs.go b/cmd/containerd-shim-runhcs-v1/rootfs.go index c4d2d072e8..864fca1d28 100644 --- a/cmd/containerd-shim-runhcs-v1/rootfs.go +++ b/cmd/containerd-shim-runhcs-v1/rootfs.go @@ -56,17 +56,10 @@ func parseLegacyRootfsMount(m *types.Mount) (string, []string, error) { // // The OCI spec expects: // layerN, layerN-1, ..., layer0, scratch - var parentLayerPaths []string - for _, option := range m.Options { - if strings.HasPrefix(option, mount.ParentLayerPathsFlag) { - err := json.Unmarshal([]byte(option[len(mount.ParentLayerPathsFlag):]), &parentLayerPaths) - if err != nil { - return "", nil, fmt.Errorf("unmarshal parent layer paths from mount: %v: %w", err, errdefs.ErrFailedPrecondition) - } - // Would perhaps be worthwhile to check for unrecognized options and return an error, - // but since this is a legacy layer mount we don't do that to avoid breaking anyone. - break - } + containerdMount := mount.Mount{Type: m.Type, Source: m.Source, Target: m.Target, Options: m.Options} + parentLayerPaths, err := containerdMount.GetParentPaths() + if err != nil { + return "", nil, fmt.Errorf("failed to get mount's parent layer paths: %v: %w", err, errdefs.ErrFailedPrecondition) } return m.Source, parentLayerPaths, nil } @@ -100,7 +93,7 @@ func getLCOWLayers(rootfs []*types.Mount, layerFolders []string) (*layers.LCOWLa m := rootfs[0] switch m.Type { case "lcow-layer": - scratchLayer, parentLayers, err := parseLegacyRootfsMount(rootfs[0]) + scratchLayer, parentLayers, err := parseLegacyRootfsMount(m) if err != nil { return nil, err } diff --git a/test/internal/layers/layerfolders.go b/test/internal/layers/layerfolders.go index 13c6be54df..6b848579e4 100644 --- a/test/internal/layers/layerfolders.go +++ b/test/internal/layers/layerfolders.go @@ -4,8 +4,6 @@ package layers import ( "context" - "encoding/json" - "strings" "testing" "github.com/containerd/containerd" @@ -35,13 +33,9 @@ func FromChainID(ctx context.Context, tb testing.TB, client *containerd.Client, // FromMount returns the layer paths of a given mount func FromMount(_ context.Context, tb testing.TB, m mount.Mount) (layers []string) { tb.Helper() - for _, option := range m.Options { - if strings.HasPrefix(option, mount.ParentLayerPathsFlag) { - err := json.Unmarshal([]byte(option[len(mount.ParentLayerPathsFlag):]), &layers) - if err != nil { - tb.Fatalf("failed to unmarshal parent layer paths from mount: %v", err) - } - } + layers, err := m.GetParentPaths() + if err != nil { + tb.Fatalf("failed to get mount's parent layer paths: %v", err) } layers = append(layers, m.Source)