|
| 1 | +package snapshot |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + |
| 6 | + "github.com/containerd/containerd/snapshots" |
| 7 | + "github.com/containerd/containerd/v2/core/mount" |
| 8 | +) |
| 9 | + |
| 10 | +var _ snapshots.Snapshotter = &snapshotter{} |
| 11 | + |
| 12 | +type snapshotter struct { |
| 13 | +} |
| 14 | + |
| 15 | +func NewSnapshotter(ctx context.Context) (snapshots.Snapshotter, error) { |
| 16 | + return &snapshotter{}, nil |
| 17 | +} |
| 18 | + |
| 19 | +// Should be used for parent resolution, existence checks and to discern |
| 20 | +// the kind of snapshot. |
| 21 | +func (o *snapshotter) Stat(ctx context.Context, key string) (Info, error) { |
| 22 | + return nil |
| 23 | +} |
| 24 | + |
| 25 | +// Update updates the info for a snapshot. |
| 26 | +// |
| 27 | +// Only mutable properties of a snapshot may be updated. |
| 28 | +func (o *snapshotter) Update(ctx context.Context, info Info, fieldpaths ...string) (Info, error) { |
| 29 | + return nil, nil |
| 30 | +} |
| 31 | + |
| 32 | +// Usage returns the resource usage of an active or committed snapshot |
| 33 | +// excluding the usage of parent snapshots. |
| 34 | +// |
| 35 | +// The running time of this call for active snapshots is dependent on |
| 36 | +// implementation, but may be proportional to the size of the resource. |
| 37 | +// Callers should take this into consideration. Implementations should |
| 38 | +// attempt to honor context cancellation and avoid taking locks when making |
| 39 | +// the calculation. |
| 40 | +func (o *snapshotter) Usage(ctx context.Context, key string) (Usage, error) { |
| 41 | + return nil, nil |
| 42 | +} |
| 43 | + |
| 44 | +// Mounts returns the mounts for the active snapshot transaction identified |
| 45 | +// by key. Can be called on a read-write or readonly transaction. This is |
| 46 | +// available only for active snapshots. |
| 47 | +// |
| 48 | +// This can be used to recover mounts after calling View or Prepare. |
| 49 | +func (o *snapshotter) Mounts(ctx context.Context, key string) ([]mount.Mount, error) { |
| 50 | + return nil, nil |
| 51 | +} |
| 52 | + |
| 53 | +// Prepare creates an active snapshot identified by key descending from the |
| 54 | +// provided parent. The returned mounts can be used to mount the snapshot |
| 55 | +// to capture changes. |
| 56 | +// |
| 57 | +// If a parent is provided, after performing the mounts, the destination |
| 58 | +// will start with the content of the parent. The parent must be a |
| 59 | +// committed snapshot. Changes to the mounted destination will be captured |
| 60 | +// in relation to the parent. The default parent, "", is an empty |
| 61 | +// directory. |
| 62 | +// |
| 63 | +// The changes may be saved to a committed snapshot by calling Commit. When |
| 64 | +// one is done with the transaction, Remove should be called on the key. |
| 65 | +// |
| 66 | +// Multiple calls to Prepare or View with the same key should fail. |
| 67 | +func (o *snapshotter) Prepare(ctx context.Context, key, parent string, opts ...Opt) ([]mount.Mount, error) { |
| 68 | + return nil, nil |
| 69 | +} |
| 70 | + |
| 71 | +// View behaves identically to Prepare except the result may not be |
| 72 | +// committed back to the snapshot snapshotter. View returns a readonly view on |
| 73 | +// the parent, with the active snapshot being tracked by the given key. |
| 74 | +// |
| 75 | +// This method operates identically to Prepare, except the mounts returned |
| 76 | +// may have the readonly flag set. Any modifications to the underlying |
| 77 | +// filesystem will be ignored. Implementations may perform this in a more |
| 78 | +// efficient manner that differs from what would be attempted with |
| 79 | +// `Prepare`. |
| 80 | +// |
| 81 | +// Commit may not be called on the provided key and will return an error. |
| 82 | +// To collect the resources associated with key, Remove must be called with |
| 83 | +// key as the argument. |
| 84 | +func (o *snapshotter) View(ctx context.Context, key, parent string, opts ...Opt) ([]mount.Mount, error) { |
| 85 | + return nil, nil |
| 86 | +} |
| 87 | + |
| 88 | +// Commit captures the changes between key and its parent into a snapshot |
| 89 | +// identified by name. The name can then be used with the snapshotter's other |
| 90 | +// methods to create subsequent snapshots. |
| 91 | +// |
| 92 | +// A committed snapshot will be created under name with the parent of the |
| 93 | +// active snapshot. |
| 94 | +// |
| 95 | +// After commit, the snapshot identified by key is removed. |
| 96 | +func (o *snapshotter) Commit(ctx context.Context, name, key string, opts ...Opt) error { |
| 97 | + return nil |
| 98 | +} |
| 99 | + |
| 100 | +// Remove the committed or active snapshot by the provided key. |
| 101 | +// |
| 102 | +// All resources associated with the key will be removed. |
| 103 | +// |
| 104 | +// If the snapshot is a parent of another snapshot, its children must be |
| 105 | +// removed before proceeding. |
| 106 | +func (o *snapshotter) Remove(ctx context.Context, key string) error { |
| 107 | + return nil |
| 108 | +} |
| 109 | + |
| 110 | +// Walk will call the provided function for each snapshot in the |
| 111 | +// snapshotter which match the provided filters. If no filters are |
| 112 | +// given all items will be walked. |
| 113 | +// Filters: |
| 114 | +// |
| 115 | +// name |
| 116 | +// parent |
| 117 | +// kind (active,view,committed) |
| 118 | +// labels.(label) |
| 119 | +func (o *snapshotter) Walk(ctx context.Context, fn WalkFunc, filters ...string) error { |
| 120 | + return nil |
| 121 | +} |
| 122 | + |
| 123 | +// Close releases the internal resources. |
| 124 | +// |
| 125 | +// Close is expected to be called on the end of the lifecycle of the snapshotter, |
| 126 | +// but not mandatory. |
| 127 | +// |
| 128 | +// Close returns nil when it is already closed. |
| 129 | +func (o *snapshotter) Close() error { |
| 130 | + return nil |
| 131 | +} |
0 commit comments