Add metadata function to layer store
| ... | ... |
@@ -97,7 +97,7 @@ func (daemon *Daemon) populateCommand(c *container.Container, env []string) erro |
| 97 | 97 |
} |
| 98 | 98 |
} |
| 99 | 99 |
|
| 100 |
- m, err := layer.RWLayerMetadata(daemon.layerStore, c.ID) |
|
| 100 |
+ m, err := daemon.layerStore.Metadata(c.ID) |
|
| 101 | 101 |
if err != nil {
|
| 102 | 102 |
return derr.ErrorCodeGetLayerMetadata.WithArgs(err) |
| 103 | 103 |
} |
| ... | ... |
@@ -10,7 +10,6 @@ import ( |
| 10 | 10 |
"github.com/docker/docker/container" |
| 11 | 11 |
"github.com/docker/docker/daemon/exec" |
| 12 | 12 |
"github.com/docker/docker/daemon/network" |
| 13 |
- "github.com/docker/docker/layer" |
|
| 14 | 13 |
"github.com/docker/docker/pkg/version" |
| 15 | 14 |
) |
| 16 | 15 |
|
| ... | ... |
@@ -164,17 +163,7 @@ func (daemon *Daemon) getInspectData(container *container.Container, size bool) |
| 164 | 164 |
|
| 165 | 165 |
contJSONBase.GraphDriver.Name = container.Driver |
| 166 | 166 |
|
| 167 |
- image, err := daemon.imageStore.Get(container.ImageID) |
|
| 168 |
- if err != nil {
|
|
| 169 |
- return nil, err |
|
| 170 |
- } |
|
| 171 |
- l, err := daemon.layerStore.Get(image.RootFS.ChainID()) |
|
| 172 |
- if err != nil {
|
|
| 173 |
- return nil, err |
|
| 174 |
- } |
|
| 175 |
- defer layer.ReleaseAndLog(daemon.layerStore, l) |
|
| 176 |
- |
|
| 177 |
- graphDriverData, err := l.Metadata() |
|
| 167 |
+ graphDriverData, err := daemon.layerStore.Metadata(container.ID) |
|
| 178 | 168 |
if err != nil {
|
| 179 | 169 |
return nil, err |
| 180 | 170 |
} |
| ... | ... |
@@ -132,6 +132,10 @@ func (ls *mockLayerStore) Changes(id string) ([]archive.Change, error) {
|
| 132 | 132 |
return nil, errors.New("not implemented")
|
| 133 | 133 |
} |
| 134 | 134 |
|
| 135 |
+func (ls *mockLayerStore) Metadata(id string) (map[string]string, error) {
|
|
| 136 |
+ return nil, errors.New("not implemented")
|
|
| 137 |
+} |
|
| 138 |
+ |
|
| 135 | 139 |
type mockDownloadDescriptor struct {
|
| 136 | 140 |
currentDownloads *int32 |
| 137 | 141 |
id string |
| ... | ... |
@@ -209,9 +209,14 @@ func (s *DockerSuite) TestInspectContainerGraphDriver(c *check.C) {
|
| 209 | 209 |
return |
| 210 | 210 |
} |
| 211 | 211 |
|
| 212 |
+ imageDeviceID, err := inspectField("busybox", "GraphDriver.Data.DeviceId")
|
|
| 213 |
+ c.Assert(err, checker.IsNil) |
|
| 214 |
+ |
|
| 212 | 215 |
deviceID, err := inspectField(out, "GraphDriver.Data.DeviceId") |
| 213 | 216 |
c.Assert(err, checker.IsNil) |
| 214 | 217 |
|
| 218 |
+ c.Assert(imageDeviceID, checker.Not(checker.Equals), deviceID) |
|
| 219 |
+ |
|
| 215 | 220 |
_, err = strconv.Atoi(deviceID) |
| 216 | 221 |
c.Assert(err, checker.IsNil, check.Commentf("failed to inspect DeviceId of the image: %s, %v", deviceID, err))
|
| 217 | 222 |
|
| ... | ... |
@@ -151,6 +151,7 @@ type Store interface {
|
| 151 | 151 |
Unmount(id string) error |
| 152 | 152 |
DeleteMount(id string) ([]Metadata, error) |
| 153 | 153 |
Changes(id string) ([]archive.Change, error) |
| 154 |
+ Metadata(id string) (map[string]string, error) |
|
| 154 | 155 |
} |
| 155 | 156 |
|
| 156 | 157 |
// MetadataTransaction represents functions for setting layer metadata |
| ... | ... |
@@ -621,6 +621,17 @@ func (ls *layerStore) assembleTar(graphID string, metadata io.ReadCloser, size * |
| 621 | 621 |
return pR, nil |
| 622 | 622 |
} |
| 623 | 623 |
|
| 624 |
+// Metadata returns the low level metadata from the mount with the given name |
|
| 625 |
+func (ls *layerStore) Metadata(name string) (map[string]string, error) {
|
|
| 626 |
+ ls.mountL.Lock() |
|
| 627 |
+ m := ls.mounts[name] |
|
| 628 |
+ ls.mountL.Unlock() |
|
| 629 |
+ if m == nil {
|
|
| 630 |
+ return nil, ErrMountDoesNotExist |
|
| 631 |
+ } |
|
| 632 |
+ return ls.driver.GetMetadata(m.mountID) |
|
| 633 |
+} |
|
| 634 |
+ |
|
| 624 | 635 |
type naiveDiffPathDriver struct {
|
| 625 | 636 |
graphdriver.Driver |
| 626 | 637 |
} |
| ... | ... |
@@ -34,24 +34,6 @@ func GetLayerPath(s Store, layer ChainID) (string, error) {
|
| 34 | 34 |
return path, nil |
| 35 | 35 |
} |
| 36 | 36 |
|
| 37 |
-// RWLayerMetadata returns the graph metadata for the provided |
|
| 38 |
-// mount name. |
|
| 39 |
-func RWLayerMetadata(s Store, name string) (map[string]string, error) {
|
|
| 40 |
- ls, ok := s.(*layerStore) |
|
| 41 |
- if !ok {
|
|
| 42 |
- return nil, errors.New("unsupported layer store")
|
|
| 43 |
- } |
|
| 44 |
- ls.mountL.Lock() |
|
| 45 |
- defer ls.mountL.Unlock() |
|
| 46 |
- |
|
| 47 |
- ml, ok := ls.mounts[name] |
|
| 48 |
- if !ok {
|
|
| 49 |
- return nil, errors.New("mount does not exist")
|
|
| 50 |
- } |
|
| 51 |
- |
|
| 52 |
- return ls.driver.GetMetadata(ml.mountID) |
|
| 53 |
-} |
|
| 54 |
- |
|
| 55 | 37 |
func (ls *layerStore) RegisterDiffID(graphID string, size int64) (Layer, error) {
|
| 56 | 38 |
var err error // this is used for cleanup in existingLayer case |
| 57 | 39 |
diffID, err := digest.FromBytes([]byte(graphID)) |