-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathovermount.go
More file actions
135 lines (114 loc) · 4.08 KB
/
overmount.go
File metadata and controls
135 lines (114 loc) · 4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// Package overmount - mount tars in an overlay filesystem
//
// overmount is intended to mount docker images, or work with similar
// functionality to achieve a series of layered filesystems which can be composed
// into an image.
//
// See the examples/ directory for examples of how to use the API.
//
// github.com/pkg/errors.Wrap is in use with many of our errors; look at the
// errors.Cause API in that package for more information on how to extract the
// static error constants.
package overmount
import (
"io"
"sync"
"github.com/pkg/errors"
)
var (
// ErrParentNotMounted is returned when the parent layer is not mounted (but exists)
ErrParentNotMounted = errors.New("parent not mounted, cannot continue")
// ErrMountFailed returns an underlying error when the mount has failed.
ErrMountFailed = errors.New("mount failed")
// ErrUnmountFailed returns an underlying error when the unmount has failed.
ErrUnmountFailed = errors.New("unmount failed")
// ErrMountCannotProceed returns an underlying error when the mount cannot be processed.
ErrMountCannotProceed = errors.New("mount cannot proceed")
// ErrImageCannotBeComposed is returned when an image (a set of layers) fails validation.
ErrImageCannotBeComposed = errors.New("image cannot be composed")
// ErrInvalidAsset is returned when the asset cannot be used.
ErrInvalidAsset = errors.New("invalid asset")
// ErrInvalidLayer is returned when the layer cannot be used.
ErrInvalidLayer = errors.New("invalid layer")
// ErrLayerExists is called when a layer id already exists in the repository.
ErrLayerExists = errors.New("layer already exists")
// ErrMountExists is called when a mount already exists in the repository.
ErrMountExists = errors.New("mount already exists")
)
const (
tmpdirBase = "tmp"
mountBase = "mount"
layerBase = "layers"
)
// Repository is a collection of mounts/layers. Repositories have a base path
// and a collection of layers and mounts. Overlay work directories are stored
// in `tmp`.
//
// In summary:
//
// basedir/
// layers/
// layer-id/
// top-layer/
// tmp/
// some-random-workdir/
// mount/
// another-layer-id/
// top-layer/
//
// Repositories can hold any number of mounts and layers. They do not
// necessarily need to be related.
type Repository struct {
baseDir string
layers map[string]*Layer
mounts []*Mount
virtual bool
editMutex *sync.Mutex
}
// Mount represents a single overlay mount. The lower value is computed from
// the parent layer of the layer provided to the NewMount call. The target and
// upper dirs are computed from the passed layer.
type Mount struct {
target string
upper string
lower string
repository *Repository
work string
mounted bool
}
// Layer is the representation of a filesystem layer. Layers are organized in a
// reverse linked-list from topmost layer to the root layer. In an
// (*Image).Mount() scenario, the layers are mounted from the bottom up to
// culminate in a mount path that represents the top-most layer merged with all
// the lower layers.
//
// See https://www.kernel.org/doc/Documentation/filesystems/overlayfs.txt for
// more information on mount flags.
type Layer struct {
Parent *Layer
id string
asset *Asset
repository *Repository
virtual bool
editMutex *sync.Mutex
}
// Image is the representation of a set of sequential layers to be mounted.
type Image struct {
repository *Repository
layer *Layer
mount *Mount
}
// Importer is an interface to image importers; ways to get images into
// overmount repositories.
type Importer interface {
// Import takes a tar represented as an io.ReadCloser, and converts and unpacks
// it into the overmount repository. Returns the top-most layer and any
// error.
Import(*Repository, io.ReadCloser) ([]*Layer, error)
}
// Exporter is an interface to image exporters; ways to get images out of
// overmount repositories.
type Exporter interface {
// Export produces a tar represented as an io.ReadCloser from the Layer provided.
Export(*Repository, *Layer, []string) (io.ReadCloser, error)
}