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

Compute TarSum on storage of image layer content #8964

Merged
merged 1 commit into from
Nov 14, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions graph/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ func (s *TagStore) CmdLookup(job *engine.Job) engine.Status {
out.Set("Os", image.OS)
out.SetInt64("Size", image.Size)
out.SetInt64("VirtualSize", image.GetParentsSize(0)+image.Size)
out.Set("Checksum", image.Checksum)
if _, err = out.WriteTo(job.Stdout); err != nil {
return job.Error(err)
}
Expand Down
34 changes: 30 additions & 4 deletions image/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

log "github.com/Sirupsen/logrus"
"github.com/docker/docker/pkg/archive"
"github.com/docker/docker/pkg/tarsum"
"github.com/docker/docker/runconfig"
"github.com/docker/docker/utils"
)
Expand All @@ -32,6 +33,7 @@ type Image struct {
Config *runconfig.Config `json:"config,omitempty"`
Architecture string `json:"architecture,omitempty"`
OS string `json:"os,omitempty"`
Checksum string `json:"checksum"`
Size int64

graph Graph
Expand Down Expand Up @@ -74,19 +76,43 @@ func LoadImage(root string) (*Image, error) {
return img, nil
}

// StoreImage stores file system layer data for the given image to the
// image's registered storage driver. Image metadata is stored in a file
// at the specified root directory. This function also computes the TarSum
// of `layerData` (currently using tarsum.dev).
func StoreImage(img *Image, layerData archive.ArchiveReader, root string) error {
// Store the layer
var (
size int64
err error
driver = img.graph.Driver()
size int64
err error
driver = img.graph.Driver()
layerTarSum tarsum.TarSum
)

// If layerData is not nil, unpack it into the new layer
if layerData != nil {
if size, err = driver.ApplyDiff(img.ID, img.Parent, layerData); err != nil {
layerDataDecompressed, err := archive.DecompressStream(layerData)
if err != nil {
return err
}

defer layerDataDecompressed.Close()

if layerTarSum, err = tarsum.NewTarSum(layerDataDecompressed, true, tarsum.VersionDev); err != nil {
return err
}

if size, err = driver.ApplyDiff(img.ID, img.Parent, layerTarSum); err != nil {
return err
}

checksum := layerTarSum.Sum(nil)

if img.Checksum != "" && img.Checksum != checksum {
log.Warn("image layer checksum mismatch: computed %q, expected %q", checksum, img.Checksum)
}

img.Checksum = checksum
}

img.Size = size
Expand Down