Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[optimization]optimize TarStream for overlay2 #38436

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions daemon/graphdriver/overlay2/overlay.go
Expand Up @@ -546,6 +546,12 @@ func (d *Driver) Remove(id string) error {
return nil
}

//GetDiffPath return the diff directory
func (d *Driver) GetDiffPath(id string) containerfs.ContainerFS {
diffPath := path.Join(d.dir(id), "diff")
return containerfs.NewLocalContainerFS(diffPath)
}

// Get creates and mounts the required file system for the given id and returns the mount path.
func (d *Driver) Get(id, mountLabel string) (_ containerfs.ContainerFS, retErr error) {
d.locker.Lock(id)
Expand Down
29 changes: 23 additions & 6 deletions layer/layer_store.go
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/docker/distribution"
"github.com/docker/docker/daemon/graphdriver"
"github.com/docker/docker/pkg/containerfs"
"github.com/docker/docker/pkg/idtools"
"github.com/docker/docker/pkg/plugingetter"
"github.com/docker/docker/pkg/stringid"
Expand Down Expand Up @@ -738,18 +739,34 @@ type naiveDiffPathDriver struct {

type fileGetPutter struct {
storage.FileGetter
driver graphdriver.Driver
id string
driver graphdriver.Driver
id string
isOverlay2 bool
}

func (w *fileGetPutter) Close() error {
if w.isOverlay2 {
//do nothing
return nil
}
return w.driver.Put(w.id)
}

func (n *naiveDiffPathDriver) DiffGetter(id string) (graphdriver.FileGetCloser, error) {
p, err := n.Driver.Get(id, "")
if err != nil {
return nil, err

var p containerfs.ContainerFS
isOverlay2 := false
if inter, ok := n.Driver.(interface {
GetDiffPath(id string) containerfs.ContainerFS
}); ok {
p = inter.GetDiffPath(id)
isOverlay2 = true
} else {
var err error
p, err = n.Driver.Get(id, "")
if err != nil {
return nil, err
}
}
return &fileGetPutter{storage.NewPathFileGetter(p.Path()), n.Driver, id}, nil
return &fileGetPutter{storage.NewPathFileGetter(p.Path()), n.Driver, id, isOverlay2}, nil
}