Merge ce22b34c6d
into 7b69d43198
This commit is contained in:
commit
58534478e3
51 changed files with 1914 additions and 988 deletions
|
@ -208,7 +208,7 @@ func (i *containerImageRef) NewImageSource(sc *types.SystemContext, manifestType
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// Start reading the layer.
|
// Start reading the layer.
|
||||||
rc, err := i.store.Diff("", layerID)
|
rc, err := i.store.Diff("", layerID, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "error extracting layer %q", layerID)
|
return nil, errors.Wrapf(err, "error extracting layer %q", layerID)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,8 @@ k8s.io/apimachinery release-1.6 https://github.com/kubernetes/apimachinery
|
||||||
k8s.io/apiserver release-1.6 https://github.com/kubernetes/apiserver
|
k8s.io/apiserver release-1.6 https://github.com/kubernetes/apiserver
|
||||||
#
|
#
|
||||||
github.com/Sirupsen/logrus v0.11.5
|
github.com/Sirupsen/logrus v0.11.5
|
||||||
github.com/containers/image cd150088f25d1ac81c6dff3a0bf458725cb8b339
|
github.com/containers/image c2a797dfe5bb4a9dd7f48332ce40c6223ffba492
|
||||||
github.com/containers/storage 2c75d14b978bff468e7d5ec3ff8a003eca443209
|
github.com/containers/storage 5d8c2f87387fa5be9fa526ae39fbd79b8bdf27be
|
||||||
github.com/containernetworking/cni v0.4.0
|
github.com/containernetworking/cni v0.4.0
|
||||||
google.golang.org/grpc v1.0.1-GA https://github.com/grpc/grpc-go
|
google.golang.org/grpc v1.0.1-GA https://github.com/grpc/grpc-go
|
||||||
github.com/opencontainers/selinux v1.0.0-rc1
|
github.com/opencontainers/selinux v1.0.0-rc1
|
||||||
|
|
14
vendor/github.com/containers/image/README.md
generated
vendored
14
vendor/github.com/containers/image/README.md
generated
vendored
|
@ -51,14 +51,20 @@ Ensure that the dependencies documented [in vendor.conf](https://github.com/cont
|
||||||
are also available
|
are also available
|
||||||
(using those exact versions or different versions of your choosing).
|
(using those exact versions or different versions of your choosing).
|
||||||
|
|
||||||
This library, by default, also depends on the GpgME C library. Either install it:
|
This library, by default, also depends on the GpgME and libostree C libraries. Either install them:
|
||||||
```sh
|
```sh
|
||||||
Fedora$ dnf install gpgme-devel libassuan-devel
|
Fedora$ dnf install gpgme-devel libassuan-devel libostree-devel
|
||||||
macOS$ brew install gpgme
|
macOS$ brew install gpgme
|
||||||
```
|
```
|
||||||
or use the `containers_image_openpgp` build tag (e.g. using `go build -tags …`)
|
or use the build tags described below to avoid the dependencies (e.g. using `go build -tags …`)
|
||||||
This will use a Golang-only OpenPGP implementation for signature verification instead of the default cgo/gpgme-based implementation;
|
|
||||||
|
### Supported build tags
|
||||||
|
|
||||||
|
- `containers_image_openpgp`: Use a Golang-only OpenPGP implementation for signature verification instead of the default cgo/gpgme-based implementation;
|
||||||
the primary downside is that creating new signatures with the Golang-only implementation is not supported.
|
the primary downside is that creating new signatures with the Golang-only implementation is not supported.
|
||||||
|
- `containers_image_ostree_stub`: Instead of importing `ostree:` transport in `github.com/containers/image/transports/alltransports`, use a stub which reports that the transport is not supported. This allows building the library without requiring the `libostree` development libraries.
|
||||||
|
|
||||||
|
(Note that explicitly importing `github.com/containers/image/ostree` will still depend on the `libostree` library, this build tag only affects generic users of …`/alltransports`.)
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
|
|
21
vendor/github.com/containers/image/copy/copy.go
generated
vendored
21
vendor/github.com/containers/image/copy/copy.go
generated
vendored
|
@ -7,6 +7,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -157,6 +158,10 @@ func Image(policyContext *signature.PolicyContext, destRef, srcRef types.ImageRe
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
if err := checkImageDestinationForCurrentRuntimeOS(src, dest); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
if src.IsMultiImage() {
|
if src.IsMultiImage() {
|
||||||
return errors.Errorf("can not copy %s: manifest contains multiple images", transports.ImageName(srcRef))
|
return errors.Errorf("can not copy %s: manifest contains multiple images", transports.ImageName(srcRef))
|
||||||
}
|
}
|
||||||
|
@ -277,6 +282,22 @@ func Image(policyContext *signature.PolicyContext, destRef, srcRef types.ImageRe
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func checkImageDestinationForCurrentRuntimeOS(src types.Image, dest types.ImageDestination) error {
|
||||||
|
if dest.MustMatchRuntimeOS() {
|
||||||
|
c, err := src.OCIConfig()
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrapf(err, "Error parsing image configuration")
|
||||||
|
}
|
||||||
|
osErr := fmt.Errorf("image operating system %q cannot be used on %q", c.OS, runtime.GOOS)
|
||||||
|
if runtime.GOOS == "windows" && c.OS == "linux" {
|
||||||
|
return osErr
|
||||||
|
} else if runtime.GOOS != "windows" && c.OS == "windows" {
|
||||||
|
return osErr
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// updateEmbeddedDockerReference handles the Docker reference embedded in Docker schema1 manifests.
|
// updateEmbeddedDockerReference handles the Docker reference embedded in Docker schema1 manifests.
|
||||||
func updateEmbeddedDockerReference(manifestUpdates *types.ManifestUpdateOptions, dest types.ImageDestination, src types.Image, canModifyManifest bool) error {
|
func updateEmbeddedDockerReference(manifestUpdates *types.ManifestUpdateOptions, dest types.ImageDestination, src types.Image, canModifyManifest bool) error {
|
||||||
destRef := dest.Reference().DockerReference()
|
destRef := dest.Reference().DockerReference()
|
||||||
|
|
5
vendor/github.com/containers/image/directory/directory_dest.go
generated
vendored
5
vendor/github.com/containers/image/directory/directory_dest.go
generated
vendored
|
@ -51,6 +51,11 @@ func (d *dirImageDestination) AcceptsForeignLayerURLs() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MustMatchRuntimeOS returns true iff the destination can store only images targeted for the current runtime OS. False otherwise.
|
||||||
|
func (d *dirImageDestination) MustMatchRuntimeOS() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// PutBlob writes contents of stream and returns data representing the result (with all data filled in).
|
// PutBlob writes contents of stream and returns data representing the result (with all data filled in).
|
||||||
// inputInfo.Digest can be optionally provided if known; it is not mandatory for the implementation to verify it.
|
// inputInfo.Digest can be optionally provided if known; it is not mandatory for the implementation to verify it.
|
||||||
// inputInfo.Size is the expected length of stream, if known.
|
// inputInfo.Size is the expected length of stream, if known.
|
||||||
|
|
5
vendor/github.com/containers/image/docker/daemon/daemon_dest.go
generated
vendored
5
vendor/github.com/containers/image/docker/daemon/daemon_dest.go
generated
vendored
|
@ -78,6 +78,11 @@ func imageLoadGoroutine(ctx context.Context, c *client.Client, reader *io.PipeRe
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MustMatchRuntimeOS returns true iff the destination can store only images targeted for the current runtime OS. False otherwise.
|
||||||
|
func (d *daemonImageDestination) MustMatchRuntimeOS() bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
// Close removes resources associated with an initialized ImageDestination, if any.
|
// Close removes resources associated with an initialized ImageDestination, if any.
|
||||||
func (d *daemonImageDestination) Close() error {
|
func (d *daemonImageDestination) Close() error {
|
||||||
if !d.committed {
|
if !d.committed {
|
||||||
|
|
49
vendor/github.com/containers/image/docker/docker_client.go
generated
vendored
49
vendor/github.com/containers/image/docker/docker_client.go
generated
vendored
|
@ -308,31 +308,36 @@ func (c *dockerClient) setupRequestAuth(req *http.Request) error {
|
||||||
if len(c.challenges) == 0 {
|
if len(c.challenges) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
// assume just one...
|
schemeNames := make([]string, 0, len(c.challenges))
|
||||||
challenge := c.challenges[0]
|
for _, challenge := range c.challenges {
|
||||||
switch challenge.Scheme {
|
schemeNames = append(schemeNames, challenge.Scheme)
|
||||||
case "basic":
|
switch challenge.Scheme {
|
||||||
req.SetBasicAuth(c.username, c.password)
|
case "basic":
|
||||||
return nil
|
req.SetBasicAuth(c.username, c.password)
|
||||||
case "bearer":
|
return nil
|
||||||
if c.token == nil || time.Now().After(c.tokenExpiration) {
|
case "bearer":
|
||||||
realm, ok := challenge.Parameters["realm"]
|
if c.token == nil || time.Now().After(c.tokenExpiration) {
|
||||||
if !ok {
|
realm, ok := challenge.Parameters["realm"]
|
||||||
return errors.Errorf("missing realm in bearer auth challenge")
|
if !ok {
|
||||||
|
return errors.Errorf("missing realm in bearer auth challenge")
|
||||||
|
}
|
||||||
|
service, _ := challenge.Parameters["service"] // Will be "" if not present
|
||||||
|
scope := fmt.Sprintf("repository:%s:%s", c.scope.remoteName, c.scope.actions)
|
||||||
|
token, err := c.getBearerToken(realm, service, scope)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
c.token = token
|
||||||
|
c.tokenExpiration = token.IssuedAt.Add(time.Duration(token.ExpiresIn) * time.Second)
|
||||||
}
|
}
|
||||||
service, _ := challenge.Parameters["service"] // Will be "" if not present
|
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", c.token.Token))
|
||||||
scope := fmt.Sprintf("repository:%s:%s", c.scope.remoteName, c.scope.actions)
|
return nil
|
||||||
token, err := c.getBearerToken(realm, service, scope)
|
default:
|
||||||
if err != nil {
|
logrus.Debugf("no handler for %s authentication", challenge.Scheme)
|
||||||
return err
|
|
||||||
}
|
|
||||||
c.token = token
|
|
||||||
c.tokenExpiration = token.IssuedAt.Add(time.Duration(token.ExpiresIn) * time.Second)
|
|
||||||
}
|
}
|
||||||
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", c.token.Token))
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
return errors.Errorf("no handler for %s authentication", challenge.Scheme)
|
logrus.Infof("None of the challenges sent by server (%s) are supported, trying an unauthenticated request anyway", strings.Join(schemeNames, ", "))
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *dockerClient) getBearerToken(realm, service, scope string) (*bearerToken, error) {
|
func (c *dockerClient) getBearerToken(realm, service, scope string) (*bearerToken, error) {
|
||||||
|
|
5
vendor/github.com/containers/image/docker/docker_image_dest.go
generated
vendored
5
vendor/github.com/containers/image/docker/docker_image_dest.go
generated
vendored
|
@ -99,6 +99,11 @@ func (d *dockerImageDestination) AcceptsForeignLayerURLs() bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MustMatchRuntimeOS returns true iff the destination can store only images targeted for the current runtime OS. False otherwise.
|
||||||
|
func (d *dockerImageDestination) MustMatchRuntimeOS() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// sizeCounter is an io.Writer which only counts the total size of its input.
|
// sizeCounter is an io.Writer which only counts the total size of its input.
|
||||||
type sizeCounter struct{ size int64 }
|
type sizeCounter struct{ size int64 }
|
||||||
|
|
||||||
|
|
7
vendor/github.com/containers/image/docker/tarfile/dest.go
generated
vendored
7
vendor/github.com/containers/image/docker/tarfile/dest.go
generated
vendored
|
@ -81,6 +81,11 @@ func (d *Destination) AcceptsForeignLayerURLs() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MustMatchRuntimeOS returns true iff the destination can store only images targeted for the current runtime OS. False otherwise.
|
||||||
|
func (d *Destination) MustMatchRuntimeOS() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// PutBlob writes contents of stream and returns data representing the result (with all data filled in).
|
// PutBlob writes contents of stream and returns data representing the result (with all data filled in).
|
||||||
// inputInfo.Digest can be optionally provided if known; it is not mandatory for the implementation to verify it.
|
// inputInfo.Digest can be optionally provided if known; it is not mandatory for the implementation to verify it.
|
||||||
// inputInfo.Size is the expected length of stream, if known.
|
// inputInfo.Size is the expected length of stream, if known.
|
||||||
|
@ -176,7 +181,7 @@ func (d *Destination) PutManifest(m []byte) error {
|
||||||
layerPaths = append(layerPaths, l.Digest.String())
|
layerPaths = append(layerPaths, l.Digest.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
items := []manifestItem{{
|
items := []ManifestItem{{
|
||||||
Config: man.Config.Digest.String(),
|
Config: man.Config.Digest.String(),
|
||||||
RepoTags: []string{d.repoTag},
|
RepoTags: []string{d.repoTag},
|
||||||
Layers: layerPaths,
|
Layers: layerPaths,
|
||||||
|
|
31
vendor/github.com/containers/image/docker/tarfile/src.go
generated
vendored
31
vendor/github.com/containers/image/docker/tarfile/src.go
generated
vendored
|
@ -20,7 +20,7 @@ import (
|
||||||
type Source struct {
|
type Source struct {
|
||||||
tarPath string
|
tarPath string
|
||||||
// The following data is only available after ensureCachedDataIsPresent() succeeds
|
// The following data is only available after ensureCachedDataIsPresent() succeeds
|
||||||
tarManifest *manifestItem // nil if not available yet.
|
tarManifest *ManifestItem // nil if not available yet.
|
||||||
configBytes []byte
|
configBytes []byte
|
||||||
configDigest digest.Digest
|
configDigest digest.Digest
|
||||||
orderedDiffIDList []diffID
|
orderedDiffIDList []diffID
|
||||||
|
@ -145,23 +145,28 @@ func (s *Source) ensureCachedDataIsPresent() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check to make sure length is 1
|
||||||
|
if len(tarManifest) != 1 {
|
||||||
|
return errors.Errorf("Unexpected tar manifest.json: expected 1 item, got %d", len(tarManifest))
|
||||||
|
}
|
||||||
|
|
||||||
// Read and parse config.
|
// Read and parse config.
|
||||||
configBytes, err := s.readTarComponent(tarManifest.Config)
|
configBytes, err := s.readTarComponent(tarManifest[0].Config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
var parsedConfig image // Most fields ommitted, we only care about layer DiffIDs.
|
var parsedConfig image // Most fields ommitted, we only care about layer DiffIDs.
|
||||||
if err := json.Unmarshal(configBytes, &parsedConfig); err != nil {
|
if err := json.Unmarshal(configBytes, &parsedConfig); err != nil {
|
||||||
return errors.Wrapf(err, "Error decoding tar config %s", tarManifest.Config)
|
return errors.Wrapf(err, "Error decoding tar config %s", tarManifest[0].Config)
|
||||||
}
|
}
|
||||||
|
|
||||||
knownLayers, err := s.prepareLayerData(tarManifest, &parsedConfig)
|
knownLayers, err := s.prepareLayerData(&tarManifest[0], &parsedConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Success; commit.
|
// Success; commit.
|
||||||
s.tarManifest = tarManifest
|
s.tarManifest = &tarManifest[0]
|
||||||
s.configBytes = configBytes
|
s.configBytes = configBytes
|
||||||
s.configDigest = digest.FromBytes(configBytes)
|
s.configDigest = digest.FromBytes(configBytes)
|
||||||
s.orderedDiffIDList = parsedConfig.RootFS.DiffIDs
|
s.orderedDiffIDList = parsedConfig.RootFS.DiffIDs
|
||||||
|
@ -170,23 +175,25 @@ func (s *Source) ensureCachedDataIsPresent() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// loadTarManifest loads and decodes the manifest.json.
|
// loadTarManifest loads and decodes the manifest.json.
|
||||||
func (s *Source) loadTarManifest() (*manifestItem, error) {
|
func (s *Source) loadTarManifest() ([]ManifestItem, error) {
|
||||||
// FIXME? Do we need to deal with the legacy format?
|
// FIXME? Do we need to deal with the legacy format?
|
||||||
bytes, err := s.readTarComponent(manifestFileName)
|
bytes, err := s.readTarComponent(manifestFileName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var items []manifestItem
|
var items []ManifestItem
|
||||||
if err := json.Unmarshal(bytes, &items); err != nil {
|
if err := json.Unmarshal(bytes, &items); err != nil {
|
||||||
return nil, errors.Wrap(err, "Error decoding tar manifest.json")
|
return nil, errors.Wrap(err, "Error decoding tar manifest.json")
|
||||||
}
|
}
|
||||||
if len(items) != 1 {
|
return items, nil
|
||||||
return nil, errors.Errorf("Unexpected tar manifest.json: expected 1 item, got %d", len(items))
|
|
||||||
}
|
|
||||||
return &items[0], nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) prepareLayerData(tarManifest *manifestItem, parsedConfig *image) (map[diffID]*layerInfo, error) {
|
// LoadTarManifest loads and decodes the manifest.json
|
||||||
|
func (s *Source) LoadTarManifest() ([]ManifestItem, error) {
|
||||||
|
return s.loadTarManifest()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Source) prepareLayerData(tarManifest *ManifestItem, parsedConfig *image) (map[diffID]*layerInfo, error) {
|
||||||
// Collect layer data available in manifest and config.
|
// Collect layer data available in manifest and config.
|
||||||
if len(tarManifest.Layers) != len(parsedConfig.RootFS.DiffIDs) {
|
if len(tarManifest.Layers) != len(parsedConfig.RootFS.DiffIDs) {
|
||||||
return nil, errors.Errorf("Inconsistent layer count: %d in manifest, %d in config", len(tarManifest.Layers), len(parsedConfig.RootFS.DiffIDs))
|
return nil, errors.Errorf("Inconsistent layer count: %d in manifest, %d in config", len(tarManifest.Layers), len(parsedConfig.RootFS.DiffIDs))
|
||||||
|
|
3
vendor/github.com/containers/image/docker/tarfile/types.go
generated
vendored
3
vendor/github.com/containers/image/docker/tarfile/types.go
generated
vendored
|
@ -13,7 +13,8 @@ const (
|
||||||
// legacyRepositoriesFileName = "repositories"
|
// legacyRepositoriesFileName = "repositories"
|
||||||
)
|
)
|
||||||
|
|
||||||
type manifestItem struct {
|
// ManifestItem is an element of the array stored in the top-level manifest.json file.
|
||||||
|
type ManifestItem struct {
|
||||||
Config string
|
Config string
|
||||||
RepoTags []string
|
RepoTags []string
|
||||||
Layers []string
|
Layers []string
|
||||||
|
|
2
vendor/github.com/containers/image/image/docker_list.go
generated
vendored
2
vendor/github.com/containers/image/image/docker_list.go
generated
vendored
|
@ -16,7 +16,7 @@ type platformSpec struct {
|
||||||
OSVersion string `json:"os.version,omitempty"`
|
OSVersion string `json:"os.version,omitempty"`
|
||||||
OSFeatures []string `json:"os.features,omitempty"`
|
OSFeatures []string `json:"os.features,omitempty"`
|
||||||
Variant string `json:"variant,omitempty"`
|
Variant string `json:"variant,omitempty"`
|
||||||
Features []string `json:"features,omitempty"`
|
Features []string `json:"features,omitempty"` // removed in OCI
|
||||||
}
|
}
|
||||||
|
|
||||||
// A manifestDescriptor references a platform-specific manifest.
|
// A manifestDescriptor references a platform-specific manifest.
|
||||||
|
|
15
vendor/github.com/containers/image/image/docker_schema2.go
generated
vendored
15
vendor/github.com/containers/image/image/docker_schema2.go
generated
vendored
|
@ -183,6 +183,7 @@ func (m *manifestSchema2) UpdatedImage(options types.ManifestUpdateOptions) (typ
|
||||||
}
|
}
|
||||||
copy.LayersDescriptors = make([]descriptor, len(options.LayerInfos))
|
copy.LayersDescriptors = make([]descriptor, len(options.LayerInfos))
|
||||||
for i, info := range options.LayerInfos {
|
for i, info := range options.LayerInfos {
|
||||||
|
copy.LayersDescriptors[i].MediaType = m.LayersDescriptors[i].MediaType
|
||||||
copy.LayersDescriptors[i].Digest = info.Digest
|
copy.LayersDescriptors[i].Digest = info.Digest
|
||||||
copy.LayersDescriptors[i].Size = info.Size
|
copy.LayersDescriptors[i].Size = info.Size
|
||||||
copy.LayersDescriptors[i].URLs = info.URLs
|
copy.LayersDescriptors[i].URLs = info.URLs
|
||||||
|
@ -213,15 +214,17 @@ func (m *manifestSchema2) convertToManifestOCI1() (types.Image, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
config := descriptor{
|
config := descriptorOCI1{
|
||||||
MediaType: imgspecv1.MediaTypeImageConfig,
|
descriptor: descriptor{
|
||||||
Size: int64(len(configOCIBytes)),
|
MediaType: imgspecv1.MediaTypeImageConfig,
|
||||||
Digest: digest.FromBytes(configOCIBytes),
|
Size: int64(len(configOCIBytes)),
|
||||||
|
Digest: digest.FromBytes(configOCIBytes),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
layers := make([]descriptor, len(m.LayersDescriptors))
|
layers := make([]descriptorOCI1, len(m.LayersDescriptors))
|
||||||
for idx := range layers {
|
for idx := range layers {
|
||||||
layers[idx] = m.LayersDescriptors[idx]
|
layers[idx] = descriptorOCI1{descriptor: m.LayersDescriptors[idx]}
|
||||||
if m.LayersDescriptors[idx].MediaType == manifest.DockerV2Schema2ForeignLayerMediaType {
|
if m.LayersDescriptors[idx].MediaType == manifest.DockerV2Schema2ForeignLayerMediaType {
|
||||||
layers[idx].MediaType = imgspecv1.MediaTypeImageLayerNonDistributable
|
layers[idx].MediaType = imgspecv1.MediaTypeImageLayerNonDistributable
|
||||||
} else {
|
} else {
|
||||||
|
|
19
vendor/github.com/containers/image/image/oci.go
generated
vendored
19
vendor/github.com/containers/image/image/oci.go
generated
vendored
|
@ -12,12 +12,18 @@ import (
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type descriptorOCI1 struct {
|
||||||
|
descriptor
|
||||||
|
Annotations map[string]string `json:"annotations,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
type manifestOCI1 struct {
|
type manifestOCI1 struct {
|
||||||
src types.ImageSource // May be nil if configBlob is not nil
|
src types.ImageSource // May be nil if configBlob is not nil
|
||||||
configBlob []byte // If set, corresponds to contents of ConfigDescriptor.
|
configBlob []byte // If set, corresponds to contents of ConfigDescriptor.
|
||||||
SchemaVersion int `json:"schemaVersion"`
|
SchemaVersion int `json:"schemaVersion"`
|
||||||
ConfigDescriptor descriptor `json:"config"`
|
ConfigDescriptor descriptorOCI1 `json:"config"`
|
||||||
LayersDescriptors []descriptor `json:"layers"`
|
LayersDescriptors []descriptorOCI1 `json:"layers"`
|
||||||
|
Annotations map[string]string `json:"annotations,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func manifestOCI1FromManifest(src types.ImageSource, manifest []byte) (genericManifest, error) {
|
func manifestOCI1FromManifest(src types.ImageSource, manifest []byte) (genericManifest, error) {
|
||||||
|
@ -29,7 +35,7 @@ func manifestOCI1FromManifest(src types.ImageSource, manifest []byte) (genericMa
|
||||||
}
|
}
|
||||||
|
|
||||||
// manifestOCI1FromComponents builds a new manifestOCI1 from the supplied data:
|
// manifestOCI1FromComponents builds a new manifestOCI1 from the supplied data:
|
||||||
func manifestOCI1FromComponents(config descriptor, src types.ImageSource, configBlob []byte, layers []descriptor) genericManifest {
|
func manifestOCI1FromComponents(config descriptorOCI1, src types.ImageSource, configBlob []byte, layers []descriptorOCI1) genericManifest {
|
||||||
return &manifestOCI1{
|
return &manifestOCI1{
|
||||||
src: src,
|
src: src,
|
||||||
configBlob: configBlob,
|
configBlob: configBlob,
|
||||||
|
@ -148,8 +154,9 @@ func (m *manifestOCI1) UpdatedImage(options types.ManifestUpdateOptions) (types.
|
||||||
if len(copy.LayersDescriptors) != len(options.LayerInfos) {
|
if len(copy.LayersDescriptors) != len(options.LayerInfos) {
|
||||||
return nil, errors.Errorf("Error preparing updated manifest: layer count changed from %d to %d", len(copy.LayersDescriptors), len(options.LayerInfos))
|
return nil, errors.Errorf("Error preparing updated manifest: layer count changed from %d to %d", len(copy.LayersDescriptors), len(options.LayerInfos))
|
||||||
}
|
}
|
||||||
copy.LayersDescriptors = make([]descriptor, len(options.LayerInfos))
|
copy.LayersDescriptors = make([]descriptorOCI1, len(options.LayerInfos))
|
||||||
for i, info := range options.LayerInfos {
|
for i, info := range options.LayerInfos {
|
||||||
|
copy.LayersDescriptors[i].MediaType = m.LayersDescriptors[i].MediaType
|
||||||
copy.LayersDescriptors[i].Digest = info.Digest
|
copy.LayersDescriptors[i].Digest = info.Digest
|
||||||
copy.LayersDescriptors[i].Size = info.Size
|
copy.LayersDescriptors[i].Size = info.Size
|
||||||
}
|
}
|
||||||
|
@ -169,7 +176,7 @@ func (m *manifestOCI1) UpdatedImage(options types.ManifestUpdateOptions) (types.
|
||||||
|
|
||||||
func (m *manifestOCI1) convertToManifestSchema2() (types.Image, error) {
|
func (m *manifestOCI1) convertToManifestSchema2() (types.Image, error) {
|
||||||
// Create a copy of the descriptor.
|
// Create a copy of the descriptor.
|
||||||
config := m.ConfigDescriptor
|
config := m.ConfigDescriptor.descriptor
|
||||||
|
|
||||||
// The only difference between OCI and DockerSchema2 is the mediatypes. The
|
// The only difference between OCI and DockerSchema2 is the mediatypes. The
|
||||||
// media type of the manifest is handled by manifestSchema2FromComponents.
|
// media type of the manifest is handled by manifestSchema2FromComponents.
|
||||||
|
@ -177,7 +184,7 @@ func (m *manifestOCI1) convertToManifestSchema2() (types.Image, error) {
|
||||||
|
|
||||||
layers := make([]descriptor, len(m.LayersDescriptors))
|
layers := make([]descriptor, len(m.LayersDescriptors))
|
||||||
for idx := range layers {
|
for idx := range layers {
|
||||||
layers[idx] = m.LayersDescriptors[idx]
|
layers[idx] = m.LayersDescriptors[idx].descriptor
|
||||||
layers[idx].MediaType = manifest.DockerV2Schema2LayerMediaType
|
layers[idx].MediaType = manifest.DockerV2Schema2LayerMediaType
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
5
vendor/github.com/containers/image/oci/layout/oci_dest.go
generated
vendored
5
vendor/github.com/containers/image/oci/layout/oci_dest.go
generated
vendored
|
@ -66,6 +66,11 @@ func (d *ociImageDestination) AcceptsForeignLayerURLs() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MustMatchRuntimeOS returns true iff the destination can store only images targeted for the current runtime OS. False otherwise.
|
||||||
|
func (d *ociImageDestination) MustMatchRuntimeOS() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// PutBlob writes contents of stream and returns data representing the result (with all data filled in).
|
// PutBlob writes contents of stream and returns data representing the result (with all data filled in).
|
||||||
// inputInfo.Digest can be optionally provided if known; it is not mandatory for the implementation to verify it.
|
// inputInfo.Digest can be optionally provided if known; it is not mandatory for the implementation to verify it.
|
||||||
// inputInfo.Size is the expected length of stream, if known.
|
// inputInfo.Size is the expected length of stream, if known.
|
||||||
|
|
5
vendor/github.com/containers/image/openshift/openshift.go
generated
vendored
5
vendor/github.com/containers/image/openshift/openshift.go
generated
vendored
|
@ -358,6 +358,11 @@ func (d *openshiftImageDestination) AcceptsForeignLayerURLs() bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MustMatchRuntimeOS returns true iff the destination can store only images targeted for the current runtime OS. False otherwise.
|
||||||
|
func (d *openshiftImageDestination) MustMatchRuntimeOS() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// PutBlob writes contents of stream and returns data representing the result (with all data filled in).
|
// PutBlob writes contents of stream and returns data representing the result (with all data filled in).
|
||||||
// inputInfo.Digest can be optionally provided if known; it is not mandatory for the implementation to verify it.
|
// inputInfo.Digest can be optionally provided if known; it is not mandatory for the implementation to verify it.
|
||||||
// inputInfo.Size is the expected length of stream, if known.
|
// inputInfo.Size is the expected length of stream, if known.
|
||||||
|
|
48
vendor/github.com/containers/image/ostree/ostree_dest.go
generated
vendored
48
vendor/github.com/containers/image/ostree/ostree_dest.go
generated
vendored
|
@ -11,12 +11,15 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/containers/image/manifest"
|
"github.com/containers/image/manifest"
|
||||||
"github.com/containers/image/types"
|
"github.com/containers/image/types"
|
||||||
"github.com/containers/storage/pkg/archive"
|
"github.com/containers/storage/pkg/archive"
|
||||||
"github.com/opencontainers/go-digest"
|
"github.com/opencontainers/go-digest"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
|
"github.com/ostreedev/ostree-go/pkg/otbuiltin"
|
||||||
)
|
)
|
||||||
|
|
||||||
type blobToImport struct {
|
type blobToImport struct {
|
||||||
|
@ -86,6 +89,11 @@ func (d *ostreeImageDestination) AcceptsForeignLayerURLs() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MustMatchRuntimeOS returns true iff the destination can store only images targeted for the current runtime OS. False otherwise.
|
||||||
|
func (d *ostreeImageDestination) MustMatchRuntimeOS() bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
func (d *ostreeImageDestination) PutBlob(stream io.Reader, inputInfo types.BlobInfo) (types.BlobInfo, error) {
|
func (d *ostreeImageDestination) PutBlob(stream io.Reader, inputInfo types.BlobInfo) (types.BlobInfo, error) {
|
||||||
tmpDir, err := ioutil.TempDir(d.tmpDirPath, "blob")
|
tmpDir, err := ioutil.TempDir(d.tmpDirPath, "blob")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -153,7 +161,17 @@ func fixFiles(dir string, usermode bool) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *ostreeImageDestination) importBlob(blob *blobToImport) error {
|
func (d *ostreeImageDestination) ostreeCommit(repo *otbuiltin.Repo, branch string, root string, metadata []string) error {
|
||||||
|
opts := otbuiltin.NewCommitOptions()
|
||||||
|
opts.AddMetadataString = metadata
|
||||||
|
opts.Timestamp = time.Now()
|
||||||
|
// OCI layers have no parent OSTree commit
|
||||||
|
opts.Parent = "0000000000000000000000000000000000000000000000000000000000000000"
|
||||||
|
_, err := repo.Commit(root, branch, opts)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *ostreeImageDestination) importBlob(repo *otbuiltin.Repo, blob *blobToImport) error {
|
||||||
ostreeBranch := fmt.Sprintf("ociimage/%s", blob.Digest.Hex())
|
ostreeBranch := fmt.Sprintf("ociimage/%s", blob.Digest.Hex())
|
||||||
destinationPath := filepath.Join(d.tmpDirPath, blob.Digest.Hex(), "root")
|
destinationPath := filepath.Join(d.tmpDirPath, blob.Digest.Hex(), "root")
|
||||||
if err := ensureDirectoryExists(destinationPath); err != nil {
|
if err := ensureDirectoryExists(destinationPath); err != nil {
|
||||||
|
@ -181,11 +199,7 @@ func (d *ostreeImageDestination) importBlob(blob *blobToImport) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return exec.Command("ostree", "commit",
|
return d.ostreeCommit(repo, ostreeBranch, destinationPath, []string{fmt.Sprintf("docker.size=%d", blob.Size)})
|
||||||
"--repo", d.ref.repo,
|
|
||||||
fmt.Sprintf("--add-metadata-string=docker.size=%d", blob.Size),
|
|
||||||
"--branch", ostreeBranch,
|
|
||||||
fmt.Sprintf("--tree=dir=%s", destinationPath)).Run()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *ostreeImageDestination) importConfig(blob *blobToImport) error {
|
func (d *ostreeImageDestination) importConfig(blob *blobToImport) error {
|
||||||
|
@ -253,6 +267,16 @@ func (d *ostreeImageDestination) PutSignatures(signatures [][]byte) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *ostreeImageDestination) Commit() error {
|
func (d *ostreeImageDestination) Commit() error {
|
||||||
|
repo, err := otbuiltin.OpenRepo(d.ref.repo)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = repo.PrepareTransaction()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
for _, layer := range d.schema.LayersDescriptors {
|
for _, layer := range d.schema.LayersDescriptors {
|
||||||
hash := layer.Digest.Hex()
|
hash := layer.Digest.Hex()
|
||||||
blob := d.blobs[hash]
|
blob := d.blobs[hash]
|
||||||
|
@ -261,7 +285,7 @@ func (d *ostreeImageDestination) Commit() error {
|
||||||
if blob == nil {
|
if blob == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
err := d.importBlob(blob)
|
err := d.importBlob(repo, blob)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -277,11 +301,11 @@ func (d *ostreeImageDestination) Commit() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
manifestPath := filepath.Join(d.tmpDirPath, "manifest")
|
manifestPath := filepath.Join(d.tmpDirPath, "manifest")
|
||||||
err := exec.Command("ostree", "commit",
|
|
||||||
"--repo", d.ref.repo,
|
metadata := []string{fmt.Sprintf("docker.manifest=%s", string(d.manifest))}
|
||||||
fmt.Sprintf("--add-metadata-string=docker.manifest=%s", string(d.manifest)),
|
err = d.ostreeCommit(repo, fmt.Sprintf("ociimage/%s", d.ref.branchName), manifestPath, metadata)
|
||||||
fmt.Sprintf("--branch=ociimage/%s", d.ref.branchName),
|
|
||||||
manifestPath).Run()
|
_, err = repo.CommitTransaction()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
19
vendor/github.com/containers/image/storage/storage_image.go
generated
vendored
19
vendor/github.com/containers/image/storage/storage_image.go
generated
vendored
|
@ -174,11 +174,11 @@ func (s *storageImageDestination) putBlob(stream io.Reader, blobinfo types.BlobI
|
||||||
}
|
}
|
||||||
// Attempt to create the identified layer and import its contents.
|
// Attempt to create the identified layer and import its contents.
|
||||||
layer, uncompressedSize, err := s.imageRef.transport.store.PutLayer(id, parentLayer, nil, "", true, multi)
|
layer, uncompressedSize, err := s.imageRef.transport.store.PutLayer(id, parentLayer, nil, "", true, multi)
|
||||||
if err != nil && err != storage.ErrDuplicateID {
|
if err != nil && errors.Cause(err) != storage.ErrDuplicateID {
|
||||||
logrus.Debugf("error importing layer blob %q as %q: %v", blobinfo.Digest, id, err)
|
logrus.Debugf("error importing layer blob %q as %q: %v", blobinfo.Digest, id, err)
|
||||||
return errorBlobInfo, err
|
return errorBlobInfo, err
|
||||||
}
|
}
|
||||||
if err == storage.ErrDuplicateID {
|
if errors.Cause(err) == storage.ErrDuplicateID {
|
||||||
// We specified an ID, and there's already a layer with
|
// We specified an ID, and there's already a layer with
|
||||||
// the same ID. Drain the input so that we can look at
|
// the same ID. Drain the input so that we can look at
|
||||||
// its length and digest.
|
// its length and digest.
|
||||||
|
@ -291,7 +291,7 @@ func (s *storageImageDestination) PutBlob(stream io.Reader, blobinfo types.BlobI
|
||||||
// it returns a non-nil error only on an unexpected failure.
|
// it returns a non-nil error only on an unexpected failure.
|
||||||
func (s *storageImageDestination) HasBlob(blobinfo types.BlobInfo) (bool, int64, error) {
|
func (s *storageImageDestination) HasBlob(blobinfo types.BlobInfo) (bool, int64, error) {
|
||||||
if blobinfo.Digest == "" {
|
if blobinfo.Digest == "" {
|
||||||
return false, -1, errors.Errorf(`"Can not check for a blob with unknown digest`)
|
return false, -1, errors.Errorf(`Can not check for a blob with unknown digest`)
|
||||||
}
|
}
|
||||||
for _, blob := range s.BlobList {
|
for _, blob := range s.BlobList {
|
||||||
if blob.Digest == blobinfo.Digest {
|
if blob.Digest == blobinfo.Digest {
|
||||||
|
@ -331,7 +331,7 @@ func (s *storageImageDestination) Commit() error {
|
||||||
}
|
}
|
||||||
img, err := s.imageRef.transport.store.CreateImage(s.ID, nil, lastLayer, "", nil)
|
img, err := s.imageRef.transport.store.CreateImage(s.ID, nil, lastLayer, "", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err != storage.ErrDuplicateID {
|
if errors.Cause(err) != storage.ErrDuplicateID {
|
||||||
logrus.Debugf("error creating image: %q", err)
|
logrus.Debugf("error creating image: %q", err)
|
||||||
return errors.Wrapf(err, "error creating image %q", s.ID)
|
return errors.Wrapf(err, "error creating image %q", s.ID)
|
||||||
}
|
}
|
||||||
|
@ -340,8 +340,8 @@ func (s *storageImageDestination) Commit() error {
|
||||||
return errors.Wrapf(err, "error reading image %q", s.ID)
|
return errors.Wrapf(err, "error reading image %q", s.ID)
|
||||||
}
|
}
|
||||||
if img.TopLayer != lastLayer {
|
if img.TopLayer != lastLayer {
|
||||||
logrus.Debugf("error creating image: image with ID %q exists, but uses different layers", err)
|
logrus.Debugf("error creating image: image with ID %q exists, but uses different layers", s.ID)
|
||||||
return errors.Wrapf(err, "image with ID %q already exists, but uses a different top layer", s.ID)
|
return errors.Wrapf(storage.ErrDuplicateID, "image with ID %q already exists, but uses a different top layer", s.ID)
|
||||||
}
|
}
|
||||||
logrus.Debugf("reusing image ID %q", img.ID)
|
logrus.Debugf("reusing image ID %q", img.ID)
|
||||||
} else {
|
} else {
|
||||||
|
@ -449,6 +449,11 @@ func (s *storageImageDestination) AcceptsForeignLayerURLs() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MustMatchRuntimeOS returns true iff the destination can store only images targeted for the current runtime OS. False otherwise.
|
||||||
|
func (s *storageImageDestination) MustMatchRuntimeOS() bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
func (s *storageImageDestination) PutSignatures(signatures [][]byte) error {
|
func (s *storageImageDestination) PutSignatures(signatures [][]byte) error {
|
||||||
sizes := []int{}
|
sizes := []int{}
|
||||||
sigblob := []byte{}
|
sigblob := []byte{}
|
||||||
|
@ -516,7 +521,7 @@ func diffLayer(store storage.Store, layerID string) (rc io.ReadCloser, n int64,
|
||||||
} else {
|
} else {
|
||||||
n = layerMeta.CompressedSize
|
n = layerMeta.CompressedSize
|
||||||
}
|
}
|
||||||
diff, err := store.Diff("", layer.ID)
|
diff, err := store.Diff("", layer.ID, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, -1, err
|
return nil, -1, err
|
||||||
}
|
}
|
||||||
|
|
20
vendor/github.com/containers/image/storage/storage_reference.go
generated
vendored
20
vendor/github.com/containers/image/storage/storage_reference.go
generated
vendored
|
@ -70,7 +70,9 @@ func (s *storageReference) resolveImage() (*storage.Image, error) {
|
||||||
// to build this reference object.
|
// to build this reference object.
|
||||||
func (s storageReference) Transport() types.ImageTransport {
|
func (s storageReference) Transport() types.ImageTransport {
|
||||||
return &storageTransport{
|
return &storageTransport{
|
||||||
store: s.transport.store,
|
store: s.transport.store,
|
||||||
|
defaultUIDMap: s.transport.defaultUIDMap,
|
||||||
|
defaultGIDMap: s.transport.defaultGIDMap,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +85,12 @@ func (s storageReference) DockerReference() reference.Named {
|
||||||
// disambiguate between images which may be present in multiple stores and
|
// disambiguate between images which may be present in multiple stores and
|
||||||
// share only their names.
|
// share only their names.
|
||||||
func (s storageReference) StringWithinTransport() string {
|
func (s storageReference) StringWithinTransport() string {
|
||||||
storeSpec := "[" + s.transport.store.GraphDriverName() + "@" + s.transport.store.GraphRoot() + "]"
|
optionsList := ""
|
||||||
|
options := s.transport.store.GraphOptions()
|
||||||
|
if len(options) > 0 {
|
||||||
|
optionsList = ":" + strings.Join(options, ",")
|
||||||
|
}
|
||||||
|
storeSpec := "[" + s.transport.store.GraphDriverName() + "@" + s.transport.store.GraphRoot() + "+" + s.transport.store.RunRoot() + optionsList + "]"
|
||||||
if s.name == nil {
|
if s.name == nil {
|
||||||
return storeSpec + "@" + s.id
|
return storeSpec + "@" + s.id
|
||||||
}
|
}
|
||||||
|
@ -94,7 +101,14 @@ func (s storageReference) StringWithinTransport() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s storageReference) PolicyConfigurationIdentity() string {
|
func (s storageReference) PolicyConfigurationIdentity() string {
|
||||||
return s.StringWithinTransport()
|
storeSpec := "[" + s.transport.store.GraphDriverName() + "@" + s.transport.store.GraphRoot() + "]"
|
||||||
|
if s.name == nil {
|
||||||
|
return storeSpec + "@" + s.id
|
||||||
|
}
|
||||||
|
if s.id == "" {
|
||||||
|
return storeSpec + s.reference
|
||||||
|
}
|
||||||
|
return storeSpec + s.reference + "@" + s.id
|
||||||
}
|
}
|
||||||
|
|
||||||
// Also accept policy that's tied to the combination of the graph root and
|
// Also accept policy that's tied to the combination of the graph root and
|
||||||
|
|
145
vendor/github.com/containers/image/storage/storage_transport.go
generated
vendored
145
vendor/github.com/containers/image/storage/storage_transport.go
generated
vendored
|
@ -11,6 +11,7 @@ import (
|
||||||
"github.com/containers/image/transports"
|
"github.com/containers/image/transports"
|
||||||
"github.com/containers/image/types"
|
"github.com/containers/image/types"
|
||||||
"github.com/containers/storage"
|
"github.com/containers/storage"
|
||||||
|
"github.com/containers/storage/pkg/idtools"
|
||||||
"github.com/opencontainers/go-digest"
|
"github.com/opencontainers/go-digest"
|
||||||
ddigest "github.com/opencontainers/go-digest"
|
ddigest "github.com/opencontainers/go-digest"
|
||||||
)
|
)
|
||||||
|
@ -46,10 +47,20 @@ type StoreTransport interface {
|
||||||
// ParseStoreReference parses a reference, overriding any store
|
// ParseStoreReference parses a reference, overriding any store
|
||||||
// specification that it may contain.
|
// specification that it may contain.
|
||||||
ParseStoreReference(store storage.Store, reference string) (*storageReference, error)
|
ParseStoreReference(store storage.Store, reference string) (*storageReference, error)
|
||||||
|
// SetDefaultUIDMap sets the default UID map to use when opening stores.
|
||||||
|
SetDefaultUIDMap(idmap []idtools.IDMap)
|
||||||
|
// SetDefaultGIDMap sets the default GID map to use when opening stores.
|
||||||
|
SetDefaultGIDMap(idmap []idtools.IDMap)
|
||||||
|
// DefaultUIDMap returns the default UID map used when opening stores.
|
||||||
|
DefaultUIDMap() []idtools.IDMap
|
||||||
|
// DefaultGIDMap returns the default GID map used when opening stores.
|
||||||
|
DefaultGIDMap() []idtools.IDMap
|
||||||
}
|
}
|
||||||
|
|
||||||
type storageTransport struct {
|
type storageTransport struct {
|
||||||
store storage.Store
|
store storage.Store
|
||||||
|
defaultUIDMap []idtools.IDMap
|
||||||
|
defaultGIDMap []idtools.IDMap
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *storageTransport) Name() string {
|
func (s *storageTransport) Name() string {
|
||||||
|
@ -66,6 +77,26 @@ func (s *storageTransport) SetStore(store storage.Store) {
|
||||||
s.store = store
|
s.store = store
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetDefaultUIDMap sets the default UID map to use when opening stores.
|
||||||
|
func (s *storageTransport) SetDefaultUIDMap(idmap []idtools.IDMap) {
|
||||||
|
s.defaultUIDMap = idmap
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDefaultGIDMap sets the default GID map to use when opening stores.
|
||||||
|
func (s *storageTransport) SetDefaultGIDMap(idmap []idtools.IDMap) {
|
||||||
|
s.defaultGIDMap = idmap
|
||||||
|
}
|
||||||
|
|
||||||
|
// DefaultUIDMap returns the default UID map used when opening stores.
|
||||||
|
func (s *storageTransport) DefaultUIDMap() []idtools.IDMap {
|
||||||
|
return s.defaultUIDMap
|
||||||
|
}
|
||||||
|
|
||||||
|
// DefaultGIDMap returns the default GID map used when opening stores.
|
||||||
|
func (s *storageTransport) DefaultGIDMap() []idtools.IDMap {
|
||||||
|
return s.defaultGIDMap
|
||||||
|
}
|
||||||
|
|
||||||
// ParseStoreReference takes a name or an ID, tries to figure out which it is
|
// ParseStoreReference takes a name or an ID, tries to figure out which it is
|
||||||
// relative to the given store, and returns it in a reference object.
|
// relative to the given store, and returns it in a reference object.
|
||||||
func (s storageTransport) ParseStoreReference(store storage.Store, ref string) (*storageReference, error) {
|
func (s storageTransport) ParseStoreReference(store storage.Store, ref string) (*storageReference, error) {
|
||||||
|
@ -110,7 +141,12 @@ func (s storageTransport) ParseStoreReference(store storage.Store, ref string) (
|
||||||
// recognize.
|
// recognize.
|
||||||
return nil, ErrInvalidReference
|
return nil, ErrInvalidReference
|
||||||
}
|
}
|
||||||
storeSpec := "[" + store.GraphDriverName() + "@" + store.GraphRoot() + "]"
|
optionsList := ""
|
||||||
|
options := store.GraphOptions()
|
||||||
|
if len(options) > 0 {
|
||||||
|
optionsList = ":" + strings.Join(options, ",")
|
||||||
|
}
|
||||||
|
storeSpec := "[" + store.GraphDriverName() + "@" + store.GraphRoot() + "+" + store.RunRoot() + optionsList + "]"
|
||||||
id := ""
|
id := ""
|
||||||
if sum.Validate() == nil {
|
if sum.Validate() == nil {
|
||||||
id = sum.Hex()
|
id = sum.Hex()
|
||||||
|
@ -127,14 +163,17 @@ func (s storageTransport) ParseStoreReference(store storage.Store, ref string) (
|
||||||
} else {
|
} else {
|
||||||
logrus.Debugf("parsed reference into %q", storeSpec+refname+"@"+id)
|
logrus.Debugf("parsed reference into %q", storeSpec+refname+"@"+id)
|
||||||
}
|
}
|
||||||
return newReference(storageTransport{store: store}, refname, id, name), nil
|
return newReference(storageTransport{store: store, defaultUIDMap: s.defaultUIDMap, defaultGIDMap: s.defaultGIDMap}, refname, id, name), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *storageTransport) GetStore() (storage.Store, error) {
|
func (s *storageTransport) GetStore() (storage.Store, error) {
|
||||||
// Return the transport's previously-set store. If we don't have one
|
// Return the transport's previously-set store. If we don't have one
|
||||||
// of those, initialize one now.
|
// of those, initialize one now.
|
||||||
if s.store == nil {
|
if s.store == nil {
|
||||||
store, err := storage.GetStore(storage.DefaultStoreOptions)
|
options := storage.DefaultStoreOptions
|
||||||
|
options.UIDMap = s.defaultUIDMap
|
||||||
|
options.GIDMap = s.defaultGIDMap
|
||||||
|
store, err := storage.GetStore(options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -145,15 +184,11 @@ func (s *storageTransport) GetStore() (storage.Store, error) {
|
||||||
|
|
||||||
// ParseReference takes a name and/or an ID ("_name_"/"@_id_"/"_name_@_id_"),
|
// ParseReference takes a name and/or an ID ("_name_"/"@_id_"/"_name_@_id_"),
|
||||||
// possibly prefixed with a store specifier in the form "[_graphroot_]" or
|
// possibly prefixed with a store specifier in the form "[_graphroot_]" or
|
||||||
// "[_driver_@_graphroot_]", tries to figure out which it is, and returns it in
|
// "[_driver_@_graphroot_]" or "[_driver_@_graphroot_+_runroot_]" or
|
||||||
// a reference object. If the _graphroot_ is a location other than the default,
|
// "[_driver_@_graphroot_:_options_]" or "[_driver_@_graphroot_+_runroot_:_options_]",
|
||||||
// it needs to have been previously opened using storage.GetStore(), so that it
|
// tries to figure out which it is, and returns it in a reference object.
|
||||||
// can figure out which run root goes with the graph root.
|
|
||||||
func (s *storageTransport) ParseReference(reference string) (types.ImageReference, error) {
|
func (s *storageTransport) ParseReference(reference string) (types.ImageReference, error) {
|
||||||
store, err := s.GetStore()
|
var store storage.Store
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
// Check if there's a store location prefix. If there is, then it
|
// Check if there's a store location prefix. If there is, then it
|
||||||
// needs to match a store that was previously initialized using
|
// needs to match a store that was previously initialized using
|
||||||
// storage.GetStore(), or be enough to let the storage library fill out
|
// storage.GetStore(), or be enough to let the storage library fill out
|
||||||
|
@ -165,37 +200,65 @@ func (s *storageTransport) ParseReference(reference string) (types.ImageReferenc
|
||||||
}
|
}
|
||||||
storeSpec := reference[1:closeIndex]
|
storeSpec := reference[1:closeIndex]
|
||||||
reference = reference[closeIndex+1:]
|
reference = reference[closeIndex+1:]
|
||||||
storeInfo := strings.SplitN(storeSpec, "@", 2)
|
// Peel off a "driver@" from the start.
|
||||||
if len(storeInfo) == 1 && storeInfo[0] != "" {
|
driverInfo := ""
|
||||||
// One component: the graph root.
|
driverSplit := strings.SplitN(storeSpec, "@", 2)
|
||||||
if !filepath.IsAbs(storeInfo[0]) {
|
if len(driverSplit) != 2 {
|
||||||
return nil, ErrPathNotAbsolute
|
if storeSpec == "" {
|
||||||
|
return nil, ErrInvalidReference
|
||||||
}
|
}
|
||||||
store2, err := storage.GetStore(storage.StoreOptions{
|
|
||||||
GraphRoot: storeInfo[0],
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
store = store2
|
|
||||||
} else if len(storeInfo) == 2 && storeInfo[0] != "" && storeInfo[1] != "" {
|
|
||||||
// Two components: the driver type and the graph root.
|
|
||||||
if !filepath.IsAbs(storeInfo[1]) {
|
|
||||||
return nil, ErrPathNotAbsolute
|
|
||||||
}
|
|
||||||
store2, err := storage.GetStore(storage.StoreOptions{
|
|
||||||
GraphDriverName: storeInfo[0],
|
|
||||||
GraphRoot: storeInfo[1],
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
store = store2
|
|
||||||
} else {
|
} else {
|
||||||
// Anything else: store specified in a form we don't
|
driverInfo = driverSplit[0]
|
||||||
// recognize.
|
if driverInfo == "" {
|
||||||
return nil, ErrInvalidReference
|
return nil, ErrInvalidReference
|
||||||
|
}
|
||||||
|
storeSpec = driverSplit[1]
|
||||||
|
if storeSpec == "" {
|
||||||
|
return nil, ErrInvalidReference
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
// Peel off a ":options" from the end.
|
||||||
|
var options []string
|
||||||
|
optionsSplit := strings.SplitN(storeSpec, ":", 2)
|
||||||
|
if len(optionsSplit) == 2 {
|
||||||
|
options = strings.Split(optionsSplit[1], ",")
|
||||||
|
storeSpec = optionsSplit[0]
|
||||||
|
}
|
||||||
|
// Peel off a "+runroot" from the new end.
|
||||||
|
runRootInfo := ""
|
||||||
|
runRootSplit := strings.SplitN(storeSpec, "+", 2)
|
||||||
|
if len(runRootSplit) == 2 {
|
||||||
|
runRootInfo = runRootSplit[1]
|
||||||
|
storeSpec = runRootSplit[0]
|
||||||
|
}
|
||||||
|
// The rest is our graph root.
|
||||||
|
rootInfo := storeSpec
|
||||||
|
// Check that any paths are absolute paths.
|
||||||
|
if rootInfo != "" && !filepath.IsAbs(rootInfo) {
|
||||||
|
return nil, ErrPathNotAbsolute
|
||||||
|
}
|
||||||
|
if runRootInfo != "" && !filepath.IsAbs(runRootInfo) {
|
||||||
|
return nil, ErrPathNotAbsolute
|
||||||
|
}
|
||||||
|
store2, err := storage.GetStore(storage.StoreOptions{
|
||||||
|
GraphDriverName: driverInfo,
|
||||||
|
GraphRoot: rootInfo,
|
||||||
|
RunRoot: runRootInfo,
|
||||||
|
GraphDriverOptions: options,
|
||||||
|
UIDMap: s.defaultUIDMap,
|
||||||
|
GIDMap: s.defaultGIDMap,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
store = store2
|
||||||
|
} else {
|
||||||
|
// We didn't have a store spec, so use the default.
|
||||||
|
store2, err := s.GetStore()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
store = store2
|
||||||
}
|
}
|
||||||
return s.ParseStoreReference(store, reference)
|
return s.ParseStoreReference(store, reference)
|
||||||
}
|
}
|
||||||
|
@ -250,7 +313,7 @@ func (s storageTransport) ValidatePolicyConfigurationScope(scope string) error {
|
||||||
return ErrPathNotAbsolute
|
return ErrPathNotAbsolute
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Anything else: store specified in a form we don't
|
// Anything else: scope specified in a form we don't
|
||||||
// recognize.
|
// recognize.
|
||||||
return ErrInvalidReference
|
return ErrInvalidReference
|
||||||
}
|
}
|
||||||
|
|
2
vendor/github.com/containers/image/transports/alltransports/alltransports.go
generated
vendored
2
vendor/github.com/containers/image/transports/alltransports/alltransports.go
generated
vendored
|
@ -12,7 +12,7 @@ import (
|
||||||
_ "github.com/containers/image/docker/daemon"
|
_ "github.com/containers/image/docker/daemon"
|
||||||
_ "github.com/containers/image/oci/layout"
|
_ "github.com/containers/image/oci/layout"
|
||||||
_ "github.com/containers/image/openshift"
|
_ "github.com/containers/image/openshift"
|
||||||
_ "github.com/containers/image/ostree"
|
// The ostree transport is registered by ostree*.go
|
||||||
_ "github.com/containers/image/storage"
|
_ "github.com/containers/image/storage"
|
||||||
"github.com/containers/image/transports"
|
"github.com/containers/image/transports"
|
||||||
"github.com/containers/image/types"
|
"github.com/containers/image/types"
|
||||||
|
|
13
vendor/github.com/containers/image/transports/transports.go
generated
vendored
13
vendor/github.com/containers/image/transports/transports.go
generated
vendored
|
@ -2,6 +2,7 @@ package transports
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/containers/image/types"
|
"github.com/containers/image/types"
|
||||||
|
@ -69,3 +70,15 @@ func Register(t types.ImageTransport) {
|
||||||
func ImageName(ref types.ImageReference) string {
|
func ImageName(ref types.ImageReference) string {
|
||||||
return ref.Transport().Name() + ":" + ref.StringWithinTransport()
|
return ref.Transport().Name() + ":" + ref.StringWithinTransport()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListNames returns a list of transport names
|
||||||
|
func ListNames() []string {
|
||||||
|
kt.mu.Lock()
|
||||||
|
defer kt.mu.Unlock()
|
||||||
|
var names []string
|
||||||
|
for _, transport := range kt.transports {
|
||||||
|
names = append(names, transport.Name())
|
||||||
|
}
|
||||||
|
sort.Strings(names)
|
||||||
|
return names
|
||||||
|
}
|
||||||
|
|
4
vendor/github.com/containers/image/types/types.go
generated
vendored
4
vendor/github.com/containers/image/types/types.go
generated
vendored
|
@ -148,11 +148,11 @@ type ImageDestination interface {
|
||||||
SupportsSignatures() error
|
SupportsSignatures() error
|
||||||
// ShouldCompressLayers returns true iff it is desirable to compress layer blobs written to this destination.
|
// ShouldCompressLayers returns true iff it is desirable to compress layer blobs written to this destination.
|
||||||
ShouldCompressLayers() bool
|
ShouldCompressLayers() bool
|
||||||
|
|
||||||
// AcceptsForeignLayerURLs returns false iff foreign layers in manifest should be actually
|
// AcceptsForeignLayerURLs returns false iff foreign layers in manifest should be actually
|
||||||
// uploaded to the image destination, true otherwise.
|
// uploaded to the image destination, true otherwise.
|
||||||
AcceptsForeignLayerURLs() bool
|
AcceptsForeignLayerURLs() bool
|
||||||
|
// MustMatchRuntimeOS returns true iff the destination can store only images targeted for the current runtime OS. False otherwise.
|
||||||
|
MustMatchRuntimeOS() bool
|
||||||
// PutBlob writes contents of stream and returns data representing the result (with all data filled in).
|
// PutBlob writes contents of stream and returns data representing the result (with all data filled in).
|
||||||
// inputInfo.Digest can be optionally provided if known; it is not mandatory for the implementation to verify it.
|
// inputInfo.Digest can be optionally provided if known; it is not mandatory for the implementation to verify it.
|
||||||
// inputInfo.Size is the expected length of stream, if known.
|
// inputInfo.Size is the expected length of stream, if known.
|
||||||
|
|
6
vendor/github.com/containers/image/vendor.conf
generated
vendored
6
vendor/github.com/containers/image/vendor.conf
generated
vendored
|
@ -1,5 +1,5 @@
|
||||||
github.com/Sirupsen/logrus 7f4b1adc791766938c29457bed0703fb9134421a
|
github.com/Sirupsen/logrus 7f4b1adc791766938c29457bed0703fb9134421a
|
||||||
github.com/containers/storage 989b1c1d85f5dfe2076c67b54289cc13dc836c8c
|
github.com/containers/storage 105f7c77aef0c797429e41552743bf5b03b63263
|
||||||
github.com/davecgh/go-spew 346938d642f2ec3594ed81d874461961cd0faa76
|
github.com/davecgh/go-spew 346938d642f2ec3594ed81d874461961cd0faa76
|
||||||
github.com/docker/distribution df5327f76fb6468b84a87771e361762b8be23fdb
|
github.com/docker/distribution df5327f76fb6468b84a87771e361762b8be23fdb
|
||||||
github.com/docker/docker 75843d36aa5c3eaade50da005f9e0ff2602f3d5e
|
github.com/docker/docker 75843d36aa5c3eaade50da005f9e0ff2602f3d5e
|
||||||
|
@ -15,7 +15,7 @@ github.com/mattn/go-shellwords 005a0944d84452842197c2108bd9168ced206f78
|
||||||
github.com/mistifyio/go-zfs c0224de804d438efd11ea6e52ada8014537d6062
|
github.com/mistifyio/go-zfs c0224de804d438efd11ea6e52ada8014537d6062
|
||||||
github.com/mtrmac/gpgme b2432428689ca58c2b8e8dea9449d3295cf96fc9
|
github.com/mtrmac/gpgme b2432428689ca58c2b8e8dea9449d3295cf96fc9
|
||||||
github.com/opencontainers/go-digest aa2ec055abd10d26d539eb630a92241b781ce4bc
|
github.com/opencontainers/go-digest aa2ec055abd10d26d539eb630a92241b781ce4bc
|
||||||
github.com/opencontainers/image-spec v1.0.0-rc6
|
github.com/opencontainers/image-spec v1.0.0
|
||||||
github.com/opencontainers/runc 6b1d0e76f239ffb435445e5ae316d2676c07c6e3
|
github.com/opencontainers/runc 6b1d0e76f239ffb435445e5ae316d2676c07c6e3
|
||||||
github.com/pborman/uuid 1b00554d822231195d1babd97ff4a781231955c9
|
github.com/pborman/uuid 1b00554d822231195d1babd97ff4a781231955c9
|
||||||
github.com/pkg/errors 248dadf4e9068a0b3e79f02ed0a610d935de5302
|
github.com/pkg/errors 248dadf4e9068a0b3e79f02ed0a610d935de5302
|
||||||
|
@ -34,4 +34,4 @@ github.com/xeipuuv/gojsonpointer master
|
||||||
github.com/tchap/go-patricia v2.2.6
|
github.com/tchap/go-patricia v2.2.6
|
||||||
github.com/opencontainers/selinux ba1aefe8057f1d0cfb8e88d0ec1dc85925ef987d
|
github.com/opencontainers/selinux ba1aefe8057f1d0cfb8e88d0ec1dc85925ef987d
|
||||||
github.com/BurntSushi/toml b26d9c308763d68093482582cea63d69be07a0f0
|
github.com/BurntSushi/toml b26d9c308763d68093482582cea63d69be07a0f0
|
||||||
github.com/ostreedev/ostree-go 61532f383f1f48e5c27080b0b9c8b022c3706a97
|
github.com/ostreedev/ostree-go aeb02c6b6aa2889db3ef62f7855650755befd460
|
||||||
|
|
4
vendor/github.com/containers/storage/README.md
generated
vendored
4
vendor/github.com/containers/storage/README.md
generated
vendored
|
@ -1,6 +1,6 @@
|
||||||
`storage` is a Go library which aims to provide methods for storing filesystem
|
`storage` is a Go library which aims to provide methods for storing filesystem
|
||||||
layers, container images, and containers. An `oci-storage` CLI wrapper is also
|
layers, container images, and containers. A `containers-storage` CLI wrapper
|
||||||
included for manual and scripting use.
|
is also included for manual and scripting use.
|
||||||
|
|
||||||
To build the CLI wrapper, use 'make build-binary'.
|
To build the CLI wrapper, use 'make build-binary'.
|
||||||
|
|
||||||
|
|
54
vendor/github.com/containers/storage/containers.go
generated
vendored
54
vendor/github.com/containers/storage/containers.go
generated
vendored
|
@ -50,6 +50,12 @@ type Container struct {
|
||||||
// that has been stored, if they're known.
|
// that has been stored, if they're known.
|
||||||
BigDataSizes map[string]int64 `json:"big-data-sizes,omitempty"`
|
BigDataSizes map[string]int64 `json:"big-data-sizes,omitempty"`
|
||||||
|
|
||||||
|
// Created is the datestamp for when this container was created. Older
|
||||||
|
// versions of the library did not track this information, so callers
|
||||||
|
// will likely want to use the IsZero() method to verify that a value
|
||||||
|
// is set before using it.
|
||||||
|
Created time.Time `json:"created,omitempty"`
|
||||||
|
|
||||||
Flags map[string]interface{} `json:"flags,omitempty"`
|
Flags map[string]interface{} `json:"flags,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,7 +99,7 @@ type ContainerStore interface {
|
||||||
type containerStore struct {
|
type containerStore struct {
|
||||||
lockfile Locker
|
lockfile Locker
|
||||||
dir string
|
dir string
|
||||||
containers []Container
|
containers []*Container
|
||||||
idindex *truncindex.TruncIndex
|
idindex *truncindex.TruncIndex
|
||||||
byid map[string]*Container
|
byid map[string]*Container
|
||||||
bylayer map[string]*Container
|
bylayer map[string]*Container
|
||||||
|
@ -101,7 +107,11 @@ type containerStore struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *containerStore) Containers() ([]Container, error) {
|
func (r *containerStore) Containers() ([]Container, error) {
|
||||||
return r.containers, nil
|
containers := make([]Container, len(r.containers))
|
||||||
|
for i := range r.containers {
|
||||||
|
containers[i] = *(r.containers[i])
|
||||||
|
}
|
||||||
|
return containers, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *containerStore) containerspath() string {
|
func (r *containerStore) containerspath() string {
|
||||||
|
@ -123,7 +133,7 @@ func (r *containerStore) Load() error {
|
||||||
if err != nil && !os.IsNotExist(err) {
|
if err != nil && !os.IsNotExist(err) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
containers := []Container{}
|
containers := []*Container{}
|
||||||
layers := make(map[string]*Container)
|
layers := make(map[string]*Container)
|
||||||
idlist := []string{}
|
idlist := []string{}
|
||||||
ids := make(map[string]*Container)
|
ids := make(map[string]*Container)
|
||||||
|
@ -131,14 +141,14 @@ func (r *containerStore) Load() error {
|
||||||
if err = json.Unmarshal(data, &containers); len(data) == 0 || err == nil {
|
if err = json.Unmarshal(data, &containers); len(data) == 0 || err == nil {
|
||||||
for n, container := range containers {
|
for n, container := range containers {
|
||||||
idlist = append(idlist, container.ID)
|
idlist = append(idlist, container.ID)
|
||||||
ids[container.ID] = &containers[n]
|
ids[container.ID] = containers[n]
|
||||||
layers[container.LayerID] = &containers[n]
|
layers[container.LayerID] = containers[n]
|
||||||
for _, name := range container.Names {
|
for _, name := range container.Names {
|
||||||
if conflict, ok := names[name]; ok {
|
if conflict, ok := names[name]; ok {
|
||||||
r.removeName(conflict, name)
|
r.removeName(conflict, name)
|
||||||
needSave = true
|
needSave = true
|
||||||
}
|
}
|
||||||
names[name] = &containers[n]
|
names[name] = containers[n]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -148,7 +158,6 @@ func (r *containerStore) Load() error {
|
||||||
r.bylayer = layers
|
r.bylayer = layers
|
||||||
r.byname = names
|
r.byname = names
|
||||||
if needSave {
|
if needSave {
|
||||||
r.Touch()
|
|
||||||
return r.Save()
|
return r.Save()
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -163,6 +172,7 @@ func (r *containerStore) Save() error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
defer r.Touch()
|
||||||
return ioutils.AtomicWriteFile(rpath, jdata, 0600)
|
return ioutils.AtomicWriteFile(rpath, jdata, 0600)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,7 +189,7 @@ func newContainerStore(dir string) (ContainerStore, error) {
|
||||||
cstore := containerStore{
|
cstore := containerStore{
|
||||||
lockfile: lockfile,
|
lockfile: lockfile,
|
||||||
dir: dir,
|
dir: dir,
|
||||||
containers: []Container{},
|
containers: []*Container{},
|
||||||
byid: make(map[string]*Container),
|
byid: make(map[string]*Container),
|
||||||
bylayer: make(map[string]*Container),
|
bylayer: make(map[string]*Container),
|
||||||
byname: make(map[string]*Container),
|
byname: make(map[string]*Container),
|
||||||
|
@ -241,7 +251,7 @@ func (r *containerStore) Create(id string, names []string, image, layer, metadat
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
newContainer := Container{
|
container = &Container{
|
||||||
ID: id,
|
ID: id,
|
||||||
Names: names,
|
Names: names,
|
||||||
ImageID: image,
|
ImageID: image,
|
||||||
|
@ -249,10 +259,10 @@ func (r *containerStore) Create(id string, names []string, image, layer, metadat
|
||||||
Metadata: metadata,
|
Metadata: metadata,
|
||||||
BigDataNames: []string{},
|
BigDataNames: []string{},
|
||||||
BigDataSizes: make(map[string]int64),
|
BigDataSizes: make(map[string]int64),
|
||||||
|
Created: time.Now().UTC(),
|
||||||
Flags: make(map[string]interface{}),
|
Flags: make(map[string]interface{}),
|
||||||
}
|
}
|
||||||
r.containers = append(r.containers, newContainer)
|
r.containers = append(r.containers, container)
|
||||||
container = &r.containers[len(r.containers)-1]
|
|
||||||
r.byid[id] = container
|
r.byid[id] = container
|
||||||
r.idindex.Add(id)
|
r.idindex.Add(id)
|
||||||
r.bylayer[layer] = container
|
r.bylayer[layer] = container
|
||||||
|
@ -306,10 +316,11 @@ func (r *containerStore) Delete(id string) error {
|
||||||
return ErrContainerUnknown
|
return ErrContainerUnknown
|
||||||
}
|
}
|
||||||
id = container.ID
|
id = container.ID
|
||||||
newContainers := []Container{}
|
toDeleteIndex := -1
|
||||||
for _, candidate := range r.containers {
|
for i, candidate := range r.containers {
|
||||||
if candidate.ID != id {
|
if candidate.ID == id {
|
||||||
newContainers = append(newContainers, candidate)
|
toDeleteIndex = i
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete(r.byid, id)
|
delete(r.byid, id)
|
||||||
|
@ -318,7 +329,14 @@ func (r *containerStore) Delete(id string) error {
|
||||||
for _, name := range container.Names {
|
for _, name := range container.Names {
|
||||||
delete(r.byname, name)
|
delete(r.byname, name)
|
||||||
}
|
}
|
||||||
r.containers = newContainers
|
if toDeleteIndex != -1 {
|
||||||
|
// delete the container at toDeleteIndex
|
||||||
|
if toDeleteIndex == len(r.containers)-1 {
|
||||||
|
r.containers = r.containers[:len(r.containers)-1]
|
||||||
|
} else {
|
||||||
|
r.containers = append(r.containers[:toDeleteIndex], r.containers[toDeleteIndex+1:]...)
|
||||||
|
}
|
||||||
|
}
|
||||||
if err := r.Save(); err != nil {
|
if err := r.Save(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -437,6 +455,10 @@ func (r *containerStore) Modified() (bool, error) {
|
||||||
return r.lockfile.Modified()
|
return r.lockfile.Modified()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *containerStore) IsReadWrite() bool {
|
||||||
|
return r.lockfile.IsReadWrite()
|
||||||
|
}
|
||||||
|
|
||||||
func (r *containerStore) TouchedSince(when time.Time) bool {
|
func (r *containerStore) TouchedSince(when time.Time) bool {
|
||||||
return r.lockfile.TouchedSince(when)
|
return r.lockfile.TouchedSince(when)
|
||||||
}
|
}
|
||||||
|
|
11
vendor/github.com/containers/storage/drivers/aufs/aufs.go
generated
vendored
11
vendor/github.com/containers/storage/drivers/aufs/aufs.go
generated
vendored
|
@ -47,6 +47,7 @@ import (
|
||||||
|
|
||||||
rsystem "github.com/opencontainers/runc/libcontainer/system"
|
rsystem "github.com/opencontainers/runc/libcontainer/system"
|
||||||
"github.com/opencontainers/selinux/go-selinux/label"
|
"github.com/opencontainers/selinux/go-selinux/label"
|
||||||
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -81,7 +82,7 @@ func Init(root string, options []string, uidMaps, gidMaps []idtools.IDMap) (grap
|
||||||
|
|
||||||
// Try to load the aufs kernel module
|
// Try to load the aufs kernel module
|
||||||
if err := supportsAufs(); err != nil {
|
if err := supportsAufs(); err != nil {
|
||||||
return nil, graphdriver.ErrNotSupported
|
return nil, errors.Wrap(graphdriver.ErrNotSupported, "kernel does not support aufs")
|
||||||
}
|
}
|
||||||
|
|
||||||
fsMagic, err := graphdriver.GetFSMagic(root)
|
fsMagic, err := graphdriver.GetFSMagic(root)
|
||||||
|
@ -95,7 +96,7 @@ func Init(root string, options []string, uidMaps, gidMaps []idtools.IDMap) (grap
|
||||||
switch fsMagic {
|
switch fsMagic {
|
||||||
case graphdriver.FsMagicAufs, graphdriver.FsMagicBtrfs, graphdriver.FsMagicEcryptfs:
|
case graphdriver.FsMagicAufs, graphdriver.FsMagicBtrfs, graphdriver.FsMagicEcryptfs:
|
||||||
logrus.Errorf("AUFS is not supported over %s", backingFs)
|
logrus.Errorf("AUFS is not supported over %s", backingFs)
|
||||||
return nil, graphdriver.ErrIncompatibleFS
|
return nil, errors.Wrapf(graphdriver.ErrIncompatibleFS, "AUFS is not supported over %q", backingFs)
|
||||||
}
|
}
|
||||||
|
|
||||||
paths := []string{
|
paths := []string{
|
||||||
|
@ -372,6 +373,12 @@ func (a *Driver) Diff(id, parent string) (archive.Archive, error) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AdditionalImageStores returns additional image stores supported by the driver
|
||||||
|
func (a *Driver) AdditionalImageStores() []string {
|
||||||
|
var imageStores []string
|
||||||
|
return imageStores
|
||||||
|
}
|
||||||
|
|
||||||
type fileGetNilCloser struct {
|
type fileGetNilCloser struct {
|
||||||
storage.FileGetter
|
storage.FileGetter
|
||||||
}
|
}
|
||||||
|
|
2
vendor/github.com/containers/storage/drivers/aufs/mount_unsupported.go
generated
vendored
2
vendor/github.com/containers/storage/drivers/aufs/mount_unsupported.go
generated
vendored
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
package aufs
|
package aufs
|
||||||
|
|
||||||
import "errors"
|
import "github.com/pkg/errors"
|
||||||
|
|
||||||
// MsRemount declared to specify a non-linux system mount.
|
// MsRemount declared to specify a non-linux system mount.
|
||||||
const MsRemount = 0
|
const MsRemount = 0
|
||||||
|
|
9
vendor/github.com/containers/storage/drivers/btrfs/btrfs.go
generated
vendored
9
vendor/github.com/containers/storage/drivers/btrfs/btrfs.go
generated
vendored
|
@ -29,6 +29,7 @@ import (
|
||||||
"github.com/containers/storage/pkg/parsers"
|
"github.com/containers/storage/pkg/parsers"
|
||||||
"github.com/docker/go-units"
|
"github.com/docker/go-units"
|
||||||
"github.com/opencontainers/selinux/go-selinux/label"
|
"github.com/opencontainers/selinux/go-selinux/label"
|
||||||
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -55,7 +56,7 @@ func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (grap
|
||||||
}
|
}
|
||||||
|
|
||||||
if fsMagic != graphdriver.FsMagicBtrfs {
|
if fsMagic != graphdriver.FsMagicBtrfs {
|
||||||
return nil, graphdriver.ErrPrerequisites
|
return nil, errors.Wrapf(graphdriver.ErrPrerequisites, "%q is not on a btrfs filesystem", home)
|
||||||
}
|
}
|
||||||
|
|
||||||
rootUID, rootGID, err := idtools.GetRootUIDGID(uidMaps, gidMaps)
|
rootUID, rootGID, err := idtools.GetRootUIDGID(uidMaps, gidMaps)
|
||||||
|
@ -518,3 +519,9 @@ func (d *Driver) Exists(id string) bool {
|
||||||
_, err := os.Stat(dir)
|
_, err := os.Stat(dir)
|
||||||
return err == nil
|
return err == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AdditionalImageStores returns additional image stores supported by the driver
|
||||||
|
func (d *Driver) AdditionalImageStores() []string {
|
||||||
|
var imageStores []string
|
||||||
|
return imageStores
|
||||||
|
}
|
||||||
|
|
50
vendor/github.com/containers/storage/drivers/devmapper/deviceset.go
generated
vendored
50
vendor/github.com/containers/storage/drivers/devmapper/deviceset.go
generated
vendored
|
@ -5,7 +5,6 @@ package devmapper
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
@ -28,10 +27,10 @@ import (
|
||||||
"github.com/containers/storage/pkg/loopback"
|
"github.com/containers/storage/pkg/loopback"
|
||||||
"github.com/containers/storage/pkg/mount"
|
"github.com/containers/storage/pkg/mount"
|
||||||
"github.com/containers/storage/pkg/parsers"
|
"github.com/containers/storage/pkg/parsers"
|
||||||
"github.com/containers/storage/storageversion"
|
|
||||||
"github.com/docker/go-units"
|
"github.com/docker/go-units"
|
||||||
|
|
||||||
"github.com/opencontainers/selinux/go-selinux/label"
|
"github.com/opencontainers/selinux/go-selinux/label"
|
||||||
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -1475,7 +1474,7 @@ func determineDriverCapabilities(version string) error {
|
||||||
versionSplit := strings.Split(version, ".")
|
versionSplit := strings.Split(version, ".")
|
||||||
major, err := strconv.Atoi(versionSplit[0])
|
major, err := strconv.Atoi(versionSplit[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return graphdriver.ErrNotSupported
|
return errors.Wrapf(graphdriver.ErrNotSupported, "unable to parse driver major version %q as a number", versionSplit[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
if major > 4 {
|
if major > 4 {
|
||||||
|
@ -1489,7 +1488,7 @@ func determineDriverCapabilities(version string) error {
|
||||||
|
|
||||||
minor, err := strconv.Atoi(versionSplit[1])
|
minor, err := strconv.Atoi(versionSplit[1])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return graphdriver.ErrNotSupported
|
return errors.Wrapf(graphdriver.ErrNotSupported, "unable to parse driver minor version %q as a number", versionSplit[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1656,11 +1655,11 @@ func (devices *DeviceSet) initDevmapper(doInit bool) error {
|
||||||
version, err := devicemapper.GetDriverVersion()
|
version, err := devicemapper.GetDriverVersion()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Can't even get driver version, assume not supported
|
// Can't even get driver version, assume not supported
|
||||||
return graphdriver.ErrNotSupported
|
return errors.Wrap(graphdriver.ErrNotSupported, "unable to determine version of device mapper")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := determineDriverCapabilities(version); err != nil {
|
if err := determineDriverCapabilities(version); err != nil {
|
||||||
return graphdriver.ErrNotSupported
|
return errors.Wrap(graphdriver.ErrNotSupported, "unable to determine device mapper driver capabilities")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := devices.enableDeferredRemovalDeletion(); err != nil {
|
if err := devices.enableDeferredRemovalDeletion(); err != nil {
|
||||||
|
@ -1668,17 +1667,17 @@ func (devices *DeviceSet) initDevmapper(doInit bool) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://github.com/docker/docker/issues/4036
|
// https://github.com/docker/docker/issues/4036
|
||||||
if supported := devicemapper.UdevSetSyncSupport(true); !supported {
|
// if supported := devicemapper.UdevSetSyncSupport(true); !supported {
|
||||||
if storageversion.IAmStatic == "true" {
|
// if storageversion.IAmStatic == "true" {
|
||||||
logrus.Errorf("devmapper: Udev sync is not supported. This will lead to data loss and unexpected behavior. Install a dynamic binary to use devicemapper or select a different storage driver. For more information, see https://docs.docker.com/engine/reference/commandline/daemon/#daemon-storage-driver-option")
|
// logrus.Errorf("devmapper: Udev sync is not supported. This will lead to data loss and unexpected behavior. Install a dynamic binary to use devicemapper or select a different storage driver. For more information, see https://docs.docker.com/engine/reference/commandline/daemon/#daemon-storage-driver-option")
|
||||||
} else {
|
// } else {
|
||||||
logrus.Errorf("devmapper: Udev sync is not supported. This will lead to data loss and unexpected behavior. Install a more recent version of libdevmapper or select a different storage driver. For more information, see https://docs.docker.com/engine/reference/commandline/daemon/#daemon-storage-driver-option")
|
// logrus.Errorf("devmapper: Udev sync is not supported. This will lead to data loss and unexpected behavior. Install a more recent version of libdevmapper or select a different storage driver. For more information, see https://docs.docker.com/engine/reference/commandline/daemon/#daemon-storage-driver-option")
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if !devices.overrideUdevSyncCheck {
|
// if !devices.overrideUdevSyncCheck {
|
||||||
return graphdriver.ErrNotSupported
|
// return graphdriver.ErrNotSupported
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
//create the root dir of the devmapper driver ownership to match this
|
//create the root dir of the devmapper driver ownership to match this
|
||||||
//daemon's remapped root uid/gid so containers can start properly
|
//daemon's remapped root uid/gid so containers can start properly
|
||||||
|
@ -1734,6 +1733,15 @@ func (devices *DeviceSet) initDevmapper(doInit bool) error {
|
||||||
metadataFile *os.File
|
metadataFile *os.File
|
||||||
)
|
)
|
||||||
|
|
||||||
|
fsMagic, err := graphdriver.GetFSMagic(devices.loopbackDir())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
switch fsMagic {
|
||||||
|
case graphdriver.FsMagicAufs:
|
||||||
|
return errors.Errorf("devmapper: Loopback devices can not be created on AUFS filesystems")
|
||||||
|
}
|
||||||
|
|
||||||
if devices.dataDevice == "" {
|
if devices.dataDevice == "" {
|
||||||
// Make sure the sparse images exist in <root>/devicemapper/data
|
// Make sure the sparse images exist in <root>/devicemapper/data
|
||||||
|
|
||||||
|
@ -1960,7 +1968,7 @@ func (devices *DeviceSet) deleteTransaction(info *devInfo, syncDelete bool) erro
|
||||||
// If syncDelete is true, we want to return error. If deferred
|
// If syncDelete is true, we want to return error. If deferred
|
||||||
// deletion is not enabled, we return an error. If error is
|
// deletion is not enabled, we return an error. If error is
|
||||||
// something other then EBUSY, return an error.
|
// something other then EBUSY, return an error.
|
||||||
if syncDelete || !devices.deferredDelete || err != devicemapper.ErrBusy {
|
if syncDelete || !devices.deferredDelete || errors.Cause(err) != devicemapper.ErrBusy {
|
||||||
logrus.Debugf("devmapper: Error deleting device: %s", err)
|
logrus.Debugf("devmapper: Error deleting device: %s", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -2115,7 +2123,7 @@ func (devices *DeviceSet) removeDevice(devname string) error {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if err != devicemapper.ErrBusy {
|
if errors.Cause(err) != devicemapper.ErrBusy {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2150,12 +2158,12 @@ func (devices *DeviceSet) cancelDeferredRemoval(info *devInfo) error {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
if err == devicemapper.ErrEnxio {
|
if errors.Cause(err) == devicemapper.ErrEnxio {
|
||||||
// Device is probably already gone. Return success.
|
// Device is probably already gone. Return success.
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != devicemapper.ErrBusy {
|
if errors.Cause(err) != devicemapper.ErrBusy {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
6
vendor/github.com/containers/storage/drivers/devmapper/driver.go
generated
vendored
6
vendor/github.com/containers/storage/drivers/devmapper/driver.go
generated
vendored
|
@ -224,3 +224,9 @@ func (d *Driver) Put(id string) error {
|
||||||
func (d *Driver) Exists(id string) bool {
|
func (d *Driver) Exists(id string) bool {
|
||||||
return d.DeviceSet.HasDevice(id)
|
return d.DeviceSet.HasDevice(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AdditionalImageStores returns additional image stores supported by the driver
|
||||||
|
func (d *Driver) AdditionalImageStores() []string {
|
||||||
|
var imageStores []string
|
||||||
|
return imageStores
|
||||||
|
}
|
||||||
|
|
11
vendor/github.com/containers/storage/drivers/driver.go
generated
vendored
11
vendor/github.com/containers/storage/drivers/driver.go
generated
vendored
|
@ -1,13 +1,13 @@
|
||||||
package graphdriver
|
package graphdriver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"github.com/vbatts/tar-split/tar/storage"
|
"github.com/vbatts/tar-split/tar/storage"
|
||||||
|
|
||||||
"github.com/containers/storage/pkg/archive"
|
"github.com/containers/storage/pkg/archive"
|
||||||
|
@ -74,6 +74,8 @@ type ProtoDriver interface {
|
||||||
// held by the driver, e.g., unmounting all layered filesystems
|
// held by the driver, e.g., unmounting all layered filesystems
|
||||||
// known to this driver.
|
// known to this driver.
|
||||||
Cleanup() error
|
Cleanup() error
|
||||||
|
// AdditionalImageStores returns additional image stores supported by the driver
|
||||||
|
AdditionalImageStores() []string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Driver is the interface for layered/snapshot file system drivers.
|
// Driver is the interface for layered/snapshot file system drivers.
|
||||||
|
@ -142,7 +144,7 @@ func GetDriver(name, home string, options []string, uidMaps, gidMaps []idtools.I
|
||||||
return pluginDriver, nil
|
return pluginDriver, nil
|
||||||
}
|
}
|
||||||
logrus.Errorf("Failed to GetDriver graph %s %s", name, home)
|
logrus.Errorf("Failed to GetDriver graph %s %s", name, home)
|
||||||
return nil, ErrNotSupported
|
return nil, errors.Wrapf(ErrNotSupported, "failed to GetDriver graph %s %s", name, home)
|
||||||
}
|
}
|
||||||
|
|
||||||
// getBuiltinDriver initializes and returns the registered driver, but does not try to load from plugins
|
// getBuiltinDriver initializes and returns the registered driver, but does not try to load from plugins
|
||||||
|
@ -151,7 +153,7 @@ func getBuiltinDriver(name, home string, options []string, uidMaps, gidMaps []id
|
||||||
return initFunc(filepath.Join(home, name), options, uidMaps, gidMaps)
|
return initFunc(filepath.Join(home, name), options, uidMaps, gidMaps)
|
||||||
}
|
}
|
||||||
logrus.Errorf("Failed to built-in GetDriver graph %s %s", name, home)
|
logrus.Errorf("Failed to built-in GetDriver graph %s %s", name, home)
|
||||||
return nil, ErrNotSupported
|
return nil, errors.Wrapf(ErrNotSupported, "failed to built-in GetDriver graph %s %s", name, home)
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates the driver and initializes it at the specified root.
|
// New creates the driver and initializes it at the specified root.
|
||||||
|
@ -226,7 +228,8 @@ func New(root string, name string, options []string, uidMaps, gidMaps []idtools.
|
||||||
// isDriverNotSupported returns true if the error initializing
|
// isDriverNotSupported returns true if the error initializing
|
||||||
// the graph driver is a non-supported error.
|
// the graph driver is a non-supported error.
|
||||||
func isDriverNotSupported(err error) bool {
|
func isDriverNotSupported(err error) bool {
|
||||||
return err == ErrNotSupported || err == ErrPrerequisites || err == ErrIncompatibleFS
|
cause := errors.Cause(err)
|
||||||
|
return cause == ErrNotSupported || cause == ErrPrerequisites || cause == ErrIncompatibleFS
|
||||||
}
|
}
|
||||||
|
|
||||||
// scanPriorDrivers returns an un-ordered scan of directories of prior storage drivers
|
// scanPriorDrivers returns an un-ordered scan of directories of prior storage drivers
|
||||||
|
|
2
vendor/github.com/containers/storage/drivers/driver_linux.go
generated
vendored
2
vendor/github.com/containers/storage/drivers/driver_linux.go
generated
vendored
|
@ -53,7 +53,7 @@ const (
|
||||||
var (
|
var (
|
||||||
// Slice of drivers that should be used in an order
|
// Slice of drivers that should be used in an order
|
||||||
priority = []string{
|
priority = []string{
|
||||||
"overlay2",
|
"overlay",
|
||||||
"devicemapper",
|
"devicemapper",
|
||||||
"aufs",
|
"aufs",
|
||||||
"btrfs",
|
"btrfs",
|
||||||
|
|
3
vendor/github.com/containers/storage/drivers/driver_solaris.go
generated
vendored
3
vendor/github.com/containers/storage/drivers/driver_solaris.go
generated
vendored
|
@ -20,6 +20,7 @@ import (
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -56,7 +57,7 @@ func Mounted(fsType FsMagic, mountPath string) (bool, error) {
|
||||||
(buf.f_basetype[3] != 0) {
|
(buf.f_basetype[3] != 0) {
|
||||||
log.Debugf("[zfs] no zfs dataset found for rootdir '%s'", mountPath)
|
log.Debugf("[zfs] no zfs dataset found for rootdir '%s'", mountPath)
|
||||||
C.free(unsafe.Pointer(buf))
|
C.free(unsafe.Pointer(buf))
|
||||||
return false, ErrPrerequisites
|
return false, errors.Wrapf(graphdriver.ErrPrerequisites, "no zfs dataset found for rootdir '%s'", mountPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
C.free(unsafe.Pointer(buf))
|
C.free(unsafe.Pointer(buf))
|
||||||
|
|
81
vendor/github.com/containers/storage/drivers/overlay/overlay.go
generated
vendored
81
vendor/github.com/containers/storage/drivers/overlay/overlay.go
generated
vendored
|
@ -4,12 +4,12 @@ package overlay
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
@ -26,6 +26,7 @@ import (
|
||||||
"github.com/containers/storage/pkg/parsers/kernel"
|
"github.com/containers/storage/pkg/parsers/kernel"
|
||||||
|
|
||||||
"github.com/opencontainers/selinux/go-selinux/label"
|
"github.com/opencontainers/selinux/go-selinux/label"
|
||||||
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -82,6 +83,7 @@ type Driver struct {
|
||||||
uidMaps []idtools.IDMap
|
uidMaps []idtools.IDMap
|
||||||
gidMaps []idtools.IDMap
|
gidMaps []idtools.IDMap
|
||||||
ctr *graphdriver.RefCounter
|
ctr *graphdriver.RefCounter
|
||||||
|
opts *overlayOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
var backingFs = "<unknown>"
|
var backingFs = "<unknown>"
|
||||||
|
@ -100,7 +102,7 @@ func InitWithName(name, home string, options []string, uidMaps, gidMaps []idtool
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := supportsOverlay(); err != nil {
|
if err := supportsOverlay(); err != nil {
|
||||||
return nil, graphdriver.ErrNotSupported
|
return nil, errors.Wrap(graphdriver.ErrNotSupported, "kernel does not support overlay fs")
|
||||||
}
|
}
|
||||||
|
|
||||||
// require kernel 4.0.0 to ensure multiple lower dirs are supported
|
// require kernel 4.0.0 to ensure multiple lower dirs are supported
|
||||||
|
@ -110,7 +112,7 @@ func InitWithName(name, home string, options []string, uidMaps, gidMaps []idtool
|
||||||
}
|
}
|
||||||
if kernel.CompareKernelVersion(*v, kernel.VersionInfo{Kernel: 4, Major: 0, Minor: 0}) < 0 {
|
if kernel.CompareKernelVersion(*v, kernel.VersionInfo{Kernel: 4, Major: 0, Minor: 0}) < 0 {
|
||||||
if !opts.overrideKernelCheck {
|
if !opts.overrideKernelCheck {
|
||||||
return nil, graphdriver.ErrNotSupported
|
return nil, errors.Wrap(graphdriver.ErrNotSupported, "kernel too old to provide multiple lowers feature for overlay")
|
||||||
}
|
}
|
||||||
logrus.Warnf("Using pre-4.0.0 kernel for overlay, mount failures may require kernel update")
|
logrus.Warnf("Using pre-4.0.0 kernel for overlay, mount failures may require kernel update")
|
||||||
}
|
}
|
||||||
|
@ -127,7 +129,7 @@ func InitWithName(name, home string, options []string, uidMaps, gidMaps []idtool
|
||||||
switch fsMagic {
|
switch fsMagic {
|
||||||
case graphdriver.FsMagicBtrfs, graphdriver.FsMagicAufs, graphdriver.FsMagicZfs, graphdriver.FsMagicOverlay, graphdriver.FsMagicEcryptfs:
|
case graphdriver.FsMagicBtrfs, graphdriver.FsMagicAufs, graphdriver.FsMagicZfs, graphdriver.FsMagicOverlay, graphdriver.FsMagicEcryptfs:
|
||||||
logrus.Errorf("'overlay' is not supported over %s", backingFs)
|
logrus.Errorf("'overlay' is not supported over %s", backingFs)
|
||||||
return nil, graphdriver.ErrIncompatibleFS
|
return nil, errors.Wrapf(graphdriver.ErrIncompatibleFS, "'overlay' is not supported over %s", backingFs)
|
||||||
}
|
}
|
||||||
|
|
||||||
rootUID, rootGID, err := idtools.GetRootUIDGID(uidMaps, gidMaps)
|
rootUID, rootGID, err := idtools.GetRootUIDGID(uidMaps, gidMaps)
|
||||||
|
@ -149,6 +151,7 @@ func InitWithName(name, home string, options []string, uidMaps, gidMaps []idtool
|
||||||
uidMaps: uidMaps,
|
uidMaps: uidMaps,
|
||||||
gidMaps: gidMaps,
|
gidMaps: gidMaps,
|
||||||
ctr: graphdriver.NewRefCounter(graphdriver.NewFsChecker(graphdriver.FsMagicOverlay)),
|
ctr: graphdriver.NewRefCounter(graphdriver.NewFsChecker(graphdriver.FsMagicOverlay)),
|
||||||
|
opts: opts,
|
||||||
}
|
}
|
||||||
|
|
||||||
return d, nil
|
return d, nil
|
||||||
|
@ -170,6 +173,7 @@ func InitAsOverlay2(home string, options []string, uidMaps, gidMaps []idtools.ID
|
||||||
|
|
||||||
type overlayOptions struct {
|
type overlayOptions struct {
|
||||||
overrideKernelCheck bool
|
overrideKernelCheck bool
|
||||||
|
imageStores []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseOptions(options []string) (*overlayOptions, error) {
|
func parseOptions(options []string) (*overlayOptions, error) {
|
||||||
|
@ -186,6 +190,22 @@ func parseOptions(options []string) (*overlayOptions, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
case "overlay.imagestore":
|
||||||
|
// Additional read only image stores to use for lower paths
|
||||||
|
for _, store := range strings.Split(val, ",") {
|
||||||
|
store = filepath.Clean(store)
|
||||||
|
if !filepath.IsAbs(store) {
|
||||||
|
return nil, fmt.Errorf("overlay: image path %q is not absolute. Can not be relative", store)
|
||||||
|
}
|
||||||
|
st, err := os.Stat(store)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("overlay: Can't stat imageStore dir %s: %v", store, err)
|
||||||
|
}
|
||||||
|
if !st.IsDir() {
|
||||||
|
return nil, fmt.Errorf("overlay: image path %q must be a directory", store)
|
||||||
|
}
|
||||||
|
o.imageStores = append(o.imageStores, store)
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("overlay: Unknown option %s", key)
|
return nil, fmt.Errorf("overlay: Unknown option %s", key)
|
||||||
}
|
}
|
||||||
|
@ -211,7 +231,7 @@ func supportsOverlay() error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logrus.Error("'overlay' not found as a supported filesystem on this host. Please ensure kernel is new enough and has overlay support loaded.")
|
logrus.Error("'overlay' not found as a supported filesystem on this host. Please ensure kernel is new enough and has overlay support loaded.")
|
||||||
return graphdriver.ErrNotSupported
|
return errors.Wrap(graphdriver.ErrNotSupported, "'overlay' not found as a supported filesystem on this host. Please ensure kernel is new enough and has overlay support loaded.")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Driver) String() string {
|
func (d *Driver) String() string {
|
||||||
|
@ -357,8 +377,18 @@ func (d *Driver) getLower(parent string) (string, error) {
|
||||||
return strings.Join(lowers, ":"), nil
|
return strings.Join(lowers, ":"), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Driver) dir(id string) string {
|
func (d *Driver) dir(val string) string {
|
||||||
return path.Join(d.home, id)
|
newpath := path.Join(d.home, val)
|
||||||
|
if _, err := os.Stat(newpath); err != nil {
|
||||||
|
for _, p := range d.AdditionalImageStores() {
|
||||||
|
l := path.Join(p, d.name, val)
|
||||||
|
_, err = os.Stat(l)
|
||||||
|
if err == nil {
|
||||||
|
return l
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return newpath
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Driver) getLowerDirs(id string) ([]string, error) {
|
func (d *Driver) getLowerDirs(id string) ([]string, error) {
|
||||||
|
@ -366,11 +396,12 @@ func (d *Driver) getLowerDirs(id string) ([]string, error) {
|
||||||
lowers, err := ioutil.ReadFile(path.Join(d.dir(id), lowerFile))
|
lowers, err := ioutil.ReadFile(path.Join(d.dir(id), lowerFile))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
for _, s := range strings.Split(string(lowers), ":") {
|
for _, s := range strings.Split(string(lowers), ":") {
|
||||||
lp, err := os.Readlink(path.Join(d.home, s))
|
lower := d.dir(s)
|
||||||
|
lp, err := os.Readlink(lower)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
lowersArray = append(lowersArray, path.Clean(path.Join(d.home, "link", lp)))
|
lowersArray = append(lowersArray, path.Clean(d.dir(path.Join("link", lp))))
|
||||||
}
|
}
|
||||||
} else if !os.IsNotExist(err) {
|
} else if !os.IsNotExist(err) {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -411,6 +442,31 @@ func (d *Driver) Get(id string, mountLabel string) (s string, err error) {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
newlowers := ""
|
||||||
|
for _, l := range strings.Split(string(lowers), ":") {
|
||||||
|
lower := ""
|
||||||
|
newpath := path.Join(d.home, l)
|
||||||
|
if _, err := os.Stat(newpath); err != nil {
|
||||||
|
for _, p := range d.AdditionalImageStores() {
|
||||||
|
lower = path.Join(p, d.name, l)
|
||||||
|
if _, err2 := os.Stat(lower); err2 == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
lower = ""
|
||||||
|
}
|
||||||
|
if lower == "" {
|
||||||
|
return "", fmt.Errorf("Can't stat lower layer %q: %v", newpath, err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
lower = l
|
||||||
|
}
|
||||||
|
if newlowers == "" {
|
||||||
|
newlowers = lower
|
||||||
|
} else {
|
||||||
|
newlowers = newlowers + ":" + lower
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mergedDir := path.Join(dir, "merged")
|
mergedDir := path.Join(dir, "merged")
|
||||||
if count := d.ctr.Increment(mergedDir); count > 1 {
|
if count := d.ctr.Increment(mergedDir); count > 1 {
|
||||||
return mergedDir, nil
|
return mergedDir, nil
|
||||||
|
@ -424,7 +480,7 @@ func (d *Driver) Get(id string, mountLabel string) (s string, err error) {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
workDir := path.Join(dir, "work")
|
workDir := path.Join(dir, "work")
|
||||||
opts := fmt.Sprintf("lowerdir=%s,upperdir=%s,workdir=%s", string(lowers), path.Join(id, "diff"), path.Join(id, "work"))
|
opts := fmt.Sprintf("lowerdir=%s,upperdir=%s,workdir=%s", newlowers, path.Join(id, "diff"), path.Join(id, "work"))
|
||||||
mountLabel = label.FormatMountLabel(opts, mountLabel)
|
mountLabel = label.FormatMountLabel(opts, mountLabel)
|
||||||
if len(mountLabel) > syscall.Getpagesize() {
|
if len(mountLabel) > syscall.Getpagesize() {
|
||||||
return "", fmt.Errorf("cannot mount layer, mount label too large %d", len(mountLabel))
|
return "", fmt.Errorf("cannot mount layer, mount label too large %d", len(mountLabel))
|
||||||
|
@ -527,3 +583,8 @@ func (d *Driver) Changes(id, parent string) ([]archive.Change, error) {
|
||||||
|
|
||||||
return archive.OverlayChanges(layers, diffPath)
|
return archive.OverlayChanges(layers, diffPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AdditionalImageStores returns additional image stores supported by the driver
|
||||||
|
func (d *Driver) AdditionalImageStores() []string {
|
||||||
|
return d.opts.imageStores
|
||||||
|
}
|
||||||
|
|
2
vendor/github.com/containers/storage/drivers/proxy.go
generated
vendored
2
vendor/github.com/containers/storage/drivers/proxy.go
generated
vendored
|
@ -3,10 +3,10 @@
|
||||||
package graphdriver
|
package graphdriver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/containers/storage/pkg/archive"
|
"github.com/containers/storage/pkg/archive"
|
||||||
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
type graphDriverProxy struct {
|
type graphDriverProxy struct {
|
||||||
|
|
6
vendor/github.com/containers/storage/drivers/vfs/driver.go
generated
vendored
6
vendor/github.com/containers/storage/drivers/vfs/driver.go
generated
vendored
|
@ -143,3 +143,9 @@ func (d *Driver) Exists(id string) bool {
|
||||||
_, err := os.Stat(d.dir(id))
|
_, err := os.Stat(d.dir(id))
|
||||||
return err == nil
|
return err == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AdditionalImageStores returns additional image stores supported by the driver
|
||||||
|
func (d *Driver) AdditionalImageStores() []string {
|
||||||
|
var imageStores []string
|
||||||
|
return imageStores
|
||||||
|
}
|
||||||
|
|
11
vendor/github.com/containers/storage/drivers/zfs/zfs.go
generated
vendored
11
vendor/github.com/containers/storage/drivers/zfs/zfs.go
generated
vendored
|
@ -20,6 +20,7 @@ import (
|
||||||
"github.com/containers/storage/pkg/parsers"
|
"github.com/containers/storage/pkg/parsers"
|
||||||
zfs "github.com/mistifyio/go-zfs"
|
zfs "github.com/mistifyio/go-zfs"
|
||||||
"github.com/opencontainers/selinux/go-selinux/label"
|
"github.com/opencontainers/selinux/go-selinux/label"
|
||||||
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
type zfsOptions struct {
|
type zfsOptions struct {
|
||||||
|
@ -47,13 +48,13 @@ func Init(base string, opt []string, uidMaps, gidMaps []idtools.IDMap) (graphdri
|
||||||
|
|
||||||
if _, err := exec.LookPath("zfs"); err != nil {
|
if _, err := exec.LookPath("zfs"); err != nil {
|
||||||
logrus.Debugf("[zfs] zfs command is not available: %v", err)
|
logrus.Debugf("[zfs] zfs command is not available: %v", err)
|
||||||
return nil, graphdriver.ErrPrerequisites
|
return nil, errors.Wrap(graphdriver.ErrPrerequisites, "the 'zfs' command is not available")
|
||||||
}
|
}
|
||||||
|
|
||||||
file, err := os.OpenFile("/dev/zfs", os.O_RDWR, 600)
|
file, err := os.OpenFile("/dev/zfs", os.O_RDWR, 600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Debugf("[zfs] cannot open /dev/zfs: %v", err)
|
logrus.Debugf("[zfs] cannot open /dev/zfs: %v", err)
|
||||||
return nil, graphdriver.ErrPrerequisites
|
return nil, errors.Wrapf(graphdriver.ErrPrerequisites, "could not open /dev/zfs: %v", err)
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
|
@ -403,3 +404,9 @@ func (d *Driver) Exists(id string) bool {
|
||||||
defer d.Unlock()
|
defer d.Unlock()
|
||||||
return d.filesystemsCache[d.zfsPath(id)] == true
|
return d.filesystemsCache[d.zfsPath(id)] == true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AdditionalImageStores returns additional image stores supported by the driver
|
||||||
|
func (d *Driver) AdditionalImageStores() []string {
|
||||||
|
var imageStores []string
|
||||||
|
return imageStores
|
||||||
|
}
|
||||||
|
|
3
vendor/github.com/containers/storage/drivers/zfs/zfs_freebsd.go
generated
vendored
3
vendor/github.com/containers/storage/drivers/zfs/zfs_freebsd.go
generated
vendored
|
@ -7,6 +7,7 @@ import (
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
"github.com/containers/storage/drivers"
|
"github.com/containers/storage/drivers"
|
||||||
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
func checkRootdirFs(rootdir string) error {
|
func checkRootdirFs(rootdir string) error {
|
||||||
|
@ -18,7 +19,7 @@ func checkRootdirFs(rootdir string) error {
|
||||||
// on FreeBSD buf.Fstypename contains ['z', 'f', 's', 0 ... ]
|
// on FreeBSD buf.Fstypename contains ['z', 'f', 's', 0 ... ]
|
||||||
if (buf.Fstypename[0] != 122) || (buf.Fstypename[1] != 102) || (buf.Fstypename[2] != 115) || (buf.Fstypename[3] != 0) {
|
if (buf.Fstypename[0] != 122) || (buf.Fstypename[1] != 102) || (buf.Fstypename[2] != 115) || (buf.Fstypename[3] != 0) {
|
||||||
logrus.Debugf("[zfs] no zfs dataset found for rootdir '%s'", rootdir)
|
logrus.Debugf("[zfs] no zfs dataset found for rootdir '%s'", rootdir)
|
||||||
return graphdriver.ErrPrerequisites
|
return errors.Wrapf(graphdriver.ErrPrerequisites, "no zfs dataset found for rootdir '%s'", rootdir)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
3
vendor/github.com/containers/storage/drivers/zfs/zfs_linux.go
generated
vendored
3
vendor/github.com/containers/storage/drivers/zfs/zfs_linux.go
generated
vendored
|
@ -6,6 +6,7 @@ import (
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
"github.com/containers/storage/drivers"
|
"github.com/containers/storage/drivers"
|
||||||
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
func checkRootdirFs(rootdir string) error {
|
func checkRootdirFs(rootdir string) error {
|
||||||
|
@ -16,7 +17,7 @@ func checkRootdirFs(rootdir string) error {
|
||||||
|
|
||||||
if graphdriver.FsMagic(buf.Type) != graphdriver.FsMagicZfs {
|
if graphdriver.FsMagic(buf.Type) != graphdriver.FsMagicZfs {
|
||||||
logrus.Debugf("[zfs] no zfs dataset found for rootdir '%s'", rootdir)
|
logrus.Debugf("[zfs] no zfs dataset found for rootdir '%s'", rootdir)
|
||||||
return graphdriver.ErrPrerequisites
|
return errors.Wrapf(graphdriver.ErrPrerequisites, "no zfs dataset found for rootdir '%s'", rootdir)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
3
vendor/github.com/containers/storage/drivers/zfs/zfs_solaris.go
generated
vendored
3
vendor/github.com/containers/storage/drivers/zfs/zfs_solaris.go
generated
vendored
|
@ -22,6 +22,7 @@ import (
|
||||||
|
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
"github.com/containers/storage/drivers"
|
"github.com/containers/storage/drivers"
|
||||||
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
func checkRootdirFs(rootdir string) error {
|
func checkRootdirFs(rootdir string) error {
|
||||||
|
@ -34,7 +35,7 @@ func checkRootdirFs(rootdir string) error {
|
||||||
(buf.f_basetype[3] != 0) {
|
(buf.f_basetype[3] != 0) {
|
||||||
log.Debugf("[zfs] no zfs dataset found for rootdir '%s'", rootdir)
|
log.Debugf("[zfs] no zfs dataset found for rootdir '%s'", rootdir)
|
||||||
C.free(unsafe.Pointer(buf))
|
C.free(unsafe.Pointer(buf))
|
||||||
return graphdriver.ErrPrerequisites
|
return errors.Wrapf(graphdriver.ErrPrerequisites, "no zfs dataset found for rootdir '%s'", rootdir)
|
||||||
}
|
}
|
||||||
|
|
||||||
C.free(unsafe.Pointer(buf))
|
C.free(unsafe.Pointer(buf))
|
||||||
|
|
164
vendor/github.com/containers/storage/images.go
generated
vendored
164
vendor/github.com/containers/storage/images.go
generated
vendored
|
@ -2,7 +2,6 @@ package storage
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -11,6 +10,7 @@ import (
|
||||||
"github.com/containers/storage/pkg/ioutils"
|
"github.com/containers/storage/pkg/ioutils"
|
||||||
"github.com/containers/storage/pkg/stringid"
|
"github.com/containers/storage/pkg/stringid"
|
||||||
"github.com/containers/storage/pkg/truncindex"
|
"github.com/containers/storage/pkg/truncindex"
|
||||||
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -46,24 +46,20 @@ type Image struct {
|
||||||
// that has been stored, if they're known.
|
// that has been stored, if they're known.
|
||||||
BigDataSizes map[string]int64 `json:"big-data-sizes,omitempty"`
|
BigDataSizes map[string]int64 `json:"big-data-sizes,omitempty"`
|
||||||
|
|
||||||
|
// Created is the datestamp for when this image was created. Older
|
||||||
|
// versions of the library did not track this information, so callers
|
||||||
|
// will likely want to use the IsZero() method to verify that a value
|
||||||
|
// is set before using it.
|
||||||
|
Created time.Time `json:"created,omitempty"`
|
||||||
|
|
||||||
Flags map[string]interface{} `json:"flags,omitempty"`
|
Flags map[string]interface{} `json:"flags,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ImageStore provides bookkeeping for information about Images.
|
// ROImageStore provides bookkeeping for information about Images.
|
||||||
type ImageStore interface {
|
type ROImageStore interface {
|
||||||
FileBasedStore
|
ROFileBasedStore
|
||||||
MetadataStore
|
ROMetadataStore
|
||||||
BigDataStore
|
ROBigDataStore
|
||||||
FlaggableStore
|
|
||||||
|
|
||||||
// Create creates an image that has a specified ID (or a random one) and
|
|
||||||
// optional names, using the specified layer as its topmost (hopefully
|
|
||||||
// read-only) layer. That layer can be referenced by multiple images.
|
|
||||||
Create(id string, names []string, layer, metadata string) (*Image, error)
|
|
||||||
|
|
||||||
// SetNames replaces the list of names associated with an image with the
|
|
||||||
// supplied values.
|
|
||||||
SetNames(id string, names []string) error
|
|
||||||
|
|
||||||
// Exists checks if there is an image with the given ID or name.
|
// Exists checks if there is an image with the given ID or name.
|
||||||
Exists(id string) bool
|
Exists(id string) bool
|
||||||
|
@ -71,12 +67,6 @@ type ImageStore interface {
|
||||||
// Get retrieves information about an image given an ID or name.
|
// Get retrieves information about an image given an ID or name.
|
||||||
Get(id string) (*Image, error)
|
Get(id string) (*Image, error)
|
||||||
|
|
||||||
// Delete removes the record of the image.
|
|
||||||
Delete(id string) error
|
|
||||||
|
|
||||||
// Wipe removes records of all images.
|
|
||||||
Wipe() error
|
|
||||||
|
|
||||||
// Lookup attempts to translate a name to an ID. Most methods do this
|
// Lookup attempts to translate a name to an ID. Most methods do this
|
||||||
// implicitly.
|
// implicitly.
|
||||||
Lookup(name string) (string, error)
|
Lookup(name string) (string, error)
|
||||||
|
@ -85,17 +75,45 @@ type ImageStore interface {
|
||||||
Images() ([]Image, error)
|
Images() ([]Image, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ImageStore provides bookkeeping for information about Images.
|
||||||
|
type ImageStore interface {
|
||||||
|
ROImageStore
|
||||||
|
RWFileBasedStore
|
||||||
|
RWMetadataStore
|
||||||
|
RWBigDataStore
|
||||||
|
FlaggableStore
|
||||||
|
|
||||||
|
// Create creates an image that has a specified ID (or a random one) and
|
||||||
|
// optional names, using the specified layer as its topmost (hopefully
|
||||||
|
// read-only) layer. That layer can be referenced by multiple images.
|
||||||
|
Create(id string, names []string, layer, metadata string, created time.Time) (*Image, error)
|
||||||
|
|
||||||
|
// SetNames replaces the list of names associated with an image with the
|
||||||
|
// supplied values.
|
||||||
|
SetNames(id string, names []string) error
|
||||||
|
|
||||||
|
// Delete removes the record of the image.
|
||||||
|
Delete(id string) error
|
||||||
|
|
||||||
|
// Wipe removes records of all images.
|
||||||
|
Wipe() error
|
||||||
|
}
|
||||||
|
|
||||||
type imageStore struct {
|
type imageStore struct {
|
||||||
lockfile Locker
|
lockfile Locker
|
||||||
dir string
|
dir string
|
||||||
images []Image
|
images []*Image
|
||||||
idindex *truncindex.TruncIndex
|
idindex *truncindex.TruncIndex
|
||||||
byid map[string]*Image
|
byid map[string]*Image
|
||||||
byname map[string]*Image
|
byname map[string]*Image
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *imageStore) Images() ([]Image, error) {
|
func (r *imageStore) Images() ([]Image, error) {
|
||||||
return r.images, nil
|
images := make([]Image, len(r.images))
|
||||||
|
for i := range r.images {
|
||||||
|
images[i] = *(r.images[i])
|
||||||
|
}
|
||||||
|
return images, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *imageStore) imagespath() string {
|
func (r *imageStore) imagespath() string {
|
||||||
|
@ -111,41 +129,46 @@ func (r *imageStore) datapath(id, key string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *imageStore) Load() error {
|
func (r *imageStore) Load() error {
|
||||||
needSave := false
|
shouldSave := false
|
||||||
rpath := r.imagespath()
|
rpath := r.imagespath()
|
||||||
data, err := ioutil.ReadFile(rpath)
|
data, err := ioutil.ReadFile(rpath)
|
||||||
if err != nil && !os.IsNotExist(err) {
|
if err != nil && !os.IsNotExist(err) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
images := []Image{}
|
images := []*Image{}
|
||||||
idlist := []string{}
|
idlist := []string{}
|
||||||
ids := make(map[string]*Image)
|
ids := make(map[string]*Image)
|
||||||
names := make(map[string]*Image)
|
names := make(map[string]*Image)
|
||||||
if err = json.Unmarshal(data, &images); len(data) == 0 || err == nil {
|
if err = json.Unmarshal(data, &images); len(data) == 0 || err == nil {
|
||||||
for n, image := range images {
|
for n, image := range images {
|
||||||
ids[image.ID] = &images[n]
|
ids[image.ID] = images[n]
|
||||||
idlist = append(idlist, image.ID)
|
idlist = append(idlist, image.ID)
|
||||||
for _, name := range image.Names {
|
for _, name := range image.Names {
|
||||||
if conflict, ok := names[name]; ok {
|
if conflict, ok := names[name]; ok {
|
||||||
r.removeName(conflict, name)
|
r.removeName(conflict, name)
|
||||||
needSave = true
|
shouldSave = true
|
||||||
}
|
}
|
||||||
names[name] = &images[n]
|
names[name] = images[n]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if shouldSave && !r.IsReadWrite() {
|
||||||
|
return errors.New("image store assigns the same name to multiple images")
|
||||||
|
}
|
||||||
r.images = images
|
r.images = images
|
||||||
r.idindex = truncindex.NewTruncIndex(idlist)
|
r.idindex = truncindex.NewTruncIndex(idlist)
|
||||||
r.byid = ids
|
r.byid = ids
|
||||||
r.byname = names
|
r.byname = names
|
||||||
if needSave {
|
if shouldSave {
|
||||||
r.Touch()
|
|
||||||
return r.Save()
|
return r.Save()
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *imageStore) Save() error {
|
func (r *imageStore) Save() error {
|
||||||
|
if !r.IsReadWrite() {
|
||||||
|
return errors.Wrapf(ErrStoreIsReadOnly, "not allowed to modify the image store at %q", r.imagespath())
|
||||||
|
}
|
||||||
rpath := r.imagespath()
|
rpath := r.imagespath()
|
||||||
if err := os.MkdirAll(filepath.Dir(rpath), 0700); err != nil {
|
if err := os.MkdirAll(filepath.Dir(rpath), 0700); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -154,6 +177,7 @@ func (r *imageStore) Save() error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
defer r.Touch()
|
||||||
return ioutils.AtomicWriteFile(rpath, jdata, 0600)
|
return ioutils.AtomicWriteFile(rpath, jdata, 0600)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,7 +194,27 @@ func newImageStore(dir string) (ImageStore, error) {
|
||||||
istore := imageStore{
|
istore := imageStore{
|
||||||
lockfile: lockfile,
|
lockfile: lockfile,
|
||||||
dir: dir,
|
dir: dir,
|
||||||
images: []Image{},
|
images: []*Image{},
|
||||||
|
byid: make(map[string]*Image),
|
||||||
|
byname: make(map[string]*Image),
|
||||||
|
}
|
||||||
|
if err := istore.Load(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &istore, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func newROImageStore(dir string) (ROImageStore, error) {
|
||||||
|
lockfile, err := GetROLockfile(filepath.Join(dir, "images.lock"))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
lockfile.Lock()
|
||||||
|
defer lockfile.Unlock()
|
||||||
|
istore := imageStore{
|
||||||
|
lockfile: lockfile,
|
||||||
|
dir: dir,
|
||||||
|
images: []*Image{},
|
||||||
byid: make(map[string]*Image),
|
byid: make(map[string]*Image),
|
||||||
byname: make(map[string]*Image),
|
byname: make(map[string]*Image),
|
||||||
}
|
}
|
||||||
|
@ -193,6 +237,9 @@ func (r *imageStore) lookup(id string) (*Image, bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *imageStore) ClearFlag(id string, flag string) error {
|
func (r *imageStore) ClearFlag(id string, flag string) error {
|
||||||
|
if !r.IsReadWrite() {
|
||||||
|
return errors.Wrapf(ErrStoreIsReadOnly, "not allowed to clear flags on images at %q", r.imagespath())
|
||||||
|
}
|
||||||
image, ok := r.lookup(id)
|
image, ok := r.lookup(id)
|
||||||
if !ok {
|
if !ok {
|
||||||
return ErrImageUnknown
|
return ErrImageUnknown
|
||||||
|
@ -202,6 +249,9 @@ func (r *imageStore) ClearFlag(id string, flag string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *imageStore) SetFlag(id string, flag string, value interface{}) error {
|
func (r *imageStore) SetFlag(id string, flag string, value interface{}) error {
|
||||||
|
if !r.IsReadWrite() {
|
||||||
|
return errors.Wrapf(ErrStoreIsReadOnly, "not allowed to set flags on images at %q", r.imagespath())
|
||||||
|
}
|
||||||
image, ok := r.lookup(id)
|
image, ok := r.lookup(id)
|
||||||
if !ok {
|
if !ok {
|
||||||
return ErrImageUnknown
|
return ErrImageUnknown
|
||||||
|
@ -210,7 +260,10 @@ func (r *imageStore) SetFlag(id string, flag string, value interface{}) error {
|
||||||
return r.Save()
|
return r.Save()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *imageStore) Create(id string, names []string, layer, metadata string) (image *Image, err error) {
|
func (r *imageStore) Create(id string, names []string, layer, metadata string, created time.Time) (image *Image, err error) {
|
||||||
|
if !r.IsReadWrite() {
|
||||||
|
return nil, errors.Wrapf(ErrStoreIsReadOnly, "not allowed to create new images at %q", r.imagespath())
|
||||||
|
}
|
||||||
if id == "" {
|
if id == "" {
|
||||||
id = stringid.GenerateRandomID()
|
id = stringid.GenerateRandomID()
|
||||||
_, idInUse := r.byid[id]
|
_, idInUse := r.byid[id]
|
||||||
|
@ -227,18 +280,21 @@ func (r *imageStore) Create(id string, names []string, layer, metadata string) (
|
||||||
return nil, ErrDuplicateName
|
return nil, ErrDuplicateName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if created.IsZero() {
|
||||||
|
created = time.Now().UTC()
|
||||||
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
newImage := Image{
|
image = &Image{
|
||||||
ID: id,
|
ID: id,
|
||||||
Names: names,
|
Names: names,
|
||||||
TopLayer: layer,
|
TopLayer: layer,
|
||||||
Metadata: metadata,
|
Metadata: metadata,
|
||||||
BigDataNames: []string{},
|
BigDataNames: []string{},
|
||||||
BigDataSizes: make(map[string]int64),
|
BigDataSizes: make(map[string]int64),
|
||||||
|
Created: created,
|
||||||
Flags: make(map[string]interface{}),
|
Flags: make(map[string]interface{}),
|
||||||
}
|
}
|
||||||
r.images = append(r.images, newImage)
|
r.images = append(r.images, image)
|
||||||
image = &r.images[len(r.images)-1]
|
|
||||||
r.idindex.Add(id)
|
r.idindex.Add(id)
|
||||||
r.byid[id] = image
|
r.byid[id] = image
|
||||||
for _, name := range names {
|
for _, name := range names {
|
||||||
|
@ -257,6 +313,9 @@ func (r *imageStore) Metadata(id string) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *imageStore) SetMetadata(id, metadata string) error {
|
func (r *imageStore) SetMetadata(id, metadata string) error {
|
||||||
|
if !r.IsReadWrite() {
|
||||||
|
return errors.Wrapf(ErrStoreIsReadOnly, "not allowed to modify image metadata at %q", r.imagespath())
|
||||||
|
}
|
||||||
if image, ok := r.lookup(id); ok {
|
if image, ok := r.lookup(id); ok {
|
||||||
image.Metadata = metadata
|
image.Metadata = metadata
|
||||||
return r.Save()
|
return r.Save()
|
||||||
|
@ -269,6 +328,9 @@ func (r *imageStore) removeName(image *Image, name string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *imageStore) SetNames(id string, names []string) error {
|
func (r *imageStore) SetNames(id string, names []string) error {
|
||||||
|
if !r.IsReadWrite() {
|
||||||
|
return errors.Wrapf(ErrStoreIsReadOnly, "not allowed to change image name assignments at %q", r.imagespath())
|
||||||
|
}
|
||||||
if image, ok := r.lookup(id); ok {
|
if image, ok := r.lookup(id); ok {
|
||||||
for _, name := range image.Names {
|
for _, name := range image.Names {
|
||||||
delete(r.byname, name)
|
delete(r.byname, name)
|
||||||
|
@ -286,15 +348,18 @@ func (r *imageStore) SetNames(id string, names []string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *imageStore) Delete(id string) error {
|
func (r *imageStore) Delete(id string) error {
|
||||||
|
if !r.IsReadWrite() {
|
||||||
|
return errors.Wrapf(ErrStoreIsReadOnly, "not allowed to delete images at %q", r.imagespath())
|
||||||
|
}
|
||||||
image, ok := r.lookup(id)
|
image, ok := r.lookup(id)
|
||||||
if !ok {
|
if !ok {
|
||||||
return ErrImageUnknown
|
return ErrImageUnknown
|
||||||
}
|
}
|
||||||
id = image.ID
|
id = image.ID
|
||||||
newImages := []Image{}
|
toDeleteIndex := -1
|
||||||
for _, candidate := range r.images {
|
for i, candidate := range r.images {
|
||||||
if candidate.ID != id {
|
if candidate.ID == id {
|
||||||
newImages = append(newImages, candidate)
|
toDeleteIndex = i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete(r.byid, id)
|
delete(r.byid, id)
|
||||||
|
@ -302,7 +367,14 @@ func (r *imageStore) Delete(id string) error {
|
||||||
for _, name := range image.Names {
|
for _, name := range image.Names {
|
||||||
delete(r.byname, name)
|
delete(r.byname, name)
|
||||||
}
|
}
|
||||||
r.images = newImages
|
if toDeleteIndex != -1 {
|
||||||
|
// delete the image at toDeleteIndex
|
||||||
|
if toDeleteIndex == len(r.images)-1 {
|
||||||
|
r.images = r.images[:len(r.images)-1]
|
||||||
|
} else {
|
||||||
|
r.images = append(r.images[:toDeleteIndex], r.images[toDeleteIndex+1:]...)
|
||||||
|
}
|
||||||
|
}
|
||||||
if err := r.Save(); err != nil {
|
if err := r.Save(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -359,6 +431,9 @@ func (r *imageStore) BigDataNames(id string) ([]string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *imageStore) SetBigData(id, key string, data []byte) error {
|
func (r *imageStore) SetBigData(id, key string, data []byte) error {
|
||||||
|
if !r.IsReadWrite() {
|
||||||
|
return errors.Wrapf(ErrStoreIsReadOnly, "not allowed to save data items associated with images at %q", r.imagespath())
|
||||||
|
}
|
||||||
image, ok := r.lookup(id)
|
image, ok := r.lookup(id)
|
||||||
if !ok {
|
if !ok {
|
||||||
return ErrImageUnknown
|
return ErrImageUnknown
|
||||||
|
@ -393,6 +468,9 @@ func (r *imageStore) SetBigData(id, key string, data []byte) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *imageStore) Wipe() error {
|
func (r *imageStore) Wipe() error {
|
||||||
|
if !r.IsReadWrite() {
|
||||||
|
return errors.Wrapf(ErrStoreIsReadOnly, "not allowed to delete images at %q", r.imagespath())
|
||||||
|
}
|
||||||
ids := []string{}
|
ids := []string{}
|
||||||
for id := range r.byid {
|
for id := range r.byid {
|
||||||
ids = append(ids, id)
|
ids = append(ids, id)
|
||||||
|
@ -421,6 +499,10 @@ func (r *imageStore) Modified() (bool, error) {
|
||||||
return r.lockfile.Modified()
|
return r.lockfile.Modified()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *imageStore) IsReadWrite() bool {
|
||||||
|
return r.lockfile.IsReadWrite()
|
||||||
|
}
|
||||||
|
|
||||||
func (r *imageStore) TouchedSince(when time.Time) bool {
|
func (r *imageStore) TouchedSince(when time.Time) bool {
|
||||||
return r.lockfile.TouchedSince(when)
|
return r.lockfile.TouchedSince(when)
|
||||||
}
|
}
|
||||||
|
|
475
vendor/github.com/containers/storage/layers.go
generated
vendored
475
vendor/github.com/containers/storage/layers.go
generated
vendored
|
@ -4,7 +4,6 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
@ -16,6 +15,8 @@ import (
|
||||||
"github.com/containers/storage/pkg/ioutils"
|
"github.com/containers/storage/pkg/ioutils"
|
||||||
"github.com/containers/storage/pkg/stringid"
|
"github.com/containers/storage/pkg/stringid"
|
||||||
"github.com/containers/storage/pkg/truncindex"
|
"github.com/containers/storage/pkg/truncindex"
|
||||||
|
digest "github.com/opencontainers/go-digest"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"github.com/vbatts/tar-split/tar/asm"
|
"github.com/vbatts/tar-split/tar/asm"
|
||||||
"github.com/vbatts/tar-split/tar/storage"
|
"github.com/vbatts/tar-split/tar/storage"
|
||||||
)
|
)
|
||||||
|
@ -66,6 +67,38 @@ type Layer struct {
|
||||||
// mounted at the mount point.
|
// mounted at the mount point.
|
||||||
MountCount int `json:"-"`
|
MountCount int `json:"-"`
|
||||||
|
|
||||||
|
// Created is the datestamp for when this layer was created. Older
|
||||||
|
// versions of the library did not track this information, so callers
|
||||||
|
// will likely want to use the IsZero() method to verify that a value
|
||||||
|
// is set before using it.
|
||||||
|
Created time.Time `json:"created,omitempty"`
|
||||||
|
|
||||||
|
// CompressedDigest is the digest of the blob that was last passed to
|
||||||
|
// ApplyDiff() or Put(), as it was presented to us.
|
||||||
|
CompressedDigest digest.Digest `json:"compressed-diff-digest,omitempty"`
|
||||||
|
|
||||||
|
// CompressedSize is the length of the blob that was last passed to
|
||||||
|
// ApplyDiff() or Put(), as it was presented to us. If
|
||||||
|
// CompressedDigest is not set, this should be treated as if it were an
|
||||||
|
// uninitialized value.
|
||||||
|
CompressedSize int64 `json:"compressed-size,omitempty"`
|
||||||
|
|
||||||
|
// UncompressedDigest is the digest of the blob that was last passed to
|
||||||
|
// ApplyDiff() or Put(), after we decompressed it. Often referred to
|
||||||
|
// as a DiffID.
|
||||||
|
UncompressedDigest digest.Digest `json:"diff-digest,omitempty"`
|
||||||
|
|
||||||
|
// UncompressedSize is the length of the blob that was last passed to
|
||||||
|
// ApplyDiff() or Put(), after we decompressed it. If
|
||||||
|
// UncompressedDigest is not set, this should be treated as if it were
|
||||||
|
// an uninitialized value.
|
||||||
|
UncompressedSize int64 `json:"diff-size,omitempty"`
|
||||||
|
|
||||||
|
// CompressionType is the type of compression which we detected on the blob
|
||||||
|
// that was last passed to ApplyDiff() or Put().
|
||||||
|
CompressionType archive.Compression `json:"compression,omitempty"`
|
||||||
|
|
||||||
|
// Flags is arbitrary data about the layer.
|
||||||
Flags map[string]interface{} `json:"flags,omitempty"`
|
Flags map[string]interface{} `json:"flags,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,12 +108,74 @@ type layerMountPoint struct {
|
||||||
MountCount int `json:"count"`
|
MountCount int `json:"count"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DiffOptions override the default behavior of Diff() methods.
|
||||||
|
type DiffOptions struct {
|
||||||
|
// Compression, if set overrides the default compressor when generating a diff.
|
||||||
|
Compression *archive.Compression
|
||||||
|
}
|
||||||
|
|
||||||
|
// ROLayerStore wraps a graph driver, adding the ability to refer to layers by
|
||||||
|
// name, and keeping track of parent-child relationships, along with a list of
|
||||||
|
// all known layers.
|
||||||
|
type ROLayerStore interface {
|
||||||
|
ROFileBasedStore
|
||||||
|
ROMetadataStore
|
||||||
|
|
||||||
|
// Exists checks if a layer with the specified name or ID is known.
|
||||||
|
Exists(id string) bool
|
||||||
|
|
||||||
|
// Get retrieves information about a layer given an ID or name.
|
||||||
|
Get(id string) (*Layer, error)
|
||||||
|
|
||||||
|
// Status returns an slice of key-value pairs, suitable for human consumption,
|
||||||
|
// relaying whatever status information the underlying driver can share.
|
||||||
|
Status() ([][2]string, error)
|
||||||
|
|
||||||
|
// Changes returns a slice of Change structures, which contain a pathname
|
||||||
|
// (Path) and a description of what sort of change (Kind) was made by the
|
||||||
|
// layer (either ChangeModify, ChangeAdd, or ChangeDelete), relative to a
|
||||||
|
// specified layer. By default, the layer's parent is used as a reference.
|
||||||
|
Changes(from, to string) ([]archive.Change, error)
|
||||||
|
|
||||||
|
// Diff produces a tarstream which can be applied to a layer with the contents
|
||||||
|
// of the first layer to produce a layer with the contents of the second layer.
|
||||||
|
// By default, the parent of the second layer is used as the first
|
||||||
|
// layer, so it need not be specified. Options can be used to override
|
||||||
|
// default behavior, but are also not required.
|
||||||
|
Diff(from, to string, options *DiffOptions) (io.ReadCloser, error)
|
||||||
|
|
||||||
|
// DiffSize produces an estimate of the length of the tarstream which would be
|
||||||
|
// produced by Diff.
|
||||||
|
DiffSize(from, to string) (int64, error)
|
||||||
|
|
||||||
|
// Size produces a cached value for the uncompressed size of the layer,
|
||||||
|
// if one is known, or -1 if it is not known. If the layer can not be
|
||||||
|
// found, it returns an error.
|
||||||
|
Size(name string) (int64, error)
|
||||||
|
|
||||||
|
// Lookup attempts to translate a name to an ID. Most methods do this
|
||||||
|
// implicitly.
|
||||||
|
Lookup(name string) (string, error)
|
||||||
|
|
||||||
|
// LayersByCompressedDigest returns a slice of the layers with the
|
||||||
|
// specified compressed digest value recorded for them.
|
||||||
|
LayersByCompressedDigest(d digest.Digest) ([]Layer, error)
|
||||||
|
|
||||||
|
// LayersByUncompressedDigest returns a slice of the layers with the
|
||||||
|
// specified uncompressed digest value recorded for them.
|
||||||
|
LayersByUncompressedDigest(d digest.Digest) ([]Layer, error)
|
||||||
|
|
||||||
|
// Layers returns a slice of the known layers.
|
||||||
|
Layers() ([]Layer, error)
|
||||||
|
}
|
||||||
|
|
||||||
// LayerStore wraps a graph driver, adding the ability to refer to layers by
|
// LayerStore wraps a graph driver, adding the ability to refer to layers by
|
||||||
// name, and keeping track of parent-child relationships, along with a list of
|
// name, and keeping track of parent-child relationships, along with a list of
|
||||||
// all known layers.
|
// all known layers.
|
||||||
type LayerStore interface {
|
type LayerStore interface {
|
||||||
FileBasedStore
|
ROLayerStore
|
||||||
MetadataStore
|
RWFileBasedStore
|
||||||
|
RWMetadataStore
|
||||||
FlaggableStore
|
FlaggableStore
|
||||||
|
|
||||||
// Create creates a new layer, optionally giving it a specified ID rather than
|
// Create creates a new layer, optionally giving it a specified ID rather than
|
||||||
|
@ -98,20 +193,10 @@ type LayerStore interface {
|
||||||
// Put combines the functions of CreateWithFlags and ApplyDiff.
|
// Put combines the functions of CreateWithFlags and ApplyDiff.
|
||||||
Put(id, parent string, names []string, mountLabel string, options map[string]string, writeable bool, flags map[string]interface{}, diff archive.Reader) (*Layer, int64, error)
|
Put(id, parent string, names []string, mountLabel string, options map[string]string, writeable bool, flags map[string]interface{}, diff archive.Reader) (*Layer, int64, error)
|
||||||
|
|
||||||
// Exists checks if a layer with the specified name or ID is known.
|
|
||||||
Exists(id string) bool
|
|
||||||
|
|
||||||
// Get retrieves information about a layer given an ID or name.
|
|
||||||
Get(id string) (*Layer, error)
|
|
||||||
|
|
||||||
// SetNames replaces the list of names associated with a layer with the
|
// SetNames replaces the list of names associated with a layer with the
|
||||||
// supplied values.
|
// supplied values.
|
||||||
SetNames(id string, names []string) error
|
SetNames(id string, names []string) error
|
||||||
|
|
||||||
// Status returns an slice of key-value pairs, suitable for human consumption,
|
|
||||||
// relaying whatever status information the underlying driver can share.
|
|
||||||
Status() ([][2]string, error)
|
|
||||||
|
|
||||||
// Delete deletes a layer with the specified name or ID.
|
// Delete deletes a layer with the specified name or ID.
|
||||||
Delete(id string) error
|
Delete(id string) error
|
||||||
|
|
||||||
|
@ -126,48 +211,31 @@ type LayerStore interface {
|
||||||
// Unmount unmounts a layer when it is no longer in use.
|
// Unmount unmounts a layer when it is no longer in use.
|
||||||
Unmount(id string) error
|
Unmount(id string) error
|
||||||
|
|
||||||
// Changes returns a slice of Change structures, which contain a pathname
|
|
||||||
// (Path) and a description of what sort of change (Kind) was made by the
|
|
||||||
// layer (either ChangeModify, ChangeAdd, or ChangeDelete), relative to a
|
|
||||||
// specified layer. By default, the layer's parent is used as a reference.
|
|
||||||
Changes(from, to string) ([]archive.Change, error)
|
|
||||||
|
|
||||||
// Diff produces a tarstream which can be applied to a layer with the contents
|
|
||||||
// of the first layer to produce a layer with the contents of the second layer.
|
|
||||||
// By default, the parent of the second layer is used as the first
|
|
||||||
// layer, so it need not be specified.
|
|
||||||
Diff(from, to string) (io.ReadCloser, error)
|
|
||||||
|
|
||||||
// DiffSize produces an estimate of the length of the tarstream which would be
|
|
||||||
// produced by Diff.
|
|
||||||
DiffSize(from, to string) (int64, error)
|
|
||||||
|
|
||||||
// ApplyDiff reads a tarstream which was created by a previous call to Diff and
|
// ApplyDiff reads a tarstream which was created by a previous call to Diff and
|
||||||
// applies its changes to a specified layer.
|
// applies its changes to a specified layer.
|
||||||
ApplyDiff(to string, diff archive.Reader) (int64, error)
|
ApplyDiff(to string, diff archive.Reader) (int64, error)
|
||||||
|
|
||||||
// Lookup attempts to translate a name to an ID. Most methods do this
|
|
||||||
// implicitly.
|
|
||||||
Lookup(name string) (string, error)
|
|
||||||
|
|
||||||
// Layers returns a slice of the known layers.
|
|
||||||
Layers() ([]Layer, error)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type layerStore struct {
|
type layerStore struct {
|
||||||
lockfile Locker
|
lockfile Locker
|
||||||
rundir string
|
rundir string
|
||||||
driver drivers.Driver
|
driver drivers.Driver
|
||||||
layerdir string
|
layerdir string
|
||||||
layers []Layer
|
layers []*Layer
|
||||||
idindex *truncindex.TruncIndex
|
idindex *truncindex.TruncIndex
|
||||||
byid map[string]*Layer
|
byid map[string]*Layer
|
||||||
byname map[string]*Layer
|
byname map[string]*Layer
|
||||||
bymount map[string]*Layer
|
bymount map[string]*Layer
|
||||||
|
bycompressedsum map[digest.Digest][]string
|
||||||
|
byuncompressedsum map[digest.Digest][]string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *layerStore) Layers() ([]Layer, error) {
|
func (r *layerStore) Layers() ([]Layer, error) {
|
||||||
return r.layers, nil
|
layers := make([]Layer, len(r.layers))
|
||||||
|
for i := range r.layers {
|
||||||
|
layers[i] = *(r.layers[i])
|
||||||
|
}
|
||||||
|
return layers, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *layerStore) mountspath() string {
|
func (r *layerStore) mountspath() string {
|
||||||
|
@ -179,36 +247,41 @@ func (r *layerStore) layerspath() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *layerStore) Load() error {
|
func (r *layerStore) Load() error {
|
||||||
needSave := false
|
shouldSave := false
|
||||||
rpath := r.layerspath()
|
rpath := r.layerspath()
|
||||||
data, err := ioutil.ReadFile(rpath)
|
data, err := ioutil.ReadFile(rpath)
|
||||||
if err != nil && !os.IsNotExist(err) {
|
if err != nil && !os.IsNotExist(err) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
layers := []Layer{}
|
layers := []*Layer{}
|
||||||
idlist := []string{}
|
idlist := []string{}
|
||||||
ids := make(map[string]*Layer)
|
ids := make(map[string]*Layer)
|
||||||
names := make(map[string]*Layer)
|
names := make(map[string]*Layer)
|
||||||
mounts := make(map[string]*Layer)
|
mounts := make(map[string]*Layer)
|
||||||
parents := make(map[string][]*Layer)
|
compressedsums := make(map[digest.Digest][]string)
|
||||||
|
uncompressedsums := make(map[digest.Digest][]string)
|
||||||
if err = json.Unmarshal(data, &layers); len(data) == 0 || err == nil {
|
if err = json.Unmarshal(data, &layers); len(data) == 0 || err == nil {
|
||||||
for n, layer := range layers {
|
for n, layer := range layers {
|
||||||
ids[layer.ID] = &layers[n]
|
ids[layer.ID] = layers[n]
|
||||||
idlist = append(idlist, layer.ID)
|
idlist = append(idlist, layer.ID)
|
||||||
for _, name := range layer.Names {
|
for _, name := range layer.Names {
|
||||||
if conflict, ok := names[name]; ok {
|
if conflict, ok := names[name]; ok {
|
||||||
r.removeName(conflict, name)
|
r.removeName(conflict, name)
|
||||||
needSave = true
|
shouldSave = true
|
||||||
}
|
}
|
||||||
names[name] = &layers[n]
|
names[name] = layers[n]
|
||||||
}
|
}
|
||||||
if pslice, ok := parents[layer.Parent]; ok {
|
if layer.CompressedDigest != "" {
|
||||||
parents[layer.Parent] = append(pslice, &layers[n])
|
compressedsums[layer.CompressedDigest] = append(compressedsums[layer.CompressedDigest], layer.ID)
|
||||||
} else {
|
}
|
||||||
parents[layer.Parent] = []*Layer{&layers[n]}
|
if layer.UncompressedDigest != "" {
|
||||||
|
uncompressedsums[layer.UncompressedDigest] = append(uncompressedsums[layer.UncompressedDigest], layer.ID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if shouldSave && !r.IsReadWrite() {
|
||||||
|
return errors.New("layer store assigns the same name to multiple layers")
|
||||||
|
}
|
||||||
mpath := r.mountspath()
|
mpath := r.mountspath()
|
||||||
data, err = ioutil.ReadFile(mpath)
|
data, err = ioutil.ReadFile(mpath)
|
||||||
if err != nil && !os.IsNotExist(err) {
|
if err != nil && !os.IsNotExist(err) {
|
||||||
|
@ -231,29 +304,35 @@ func (r *layerStore) Load() error {
|
||||||
r.byid = ids
|
r.byid = ids
|
||||||
r.byname = names
|
r.byname = names
|
||||||
r.bymount = mounts
|
r.bymount = mounts
|
||||||
|
r.bycompressedsum = compressedsums
|
||||||
|
r.byuncompressedsum = uncompressedsums
|
||||||
err = nil
|
err = nil
|
||||||
// Last step: try to remove anything that a previous user of this
|
// Last step: if we're writable, try to remove anything that a previous
|
||||||
// storage area marked for deletion but didn't manage to actually
|
// user of this storage area marked for deletion but didn't manage to
|
||||||
// delete.
|
// actually delete.
|
||||||
for _, layer := range r.layers {
|
if r.IsReadWrite() {
|
||||||
if cleanup, ok := layer.Flags[incompleteFlag]; ok {
|
for _, layer := range r.layers {
|
||||||
if b, ok := cleanup.(bool); ok && b {
|
if cleanup, ok := layer.Flags[incompleteFlag]; ok {
|
||||||
err = r.Delete(layer.ID)
|
if b, ok := cleanup.(bool); ok && b {
|
||||||
if err != nil {
|
err = r.Delete(layer.ID)
|
||||||
break
|
if err != nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
shouldSave = true
|
||||||
}
|
}
|
||||||
needSave = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
if shouldSave {
|
||||||
if needSave {
|
return r.Save()
|
||||||
r.Touch()
|
}
|
||||||
return r.Save()
|
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *layerStore) Save() error {
|
func (r *layerStore) Save() error {
|
||||||
|
if !r.IsReadWrite() {
|
||||||
|
return errors.Wrapf(ErrStoreIsReadOnly, "not allowed to modify the layer store at %q", r.layerspath())
|
||||||
|
}
|
||||||
rpath := r.layerspath()
|
rpath := r.layerspath()
|
||||||
if err := os.MkdirAll(filepath.Dir(rpath), 0700); err != nil {
|
if err := os.MkdirAll(filepath.Dir(rpath), 0700); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -283,6 +362,7 @@ func (r *layerStore) Save() error {
|
||||||
if err := ioutils.AtomicWriteFile(rpath, jldata, 0600); err != nil {
|
if err := ioutils.AtomicWriteFile(rpath, jldata, 0600); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
defer r.Touch()
|
||||||
return ioutils.AtomicWriteFile(mpath, jmdata, 0600)
|
return ioutils.AtomicWriteFile(mpath, jmdata, 0600)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -314,6 +394,28 @@ func newLayerStore(rundir string, layerdir string, driver drivers.Driver) (Layer
|
||||||
return &rlstore, nil
|
return &rlstore, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func newROLayerStore(rundir string, layerdir string, driver drivers.Driver) (ROLayerStore, error) {
|
||||||
|
lockfile, err := GetROLockfile(filepath.Join(layerdir, "layers.lock"))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
lockfile.Lock()
|
||||||
|
defer lockfile.Unlock()
|
||||||
|
rlstore := layerStore{
|
||||||
|
lockfile: lockfile,
|
||||||
|
driver: driver,
|
||||||
|
rundir: rundir,
|
||||||
|
layerdir: layerdir,
|
||||||
|
byid: make(map[string]*Layer),
|
||||||
|
bymount: make(map[string]*Layer),
|
||||||
|
byname: make(map[string]*Layer),
|
||||||
|
}
|
||||||
|
if err := rlstore.Load(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &rlstore, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (r *layerStore) lookup(id string) (*Layer, bool) {
|
func (r *layerStore) lookup(id string) (*Layer, bool) {
|
||||||
if layer, ok := r.byid[id]; ok {
|
if layer, ok := r.byid[id]; ok {
|
||||||
return layer, ok
|
return layer, ok
|
||||||
|
@ -326,7 +428,24 @@ func (r *layerStore) lookup(id string) (*Layer, bool) {
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *layerStore) Size(name string) (int64, error) {
|
||||||
|
layer, ok := r.lookup(name)
|
||||||
|
if !ok {
|
||||||
|
return -1, ErrLayerUnknown
|
||||||
|
}
|
||||||
|
// We use the presence of a non-empty digest as an indicator that the size value was intentionally set, and that
|
||||||
|
// a zero value is not just present because it was never set to anything else (which can happen if the layer was
|
||||||
|
// created by a version of this library that didn't keep track of digest and size information).
|
||||||
|
if layer.UncompressedDigest != "" {
|
||||||
|
return layer.UncompressedSize, nil
|
||||||
|
}
|
||||||
|
return -1, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (r *layerStore) ClearFlag(id string, flag string) error {
|
func (r *layerStore) ClearFlag(id string, flag string) error {
|
||||||
|
if !r.IsReadWrite() {
|
||||||
|
return errors.Wrapf(ErrStoreIsReadOnly, "not allowed to clear flags on layers at %q", r.layerspath())
|
||||||
|
}
|
||||||
layer, ok := r.lookup(id)
|
layer, ok := r.lookup(id)
|
||||||
if !ok {
|
if !ok {
|
||||||
return ErrLayerUnknown
|
return ErrLayerUnknown
|
||||||
|
@ -336,6 +455,9 @@ func (r *layerStore) ClearFlag(id string, flag string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *layerStore) SetFlag(id string, flag string, value interface{}) error {
|
func (r *layerStore) SetFlag(id string, flag string, value interface{}) error {
|
||||||
|
if !r.IsReadWrite() {
|
||||||
|
return errors.Wrapf(ErrStoreIsReadOnly, "not allowed to set flags on layers at %q", r.layerspath())
|
||||||
|
}
|
||||||
layer, ok := r.lookup(id)
|
layer, ok := r.lookup(id)
|
||||||
if !ok {
|
if !ok {
|
||||||
return ErrLayerUnknown
|
return ErrLayerUnknown
|
||||||
|
@ -349,6 +471,9 @@ func (r *layerStore) Status() ([][2]string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *layerStore) Put(id, parent string, names []string, mountLabel string, options map[string]string, writeable bool, flags map[string]interface{}, diff archive.Reader) (layer *Layer, size int64, err error) {
|
func (r *layerStore) Put(id, parent string, names []string, mountLabel string, options map[string]string, writeable bool, flags map[string]interface{}, diff archive.Reader) (layer *Layer, size int64, err error) {
|
||||||
|
if !r.IsReadWrite() {
|
||||||
|
return nil, -1, errors.Wrapf(ErrStoreIsReadOnly, "not allowed to create new layers at %q", r.layerspath())
|
||||||
|
}
|
||||||
size = -1
|
size = -1
|
||||||
if err := os.MkdirAll(r.rundir, 0700); err != nil {
|
if err := os.MkdirAll(r.rundir, 0700); err != nil {
|
||||||
return nil, -1, err
|
return nil, -1, err
|
||||||
|
@ -383,15 +508,15 @@ func (r *layerStore) Put(id, parent string, names []string, mountLabel string, o
|
||||||
err = r.driver.Create(id, parent, mountLabel, options)
|
err = r.driver.Create(id, parent, mountLabel, options)
|
||||||
}
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
newLayer := Layer{
|
layer = &Layer{
|
||||||
ID: id,
|
ID: id,
|
||||||
Parent: parent,
|
Parent: parent,
|
||||||
Names: names,
|
Names: names,
|
||||||
MountLabel: mountLabel,
|
MountLabel: mountLabel,
|
||||||
|
Created: time.Now().UTC(),
|
||||||
Flags: make(map[string]interface{}),
|
Flags: make(map[string]interface{}),
|
||||||
}
|
}
|
||||||
r.layers = append(r.layers, newLayer)
|
r.layers = append(r.layers, layer)
|
||||||
layer = &r.layers[len(r.layers)-1]
|
|
||||||
r.idindex.Add(id)
|
r.idindex.Add(id)
|
||||||
r.byid[id] = layer
|
r.byid[id] = layer
|
||||||
for _, name := range names {
|
for _, name := range names {
|
||||||
|
@ -441,6 +566,9 @@ func (r *layerStore) Create(id, parent string, names []string, mountLabel string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *layerStore) Mount(id, mountLabel string) (string, error) {
|
func (r *layerStore) Mount(id, mountLabel string) (string, error) {
|
||||||
|
if !r.IsReadWrite() {
|
||||||
|
return "", errors.Wrapf(ErrStoreIsReadOnly, "not allowed to update mount locations for layers at %q", r.mountspath())
|
||||||
|
}
|
||||||
layer, ok := r.lookup(id)
|
layer, ok := r.lookup(id)
|
||||||
if !ok {
|
if !ok {
|
||||||
return "", ErrLayerUnknown
|
return "", ErrLayerUnknown
|
||||||
|
@ -466,6 +594,9 @@ func (r *layerStore) Mount(id, mountLabel string) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *layerStore) Unmount(id string) error {
|
func (r *layerStore) Unmount(id string) error {
|
||||||
|
if !r.IsReadWrite() {
|
||||||
|
return errors.Wrapf(ErrStoreIsReadOnly, "not allowed to update mount locations for layers at %q", r.mountspath())
|
||||||
|
}
|
||||||
layer, ok := r.lookup(id)
|
layer, ok := r.lookup(id)
|
||||||
if !ok {
|
if !ok {
|
||||||
layerByMount, ok := r.bymount[filepath.Clean(id)]
|
layerByMount, ok := r.bymount[filepath.Clean(id)]
|
||||||
|
@ -495,6 +626,9 @@ func (r *layerStore) removeName(layer *Layer, name string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *layerStore) SetNames(id string, names []string) error {
|
func (r *layerStore) SetNames(id string, names []string) error {
|
||||||
|
if !r.IsReadWrite() {
|
||||||
|
return errors.Wrapf(ErrStoreIsReadOnly, "not allowed to change layer name assignments at %q", r.layerspath())
|
||||||
|
}
|
||||||
if layer, ok := r.lookup(id); ok {
|
if layer, ok := r.lookup(id); ok {
|
||||||
for _, name := range layer.Names {
|
for _, name := range layer.Names {
|
||||||
delete(r.byname, name)
|
delete(r.byname, name)
|
||||||
|
@ -519,6 +653,9 @@ func (r *layerStore) Metadata(id string) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *layerStore) SetMetadata(id, metadata string) error {
|
func (r *layerStore) SetMetadata(id, metadata string) error {
|
||||||
|
if !r.IsReadWrite() {
|
||||||
|
return errors.Wrapf(ErrStoreIsReadOnly, "not allowed to modify layer metadata at %q", r.layerspath())
|
||||||
|
}
|
||||||
if layer, ok := r.lookup(id); ok {
|
if layer, ok := r.lookup(id); ok {
|
||||||
layer.Metadata = metadata
|
layer.Metadata = metadata
|
||||||
return r.Save()
|
return r.Save()
|
||||||
|
@ -531,6 +668,9 @@ func (r *layerStore) tspath(id string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *layerStore) Delete(id string) error {
|
func (r *layerStore) Delete(id string) error {
|
||||||
|
if !r.IsReadWrite() {
|
||||||
|
return errors.Wrapf(ErrStoreIsReadOnly, "not allowed to delete layers at %q", r.layerspath())
|
||||||
|
}
|
||||||
layer, ok := r.lookup(id)
|
layer, ok := r.lookup(id)
|
||||||
if !ok {
|
if !ok {
|
||||||
return ErrLayerUnknown
|
return ErrLayerUnknown
|
||||||
|
@ -549,13 +689,21 @@ func (r *layerStore) Delete(id string) error {
|
||||||
if layer.MountPoint != "" {
|
if layer.MountPoint != "" {
|
||||||
delete(r.bymount, layer.MountPoint)
|
delete(r.bymount, layer.MountPoint)
|
||||||
}
|
}
|
||||||
newLayers := []Layer{}
|
toDeleteIndex := -1
|
||||||
for _, candidate := range r.layers {
|
for i, candidate := range r.layers {
|
||||||
if candidate.ID != id {
|
if candidate.ID == id {
|
||||||
newLayers = append(newLayers, candidate)
|
toDeleteIndex = i
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if toDeleteIndex != -1 {
|
||||||
|
// delete the layer at toDeleteIndex
|
||||||
|
if toDeleteIndex == len(r.layers)-1 {
|
||||||
|
r.layers = r.layers[:len(r.layers)-1]
|
||||||
|
} else {
|
||||||
|
r.layers = append(r.layers[:toDeleteIndex], r.layers[toDeleteIndex+1:]...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
r.layers = newLayers
|
|
||||||
if err = r.Save(); err != nil {
|
if err = r.Save(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -583,6 +731,9 @@ func (r *layerStore) Get(id string) (*Layer, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *layerStore) Wipe() error {
|
func (r *layerStore) Wipe() error {
|
||||||
|
if !r.IsReadWrite() {
|
||||||
|
return errors.Wrapf(ErrStoreIsReadOnly, "not allowed to delete layers at %q", r.layerspath())
|
||||||
|
}
|
||||||
ids := []string{}
|
ids := []string{}
|
||||||
for id := range r.byid {
|
for id := range r.byid {
|
||||||
ids = append(ids, id)
|
ids = append(ids, id)
|
||||||
|
@ -657,48 +808,64 @@ func (r *layerStore) newFileGetter(id string) (drivers.FileGetCloser, error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *layerStore) Diff(from, to string) (io.ReadCloser, error) {
|
func (r *layerStore) Diff(from, to string, options *DiffOptions) (io.ReadCloser, error) {
|
||||||
var metadata storage.Unpacker
|
var metadata storage.Unpacker
|
||||||
|
|
||||||
from, to, toLayer, err := r.findParentAndLayer(from, to)
|
from, to, toLayer, err := r.findParentAndLayer(from, to)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, ErrLayerUnknown
|
return nil, ErrLayerUnknown
|
||||||
}
|
}
|
||||||
compression := archive.Uncompressed
|
// Default to applying the type of compression that we noted was used
|
||||||
if cflag, ok := toLayer.Flags[compressionFlag]; ok {
|
// for the layerdiff when it was applied.
|
||||||
if ctype, ok := cflag.(float64); ok {
|
compression := toLayer.CompressionType
|
||||||
compression = archive.Compression(ctype)
|
// If a particular compression type (or no compression) was selected,
|
||||||
} else if ctype, ok := cflag.(archive.Compression); ok {
|
// use that instead.
|
||||||
compression = archive.Compression(ctype)
|
if options != nil && options.Compression != nil {
|
||||||
}
|
compression = *options.Compression
|
||||||
}
|
}
|
||||||
|
maybeCompressReadCloser := func(rc io.ReadCloser) (io.ReadCloser, error) {
|
||||||
|
// Depending on whether or not compression is desired, return either the
|
||||||
|
// passed-in ReadCloser, or a new one that provides its readers with a
|
||||||
|
// compressed version of the data that the original would have provided
|
||||||
|
// to its readers.
|
||||||
|
if compression == archive.Uncompressed {
|
||||||
|
return rc, nil
|
||||||
|
}
|
||||||
|
preader, pwriter := io.Pipe()
|
||||||
|
compressor, err := archive.CompressStream(pwriter, compression)
|
||||||
|
if err != nil {
|
||||||
|
rc.Close()
|
||||||
|
pwriter.Close()
|
||||||
|
preader.Close()
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
go func() {
|
||||||
|
defer pwriter.Close()
|
||||||
|
defer compressor.Close()
|
||||||
|
defer rc.Close()
|
||||||
|
io.Copy(compressor, rc)
|
||||||
|
}()
|
||||||
|
return preader, nil
|
||||||
|
}
|
||||||
|
|
||||||
if from != toLayer.Parent {
|
if from != toLayer.Parent {
|
||||||
diff, err := r.driver.Diff(to, from)
|
diff, err := r.driver.Diff(to, from)
|
||||||
if err == nil && (compression != archive.Uncompressed) {
|
if err != nil {
|
||||||
preader, pwriter := io.Pipe()
|
return nil, err
|
||||||
compressor, err := archive.CompressStream(pwriter, compression)
|
|
||||||
if err != nil {
|
|
||||||
diff.Close()
|
|
||||||
pwriter.Close()
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
go func() {
|
|
||||||
io.Copy(compressor, diff)
|
|
||||||
diff.Close()
|
|
||||||
compressor.Close()
|
|
||||||
pwriter.Close()
|
|
||||||
}()
|
|
||||||
diff = preader
|
|
||||||
}
|
}
|
||||||
return diff, err
|
return maybeCompressReadCloser(diff)
|
||||||
}
|
}
|
||||||
|
|
||||||
tsfile, err := os.Open(r.tspath(to))
|
tsfile, err := os.Open(r.tspath(to))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(err) {
|
if !os.IsNotExist(err) {
|
||||||
return r.driver.Diff(to, from)
|
return nil, err
|
||||||
}
|
}
|
||||||
return nil, err
|
diff, err := r.driver.Diff(to, from)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return maybeCompressReadCloser(diff)
|
||||||
}
|
}
|
||||||
defer tsfile.Close()
|
defer tsfile.Close()
|
||||||
|
|
||||||
|
@ -720,33 +887,16 @@ func (r *layerStore) Diff(from, to string) (io.ReadCloser, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var stream io.ReadCloser
|
tarstream := asm.NewOutputTarStream(fgetter, metadata)
|
||||||
if compression != archive.Uncompressed {
|
rc := ioutils.NewReadCloserWrapper(tarstream, func() error {
|
||||||
preader, pwriter := io.Pipe()
|
err1 := tarstream.Close()
|
||||||
compressor, err := archive.CompressStream(pwriter, compression)
|
|
||||||
if err != nil {
|
|
||||||
fgetter.Close()
|
|
||||||
pwriter.Close()
|
|
||||||
preader.Close()
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
go func() {
|
|
||||||
asm.WriteOutputTarStream(fgetter, metadata, compressor)
|
|
||||||
compressor.Close()
|
|
||||||
pwriter.Close()
|
|
||||||
}()
|
|
||||||
stream = preader
|
|
||||||
} else {
|
|
||||||
stream = asm.NewOutputTarStream(fgetter, metadata)
|
|
||||||
}
|
|
||||||
return ioutils.NewReadCloserWrapper(stream, func() error {
|
|
||||||
err1 := stream.Close()
|
|
||||||
err2 := fgetter.Close()
|
err2 := fgetter.Close()
|
||||||
if err2 == nil {
|
if err2 == nil {
|
||||||
return err1
|
return err1
|
||||||
}
|
}
|
||||||
return err2
|
return err2
|
||||||
}), nil
|
})
|
||||||
|
return maybeCompressReadCloser(rc)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *layerStore) DiffSize(from, to string) (size int64, err error) {
|
func (r *layerStore) DiffSize(from, to string) (size int64, err error) {
|
||||||
|
@ -758,6 +908,10 @@ func (r *layerStore) DiffSize(from, to string) (size int64, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *layerStore) ApplyDiff(to string, diff archive.Reader) (size int64, err error) {
|
func (r *layerStore) ApplyDiff(to string, diff archive.Reader) (size int64, err error) {
|
||||||
|
if !r.IsReadWrite() {
|
||||||
|
return -1, errors.Wrapf(ErrStoreIsReadOnly, "not allowed to modify layer contents at %q", r.layerspath())
|
||||||
|
}
|
||||||
|
|
||||||
layer, ok := r.lookup(to)
|
layer, ok := r.lookup(to)
|
||||||
if !ok {
|
if !ok {
|
||||||
return -1, ErrLayerUnknown
|
return -1, ErrLayerUnknown
|
||||||
|
@ -770,7 +924,9 @@ func (r *layerStore) ApplyDiff(to string, diff archive.Reader) (size int64, err
|
||||||
}
|
}
|
||||||
|
|
||||||
compression := archive.DetectCompression(header[:n])
|
compression := archive.DetectCompression(header[:n])
|
||||||
defragmented := io.MultiReader(bytes.NewBuffer(header[:n]), diff)
|
compressedDigest := digest.Canonical.Digester()
|
||||||
|
compressedCounter := ioutils.NewWriteCounter(compressedDigest.Hash())
|
||||||
|
defragmented := io.TeeReader(io.MultiReader(bytes.NewBuffer(header[:n]), diff), compressedCounter)
|
||||||
|
|
||||||
tsdata := bytes.Buffer{}
|
tsdata := bytes.Buffer{}
|
||||||
compressor, err := gzip.NewWriterLevel(&tsdata, gzip.BestSpeed)
|
compressor, err := gzip.NewWriterLevel(&tsdata, gzip.BestSpeed)
|
||||||
|
@ -778,15 +934,20 @@ func (r *layerStore) ApplyDiff(to string, diff archive.Reader) (size int64, err
|
||||||
compressor = gzip.NewWriter(&tsdata)
|
compressor = gzip.NewWriter(&tsdata)
|
||||||
}
|
}
|
||||||
metadata := storage.NewJSONPacker(compressor)
|
metadata := storage.NewJSONPacker(compressor)
|
||||||
decompressed, err := archive.DecompressStream(defragmented)
|
uncompressed, err := archive.DecompressStream(defragmented)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
payload, err := asm.NewInputTarStream(decompressed, metadata, storage.NewDiscardFilePutter())
|
uncompressedDigest := digest.Canonical.Digester()
|
||||||
|
uncompressedCounter := ioutils.NewWriteCounter(uncompressedDigest.Hash())
|
||||||
|
payload, err := asm.NewInputTarStream(io.TeeReader(uncompressed, uncompressedCounter), metadata, storage.NewDiscardFilePutter())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
size, err = r.driver.ApplyDiff(layer.ID, layer.Parent, payload)
|
size, err = r.driver.ApplyDiff(layer.ID, layer.Parent, payload)
|
||||||
|
if err != nil {
|
||||||
|
return -1, err
|
||||||
|
}
|
||||||
compressor.Close()
|
compressor.Close()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if err := os.MkdirAll(filepath.Dir(r.tspath(layer.ID)), 0700); err != nil {
|
if err := os.MkdirAll(filepath.Dir(r.tspath(layer.ID)), 0700); err != nil {
|
||||||
|
@ -797,15 +958,57 @@ func (r *layerStore) ApplyDiff(to string, diff archive.Reader) (size int64, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if compression != archive.Uncompressed {
|
updateDigestMap := func(m *map[digest.Digest][]string, oldvalue, newvalue digest.Digest, id string) {
|
||||||
layer.Flags[compressionFlag] = compression
|
var newList []string
|
||||||
} else {
|
if oldvalue != "" {
|
||||||
delete(layer.Flags, compressionFlag)
|
for _, value := range (*m)[oldvalue] {
|
||||||
|
if value != id {
|
||||||
|
newList = append(newList, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(newList) > 0 {
|
||||||
|
(*m)[oldvalue] = newList
|
||||||
|
} else {
|
||||||
|
delete(*m, oldvalue)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if newvalue != "" {
|
||||||
|
(*m)[newvalue] = append((*m)[newvalue], id)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
updateDigestMap(&r.bycompressedsum, layer.CompressedDigest, compressedDigest.Digest(), layer.ID)
|
||||||
|
layer.CompressedDigest = compressedDigest.Digest()
|
||||||
|
layer.CompressedSize = compressedCounter.Count
|
||||||
|
updateDigestMap(&r.byuncompressedsum, layer.UncompressedDigest, uncompressedDigest.Digest(), layer.ID)
|
||||||
|
layer.UncompressedDigest = uncompressedDigest.Digest()
|
||||||
|
layer.UncompressedSize = uncompressedCounter.Count
|
||||||
|
layer.CompressionType = compression
|
||||||
|
|
||||||
|
err = r.Save()
|
||||||
|
|
||||||
return size, err
|
return size, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *layerStore) layersByDigestMap(m map[digest.Digest][]string, d digest.Digest) ([]Layer, error) {
|
||||||
|
var layers []Layer
|
||||||
|
for _, layerID := range m[d] {
|
||||||
|
layer, ok := r.lookup(layerID)
|
||||||
|
if !ok {
|
||||||
|
return nil, ErrLayerUnknown
|
||||||
|
}
|
||||||
|
layers = append(layers, *layer)
|
||||||
|
}
|
||||||
|
return layers, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *layerStore) LayersByCompressedDigest(d digest.Digest) ([]Layer, error) {
|
||||||
|
return r.layersByDigestMap(r.bycompressedsum, d)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *layerStore) LayersByUncompressedDigest(d digest.Digest) ([]Layer, error) {
|
||||||
|
return r.layersByDigestMap(r.byuncompressedsum, d)
|
||||||
|
}
|
||||||
|
|
||||||
func (r *layerStore) Lock() {
|
func (r *layerStore) Lock() {
|
||||||
r.lockfile.Lock()
|
r.lockfile.Lock()
|
||||||
}
|
}
|
||||||
|
@ -822,6 +1025,10 @@ func (r *layerStore) Modified() (bool, error) {
|
||||||
return r.lockfile.Modified()
|
return r.lockfile.Modified()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *layerStore) IsReadWrite() bool {
|
||||||
|
return r.lockfile.IsReadWrite()
|
||||||
|
}
|
||||||
|
|
||||||
func (r *layerStore) TouchedSince(when time.Time) bool {
|
func (r *layerStore) TouchedSince(when time.Time) bool {
|
||||||
return r.lockfile.TouchedSince(when)
|
return r.lockfile.TouchedSince(when)
|
||||||
}
|
}
|
||||||
|
|
73
vendor/github.com/containers/storage/lockfile.go
generated
vendored
73
vendor/github.com/containers/storage/lockfile.go
generated
vendored
|
@ -1,14 +1,15 @@
|
||||||
package storage
|
package storage
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"golang.org/x/sys/unix"
|
|
||||||
|
|
||||||
"github.com/containers/storage/pkg/stringid"
|
"github.com/containers/storage/pkg/stringid"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
// A Locker represents a file lock where the file is used to cache an
|
// A Locker represents a file lock where the file is used to cache an
|
||||||
|
@ -27,43 +28,80 @@ type Locker interface {
|
||||||
|
|
||||||
// TouchedSince() checks if the most recent writer modified the file (likely using Touch()) after the specified time.
|
// TouchedSince() checks if the most recent writer modified the file (likely using Touch()) after the specified time.
|
||||||
TouchedSince(when time.Time) bool
|
TouchedSince(when time.Time) bool
|
||||||
|
|
||||||
|
// IsReadWrite() checks if the lock file is read-write
|
||||||
|
IsReadWrite() bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type lockfile struct {
|
type lockfile struct {
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
file string
|
file string
|
||||||
fd uintptr
|
fd uintptr
|
||||||
lw string
|
lw string
|
||||||
|
locktype int16
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
lockfiles map[string]*lockfile
|
lockfiles map[string]*lockfile
|
||||||
lockfilesLock sync.Mutex
|
lockfilesLock sync.Mutex
|
||||||
|
// ErrLockReadOnly indicates that the caller only took a read-only lock, and is not allowed to write
|
||||||
|
ErrLockReadOnly = errors.New("lock is not a read-write lock")
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetLockfile opens a lock file, creating it if necessary. The Locker object
|
// GetLockfile opens a read-write lock file, creating it if necessary. The
|
||||||
// return will be returned unlocked.
|
// Locker object it returns will be returned unlocked.
|
||||||
func GetLockfile(path string) (Locker, error) {
|
func GetLockfile(path string) (Locker, error) {
|
||||||
lockfilesLock.Lock()
|
lockfilesLock.Lock()
|
||||||
defer lockfilesLock.Unlock()
|
defer lockfilesLock.Unlock()
|
||||||
if lockfiles == nil {
|
if lockfiles == nil {
|
||||||
lockfiles = make(map[string]*lockfile)
|
lockfiles = make(map[string]*lockfile)
|
||||||
}
|
}
|
||||||
if locker, ok := lockfiles[filepath.Clean(path)]; ok {
|
cleanPath := filepath.Clean(path)
|
||||||
|
if locker, ok := lockfiles[cleanPath]; ok {
|
||||||
|
if !locker.IsReadWrite() {
|
||||||
|
return nil, errors.Wrapf(ErrLockReadOnly, "lock %q is a read-only lock", cleanPath)
|
||||||
|
}
|
||||||
return locker, nil
|
return locker, nil
|
||||||
}
|
}
|
||||||
fd, err := unix.Open(filepath.Clean(path), os.O_RDWR|os.O_CREATE, unix.S_IRUSR|unix.S_IWUSR)
|
fd, err := unix.Open(cleanPath, os.O_RDWR|os.O_CREATE, unix.S_IRUSR|unix.S_IWUSR)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, errors.Wrapf(err, "error opening %q", cleanPath)
|
||||||
}
|
}
|
||||||
locker := &lockfile{file: path, fd: uintptr(fd), lw: stringid.GenerateRandomID()}
|
unix.CloseOnExec(fd)
|
||||||
|
locker := &lockfile{file: path, fd: uintptr(fd), lw: stringid.GenerateRandomID(), locktype: unix.F_WRLCK}
|
||||||
lockfiles[filepath.Clean(path)] = locker
|
lockfiles[filepath.Clean(path)] = locker
|
||||||
return locker, nil
|
return locker, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetROLockfile opens a read-only lock file. The Locker object it returns
|
||||||
|
// will be returned unlocked.
|
||||||
|
func GetROLockfile(path string) (Locker, error) {
|
||||||
|
lockfilesLock.Lock()
|
||||||
|
defer lockfilesLock.Unlock()
|
||||||
|
if lockfiles == nil {
|
||||||
|
lockfiles = make(map[string]*lockfile)
|
||||||
|
}
|
||||||
|
cleanPath := filepath.Clean(path)
|
||||||
|
if locker, ok := lockfiles[cleanPath]; ok {
|
||||||
|
if locker.IsReadWrite() {
|
||||||
|
return nil, fmt.Errorf("lock %q is a read-write lock", cleanPath)
|
||||||
|
}
|
||||||
|
return locker, nil
|
||||||
|
}
|
||||||
|
fd, err := unix.Open(cleanPath, os.O_RDONLY, 0)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(err, "error opening %q", cleanPath)
|
||||||
|
}
|
||||||
|
unix.CloseOnExec(fd)
|
||||||
|
locker := &lockfile{file: path, fd: uintptr(fd), lw: stringid.GenerateRandomID(), locktype: unix.F_RDLCK}
|
||||||
|
lockfiles[filepath.Clean(path)] = locker
|
||||||
|
return locker, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Lock locks the lock file
|
||||||
func (l *lockfile) Lock() {
|
func (l *lockfile) Lock() {
|
||||||
lk := unix.Flock_t{
|
lk := unix.Flock_t{
|
||||||
Type: unix.F_WRLCK,
|
Type: l.locktype,
|
||||||
Whence: int16(os.SEEK_SET),
|
Whence: int16(os.SEEK_SET),
|
||||||
Start: 0,
|
Start: 0,
|
||||||
Len: 0,
|
Len: 0,
|
||||||
|
@ -75,6 +113,7 @@ func (l *lockfile) Lock() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Unlock unlocks the lock file
|
||||||
func (l *lockfile) Unlock() {
|
func (l *lockfile) Unlock() {
|
||||||
lk := unix.Flock_t{
|
lk := unix.Flock_t{
|
||||||
Type: unix.F_UNLCK,
|
Type: unix.F_UNLCK,
|
||||||
|
@ -89,6 +128,7 @@ func (l *lockfile) Unlock() {
|
||||||
l.mu.Unlock()
|
l.mu.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Touch updates the lock file with the UID of the user
|
||||||
func (l *lockfile) Touch() error {
|
func (l *lockfile) Touch() error {
|
||||||
l.lw = stringid.GenerateRandomID()
|
l.lw = stringid.GenerateRandomID()
|
||||||
id := []byte(l.lw)
|
id := []byte(l.lw)
|
||||||
|
@ -110,6 +150,7 @@ func (l *lockfile) Touch() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Modified indicates if the lock file has been updated since the last time it was loaded
|
||||||
func (l *lockfile) Modified() (bool, error) {
|
func (l *lockfile) Modified() (bool, error) {
|
||||||
id := []byte(l.lw)
|
id := []byte(l.lw)
|
||||||
_, err := unix.Seek(int(l.fd), 0, os.SEEK_SET)
|
_, err := unix.Seek(int(l.fd), 0, os.SEEK_SET)
|
||||||
|
@ -128,6 +169,7 @@ func (l *lockfile) Modified() (bool, error) {
|
||||||
return l.lw != lw, nil
|
return l.lw != lw, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TouchedSince indicates if the lock file has been touched since the specified time
|
||||||
func (l *lockfile) TouchedSince(when time.Time) bool {
|
func (l *lockfile) TouchedSince(when time.Time) bool {
|
||||||
st := unix.Stat_t{}
|
st := unix.Stat_t{}
|
||||||
err := unix.Fstat(int(l.fd), &st)
|
err := unix.Fstat(int(l.fd), &st)
|
||||||
|
@ -137,3 +179,8 @@ func (l *lockfile) TouchedSince(when time.Time) bool {
|
||||||
touched := time.Unix(statTMtimeUnix(st))
|
touched := time.Unix(statTMtimeUnix(st))
|
||||||
return when.Before(touched)
|
return when.Before(touched)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsRWLock indicates if the lock file is a read-write lock
|
||||||
|
func (l *lockfile) IsReadWrite() bool {
|
||||||
|
return (l.locktype == unix.F_WRLCK)
|
||||||
|
}
|
||||||
|
|
97
vendor/github.com/containers/storage/pkg/archive/example_changes.go
generated
vendored
Normal file
97
vendor/github.com/containers/storage/pkg/archive/example_changes.go
generated
vendored
Normal file
|
@ -0,0 +1,97 @@
|
||||||
|
// +build ignore
|
||||||
|
|
||||||
|
// Simple tool to create an archive stream from an old and new directory
|
||||||
|
//
|
||||||
|
// By default it will stream the comparison of two temporary directories with junk files
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
|
||||||
|
"github.com/Sirupsen/logrus"
|
||||||
|
"github.com/containers/storage/pkg/archive"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
flDebug = flag.Bool("D", false, "debugging output")
|
||||||
|
flNewDir = flag.String("newdir", "", "")
|
||||||
|
flOldDir = flag.String("olddir", "", "")
|
||||||
|
log = logrus.New()
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
flag.Usage = func() {
|
||||||
|
fmt.Println("Produce a tar from comparing two directory paths. By default a demo tar is created of around 200 files (including hardlinks)")
|
||||||
|
fmt.Printf("%s [OPTIONS]\n", os.Args[0])
|
||||||
|
flag.PrintDefaults()
|
||||||
|
}
|
||||||
|
flag.Parse()
|
||||||
|
log.Out = os.Stderr
|
||||||
|
if (len(os.Getenv("DEBUG")) > 0) || *flDebug {
|
||||||
|
logrus.SetLevel(logrus.DebugLevel)
|
||||||
|
}
|
||||||
|
var newDir, oldDir string
|
||||||
|
|
||||||
|
if len(*flNewDir) == 0 {
|
||||||
|
var err error
|
||||||
|
newDir, err = ioutil.TempDir("", "storage-test-newDir")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(newDir)
|
||||||
|
if _, err := prepareUntarSourceDirectory(100, newDir, true); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
newDir = *flNewDir
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(*flOldDir) == 0 {
|
||||||
|
oldDir, err := ioutil.TempDir("", "storage-test-oldDir")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(oldDir)
|
||||||
|
} else {
|
||||||
|
oldDir = *flOldDir
|
||||||
|
}
|
||||||
|
|
||||||
|
changes, err := archive.ChangesDirs(newDir, oldDir)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
a, err := archive.ExportChanges(newDir, changes)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
defer a.Close()
|
||||||
|
|
||||||
|
i, err := io.Copy(os.Stdout, a)
|
||||||
|
if err != nil && err != io.EOF {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
fmt.Fprintf(os.Stderr, "wrote archive of %d bytes", i)
|
||||||
|
}
|
||||||
|
|
||||||
|
func prepareUntarSourceDirectory(numberOfFiles int, targetPath string, makeLinks bool) (int, error) {
|
||||||
|
fileData := []byte("fooo")
|
||||||
|
for n := 0; n < numberOfFiles; n++ {
|
||||||
|
fileName := fmt.Sprintf("file-%d", n)
|
||||||
|
if err := ioutil.WriteFile(path.Join(targetPath, fileName), fileData, 0700); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
if makeLinks {
|
||||||
|
if err := os.Link(path.Join(targetPath, fileName), path.Join(targetPath, fileName+"-link")); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
totalSize := numberOfFiles * len(fileData)
|
||||||
|
return totalSize, nil
|
||||||
|
}
|
24
vendor/github.com/containers/storage/pkg/loopback/attach_loopback.go
generated
vendored
24
vendor/github.com/containers/storage/pkg/loopback/attach_loopback.go
generated
vendored
|
@ -38,7 +38,15 @@ func getNextFreeLoopbackIndex() (int, error) {
|
||||||
return index, err
|
return index, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func openNextAvailableLoopback(index int, sparseFile *os.File) (loopFile *os.File, err error) {
|
func openNextAvailableLoopback(index int, sparseName string, sparseFile *os.File) (loopFile *os.File, err error) {
|
||||||
|
// Read information about the loopback file.
|
||||||
|
var st syscall.Stat_t
|
||||||
|
err = syscall.Fstat(int(sparseFile.Fd()), &st)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Errorf("Error reading information about loopback file %s: %v", sparseName, err)
|
||||||
|
return nil, ErrAttachLoopbackDevice
|
||||||
|
}
|
||||||
|
|
||||||
// Start looking for a free /dev/loop
|
// Start looking for a free /dev/loop
|
||||||
for {
|
for {
|
||||||
target := fmt.Sprintf("/dev/loop%d", index)
|
target := fmt.Sprintf("/dev/loop%d", index)
|
||||||
|
@ -77,6 +85,18 @@ func openNextAvailableLoopback(index int, sparseFile *os.File) (loopFile *os.Fil
|
||||||
// Otherwise, we keep going with the loop
|
// Otherwise, we keep going with the loop
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if the loopback driver and underlying filesystem agree on the loopback file's
|
||||||
|
// device and inode numbers.
|
||||||
|
dev, ino, err := getLoopbackBackingFile(loopFile)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Errorf("Error getting loopback backing file: %s", err)
|
||||||
|
return nil, ErrGetLoopbackBackingFile
|
||||||
|
}
|
||||||
|
if dev != st.Dev || ino != st.Ino {
|
||||||
|
logrus.Errorf("Loopback device and filesystem disagree on device/inode for %q: %#x(%d):%#x(%d) vs %#x(%d):%#x(%d)", sparseName, dev, dev, ino, ino, st.Dev, st.Dev, st.Ino, st.Ino)
|
||||||
|
}
|
||||||
|
|
||||||
// In case of success, we finished. Break the loop.
|
// In case of success, we finished. Break the loop.
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -110,7 +130,7 @@ func AttachLoopDevice(sparseName string) (loop *os.File, err error) {
|
||||||
}
|
}
|
||||||
defer sparseFile.Close()
|
defer sparseFile.Close()
|
||||||
|
|
||||||
loopFile, err := openNextAvailableLoopback(startIndex, sparseFile)
|
loopFile, err := openNextAvailableLoopback(startIndex, sparseName, sparseFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
4
vendor/github.com/containers/storage/pkg/plugins/discovery.go
generated
vendored
4
vendor/github.com/containers/storage/pkg/plugins/discovery.go
generated
vendored
|
@ -15,8 +15,8 @@ import (
|
||||||
var (
|
var (
|
||||||
// ErrNotFound plugin not found
|
// ErrNotFound plugin not found
|
||||||
ErrNotFound = errors.New("plugin not found")
|
ErrNotFound = errors.New("plugin not found")
|
||||||
socketsPath = "/run/oci-storage/plugins"
|
socketsPath = "/run/containers/storage/plugins"
|
||||||
specsPaths = []string{"/etc/oci-storage/plugins", "/usr/lib/oci-storage/plugins"}
|
specsPaths = []string{"/etc/containers/storage/plugins", "/usr/lib/containers/storage/plugins"}
|
||||||
)
|
)
|
||||||
|
|
||||||
// localRegistry defines a registry that is local (using unix socket).
|
// localRegistry defines a registry that is local (using unix socket).
|
||||||
|
|
9
vendor/github.com/containers/storage/pkg/plugins/plugins.go
generated
vendored
9
vendor/github.com/containers/storage/pkg/plugins/plugins.go
generated
vendored
|
@ -3,10 +3,11 @@
|
||||||
//
|
//
|
||||||
// Storage discovers plugins by looking for them in the plugin directory whenever
|
// Storage discovers plugins by looking for them in the plugin directory whenever
|
||||||
// a user or container tries to use one by name. UNIX domain socket files must
|
// a user or container tries to use one by name. UNIX domain socket files must
|
||||||
// be located under /run/oci-storage/plugins, whereas spec files can be located
|
// be located under /run/containers/storage/plugins, whereas spec files can be
|
||||||
// either under /etc/oci-storage/plugins or /usr/lib/oci-storage/plugins. This
|
// located either under /etc/containers/storage/plugins or
|
||||||
// is handled by the Registry interface, which lets you list all plugins or get
|
// /usr/lib/containers/storage/plugins. This is handled by the Registry
|
||||||
// a plugin by its name if it exists.
|
// interface, which lets you list all plugins or get a plugin by its name if it
|
||||||
|
// exists.
|
||||||
//
|
//
|
||||||
// The plugins need to implement an HTTP server and bind this to the UNIX socket
|
// The plugins need to implement an HTTP server and bind this to the UNIX socket
|
||||||
// or the address specified in the spec files.
|
// or the address specified in the spec files.
|
||||||
|
|
13
vendor/github.com/containers/storage/storageversion/version_lib.go
generated
vendored
13
vendor/github.com/containers/storage/storageversion/version_lib.go
generated
vendored
|
@ -1,13 +0,0 @@
|
||||||
// +build !containersstorageautogen
|
|
||||||
|
|
||||||
// Package storageversion is auto-generated at build-time
|
|
||||||
package storageversion
|
|
||||||
|
|
||||||
// Default build-time variable for library-import.
|
|
||||||
// This file is overridden on build with build-time informations.
|
|
||||||
const (
|
|
||||||
GitCommit string = "library-import"
|
|
||||||
Version string = "library-import"
|
|
||||||
BuildTime string = "library-import"
|
|
||||||
IAmStatic string = "library-import"
|
|
||||||
)
|
|
1330
vendor/github.com/containers/storage/store.go
generated
vendored
1330
vendor/github.com/containers/storage/store.go
generated
vendored
File diff suppressed because it is too large
Load diff
3
vendor/github.com/containers/storage/vendor.conf
generated
vendored
3
vendor/github.com/containers/storage/vendor.conf
generated
vendored
|
@ -1,3 +1,4 @@
|
||||||
|
github.com/BurntSushi/toml master
|
||||||
github.com/Microsoft/go-winio 307e919c663683a9000576fdc855acaf9534c165
|
github.com/Microsoft/go-winio 307e919c663683a9000576fdc855acaf9534c165
|
||||||
github.com/Microsoft/hcsshim 0f615c198a84e0344b4ed49c464d8833d4648dfc
|
github.com/Microsoft/hcsshim 0f615c198a84e0344b4ed49c464d8833d4648dfc
|
||||||
github.com/Sirupsen/logrus 61e43dc76f7ee59a82bdf3d71033dc12bea4c77d
|
github.com/Sirupsen/logrus 61e43dc76f7ee59a82bdf3d71033dc12bea4c77d
|
||||||
|
@ -7,9 +8,11 @@ github.com/docker/go-units 0dadbb0345b35ec7ef35e228dabb8de89a65bf52
|
||||||
github.com/go-check/check 20d25e2804050c1cd24a7eea1e7a6447dd0e74ec
|
github.com/go-check/check 20d25e2804050c1cd24a7eea1e7a6447dd0e74ec
|
||||||
github.com/mattn/go-shellwords 753a2322a99f87c0eff284980e77f53041555bc6
|
github.com/mattn/go-shellwords 753a2322a99f87c0eff284980e77f53041555bc6
|
||||||
github.com/mistifyio/go-zfs c0224de804d438efd11ea6e52ada8014537d6062
|
github.com/mistifyio/go-zfs c0224de804d438efd11ea6e52ada8014537d6062
|
||||||
|
github.com/opencontainers/go-digest master
|
||||||
github.com/opencontainers/runc 6c22e77604689db8725fa866f0f2ec0b3e8c3a07
|
github.com/opencontainers/runc 6c22e77604689db8725fa866f0f2ec0b3e8c3a07
|
||||||
github.com/opencontainers/selinux ba1aefe8057f1d0cfb8e88d0ec1dc85925ef987d
|
github.com/opencontainers/selinux ba1aefe8057f1d0cfb8e88d0ec1dc85925ef987d
|
||||||
github.com/pborman/uuid 1b00554d822231195d1babd97ff4a781231955c9
|
github.com/pborman/uuid 1b00554d822231195d1babd97ff4a781231955c9
|
||||||
|
github.com/pkg/errors master
|
||||||
github.com/tchap/go-patricia v2.2.6
|
github.com/tchap/go-patricia v2.2.6
|
||||||
github.com/vbatts/tar-split bd4c5d64c3e9297f410025a3b1bd0c58f659e721
|
github.com/vbatts/tar-split bd4c5d64c3e9297f410025a3b1bd0c58f659e721
|
||||||
github.com/vdemeester/shakers 24d7f1d6a71aa5d9cbe7390e4afb66b7eef9e1b3
|
github.com/vdemeester/shakers 24d7f1d6a71aa5d9cbe7390e4afb66b7eef9e1b3
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue