MCPcopy
hub / github.com/containerd/containerd / resolveSnapshotOptions

Function resolveSnapshotOptions

client/snapshotter_opts_unix.go:62–136  ·  view source on GitHub ↗
(ctx context.Context, client *Client, snapshotterName string, snapshotter snapshots.Snapshotter, parent string, opts ...snapshots.Opt)

Source from the content-addressed store, hash-verified

60}
61
62func resolveSnapshotOptions(ctx context.Context, client *Client, snapshotterName string, snapshotter snapshots.Snapshotter, parent string, opts ...snapshots.Opt) (string, error) {
63 capabs, err := client.GetSnapshotterCapabilities(ctx, snapshotterName)
64 if err != nil {
65 return "", err
66 }
67
68 if slices.Contains(capabs, capaRemapIDs) {
69 // Snapshotter supports ID remapping, we don't need to do anything.
70 return parent, nil
71 }
72
73 var local snapshots.Info
74 for _, opt := range opts {
75 opt(&local)
76 }
77
78 needsRemap := false
79 var uidMapLabel, gidMapLabel string
80
81 if value, ok := local.Labels[snapshots.LabelSnapshotUIDMapping]; ok {
82 needsRemap = true
83 uidMapLabel = value
84 }
85 if value, ok := local.Labels[snapshots.LabelSnapshotGIDMapping]; ok {
86 needsRemap = true
87 gidMapLabel = value
88 }
89
90 if !needsRemap {
91 return parent, nil
92 }
93
94 capaOnlyRemap := false
95 for _, capa := range capabs {
96 if capa == capaOnlyRemapIDs {
97 capaOnlyRemap = true
98 }
99 }
100
101 if capaOnlyRemap {
102 return "", fmt.Errorf("snapshotter %q doesn't support idmap mounts on this host, configure `slow_chown` to allow a slower and expensive fallback", snapshotterName)
103 }
104
105 rsn := remappedSnapshot{Parent: parent}
106 if err = rsn.IDMap.Unmarshal(uidMapLabel, gidMapLabel); err != nil {
107 return "", fmt.Errorf("failed to unmarshal uid/gid map snapshotter labels: %w", err)
108 }
109
110 if _, err := rsn.IDMap.RootPair(); err != nil {
111 return "", fmt.Errorf("container UID/GID mapping entries of 0 are required but not found")
112 }
113
114 usernsID, err := rsn.ID()
115 if err != nil {
116 return "", fmt.Errorf("failed to remap snapshot: %w", err)
117 }
118
119 if _, err := snapshotter.Stat(ctx, usernsID); err == nil {

Callers 1

withNewSnapshotFunction · 0.70

Calls 9

IDMethod · 0.95
remapRootFSFunction · 0.85
UnmarshalMethod · 0.80
RootPairMethod · 0.80
StatMethod · 0.65
PrepareMethod · 0.65
RemoveMethod · 0.65
CommitMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…