From 09ad65ebd5b50fdd7621f42136278102586a7ea8 Mon Sep 17 00:00:00 2001 From: Josh Hawn Date: Tue, 16 Sep 2014 12:13:50 -0700 Subject: [PATCH] graphdriver interface name change, typo fix Signed-off-by: Josh Hawn --- daemon/graphdriver/btrfs/btrfs.go | 2 +- daemon/graphdriver/devmapper/driver.go | 2 +- daemon/graphdriver/driver.go | 19 ++++++------ daemon/graphdriver/fsdiff.go | 41 ++++++++++++++------------ daemon/graphdriver/vfs/driver.go | 2 +- 5 files changed, 35 insertions(+), 31 deletions(-) diff --git a/daemon/graphdriver/btrfs/btrfs.go b/daemon/graphdriver/btrfs/btrfs.go index 1064a26630..26102aa1ef 100644 --- a/daemon/graphdriver/btrfs/btrfs.go +++ b/daemon/graphdriver/btrfs/btrfs.go @@ -48,7 +48,7 @@ func Init(home string, options []string) (graphdriver.Driver, error) { home: home, } - return graphdriver.NewGenericDriverWrapper(driver), nil + return graphdriver.NaiveDiffDriver(driver), nil } type Driver struct { diff --git a/daemon/graphdriver/devmapper/driver.go b/daemon/graphdriver/devmapper/driver.go index 215af40153..4ea1489f34 100644 --- a/daemon/graphdriver/devmapper/driver.go +++ b/daemon/graphdriver/devmapper/driver.go @@ -43,7 +43,7 @@ func Init(home string, options []string) (graphdriver.Driver, error) { home: home, } - return graphdriver.NewGenericDriverWrapper(d), nil + return graphdriver.NaiveDiffDriver(d), nil } func (d *Driver) String() string { diff --git a/daemon/graphdriver/driver.go b/daemon/graphdriver/driver.go index c389705df9..677a1d7e18 100644 --- a/daemon/graphdriver/driver.go +++ b/daemon/graphdriver/driver.go @@ -19,17 +19,20 @@ const ( type InitFunc func(root string, options []string) (Driver, error) -// GenericDriver defines the basic capabilities of a driver. -type GenericDriver interface { +// ProtoDriver defines the basic capabilities of a driver. +// This interface exists solely to be a minimum set of methods +// for client code which choose not to implement the entire Driver +// interface and use the NaiveDiffDriver wrapper constructor. +// +// Use of ProtoDriver directly by client code is not recommended. +type ProtoDriver interface { // String returns a string representation of this driver. String() string - // Create creates a new, empty, filesystem layer with the // specified id and parent. Parent may be "". Create(id, parent string) error - // Remove attepmts to remove the filesystem layer with this id. + // Remove attempts to remove the filesystem layer with this id. Remove(id string) error - // Get returns the mountpoint for the layered filesystem referred // to by this id. You can optionally specify a mountLabel or "". // Returns the absolute path to the mounted layered filesystem. @@ -40,20 +43,18 @@ type GenericDriver interface { // Exists returns whether a filesystem layer with the specified // ID exists on this driver. Exists(id string) bool - // Status returns a set of key-value pairs which give low // level diagnostic status about this driver. Status() [][2]string - // Cleanup performs necessary tasks to release resources // held by the driver, e.g., unmounting all layered filesystems // known to this driver. Cleanup() error } +// Driver is the interface for layered/snapshot file system drivers. type Driver interface { - GenericDriver - + ProtoDriver // Diff produces an archive of the changes between the specified // layer and its parent layer which may be "". Diff(id, parent string) (archive.Archive, error) diff --git a/daemon/graphdriver/fsdiff.go b/daemon/graphdriver/fsdiff.go index 03d109e930..d9d4434aec 100644 --- a/daemon/graphdriver/fsdiff.go +++ b/daemon/graphdriver/fsdiff.go @@ -10,27 +10,30 @@ import ( "github.com/docker/docker/utils" ) -// GenericDriverWrapper takes a generic Driver and adds the -// capability of the following methods which it doesn't -// support on its own: +// naiveDiffDriver takes a ProtoDriver and adds the +// capability of the Diffing methods which it may or may not +// support on its own. See the comment on the exported +// NaiveDiffDriver function below. +// Notably, the AUFS driver doesn't need to be wrapped like this. +type naiveDiffDriver struct { + ProtoDriver +} + +// NaiveDiffDriver returns a fully functional driver that wraps the +// given ProtoDriver and adds the capability of the following methods which +// it may or may not support on its own: // Diff(id, parent string) (archive.Archive, error) // Changes(id, parent string) ([]archive.Change, error) // ApplyDiff(id, parent string, diff archive.ArchiveReader) (bytes int64, err error) // DiffSize(id, parent string) (bytes int64, err error) -// Notably, the AUFS driver doesn't need to be wrapped like this. -type GenericDriverWrapper struct { - GenericDriver -} - -// NewGenericDriverWrapper returns a fully functional driver that wraps the given GenericDriver. -func NewGenericDriverWrapper(driver GenericDriver) Driver { - return &GenericDriverWrapper{GenericDriver: driver} +func NaiveDiffDriver(driver ProtoDriver) Driver { + return &naiveDiffDriver{ProtoDriver: driver} } // Diff produces an archive of the changes between the specified // layer and its parent layer which may be "". -func (gdw *GenericDriverWrapper) Diff(id, parent string) (arch archive.Archive, err error) { - driver := gdw.GenericDriver +func (gdw *naiveDiffDriver) Diff(id, parent string) (arch archive.Archive, err error) { + driver := gdw.ProtoDriver layerFs, err := driver.Get(id, "") if err != nil { @@ -80,8 +83,8 @@ func (gdw *GenericDriverWrapper) Diff(id, parent string) (arch archive.Archive, // 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 (gdw *GenericDriverWrapper) Changes(id, parent string) ([]archive.Change, error) { - driver := gdw.GenericDriver +func (gdw *naiveDiffDriver) Changes(id, parent string) ([]archive.Change, error) { + driver := gdw.ProtoDriver layerFs, err := driver.Get(id, "") if err != nil { @@ -105,8 +108,8 @@ func (gdw *GenericDriverWrapper) Changes(id, parent string) ([]archive.Change, e // 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 (gdw *GenericDriverWrapper) ApplyDiff(id, parent string, diff archive.ArchiveReader) (bytes int64, err error) { - driver := gdw.GenericDriver +func (gdw *naiveDiffDriver) ApplyDiff(id, parent string, diff archive.ArchiveReader) (bytes int64, err error) { + driver := gdw.ProtoDriver // Mount the root filesystem so we can apply the diff/layer. layerFs, err := driver.Get(id, "") @@ -144,8 +147,8 @@ func (gdw *GenericDriverWrapper) ApplyDiff(id, parent string, diff archive.Archi // 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 (gdw *GenericDriverWrapper) DiffSize(id, parent string) (bytes int64, err error) { - driver := gdw.GenericDriver +func (gdw *naiveDiffDriver) DiffSize(id, parent string) (bytes int64, err error) { + driver := gdw.ProtoDriver changes, err := gdw.Changes(id, parent) if err != nil { diff --git a/daemon/graphdriver/vfs/driver.go b/daemon/graphdriver/vfs/driver.go index 0bbf9d421a..a186060d03 100644 --- a/daemon/graphdriver/vfs/driver.go +++ b/daemon/graphdriver/vfs/driver.go @@ -19,7 +19,7 @@ func Init(home string, options []string) (graphdriver.Driver, error) { d := &Driver{ home: home, } - return graphdriver.NewGenericDriverWrapper(d), nil + return graphdriver.NaiveDiffDriver(d), nil } type Driver struct {