1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Add metadata function to layer store

Add function to get metadata from layer store for a mutable layer

fixes #18614

Signed-off-by: Derek McGowan <derek@mcgstyle.net> (github: dmcgowan)
This commit is contained in:
Derek McGowan 2015-12-14 16:52:15 -08:00
parent 03e2923e42
commit a7e0968321
7 changed files with 23 additions and 31 deletions

View file

@ -92,7 +92,7 @@ func (daemon *Daemon) populateCommand(c *container.Container, env []string) erro
} }
} }
m, err := layer.RWLayerMetadata(daemon.layerStore, c.ID) m, err := daemon.layerStore.Metadata(c.ID)
if err != nil { if err != nil {
return derr.ErrorCodeGetLayerMetadata.WithArgs(err) return derr.ErrorCodeGetLayerMetadata.WithArgs(err)
} }

View file

@ -10,7 +10,6 @@ import (
"github.com/docker/docker/container" "github.com/docker/docker/container"
"github.com/docker/docker/daemon/exec" "github.com/docker/docker/daemon/exec"
"github.com/docker/docker/daemon/network" "github.com/docker/docker/daemon/network"
"github.com/docker/docker/layer"
"github.com/docker/docker/pkg/version" "github.com/docker/docker/pkg/version"
) )
@ -164,17 +163,7 @@ func (daemon *Daemon) getInspectData(container *container.Container, size bool)
contJSONBase.GraphDriver.Name = container.Driver contJSONBase.GraphDriver.Name = container.Driver
image, err := daemon.imageStore.Get(container.ImageID) graphDriverData, err := daemon.layerStore.Metadata(container.ID)
if err != nil {
return nil, err
}
l, err := daemon.layerStore.Get(image.RootFS.ChainID())
if err != nil {
return nil, err
}
defer layer.ReleaseAndLog(daemon.layerStore, l)
graphDriverData, err := l.Metadata()
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -132,6 +132,10 @@ func (ls *mockLayerStore) Changes(id string) ([]archive.Change, error) {
return nil, errors.New("not implemented") return nil, errors.New("not implemented")
} }
func (ls *mockLayerStore) Metadata(id string) (map[string]string, error) {
return nil, errors.New("not implemented")
}
type mockDownloadDescriptor struct { type mockDownloadDescriptor struct {
currentDownloads *int32 currentDownloads *int32
id string id string

View file

@ -209,9 +209,14 @@ func (s *DockerSuite) TestInspectContainerGraphDriver(c *check.C) {
return return
} }
imageDeviceID, err := inspectField("busybox", "GraphDriver.Data.DeviceId")
c.Assert(err, checker.IsNil)
deviceID, err := inspectField(out, "GraphDriver.Data.DeviceId") deviceID, err := inspectField(out, "GraphDriver.Data.DeviceId")
c.Assert(err, checker.IsNil) c.Assert(err, checker.IsNil)
c.Assert(imageDeviceID, checker.Not(checker.Equals), deviceID)
_, err = strconv.Atoi(deviceID) _, err = strconv.Atoi(deviceID)
c.Assert(err, checker.IsNil, check.Commentf("failed to inspect DeviceId of the image: %s, %v", deviceID, err)) c.Assert(err, checker.IsNil, check.Commentf("failed to inspect DeviceId of the image: %s, %v", deviceID, err))

View file

@ -151,6 +151,7 @@ type Store interface {
Unmount(id string) error Unmount(id string) error
DeleteMount(id string) ([]Metadata, error) DeleteMount(id string) ([]Metadata, error)
Changes(id string) ([]archive.Change, error) Changes(id string) ([]archive.Change, error)
Metadata(id string) (map[string]string, error)
} }
// MetadataTransaction represents functions for setting layer metadata // MetadataTransaction represents functions for setting layer metadata

View file

@ -621,6 +621,17 @@ func (ls *layerStore) assembleTar(graphID string, metadata io.ReadCloser, size *
return pR, nil return pR, nil
} }
// Metadata returns the low level metadata from the mount with the given name
func (ls *layerStore) Metadata(name string) (map[string]string, error) {
ls.mountL.Lock()
m := ls.mounts[name]
ls.mountL.Unlock()
if m == nil {
return nil, ErrMountDoesNotExist
}
return ls.driver.GetMetadata(m.mountID)
}
type naiveDiffPathDriver struct { type naiveDiffPathDriver struct {
graphdriver.Driver graphdriver.Driver
} }

View file

@ -34,24 +34,6 @@ func GetLayerPath(s Store, layer ChainID) (string, error) {
return path, nil return path, nil
} }
// RWLayerMetadata returns the graph metadata for the provided
// mount name.
func RWLayerMetadata(s Store, name string) (map[string]string, error) {
ls, ok := s.(*layerStore)
if !ok {
return nil, errors.New("unsupported layer store")
}
ls.mountL.Lock()
defer ls.mountL.Unlock()
ml, ok := ls.mounts[name]
if !ok {
return nil, errors.New("mount does not exist")
}
return ls.driver.GetMetadata(ml.mountID)
}
func (ls *layerStore) RegisterDiffID(graphID string, size int64) (Layer, error) { func (ls *layerStore) RegisterDiffID(graphID string, size int64) (Layer, error) {
var err error // this is used for cleanup in existingLayer case var err error // this is used for cleanup in existingLayer case
diffID, err := digest.FromBytes([]byte(graphID)) diffID, err := digest.FromBytes([]byte(graphID))