Windows: Graph driver implementation
Signed-off-by: John Howard <jhoward@microsoft.com> Upstream-commit: 52f4d09ffb376ffaa6677cb1e0413c6a97f53f24 Component: engine
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package daemon
|
||||
|
||||
import (
|
||||
"github.com/docker/docker/image"
|
||||
"github.com/docker/docker/graph"
|
||||
"github.com/docker/docker/runconfig"
|
||||
)
|
||||
|
||||
@@ -16,7 +16,7 @@ type ContainerCommitConfig struct {
|
||||
|
||||
// Commit creates a new filesystem image from the current state of a container.
|
||||
// The image can optionally be tagged into a repository
|
||||
func (daemon *Daemon) Commit(container *Container, c *ContainerCommitConfig) (*image.Image, error) {
|
||||
func (daemon *Daemon) Commit(container *Container, c *ContainerCommitConfig) (*graph.Image, error) {
|
||||
if c.Pause && !container.IsPaused() {
|
||||
container.Pause()
|
||||
defer container.Unpause()
|
||||
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
"github.com/docker/docker/daemon/logger"
|
||||
"github.com/docker/docker/daemon/logger/jsonfilelog"
|
||||
"github.com/docker/docker/daemon/network"
|
||||
"github.com/docker/docker/image"
|
||||
"github.com/docker/docker/graph"
|
||||
"github.com/docker/docker/pkg/archive"
|
||||
"github.com/docker/docker/pkg/broadcastwriter"
|
||||
"github.com/docker/docker/pkg/fileutils"
|
||||
@@ -259,6 +259,13 @@ func (container *Container) Start() (err error) {
|
||||
if err := container.Mount(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// No-op if non-Windows. Once the container filesystem is mounted,
|
||||
// prepare the layer to boot using the Windows driver.
|
||||
if err := container.PrepareStorage(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := container.initializeNetworking(); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -350,6 +357,10 @@ func (container *Container) cleanup() {
|
||||
|
||||
disableAllActiveLinks(container)
|
||||
|
||||
if err := container.CleanupStorage(); err != nil {
|
||||
logrus.Errorf("%v: Failed to cleanup storage: %v", container.ID, err)
|
||||
}
|
||||
|
||||
if err := container.Unmount(); err != nil {
|
||||
logrus.Errorf("%v: Failed to umount filesystem: %v", container.ID, err)
|
||||
}
|
||||
@@ -573,7 +584,7 @@ func (container *Container) Changes() ([]archive.Change, error) {
|
||||
return container.changes()
|
||||
}
|
||||
|
||||
func (container *Container) GetImage() (*image.Image, error) {
|
||||
func (container *Container) GetImage() (*graph.Image, error) {
|
||||
if container.daemon == nil {
|
||||
return nil, fmt.Errorf("Can't get image of unregistered container")
|
||||
}
|
||||
@@ -666,8 +677,15 @@ func (container *Container) Copy(resource string) (io.ReadCloser, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := container.PrepareStorage(); err != nil {
|
||||
container.Unmount()
|
||||
return nil, err
|
||||
}
|
||||
|
||||
reader := ioutils.NewReadCloserWrapper(archive, func() error {
|
||||
err := archive.Close()
|
||||
container.CleanupStorage()
|
||||
container.UnmountVolumes(true)
|
||||
container.Unmount()
|
||||
return err
|
||||
|
||||
+11
-2
@@ -1,4 +1,4 @@
|
||||
// +build linux
|
||||
// +build !windows
|
||||
|
||||
package daemon
|
||||
|
||||
@@ -23,6 +23,7 @@ import (
|
||||
"github.com/docker/docker/pkg/ioutils"
|
||||
"github.com/docker/docker/pkg/nat"
|
||||
"github.com/docker/docker/pkg/stringid"
|
||||
"github.com/docker/docker/pkg/system"
|
||||
"github.com/docker/docker/pkg/ulimit"
|
||||
"github.com/docker/docker/runconfig"
|
||||
"github.com/docker/docker/utils"
|
||||
@@ -970,7 +971,7 @@ func (container *Container) setupWorkingDirectory() error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(pth, 0755); err != nil {
|
||||
if err := system.MkdirAll(pth, 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -1109,3 +1110,11 @@ func (container *Container) UnmountVolumes(forceSyscall bool) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (container *Container) PrepareStorage() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (container *Container) CleanupStorage() error {
|
||||
return nil
|
||||
}
|
||||
@@ -4,10 +4,14 @@ package daemon
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/docker/daemon/execdriver"
|
||||
"github.com/docker/docker/daemon/graphdriver/windows"
|
||||
"github.com/docker/docker/graph"
|
||||
"github.com/docker/docker/pkg/archive"
|
||||
"github.com/microsoft/hcsshim"
|
||||
)
|
||||
|
||||
// This is deliberately empty on Windows as the default path will be set by
|
||||
@@ -102,6 +106,26 @@ func populateCommand(c *Container, env []string) error {
|
||||
|
||||
processConfig.Env = env
|
||||
|
||||
var layerFolder string
|
||||
var layerPaths []string
|
||||
|
||||
// The following is specific to the Windows driver. We do this to
|
||||
// enable VFS to continue operating for development purposes.
|
||||
if wd, ok := c.daemon.driver.(*windows.WindowsGraphDriver); ok {
|
||||
var err error
|
||||
var img *graph.Image
|
||||
var ids []string
|
||||
|
||||
if img, err = c.daemon.graph.Get(c.ImageID); err != nil {
|
||||
return fmt.Errorf("Failed to graph.Get on ImageID %s - %s", c.ImageID, err)
|
||||
}
|
||||
if ids, err = c.daemon.graph.ParentLayerIds(img); err != nil {
|
||||
return fmt.Errorf("Failed to get parentlayer ids %s", img.ID)
|
||||
}
|
||||
layerPaths = wd.LayerIdsToPaths(ids)
|
||||
layerFolder = filepath.Join(wd.Info().HomeDir, filepath.Base(c.ID))
|
||||
}
|
||||
|
||||
// TODO Windows: Factor out remainder of unused fields.
|
||||
c.command = &execdriver.Command{
|
||||
ID: c.ID,
|
||||
@@ -118,6 +142,8 @@ func populateCommand(c *Container, env []string) error {
|
||||
ProcessLabel: c.GetProcessLabel(),
|
||||
MountLabel: c.GetMountLabel(),
|
||||
FirstStart: !c.HasBeenStartedBefore,
|
||||
LayerFolder: layerFolder,
|
||||
LayerPaths: layerPaths,
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -165,3 +191,33 @@ func (container *Container) DisableLink(name string) {
|
||||
func (container *Container) UnmountVolumes(forceSyscall bool) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (container *Container) PrepareStorage() error {
|
||||
if wd, ok := container.daemon.driver.(*windows.WindowsGraphDriver); ok {
|
||||
// Get list of paths to parent layers.
|
||||
var ids []string
|
||||
if container.ImageID != "" {
|
||||
img, err := container.daemon.graph.Get(container.ImageID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ids, err = container.daemon.graph.ParentLayerIds(img)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err := hcsshim.PrepareLayer(wd.Info(), container.ID, wd.LayerIdsToPaths(ids)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (container *Container) CleanupStorage() error {
|
||||
if wd, ok := container.daemon.driver.(*windows.WindowsGraphDriver); ok {
|
||||
return hcsshim.UnprepareLayer(wd.Info(), container.ID)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/docker/docker/graph"
|
||||
"github.com/docker/docker/image"
|
||||
"github.com/docker/docker/pkg/parsers"
|
||||
"github.com/docker/docker/pkg/stringid"
|
||||
"github.com/docker/docker/runconfig"
|
||||
@@ -47,7 +46,7 @@ func (daemon *Daemon) Create(config *runconfig.Config, hostConfig *runconfig.Hos
|
||||
var (
|
||||
container *Container
|
||||
warnings []string
|
||||
img *image.Image
|
||||
img *graph.Image
|
||||
imgID string
|
||||
err error
|
||||
)
|
||||
|
||||
@@ -23,7 +23,6 @@ import (
|
||||
"github.com/docker/docker/daemon/logger"
|
||||
"github.com/docker/docker/daemon/network"
|
||||
"github.com/docker/docker/graph"
|
||||
"github.com/docker/docker/image"
|
||||
"github.com/docker/docker/pkg/broadcastwriter"
|
||||
"github.com/docker/docker/pkg/fileutils"
|
||||
"github.com/docker/docker/pkg/graphdb"
|
||||
@@ -338,7 +337,7 @@ func (daemon *Daemon) restore() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (daemon *Daemon) mergeAndVerifyConfig(config *runconfig.Config, img *image.Image) error {
|
||||
func (daemon *Daemon) mergeAndVerifyConfig(config *runconfig.Config, img *graph.Image) error {
|
||||
if img != nil && img.Config != nil {
|
||||
if err := runconfig.Merge(config, img.Config); err != nil {
|
||||
return err
|
||||
@@ -879,7 +878,7 @@ func (daemon *Daemon) ContainerGraph() *graphdb.Database {
|
||||
return daemon.containerGraph
|
||||
}
|
||||
|
||||
func (daemon *Daemon) ImageGetCached(imgID string, config *runconfig.Config) (*image.Image, error) {
|
||||
func (daemon *Daemon) ImageGetCached(imgID string, config *runconfig.Config) (*graph.Image, error) {
|
||||
// Retrieve all images
|
||||
images, err := daemon.Graph().Map()
|
||||
if err != nil {
|
||||
@@ -896,7 +895,7 @@ func (daemon *Daemon) ImageGetCached(imgID string, config *runconfig.Config) (*i
|
||||
}
|
||||
|
||||
// Loop on the children of the given image and check the config
|
||||
var match *image.Image
|
||||
var match *graph.Image
|
||||
for elem := range imageMap[imgID] {
|
||||
img, ok := images[elem]
|
||||
if !ok {
|
||||
|
||||
@@ -6,11 +6,14 @@ import (
|
||||
"runtime"
|
||||
"syscall"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/docker/docker/daemon/graphdriver"
|
||||
"github.com/docker/docker/daemon/graphdriver/windows"
|
||||
"github.com/docker/docker/pkg/archive"
|
||||
"github.com/docker/docker/pkg/parsers"
|
||||
"github.com/docker/docker/runconfig"
|
||||
"github.com/docker/libnetwork"
|
||||
"github.com/microsoft/hcsshim"
|
||||
)
|
||||
|
||||
func (daemon *Daemon) Changes(container *Container) ([]archive.Change, error) {
|
||||
@@ -31,8 +34,36 @@ func (daemon *Daemon) createRootfs(container *Container) error {
|
||||
if err := os.Mkdir(container.root, 0700); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := daemon.driver.Create(container.ID, container.ImageID); err != nil {
|
||||
return err
|
||||
|
||||
if wd, ok := daemon.driver.(*windows.WindowsGraphDriver); ok {
|
||||
if container.ImageID != "" {
|
||||
// Get list of paths to parent layers.
|
||||
logrus.Debugln("createRootfs: Container has parent image:", container.ImageID)
|
||||
img, err := daemon.graph.Get(container.ImageID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ids, err := daemon.graph.ParentLayerIds(img)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
logrus.Debugf("Got image ids: %d", len(ids))
|
||||
|
||||
if err := hcsshim.CreateSandboxLayer(wd.Info(), container.ID, container.ImageID, wd.LayerIdsToPaths(ids)); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if err := daemon.driver.Create(container.ID, container.ImageID); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Fall-back code path to allow the use of the VFS driver for development
|
||||
if err := daemon.driver.Create(container.ID, container.ImageID); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -101,6 +101,7 @@ func GetDriver(name, home string, options []string) (Driver, error) {
|
||||
if initFunc, exists := drivers[name]; exists {
|
||||
return initFunc(filepath.Join(home, name), options)
|
||||
}
|
||||
logrus.Errorf("Failed to GetDriver graph %s %s", name, home)
|
||||
return nil, ErrNotSupported
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,24 @@
|
||||
package graphdriver
|
||||
|
||||
type DiffDiskDriver interface {
|
||||
import (
|
||||
"github.com/docker/docker/pkg/archive"
|
||||
"github.com/microsoft/hcsshim"
|
||||
)
|
||||
|
||||
type WindowsGraphDriver interface {
|
||||
Driver
|
||||
CopyDiff(id, sourceId string) error
|
||||
CopyDiff(id, sourceId string, parentLayerPaths []string) error
|
||||
LayerIdsToPaths(ids []string) []string
|
||||
Info() hcsshim.DriverInfo
|
||||
Export(id string, parentLayerPaths []string) (archive.Archive, error)
|
||||
Import(id string, layerData archive.ArchiveReader, parentLayerPaths []string) (int64, error)
|
||||
}
|
||||
|
||||
var (
|
||||
// Slice of drivers that should be used in order
|
||||
priority = []string{
|
||||
"windows",
|
||||
"windowsfilter",
|
||||
"windowsdiff",
|
||||
"vfs",
|
||||
}
|
||||
)
|
||||
|
||||
@@ -0,0 +1,326 @@
|
||||
//+build windows
|
||||
|
||||
package windows
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/docker/docker/daemon/graphdriver"
|
||||
"github.com/docker/docker/pkg/archive"
|
||||
"github.com/docker/docker/pkg/chrootarchive"
|
||||
"github.com/docker/docker/pkg/ioutils"
|
||||
"github.com/microsoft/hcsshim"
|
||||
)
|
||||
|
||||
func init() {
|
||||
graphdriver.Register("windowsfilter", InitFilter)
|
||||
graphdriver.Register("windowsdiff", InitDiff)
|
||||
}
|
||||
|
||||
const (
|
||||
diffDriver = iota
|
||||
filterDriver
|
||||
)
|
||||
|
||||
type WindowsGraphDriver struct {
|
||||
info hcsshim.DriverInfo
|
||||
sync.Mutex // Protects concurrent modification to active
|
||||
active map[string]int
|
||||
}
|
||||
|
||||
// New returns a new Windows storage filter driver.
|
||||
func InitFilter(home string, options []string) (graphdriver.Driver, error) {
|
||||
logrus.Debugf("WindowsGraphDriver InitFilter at %s", home)
|
||||
d := &WindowsGraphDriver{
|
||||
info: hcsshim.DriverInfo{
|
||||
HomeDir: home,
|
||||
Flavour: filterDriver,
|
||||
},
|
||||
active: make(map[string]int),
|
||||
}
|
||||
return d, nil
|
||||
}
|
||||
|
||||
// New returns a new Windows differencing disk driver.
|
||||
func InitDiff(home string, options []string) (graphdriver.Driver, error) {
|
||||
logrus.Debugf("WindowsGraphDriver InitDiff at %s", home)
|
||||
d := &WindowsGraphDriver{
|
||||
info: hcsshim.DriverInfo{
|
||||
HomeDir: home,
|
||||
Flavour: diffDriver,
|
||||
},
|
||||
active: make(map[string]int),
|
||||
}
|
||||
return d, nil
|
||||
}
|
||||
|
||||
func (d *WindowsGraphDriver) Info() hcsshim.DriverInfo {
|
||||
return d.info
|
||||
}
|
||||
|
||||
func (d *WindowsGraphDriver) String() string {
|
||||
switch d.info.Flavour {
|
||||
case diffDriver:
|
||||
return "windowsdiff"
|
||||
case filterDriver:
|
||||
return "windowsfilter"
|
||||
default:
|
||||
return "Unknown driver flavour"
|
||||
}
|
||||
}
|
||||
|
||||
func (d *WindowsGraphDriver) Status() [][2]string {
|
||||
return [][2]string{
|
||||
{"Windows", ""},
|
||||
}
|
||||
}
|
||||
|
||||
// Exists returns true if the given id is registered with
|
||||
// this driver
|
||||
func (d *WindowsGraphDriver) Exists(id string) bool {
|
||||
result, err := hcsshim.LayerExists(d.info, id)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func (d *WindowsGraphDriver) Create(id, parent string) error {
|
||||
return hcsshim.CreateLayer(d.info, id, parent)
|
||||
}
|
||||
|
||||
func (d *WindowsGraphDriver) dir(id string) string {
|
||||
return filepath.Join(d.info.HomeDir, filepath.Base(id))
|
||||
}
|
||||
|
||||
// Remove unmounts and removes the dir information
|
||||
func (d *WindowsGraphDriver) Remove(id string) error {
|
||||
return hcsshim.DestroyLayer(d.info, id)
|
||||
}
|
||||
|
||||
// Get returns the rootfs path for the id. This will mount the dir at it's given path
|
||||
func (d *WindowsGraphDriver) Get(id, mountLabel string) (string, error) {
|
||||
var dir string
|
||||
|
||||
d.Lock()
|
||||
defer d.Unlock()
|
||||
|
||||
if d.active[id] == 0 {
|
||||
if err := hcsshim.ActivateLayer(d.info, id); err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
|
||||
mountPath, err := hcsshim.GetLayerMountPath(d.info, id)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// If the layer has a mount path, use that. Otherwise, use the
|
||||
// folder path.
|
||||
if mountPath != "" {
|
||||
dir = mountPath
|
||||
} else {
|
||||
dir = d.dir(id)
|
||||
}
|
||||
|
||||
d.active[id]++
|
||||
|
||||
return dir, nil
|
||||
}
|
||||
|
||||
func (d *WindowsGraphDriver) Put(id string) error {
|
||||
logrus.Debugf("WindowsGraphDriver Put() id %s", id)
|
||||
|
||||
d.Lock()
|
||||
defer d.Unlock()
|
||||
|
||||
if d.active[id] > 1 {
|
||||
d.active[id]--
|
||||
} else if d.active[id] == 1 {
|
||||
if err := hcsshim.DeactivateLayer(d.info, id); err != nil {
|
||||
return err
|
||||
}
|
||||
delete(d.active, id)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *WindowsGraphDriver) Cleanup() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Diff produces an archive of the changes between the specified
|
||||
// layer and its parent layer which may be "".
|
||||
func (d *WindowsGraphDriver) Diff(id, parent string) (arch archive.Archive, err error) {
|
||||
return nil, fmt.Errorf("The Windows graphdriver does not support Diff()")
|
||||
}
|
||||
|
||||
// Changes produces a list of changes between the specified layer
|
||||
// and its parent layer. If parent is "", then all changes will be ADD changes.
|
||||
func (d *WindowsGraphDriver) Changes(id, parent string) ([]archive.Change, error) {
|
||||
return nil, fmt.Errorf("The Windows graphdriver does not support Changes()")
|
||||
}
|
||||
|
||||
// ApplyDiff extracts the changeset from the given diff into the
|
||||
// layer with the specified id and parent, returning the size of the
|
||||
// new layer in bytes.
|
||||
func (d *WindowsGraphDriver) ApplyDiff(id, parent string, diff archive.ArchiveReader) (size int64, err error) {
|
||||
start := time.Now().UTC()
|
||||
logrus.Debugf("WindowsGraphDriver ApplyDiff: Start untar layer")
|
||||
|
||||
destination := d.dir(id)
|
||||
if d.info.Flavour == diffDriver {
|
||||
destination = filepath.Dir(destination)
|
||||
}
|
||||
|
||||
if size, err = chrootarchive.ApplyLayer(destination, diff); err != nil {
|
||||
return
|
||||
}
|
||||
logrus.Debugf("WindowsGraphDriver ApplyDiff: Untar time: %vs", time.Now().UTC().Sub(start).Seconds())
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// DiffSize calculates the changes between the specified layer
|
||||
// and its parent and returns the size in bytes of the changes
|
||||
// relative to its base filesystem directory.
|
||||
func (d *WindowsGraphDriver) DiffSize(id, parent string) (size int64, err error) {
|
||||
changes, err := d.Changes(id, parent)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
layerFs, err := d.Get(id, "")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer d.Put(id)
|
||||
|
||||
return archive.ChangesSize(layerFs, changes), nil
|
||||
}
|
||||
|
||||
func (d *WindowsGraphDriver) CopyDiff(sourceId, id string, parentLayerPaths []string) error {
|
||||
d.Lock()
|
||||
defer d.Unlock()
|
||||
|
||||
if d.info.Flavour == filterDriver && d.active[sourceId] == 0 {
|
||||
if err := hcsshim.ActivateLayer(d.info, sourceId); err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
err := hcsshim.DeactivateLayer(d.info, sourceId)
|
||||
if err != nil {
|
||||
logrus.Warnf("Failed to Deactivate %s: %s", sourceId, err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
return hcsshim.CopyLayer(d.info, sourceId, id, parentLayerPaths)
|
||||
}
|
||||
|
||||
func (d *WindowsGraphDriver) LayerIdsToPaths(ids []string) []string {
|
||||
var paths []string
|
||||
for _, id := range ids {
|
||||
path, err := d.Get(id, "")
|
||||
if err != nil {
|
||||
logrus.Debug("LayerIdsToPaths: Error getting mount path for id", id, ":", err.Error())
|
||||
return nil
|
||||
}
|
||||
if d.Put(id) != nil {
|
||||
logrus.Debug("LayerIdsToPaths: Error putting mount path for id", id, ":", err.Error())
|
||||
return nil
|
||||
}
|
||||
paths = append(paths, path)
|
||||
}
|
||||
return paths
|
||||
}
|
||||
|
||||
func (d *WindowsGraphDriver) GetMetadata(id string) (map[string]string, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (d *WindowsGraphDriver) Export(id string, parentLayerPaths []string) (arch archive.Archive, err error) {
|
||||
layerFs, err := d.Get(id, "")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer func() {
|
||||
if err != nil {
|
||||
d.Put(id)
|
||||
}
|
||||
}()
|
||||
|
||||
tempFolder := layerFs + "-temp"
|
||||
if err = os.MkdirAll(tempFolder, 0755); err != nil {
|
||||
logrus.Errorf("Could not create %s %s", tempFolder, err)
|
||||
return
|
||||
}
|
||||
defer func() {
|
||||
if err != nil {
|
||||
if err2 := os.RemoveAll(tempFolder); err2 != nil {
|
||||
logrus.Warnf("Couldn't clean-up tempFolder: %s %s", tempFolder, err2)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
if err = hcsshim.ExportLayer(d.info, id, tempFolder, parentLayerPaths); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
archive, err := archive.Tar(tempFolder, archive.Uncompressed)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return ioutils.NewReadCloserWrapper(archive, func() error {
|
||||
err := archive.Close()
|
||||
d.Put(id)
|
||||
if err2 := os.RemoveAll(tempFolder); err2 != nil {
|
||||
logrus.Warnf("Couldn't clean-up tempFolder: %s %s", tempFolder, err2)
|
||||
}
|
||||
return err
|
||||
}), nil
|
||||
|
||||
}
|
||||
|
||||
func (d *WindowsGraphDriver) Import(id string, layerData archive.ArchiveReader, parentLayerPaths []string) (size int64, err error) {
|
||||
layerFs, err := d.Get(id, "")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer func() {
|
||||
if err != nil {
|
||||
d.Put(id)
|
||||
}
|
||||
}()
|
||||
|
||||
tempFolder := layerFs + "-temp"
|
||||
if err = os.MkdirAll(tempFolder, 0755); err != nil {
|
||||
logrus.Errorf("Could not create %s %s", tempFolder, err)
|
||||
return
|
||||
}
|
||||
defer func() {
|
||||
if err2 := os.RemoveAll(tempFolder); err2 != nil {
|
||||
logrus.Warnf("Couldn't clean-up tempFolder: %s %s", tempFolder, err2)
|
||||
}
|
||||
}()
|
||||
|
||||
start := time.Now().UTC()
|
||||
logrus.Debugf("Start untar layer")
|
||||
if size, err = chrootarchive.ApplyLayer(tempFolder, layerData); err != nil {
|
||||
return
|
||||
}
|
||||
logrus.Debugf("Untar time: %vs", time.Now().UTC().Sub(start).Seconds())
|
||||
|
||||
if err = hcsshim.ImportLayer(d.info, id, tempFolder, parentLayerPaths); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/graph"
|
||||
"github.com/docker/docker/image"
|
||||
"github.com/docker/docker/pkg/parsers"
|
||||
"github.com/docker/docker/pkg/stringid"
|
||||
"github.com/docker/docker/utils"
|
||||
@@ -160,7 +159,7 @@ func (daemon *Daemon) canDeleteImage(imgID string, force bool) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := daemon.graph.WalkHistory(parent, func(p image.Image) error {
|
||||
if err := daemon.graph.WalkHistory(parent, func(p graph.Image) error {
|
||||
if imgID == p.ID {
|
||||
if container.IsRunning() {
|
||||
if force {
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/docker/docker/pkg/chrootarchive"
|
||||
"github.com/docker/docker/pkg/system"
|
||||
"github.com/docker/docker/runconfig"
|
||||
"github.com/docker/docker/volume"
|
||||
"github.com/docker/docker/volume/local"
|
||||
@@ -35,7 +36,7 @@ func (m *mountPoint) Setup() (string, error) {
|
||||
if !os.IsNotExist(err) {
|
||||
return "", err
|
||||
}
|
||||
if err := os.MkdirAll(m.Source, 0755); err != nil {
|
||||
if err := system.MkdirAll(m.Source, 0755); err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user