Skip to content

Commit

Permalink
Add metadata function to layer store
Browse files Browse the repository at this point in the history
Add function to get metadata from layer store for a mutable layer

fixes moby#18614

Signed-off-by: Derek McGowan <[email protected]> (github: dmcgowan)
  • Loading branch information
dmcgowan committed Dec 15, 2015
1 parent 03e2923 commit a7e0968
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 31 deletions.
2 changes: 1 addition & 1 deletion daemon/container_operations_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
return derr.ErrorCodeGetLayerMetadata.WithArgs(err)
}
Expand Down
13 changes: 1 addition & 12 deletions daemon/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/docker/docker/container"
"github.com/docker/docker/daemon/exec"
"github.com/docker/docker/daemon/network"
"github.com/docker/docker/layer"
"github.com/docker/docker/pkg/version"
)

Expand Down Expand Up @@ -164,17 +163,7 @@ func (daemon *Daemon) getInspectData(container *container.Container, size bool)

contJSONBase.GraphDriver.Name = container.Driver

image, err := daemon.imageStore.Get(container.ImageID)
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()
graphDriverData, err := daemon.layerStore.Metadata(container.ID)
if err != nil {
return nil, err
}
Expand Down
4 changes: 4 additions & 0 deletions distribution/xfer/download_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ func (ls *mockLayerStore) Changes(id string) ([]archive.Change, error) {
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 {
currentDownloads *int32
id string
Expand Down
5 changes: 5 additions & 0 deletions integration-cli/docker_cli_inspect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,14 @@ func (s *DockerSuite) TestInspectContainerGraphDriver(c *check.C) {
return
}

imageDeviceID, err := inspectField("busybox", "GraphDriver.Data.DeviceId")
c.Assert(err, checker.IsNil)

deviceID, err := inspectField(out, "GraphDriver.Data.DeviceId")
c.Assert(err, checker.IsNil)

c.Assert(imageDeviceID, checker.Not(checker.Equals), deviceID)

_, err = strconv.Atoi(deviceID)
c.Assert(err, checker.IsNil, check.Commentf("failed to inspect DeviceId of the image: %s, %v", deviceID, err))

Expand Down
1 change: 1 addition & 0 deletions layer/layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ type Store interface {
Unmount(id string) error
DeleteMount(id string) ([]Metadata, error)
Changes(id string) ([]archive.Change, error)
Metadata(id string) (map[string]string, error)
}

// MetadataTransaction represents functions for setting layer metadata
Expand Down
11 changes: 11 additions & 0 deletions layer/layer_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,17 @@ func (ls *layerStore) assembleTar(graphID string, metadata io.ReadCloser, size *
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 {
graphdriver.Driver
}
Expand Down
18 changes: 0 additions & 18 deletions layer/layer_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,6 @@ func GetLayerPath(s Store, layer ChainID) (string, error) {
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) {
var err error // this is used for cleanup in existingLayer case
diffID, err := digest.FromBytes([]byte(graphID))
Expand Down

0 comments on commit a7e0968

Please sign in to comment.