Merge pull request #20475 from Microsoft/jstarks/filegetter

graphdriver: Replace DiffPath with DiffGetter
Upstream-commit: 8f109829e294371cbae1eebfc771eda96d92187f
Component: engine
This commit is contained in:
David Calavera
2016-03-02 08:36:36 -08:00
4 changed files with 69 additions and 26 deletions
@@ -34,6 +34,7 @@ import (
"syscall"
"github.com/Sirupsen/logrus"
"github.com/vbatts/tar-split/tar/storage"
"github.com/docker/docker/daemon/graphdriver"
"github.com/docker/docker/pkg/archive"
@@ -374,10 +375,19 @@ func (a *Driver) Diff(id, parent string) (archive.Archive, error) {
})
}
// DiffPath returns path to the directory that contains files for the layer
// differences. Used for direct access for tar-split.
func (a *Driver) DiffPath(id string) (string, func() error, error) {
return path.Join(a.rootPath(), "diff", id), func() error { return nil }, nil
type fileGetNilCloser struct {
storage.FileGetter
}
func (f fileGetNilCloser) Close() error {
return nil
}
// DiffGetter returns a FileGetCloser that can read files from the directory that
// contains files for the layer differences. Used for direct access for tar-split.
func (a *Driver) DiffGetter(id string) (graphdriver.FileGetCloser, error) {
p := path.Join(a.rootPath(), "diff", id)
return fileGetNilCloser{storage.NewPathFileGetter(p)}, nil
}
func (a *Driver) applyDiff(id string, diff archive.Reader) error {
@@ -8,6 +8,7 @@ import (
"strings"
"github.com/Sirupsen/logrus"
"github.com/vbatts/tar-split/tar/storage"
"github.com/docker/docker/pkg/archive"
"github.com/docker/docker/pkg/idtools"
@@ -92,6 +93,23 @@ type Driver interface {
DiffSize(id, parent string) (size int64, err error)
}
// DiffGetterDriver is the interface for layered file system drivers that
// provide a specialized function for getting file contents for tar-split.
type DiffGetterDriver interface {
Driver
// DiffGetter returns an interface to efficiently retrieve the contents
// of files in a layer.
DiffGetter(id string) (FileGetCloser, error)
}
// FileGetCloser extends the storage.FileGetter interface with a Close method
// for cleaning up.
type FileGetCloser interface {
storage.FileGetter
// Close cleans up any resources associated with the FileGetCloser.
Close() error
}
func init() {
drivers = make(map[string]InitFunc)
}
@@ -22,6 +22,7 @@ import (
"github.com/docker/docker/pkg/idtools"
"github.com/docker/docker/pkg/ioutils"
"github.com/docker/docker/pkg/random"
"github.com/vbatts/tar-split/tar/storage"
)
// init registers the windows graph drivers to the register.
@@ -47,6 +48,8 @@ type Driver struct {
active map[string]int
}
var _ graphdriver.DiffGetterDriver = &Driver{}
// InitFilter returns a new Windows storage filter driver.
func InitFilter(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (graphdriver.Driver, error) {
logrus.Debugf("WindowsGraphDriver InitFilter at %s", home)
@@ -564,8 +567,20 @@ func (d *Driver) setLayerChain(id string, chain []string) error {
return nil
}
// DiffPath returns a directory that contains files needed to construct layer diff.
func (d *Driver) DiffPath(id string) (path string, release func() error, err error) {
type fileGetDestroyCloser struct {
storage.FileGetter
d *Driver
folderName string
}
func (f *fileGetDestroyCloser) Close() error {
// TODO: activate layers and release here?
return hcsshim.DestroyLayer(f.d.info, f.folderName)
}
// DiffGetter returns a FileGetCloser that can read files from the directory that
// contains files for the layer differences. Used for direct access for tar-split.
func (d *Driver) DiffGetter(id string) (fg graphdriver.FileGetCloser, err error) {
id, err = d.resolveID(id)
if err != nil {
return
@@ -597,9 +612,6 @@ func (d *Driver) DiffPath(id string) (path string, release func() error, err err
return
}
return tempFolder, func() error {
// TODO: activate layers and release here?
_, folderName := filepath.Split(tempFolder)
return hcsshim.DestroyLayer(d.info, folderName)
}, nil
_, folderName := filepath.Split(tempFolder)
return &fileGetDestroyCloser{storage.NewPathFileGetter(tempFolder), d, folderName}, nil
}