mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
daemon/graphdriver/overlay/ fix lint errors/warnings
Addresses #14756 Signed-off-by: Srini Brahmaroutu <srbrahma@us.ibm.com>
This commit is contained in:
parent
0a0e9701f7
commit
de3944219f
3 changed files with 37 additions and 11 deletions
|
@ -12,10 +12,10 @@ import (
|
||||||
"github.com/docker/docker/pkg/system"
|
"github.com/docker/docker/pkg/system"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CopyFlags int
|
type copyFlags int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
CopyHardlink CopyFlags = 1 << iota
|
copyHardlink copyFlags = 1 << iota
|
||||||
)
|
)
|
||||||
|
|
||||||
func copyRegular(srcPath, dstPath string, mode os.FileMode) error {
|
func copyRegular(srcPath, dstPath string, mode os.FileMode) error {
|
||||||
|
@ -49,7 +49,7 @@ func copyXattr(srcPath, dstPath, attr string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func copyDir(srcDir, dstDir string, flags CopyFlags) error {
|
func copyDir(srcDir, dstDir string, flags copyFlags) error {
|
||||||
err := filepath.Walk(srcDir, func(srcPath string, f os.FileInfo, err error) error {
|
err := filepath.Walk(srcDir, func(srcPath string, f os.FileInfo, err error) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -75,7 +75,7 @@ func copyDir(srcDir, dstDir string, flags CopyFlags) error {
|
||||||
|
|
||||||
switch f.Mode() & os.ModeType {
|
switch f.Mode() & os.ModeType {
|
||||||
case 0: // Regular file
|
case 0: // Regular file
|
||||||
if flags&CopyHardlink != 0 {
|
if flags©Hardlink != 0 {
|
||||||
isHardlink = true
|
isHardlink = true
|
||||||
if err := os.Link(srcPath, dstPath); err != nil {
|
if err := os.Link(srcPath, dstPath); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -23,11 +23,15 @@ import (
|
||||||
// implementation of ApplyDiff()
|
// implementation of ApplyDiff()
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
// ErrApplyDiffFallback is returned to indicate that a normal ApplyDiff is applied as a fallback from Naive diff writer.
|
||||||
ErrApplyDiffFallback = fmt.Errorf("Fall back to normal ApplyDiff")
|
ErrApplyDiffFallback = fmt.Errorf("Fall back to normal ApplyDiff")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ApplyDiffProtoDriver wraps the ProtoDriver by extending the inteface with ApplyDiff method.
|
||||||
type ApplyDiffProtoDriver interface {
|
type ApplyDiffProtoDriver interface {
|
||||||
graphdriver.ProtoDriver
|
graphdriver.ProtoDriver
|
||||||
|
// ApplyDiff writes the diff to the archive for the given id and parent id.
|
||||||
|
// It returns the size in bytes written if successful, an error ErrApplyDiffFallback is returned otherwise.
|
||||||
ApplyDiff(id, parent string, diff archive.Reader) (size int64, err error)
|
ApplyDiff(id, parent string, diff archive.Reader) (size int64, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,6 +40,7 @@ type naiveDiffDriverWithApply struct {
|
||||||
applyDiff ApplyDiffProtoDriver
|
applyDiff ApplyDiffProtoDriver
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NaiveDiffDriverWithApply returns a NaiveDiff driver with custom ApplyDiff.
|
||||||
func NaiveDiffDriverWithApply(driver ApplyDiffProtoDriver) graphdriver.Driver {
|
func NaiveDiffDriverWithApply(driver ApplyDiffProtoDriver) graphdriver.Driver {
|
||||||
return &naiveDiffDriverWithApply{
|
return &naiveDiffDriverWithApply{
|
||||||
Driver: graphdriver.NaiveDiffDriver(driver),
|
Driver: graphdriver.NaiveDiffDriver(driver),
|
||||||
|
@ -43,6 +48,7 @@ func NaiveDiffDriverWithApply(driver ApplyDiffProtoDriver) graphdriver.Driver {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ApplyDiff creates a diff layer with either the NaiveDiffDriver or with a fallback.
|
||||||
func (d *naiveDiffDriverWithApply) ApplyDiff(id, parent string, diff archive.Reader) (int64, error) {
|
func (d *naiveDiffDriverWithApply) ApplyDiff(id, parent string, diff archive.Reader) (int64, error) {
|
||||||
b, err := d.applyDiff.ApplyDiff(id, parent, diff)
|
b, err := d.applyDiff.ApplyDiff(id, parent, diff)
|
||||||
if err == ErrApplyDiffFallback {
|
if err == ErrApplyDiffFallback {
|
||||||
|
@ -79,11 +85,15 @@ func (d *naiveDiffDriverWithApply) ApplyDiff(id, parent string, diff archive.Rea
|
||||||
// of that. This means all child images share file (but not directory)
|
// of that. This means all child images share file (but not directory)
|
||||||
// data with the parent.
|
// data with the parent.
|
||||||
|
|
||||||
|
// ActiveMount contains information about the count, path and whether is mounted or not.
|
||||||
|
// This information is part of the Driver, that contains list of active mounts taht are part of this overlay.
|
||||||
type ActiveMount struct {
|
type ActiveMount struct {
|
||||||
count int
|
count int
|
||||||
path string
|
path string
|
||||||
mounted bool
|
mounted bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Driver contains information about the home directory and the list of active mounts that are created using this driver.
|
||||||
type Driver struct {
|
type Driver struct {
|
||||||
home string
|
home string
|
||||||
sync.Mutex // Protects concurrent modification to active
|
sync.Mutex // Protects concurrent modification to active
|
||||||
|
@ -96,6 +106,9 @@ func init() {
|
||||||
graphdriver.Register("overlay", Init)
|
graphdriver.Register("overlay", Init)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Init returns the NaiveDiffDriver, a native diff driver for overlay filesystem.
|
||||||
|
// If overlay filesystem is not supported on the host, graphdriver.ErrNotSupported is returned as error.
|
||||||
|
// If a overlay filesystem is not supported over a existing filesystem then error graphdriver.ErrIncompatibleFS is returned.
|
||||||
func Init(home string, options []string) (graphdriver.Driver, error) {
|
func Init(home string, options []string) (graphdriver.Driver, error) {
|
||||||
|
|
||||||
if err := supportsOverlay(); err != nil {
|
if err := supportsOverlay(); err != nil {
|
||||||
|
@ -161,12 +174,15 @@ func (d *Driver) String() string {
|
||||||
return "overlay"
|
return "overlay"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Status returns current driver information in a two dimensional string array.
|
||||||
|
// Output contains "Backing Filesystem" used in this implementation.
|
||||||
func (d *Driver) Status() [][2]string {
|
func (d *Driver) Status() [][2]string {
|
||||||
return [][2]string{
|
return [][2]string{
|
||||||
{"Backing Filesystem", backingFs},
|
{"Backing Filesystem", backingFs},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetMetadata returns meta data about the overlay driver such as root, LowerDir, UpperDir, WorkDir and MergeDir used to store data.
|
||||||
func (d *Driver) GetMetadata(id string) (map[string]string, error) {
|
func (d *Driver) GetMetadata(id string) (map[string]string, error) {
|
||||||
dir := d.dir(id)
|
dir := d.dir(id)
|
||||||
if _, err := os.Stat(dir); err != nil {
|
if _, err := os.Stat(dir); err != nil {
|
||||||
|
@ -182,12 +198,12 @@ func (d *Driver) GetMetadata(id string) (map[string]string, error) {
|
||||||
return metadata, nil
|
return metadata, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
lowerId, err := ioutil.ReadFile(path.Join(dir, "lower-id"))
|
lowerID, err := ioutil.ReadFile(path.Join(dir, "lower-id"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
metadata["LowerDir"] = path.Join(d.dir(string(lowerId)), "root")
|
metadata["LowerDir"] = path.Join(d.dir(string(lowerID)), "root")
|
||||||
metadata["UpperDir"] = path.Join(dir, "upper")
|
metadata["UpperDir"] = path.Join(dir, "upper")
|
||||||
metadata["WorkDir"] = path.Join(dir, "work")
|
metadata["WorkDir"] = path.Join(dir, "work")
|
||||||
metadata["MergedDir"] = path.Join(dir, "merged")
|
metadata["MergedDir"] = path.Join(dir, "merged")
|
||||||
|
@ -195,10 +211,14 @@ func (d *Driver) GetMetadata(id string) (map[string]string, error) {
|
||||||
return metadata, nil
|
return metadata, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Cleanup simply returns nil and do not change the existing filesystem.
|
||||||
|
// This is required to satisfy the graphdriver.Driver interface.
|
||||||
func (d *Driver) Cleanup() error {
|
func (d *Driver) Cleanup() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create is used to create the upper, lower, and merge directories required for overlay fs for a given id.
|
||||||
|
// The parent filesystem is used to configure these directories for the overlay.
|
||||||
func (d *Driver) Create(id string, parent string) (retErr error) {
|
func (d *Driver) Create(id string, parent string) (retErr error) {
|
||||||
dir := d.dir(id)
|
dir := d.dir(id)
|
||||||
if err := os.MkdirAll(path.Dir(dir), 0700); err != nil {
|
if err := os.MkdirAll(path.Dir(dir), 0700); err != nil {
|
||||||
|
@ -251,12 +271,12 @@ func (d *Driver) Create(id string, parent string) (retErr error) {
|
||||||
|
|
||||||
// Otherwise, copy the upper and the lower-id from the parent
|
// Otherwise, copy the upper and the lower-id from the parent
|
||||||
|
|
||||||
lowerId, err := ioutil.ReadFile(path.Join(parentDir, "lower-id"))
|
lowerID, err := ioutil.ReadFile(path.Join(parentDir, "lower-id"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := ioutil.WriteFile(path.Join(dir, "lower-id"), lowerId, 0666); err != nil {
|
if err := ioutil.WriteFile(path.Join(dir, "lower-id"), lowerID, 0666); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -284,6 +304,7 @@ func (d *Driver) dir(id string) string {
|
||||||
return path.Join(d.home, id)
|
return path.Join(d.home, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove cleans the directories that are created for this id.
|
||||||
func (d *Driver) Remove(id string) error {
|
func (d *Driver) Remove(id string) error {
|
||||||
dir := d.dir(id)
|
dir := d.dir(id)
|
||||||
if _, err := os.Stat(dir); err != nil {
|
if _, err := os.Stat(dir); err != nil {
|
||||||
|
@ -292,6 +313,7 @@ func (d *Driver) Remove(id string) error {
|
||||||
return os.RemoveAll(dir)
|
return os.RemoveAll(dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get creates and mounts the required file system for the given id and returns the mount path.
|
||||||
func (d *Driver) Get(id string, mountLabel string) (string, error) {
|
func (d *Driver) Get(id string, mountLabel string) (string, error) {
|
||||||
// Protect the d.active from concurrent access
|
// Protect the d.active from concurrent access
|
||||||
d.Lock()
|
d.Lock()
|
||||||
|
@ -318,11 +340,11 @@ func (d *Driver) Get(id string, mountLabel string) (string, error) {
|
||||||
return mount.path, nil
|
return mount.path, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
lowerId, err := ioutil.ReadFile(path.Join(dir, "lower-id"))
|
lowerID, err := ioutil.ReadFile(path.Join(dir, "lower-id"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
lowerDir := path.Join(d.dir(string(lowerId)), "root")
|
lowerDir := path.Join(d.dir(string(lowerID)), "root")
|
||||||
upperDir := path.Join(dir, "upper")
|
upperDir := path.Join(dir, "upper")
|
||||||
workDir := path.Join(dir, "work")
|
workDir := path.Join(dir, "work")
|
||||||
mergedDir := path.Join(dir, "merged")
|
mergedDir := path.Join(dir, "merged")
|
||||||
|
@ -338,6 +360,7 @@ func (d *Driver) Get(id string, mountLabel string) (string, error) {
|
||||||
return mount.path, nil
|
return mount.path, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Put unmounts the mount path created for the give id.
|
||||||
func (d *Driver) Put(id string) error {
|
func (d *Driver) Put(id string) error {
|
||||||
// Protect the d.active from concurrent access
|
// Protect the d.active from concurrent access
|
||||||
d.Lock()
|
d.Lock()
|
||||||
|
@ -373,6 +396,7 @@ func (d *Driver) Put(id string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ApplyDiff applies the new layer on top of the root, if parent does not exist with will return a ErrApplyDiffFallback error.
|
||||||
func (d *Driver) ApplyDiff(id string, parent string, diff archive.Reader) (size int64, err error) {
|
func (d *Driver) ApplyDiff(id string, parent string, diff archive.Reader) (size int64, err error) {
|
||||||
dir := d.dir(id)
|
dir := d.dir(id)
|
||||||
|
|
||||||
|
@ -407,7 +431,7 @@ func (d *Driver) ApplyDiff(id string, parent string, diff archive.Reader) (size
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if err = copyDir(parentRootDir, tmpRootDir, CopyHardlink); err != nil {
|
if err = copyDir(parentRootDir, tmpRootDir, copyHardlink); err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -423,6 +447,7 @@ func (d *Driver) ApplyDiff(id string, parent string, diff archive.Reader) (size
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Exists checks to see if the id is already mounted.
|
||||||
func (d *Driver) Exists(id string) bool {
|
func (d *Driver) Exists(id string) bool {
|
||||||
_, err := os.Stat(d.dir(id))
|
_, err := os.Stat(d.dir(id))
|
||||||
return err == nil
|
return err == nil
|
||||||
|
|
|
@ -27,6 +27,7 @@ packages=(
|
||||||
daemon/execdriver/windows
|
daemon/execdriver/windows
|
||||||
daemon/graphdriver/aufs
|
daemon/graphdriver/aufs
|
||||||
daemon/graphdriver/devmapper
|
daemon/graphdriver/devmapper
|
||||||
|
daemon/graphdriver/overlay
|
||||||
daemon/graphdriver/vfs
|
daemon/graphdriver/vfs
|
||||||
daemon/graphdriver/zfs
|
daemon/graphdriver/zfs
|
||||||
daemon/logger
|
daemon/logger
|
||||||
|
|
Loading…
Add table
Reference in a new issue