Skip to content

Commit

Permalink
BUG FIX containerd#123
Browse files Browse the repository at this point in the history
overlaybd snapshotter should check the image type when the label
'containerd.io/snapshot/overlaybd.writable' has been set.

this value should be ignored for normal images. containerd#123

Signed-off-by: Yifan Yuan <[email protected]>
  • Loading branch information
BigVan authored and HileQAQ committed Sep 27, 2022
1 parent 1654ecc commit 1b5636a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions pkg/snapshot/overlay.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ func (o *snapshotter) Usage(ctx context.Context, key string) (snapshots.Usage, e
return usage, nil
}

func (o *snapshotter) getWritableType(ctx context.Context, info snapshots.Info) (mode int) {
func (o *snapshotter) getWritableType(ctx context.Context, id string, info snapshots.Info) (mode int) {
defer func() {
log.G(ctx).Infof("snapshot R/W label: %d", mode)
}()
Expand All @@ -307,6 +307,11 @@ func (o *snapshotter) getWritableType(ctx context.Context, info snapshots.Info)
if !ok {
return
}
filePath := o.overlaybdWritableDataPath(id)
if _, err := os.Stat(filePath); err != nil {
log.G(ctx).Errorf("overlaybd writable file stat failed: %v", err)
return
}
if m == "dir" {
mode = rwDir
return
Expand Down Expand Up @@ -414,7 +419,7 @@ func (o *snapshotter) createMountPoint(ctx context.Context, kind snapshots.Kind,
}

stype := storageTypeNormal
writeType := o.getWritableType(ctx, info)
writeType := o.getWritableType(ctx, id, info)
// If Preparing for rootfs, find metadata from its parent (top layer), launch and mount backstore device.
if _, ok := info.Labels[labelKeyTargetSnapshotRef]; !ok {
if writeType != roDir {
Expand All @@ -428,14 +433,12 @@ func (o *snapshotter) createMountPoint(ctx context.Context, kind snapshots.Kind,
return nil, err
}
}

switch stype {
case storageTypeLocalBlock, storageTypeRemoteBlock:
if parent != "" {
parentIsAccelLayer := parentInfo.Labels[labelKeyAccelerationLayer] == "yes"
needRecordTrace := info.Labels[labelKeyRecordTrace] == "yes"
recordTracePath := info.Labels[labelKeyRecordTracePath]

log.G(ctx).Debugf("Prepare rootfs (parentIsAccelLayer: %t, needRecordTrace: %t, recordTracePath: %s)",
parentIsAccelLayer, needRecordTrace, recordTracePath)

Expand Down Expand Up @@ -550,7 +553,7 @@ func (o *snapshotter) Mounts(ctx context.Context, key string) ([]mount.Mount, er
return nil, errors.Wrap(err, "failed to get info")
}

writeType := o.getWritableType(ctx, info)
writeType := o.getWritableType(ctx, s.ID, info)
if writeType != roDir {
return o.basedOnBlockDeviceMount(ctx, s, writeType)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/snapshot/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (o *snapshotter) unmountAndDetachBlockDevice(ctx context.Context, snID stri
if err != nil {
return errors.Wrapf(err, "can't get snapshot info.")
}
writeType := o.getWritableType(ctx, info)
writeType := o.getWritableType(ctx, snID, info)

if writeType != rwDev {
mountPoint := o.overlaybdMountpoint(snID)
Expand Down

0 comments on commit 1b5636a

Please sign in to comment.