mirror of
https://github.com/containers/podman.git
synced 2025-12-01 18:49:18 +08:00
faster image inspection
Vendor the latest HEAD in c/common to pull in changes for a faster inspection of images. Previously, only the size computation was optional, now the one for the parent image is as well. In many cases, the parent image is not needed but it takes around 10ms on my local machine. With this change, we cut off 10ms from many code paths, most importantly, container creation. [NO NEW TESTS NEEDED] Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
This commit is contained in:
45
vendor/github.com/containers/common/libimage/inspect.go
generated
vendored
45
vendor/github.com/containers/common/libimage/inspect.go
generated
vendored
@@ -50,19 +50,39 @@ type RootFS struct {
|
||||
Layers []digest.Digest `json:"Layers"`
|
||||
}
|
||||
|
||||
// Inspect inspects the image. Use `withSize` to also perform the
|
||||
// comparatively expensive size computation of the image.
|
||||
func (i *Image) Inspect(ctx context.Context, withSize bool) (*ImageData, error) {
|
||||
// InspectOptions allow for customizing inspecting images.
|
||||
type InspectOptions struct {
|
||||
// Compute the size of the image (expensive).
|
||||
WithSize bool
|
||||
// Compute the parent of the image (expensive).
|
||||
WithParent bool
|
||||
}
|
||||
|
||||
// Inspect inspects the image.
|
||||
func (i *Image) Inspect(ctx context.Context, options *InspectOptions) (*ImageData, error) {
|
||||
logrus.Debugf("Inspecting image %s", i.ID())
|
||||
|
||||
if options == nil {
|
||||
options = &InspectOptions{}
|
||||
}
|
||||
|
||||
if i.cached.completeInspectData != nil {
|
||||
if withSize && i.cached.completeInspectData.Size == int64(-1) {
|
||||
if options.WithSize && i.cached.completeInspectData.Size == int64(-1) {
|
||||
size, err := i.Size()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
i.cached.completeInspectData.Size = size
|
||||
}
|
||||
if options.WithParent && i.cached.completeInspectData.Parent == "" {
|
||||
parentImage, err := i.Parent(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if parentImage != nil {
|
||||
i.cached.completeInspectData.Parent = parentImage.ID()
|
||||
}
|
||||
}
|
||||
return i.cached.completeInspectData, nil
|
||||
}
|
||||
|
||||
@@ -75,10 +95,7 @@ func (i *Image) Inspect(ctx context.Context, withSize bool) (*ImageData, error)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
parentImage, err := i.Parent(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
repoTags, err := i.RepoTags()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -93,7 +110,7 @@ func (i *Image) Inspect(ctx context.Context, withSize bool) (*ImageData, error)
|
||||
}
|
||||
|
||||
size := int64(-1)
|
||||
if withSize {
|
||||
if options.WithSize {
|
||||
size, err = i.Size()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -124,8 +141,14 @@ func (i *Image) Inspect(ctx context.Context, withSize bool) (*ImageData, error)
|
||||
NamesHistory: i.NamesHistory(),
|
||||
}
|
||||
|
||||
if parentImage != nil {
|
||||
data.Parent = parentImage.ID()
|
||||
if options.WithParent {
|
||||
parentImage, err := i.Parent(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if parentImage != nil {
|
||||
data.Parent = parentImage.ID()
|
||||
}
|
||||
}
|
||||
|
||||
// Determine the format of the image. How we determine certain data
|
||||
|
||||
Reference in New Issue
Block a user