Skip to content

Commit

Permalink
Reload layer storage if layers.json got externally modified
Browse files Browse the repository at this point in the history
This helps long running processes like CRI-O to determine changes to the
local storage, while handling corrupted images automatically.

The corresponding fix in Podman [0] handles corrupt layers by reloading
the image. This does not work for CRI-O, because it will not reload the
storage on subsequent calls of pullImage if no storage modification has
been done.

[0]: containers/podman@b4bd886

Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
  • Loading branch information
saschagrunert committed Jun 17, 2021
1 parent a52896d commit f637c5e
Showing 1 changed file with 34 additions and 17 deletions.
51 changes: 34 additions & 17 deletions layers.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,21 +271,22 @@ type LayerStore interface {
}

type layerStore struct {
lockfile Locker
mountsLockfile Locker
rundir string
driver drivers.Driver
layerdir string
layers []*Layer
idindex *truncindex.TruncIndex
byid map[string]*Layer
byname map[string]*Layer
bymount map[string]*Layer
bycompressedsum map[digest.Digest][]string
byuncompressedsum map[digest.Digest][]string
uidMap []idtools.IDMap
gidMap []idtools.IDMap
loadMut sync.Mutex
lockfile Locker
mountsLockfile Locker
rundir string
driver drivers.Driver
layerdir string
layers []*Layer
idindex *truncindex.TruncIndex
byid map[string]*Layer
byname map[string]*Layer
bymount map[string]*Layer
bycompressedsum map[digest.Digest][]string
byuncompressedsum map[digest.Digest][]string
uidMap []idtools.IDMap
gidMap []idtools.IDMap
loadMut sync.Mutex
layerspathModified time.Time
}

func copyLayer(l *Layer) *Layer {
Expand Down Expand Up @@ -1744,7 +1745,7 @@ func (r *layerStore) Touch() error {
}

func (r *layerStore) Modified() (bool, error) {
var mmodified bool
var mmodified, tmodified bool
lmodified, err := r.lockfile.Modified()
if err != nil {
return lmodified, err
Expand All @@ -1757,7 +1758,23 @@ func (r *layerStore) Modified() (bool, error) {
return lmodified, err
}
}
return lmodified || mmodified, nil

if lmodified || mmodified {
return true, nil
}

// If the layers.json file has been modified manually, then we have to
// reload the storage in any case.
info, err := os.Stat(r.layerspath())
if err != nil && !os.IsNotExist(err) {
return false, errors.Wrap(err, "stat layers file")
}
if info != nil {
tmodified = info.ModTime() != r.layerspathModified
r.layerspathModified = info.ModTime()
}

return tmodified, nil
}

func (r *layerStore) IsReadWrite() bool {
Expand Down

0 comments on commit f637c5e

Please sign in to comment.