Skip to content

Commit 21ac79b

Browse files
authored
Merge pull request #2428 from mtrmac/als-toc-fixes
Short-term kludges for recent AdditionalLayerStore changes
2 parents db02dee + 45f4f23 commit 21ac79b

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

storage/storage_dest.go

+10-4
Original file line numberDiff line numberDiff line change
@@ -388,11 +388,17 @@ func (s *storageImageDestination) tryReusingBlobAsPending(blobDigest digest.Dige
388388
if err != nil && !errors.Is(err, storage.ErrLayerUnknown) {
389389
return false, private.ReusedBlob{}, fmt.Errorf(`looking for compressed layers with digest %q and labels: %w`, blobDigest, err)
390390
} else if err == nil {
391-
d := aLayer.TOCDigest()
392-
if d == "" {
393-
return false, private.ReusedBlob{}, fmt.Errorf(`failed to get TOCDigest of %q: %w`, blobDigest, err)
391+
alsTOCDigest := aLayer.TOCDigest()
392+
if alsTOCDigest != options.TOCDigest {
393+
// FIXME: If alsTOCDigest is "", the Additional Layer Store FUSE server is probably just too old, and we could
394+
// probably go on reading the layer from other sources.
395+
//
396+
// Currently it should not be possible for alsTOCDigest to be set and not the expected value, but there’s
397+
// not that much benefit to checking for equality — we trust the FUSE server to validate the digest either way.
398+
return false, private.ReusedBlob{}, fmt.Errorf("additional layer for TOCDigest %q reports unexpected TOCDigest %q",
399+
options.TOCDigest, alsTOCDigest)
394400
}
395-
s.lockProtected.indexToTOCDigest[*options.LayerIndex] = d
401+
s.lockProtected.indexToTOCDigest[*options.LayerIndex] = options.TOCDigest
396402
s.lockProtected.indexToAdditionalLayer[*options.LayerIndex] = aLayer
397403
return true, private.ReusedBlob{
398404
Digest: blobDigest,

storage/storage_src.go

+11-7
Original file line numberDiff line numberDiff line change
@@ -307,9 +307,6 @@ func (s *storageImageSource) LayerInfosForCopy(ctx context.Context, instanceDige
307307
if err != nil {
308308
return nil, fmt.Errorf("reading layer %q in image %q: %w", layerID, s.image.ID, err)
309309
}
310-
if layer.UncompressedSize < 0 {
311-
layer.UncompressedSize = -1
312-
}
313310

314311
blobDigest := layer.UncompressedDigest
315312
if blobDigest == "" {
@@ -331,12 +328,16 @@ func (s *storageImageSource) LayerInfosForCopy(ctx context.Context, instanceDige
331328
return nil, fmt.Errorf("parsing expected diffID %q for layer %q: %w", expectedDigest, layerID, err)
332329
}
333330
}
331+
size := layer.UncompressedSize
332+
if size < 0 {
333+
size = -1
334+
}
334335
s.getBlobMutex.Lock()
335336
s.getBlobMutexProtected.digestToLayerID[blobDigest] = layer.ID
336337
s.getBlobMutex.Unlock()
337338
blobInfo := types.BlobInfo{
338339
Digest: blobDigest,
339-
Size: layer.UncompressedSize,
340+
Size: size,
340341
MediaType: uncompressedLayerType,
341342
}
342343
physicalBlobInfos = append([]types.BlobInfo{blobInfo}, physicalBlobInfos...)
@@ -455,10 +456,13 @@ func (s *storageImageSource) getSize() (int64, error) {
455456
if (layer.TOCDigest == "" && layer.UncompressedDigest == "") || (layer.TOCDigest == "" && layer.UncompressedSize < 0) {
456457
return -1, fmt.Errorf("size for layer %q is unknown, failing getSize()", layerID)
457458
}
458-
if layer.UncompressedSize < 0 {
459-
sum = 0
459+
// FIXME: We allow layer.UncompressedSize < 0 above, because currently images in an Additional Layer Store don’t provide that value.
460+
// Right now, various callers in Podman (and, also, newImage in this package) don’t expect the size computation to fail.
461+
// Should we update the callers, or do we need to continue returning inaccurate information here? Or should we pay the cost
462+
// to compute the size from the diff?
463+
if layer.UncompressedSize >= 0 {
464+
sum += layer.UncompressedSize
460465
}
461-
sum += layer.UncompressedSize
462466
if layer.Parent == "" {
463467
break
464468
}

0 commit comments

Comments
 (0)