Skip to content

Commit

Permalink
remove layerstore indexing by OS (used for LCOW)
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastiaan van Stijn <[email protected]>
  • Loading branch information
thaJeztah committed Jun 10, 2021
1 parent b7b7571 commit dc7cbb9
Show file tree
Hide file tree
Showing 27 changed files with 124 additions and 214 deletions.
2 changes: 1 addition & 1 deletion daemon/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (daemon *Daemon) newContainer(name string, operatingSystem string, config *
base.ImageID = imgID
base.NetworkSettings = &network.Settings{IsAnonymousEndpoint: noExplicitName}
base.Name = name
base.Driver = daemon.imageService.GraphDriverForOS(operatingSystem)
base.Driver = daemon.imageService.GraphDriverName()
base.OS = operatingSystem
return base, err
}
Expand Down
13 changes: 5 additions & 8 deletions daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func (daemon *Daemon) restore() error {
}
// Ignore the container if it does not support the current driver being used by the graph
if (c.Driver == "" && daemon.graphDriver == "aufs") || c.Driver == daemon.graphDriver {
rwlayer, err := daemon.imageService.GetLayerByID(c.ID, c.OS)
rwlayer, err := daemon.imageService.GetLayerByID(c.ID)
if err != nil {
log.WithError(err).Error("failed to load container mount")
return
Expand Down Expand Up @@ -1003,10 +1003,7 @@ func NewDaemon(ctx context.Context, config *config.Config, pluginStore *plugin.S
return nil, err
}

// TODO remove multiple imagestores map now that LCOW is no more
imageStore, err := image.NewImageStore(ifs, map[string]image.LayerGetReleaser{
runtime.GOOS: layerStore,
})
imageStore, err := image.NewImageStore(ifs, layerStore)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1084,7 +1081,7 @@ func NewDaemon(ctx context.Context, config *config.Config, pluginStore *plugin.S
DistributionMetadataStore: distributionMetadataStore,
EventsService: d.EventsService,
ImageStore: imageStore,
LayerStores: map[string]layer.Store{runtime.GOOS: layerStore}, // TODO remove multiple LayerStores map now that LCOW is no more
LayerStore: layerStore,
MaxConcurrentDownloads: *config.MaxConcurrentDownloads,
MaxConcurrentUploads: *config.MaxConcurrentUploads,
MaxDownloadAttempts: *config.MaxDownloadAttempts,
Expand Down Expand Up @@ -1231,7 +1228,7 @@ func (daemon *Daemon) Shutdown() error {
log.WithError(err).Error("failed to shut down container")
return
}
if mountid, err := daemon.imageService.GetLayerMountID(c.ID, c.OS); err == nil {
if mountid, err := daemon.imageService.GetLayerMountID(c.ID); err == nil {
daemon.cleanupMountsByID(mountid)
}
log.Debugf("shut down container")
Expand Down Expand Up @@ -1294,7 +1291,7 @@ func (daemon *Daemon) Mount(container *container.Container) error {
if runtime.GOOS != "windows" {
daemon.Unmount(container)
return fmt.Errorf("Error: driver %s is returning inconsistent paths for container %s ('%s' then '%s')",
daemon.imageService.GraphDriverForOS(container.OS), container.ID, container.BaseFS, dir)
daemon.imageService.GraphDriverName(), container.ID, container.BaseFS, dir)
}
}
container.BaseFS = dir // TODO: combine these fields
Expand Down
2 changes: 1 addition & 1 deletion daemon/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (daemon *Daemon) containerExport(container *container.Container) (arch io.R
if !system.IsOSSupported(container.OS) {
return nil, fmt.Errorf("cannot export %s: %s ", container.ID, system.ErrNotSupportedOperatingSystem)
}
rwlayer, err := daemon.imageService.GetLayerByID(container.ID, container.OS)
rwlayer, err := daemon.imageService.GetLayerByID(container.ID)
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions daemon/images/image_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func (i *ImageService) GetImageAndReleasableLayer(ctx context.Context, refOrID s
if !system.IsOSSupported(os) {
return nil, nil, system.ErrNotSupportedOperatingSystem
}
layer, err := newROLayerForImage(nil, i.layerStores[os])
layer, err := newROLayerForImage(nil, i.layerStore)
return nil, layer, err
}

Expand All @@ -220,7 +220,7 @@ func (i *ImageService) GetImageAndReleasableLayer(ctx context.Context, refOrID s
if !system.IsOSSupported(image.OperatingSystem()) {
return nil, nil, system.ErrNotSupportedOperatingSystem
}
layer, err := newROLayerForImage(image, i.layerStores[image.OperatingSystem()])
layer, err := newROLayerForImage(image, i.layerStore)
return image, layer, err
}
}
Expand All @@ -232,7 +232,7 @@ func (i *ImageService) GetImageAndReleasableLayer(ctx context.Context, refOrID s
if !system.IsOSSupported(image.OperatingSystem()) {
return nil, nil, system.ErrNotSupportedOperatingSystem
}
layer, err := newROLayerForImage(image, i.layerStores[image.OperatingSystem()])
layer, err := newROLayerForImage(image, i.layerStore)
return image, layer, err
}

Expand Down
11 changes: 3 additions & 8 deletions daemon/images/image_commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,12 @@ import (
"github.com/docker/docker/image"
"github.com/docker/docker/layer"
"github.com/docker/docker/pkg/ioutils"
"github.com/docker/docker/pkg/system"
"github.com/pkg/errors"
)

// CommitImage creates a new image from a commit config
func (i *ImageService) CommitImage(c backend.CommitConfig) (image.ID, error) {
layerStore, ok := i.layerStores[c.ContainerOS]
if !ok {
return "", system.ErrNotSupportedOperatingSystem
}
rwTar, err := exportContainerRw(layerStore, c.ContainerID, c.ContainerMountLabel)
rwTar, err := exportContainerRw(i.layerStore, c.ContainerID, c.ContainerMountLabel)
if err != nil {
return "", err
}
Expand All @@ -39,11 +34,11 @@ func (i *ImageService) CommitImage(c backend.CommitConfig) (image.ID, error) {
}
}

l, err := layerStore.Register(rwTar, parent.RootFS.ChainID())
l, err := i.layerStore.Register(rwTar, parent.RootFS.ChainID())
if err != nil {
return "", err
}
defer layer.ReleaseAndLog(layerStore, l)
defer layer.ReleaseAndLog(i.layerStore, l)

cc := image.ChildConfig{
ContainerID: c.ContainerID,
Expand Down
4 changes: 2 additions & 2 deletions daemon/images/image_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import (
// the same tag are exported. names is the set of tags to export, and
// outStream is the writer which the images are written to.
func (i *ImageService) ExportImage(names []string, outStream io.Writer) error {
imageExporter := tarexport.NewTarExporter(i.imageStore, i.layerStores, i.referenceStore, i)
imageExporter := tarexport.NewTarExporter(i.imageStore, i.layerStore, i.referenceStore, i)
return imageExporter.Save(names, outStream)
}

// LoadImage uploads a set of images into the repository. This is the
// complement of ExportImage. The input stream is an uncompressed tar
// ball containing images and metadata.
func (i *ImageService) LoadImage(inTar io.ReadCloser, outStream io.Writer, quiet bool) error {
imageExporter := tarexport.NewTarExporter(i.imageStore, i.layerStores, i.referenceStore, i)
imageExporter := tarexport.NewTarExporter(i.imageStore, i.layerStore, i.referenceStore, i)
return imageExporter.Load(inTar, outStream, quiet)
}
4 changes: 2 additions & 2 deletions daemon/images/image_history.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ func (i *ImageService) ImageHistory(name string) ([]*image.HistoryResponseItem,
return nil, system.ErrNotSupportedOperatingSystem
}
rootFS.Append(img.RootFS.DiffIDs[layerCounter])
l, err := i.layerStores[img.OperatingSystem()].Get(rootFS.ChainID())
l, err := i.layerStore.Get(rootFS.ChainID())
if err != nil {
return nil, err
}
layerSize, err = l.DiffSize()
layer.ReleaseAndLog(i.layerStores[img.OperatingSystem()], l)
layer.ReleaseAndLog(i.layerStore, l)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions daemon/images/image_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ func (i *ImageService) ImportImage(src string, repository, os string, tag string
if err != nil {
return err
}
l, err := i.layerStores[os].Register(inflatedLayerData, "")
l, err := i.layerStore.Register(inflatedLayerData, "")
if err != nil {
return err
}
defer layer.ReleaseAndLog(i.layerStores[os], l)
defer layer.ReleaseAndLog(i.layerStore, l)

created := time.Now().UTC()
imgConfig, err := json.Marshal(&image.Image{
Expand Down
6 changes: 3 additions & 3 deletions daemon/images/image_inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ func (i *ImageService) LookupImage(name string) (*types.ImageInspect, error) {
var layerMetadata map[string]string
layerID := img.RootFS.ChainID()
if layerID != "" {
l, err := i.layerStores[img.OperatingSystem()].Get(layerID)
l, err := i.layerStore.Get(layerID)
if err != nil {
return nil, err
}
defer layer.ReleaseAndLog(i.layerStores[img.OperatingSystem()], l)
defer layer.ReleaseAndLog(i.layerStore, l)
size, err = l.Size()
if err != nil {
return nil, err
Expand Down Expand Up @@ -87,7 +87,7 @@ func (i *ImageService) LookupImage(name string) (*types.ImageInspect, error) {
},
}

imageInspect.GraphDriver.Name = i.layerStores[img.OperatingSystem()].DriverName()
imageInspect.GraphDriver.Name = i.layerStore.DriverName()
imageInspect.GraphDriver.Data = layerMetadata

return imageInspect, nil
Expand Down
7 changes: 1 addition & 6 deletions daemon/images/image_prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,7 @@ func (i *ImageService) ImagesPrune(ctx context.Context, pruneFilters filters.Arg
}

// Filter intermediary images and get their unique size
allLayers := make(map[layer.ChainID]layer.Layer)
for _, ls := range i.layerStores {
for k, v := range ls.Map() {
allLayers[k] = v
}
}
allLayers := i.layerStore.Map()
topImages := map[image.ID]*image.Image{}
for id, img := range allImages {
select {
Expand Down
2 changes: 1 addition & 1 deletion daemon/images/image_push.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (i *ImageService) PushImage(ctx context.Context, image, tag string, metaHea
ReferenceStore: i.referenceStore,
},
ConfigMediaType: schema2.MediaTypeImageConfig,
LayerStores: distribution.NewLayerProvidersFromStores(i.layerStores),
LayerStores: distribution.NewLayerProvidersFromStore(i.layerStore),
TrustKey: i.trustKey,
UploadManager: i.uploadManager,
}
Expand Down
8 changes: 3 additions & 5 deletions daemon/images/image_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
package images // import "github.com/docker/docker/daemon/images"

import (
"runtime"

"github.com/sirupsen/logrus"
)

Expand All @@ -17,17 +15,17 @@ func (i *ImageService) GetContainerLayerSize(containerID string) (int64, int64)

// Safe to index by runtime.GOOS as Unix hosts don't support multiple
// container operating systems.
rwlayer, err := i.layerStores[runtime.GOOS].GetRWLayer(containerID)
rwlayer, err := i.layerStore.GetRWLayer(containerID)
if err != nil {
logrus.Errorf("Failed to compute size of container rootfs %v: %v", containerID, err)
return sizeRw, sizeRootfs
}
defer i.layerStores[runtime.GOOS].ReleaseRWLayer(rwlayer)
defer i.layerStore.ReleaseRWLayer(rwlayer)

sizeRw, err = rwlayer.Size()
if err != nil {
logrus.Errorf("Driver %s couldn't return diff size of container %s: %s",
i.layerStores[runtime.GOOS].DriverName(), containerID, err)
i.layerStore.DriverName(), containerID, err)
// FIXME: GetSize should return an error. Not changing it now in case
// there is a side-effect.
sizeRw = -1
Expand Down
4 changes: 2 additions & 2 deletions daemon/images/image_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ func (i *ImageService) GetLayerFolders(img *image.Image, rwLayer layer.RWLayer)
if !system.IsOSSupported(img.OperatingSystem()) {
return nil, errors.Wrapf(system.ErrNotSupportedOperatingSystem, "cannot get layerpath for ImageID %s", img.RootFS.ChainID())
}
layerPath, err := layer.GetLayerPath(i.layerStores[img.OperatingSystem()], img.RootFS.ChainID())
layerPath, err := layer.GetLayerPath(i.layerStore, img.RootFS.ChainID())
if err != nil {
return nil, errors.Wrapf(err, "failed to get layer path from graphdriver %s for ImageID %s", i.layerStores[img.OperatingSystem()], img.RootFS.ChainID())
return nil, errors.Wrapf(err, "failed to get layer path from graphdriver %s for ImageID %s", i.layerStore, img.RootFS.ChainID())
}
// Reverse order, expecting parent first
folders = append([]string{layerPath}, folders...)
Expand Down
22 changes: 7 additions & 15 deletions daemon/images/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (i *ImageService) Images(imageFilters filters.Args, all bool, withExtraAttr
layerID := img.RootFS.ChainID()
var size int64
if layerID != "" {
l, err := i.layerStores[img.OperatingSystem()].Get(layerID)
l, err := i.layerStore.Get(layerID)
if err != nil {
// The layer may have been deleted between the call to `Map()` or
// `Heads()` and the call to `Get()`, so we just ignore this error
Expand All @@ -135,7 +135,7 @@ func (i *ImageService) Images(imageFilters filters.Args, all bool, withExtraAttr
}

size, err = l.Size()
layer.ReleaseAndLog(i.layerStores[img.OperatingSystem()], l)
layer.ReleaseAndLog(i.layerStore, l)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -190,15 +190,7 @@ func (i *ImageService) Images(imageFilters filters.Args, all bool, withExtraAttr
// lazily init variables
if imagesMap == nil {
allContainers = i.containers.List()

// allLayers is built from all layerstores combined
allLayers = make(map[layer.ChainID]layer.Layer)
for _, ls := range i.layerStores {
layers := ls.Map()
for k, v := range layers {
allLayers[k] = v
}
}
allLayers = i.layerStore.Map()
imagesMap = make(map[*image.Image]*types.ImageSummary)
layerRefs = make(map[layer.ChainID]int)
}
Expand Down Expand Up @@ -285,23 +277,23 @@ func (i *ImageService) SquashImage(id, parent string) (string, error) {
if !system.IsOSSupported(img.OperatingSystem()) {
return "", errors.Wrap(err, system.ErrNotSupportedOperatingSystem.Error())
}
l, err := i.layerStores[img.OperatingSystem()].Get(img.RootFS.ChainID())
l, err := i.layerStore.Get(img.RootFS.ChainID())
if err != nil {
return "", errors.Wrap(err, "error getting image layer")
}
defer i.layerStores[img.OperatingSystem()].Release(l)
defer i.layerStore.Release(l)

ts, err := l.TarStreamFrom(parentChainID)
if err != nil {
return "", errors.Wrapf(err, "error getting tar stream to parent")
}
defer ts.Close()

newL, err := i.layerStores[img.OperatingSystem()].Register(ts, parentChainID)
newL, err := i.layerStore.Register(ts, parentChainID)
if err != nil {
return "", errors.Wrap(err, "error registering layer")
}
defer i.layerStores[img.OperatingSystem()].Release(newL)
defer i.layerStore.Release(newL)

newImage := *img
newImage.RootFS = nil
Expand Down
Loading

0 comments on commit dc7cbb9

Please sign in to comment.