Skip to content

Commit

Permalink
snapshot: fix a bug in generating mount for view snapshot
Browse files Browse the repository at this point in the history
When generating a view snapshot with only one parent, it will generate
bind mount instead of overlayfs mount, and missing extra options,
such as `KataVirtualVolume` or `extraoptions`.

Fix it by using overlayfs for view snapshot with only one parent.

Signed-off-by: Jiang Liu <[email protected]>
  • Loading branch information
jiangliu committed Sep 12, 2023
1 parent fedb996 commit 0da2966
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
2 changes: 1 addition & 1 deletion snapshot/mount_option.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ func EncodeKataVirtualVolumeToBase64(volume KataVirtualVolume) (string, error) {
if err != nil {
return "", errors.Wrapf(err, "marshal KataVirtualVolume object")
}
log.L.Infof("Mount info with kata volume %s", validKataVirtualVolumeJSON)
log.L.Infof("encode kata volume %s", validKataVirtualVolumeJSON)
option := base64.StdEncoding.EncodeToString(validKataVirtualVolumeJSON)
return option, nil
}
19 changes: 8 additions & 11 deletions snapshot/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -843,16 +843,8 @@ func overlayMount(options []string) []mount.Mount {
// `s` and `id` can represent a different layer, it's useful when View an image
func (o *snapshotter) mountRemote(ctx context.Context, labels map[string]string, s storage.Snapshot, id string) ([]mount.Mount, error) {
var overlayOptions []string
if s.Kind == snapshots.KindActive {
overlayOptions = append(overlayOptions,
fmt.Sprintf("workdir=%s", o.workPath(s.ID)),
fmt.Sprintf("upperdir=%s", o.upperPath(s.ID)),
)
if _, ok := labels[label.OverlayfsVolatileOpt]; ok {
overlayOptions = append(overlayOptions, "volatile")
}
} else if len(s.ParentIDs) == 1 {
return bindMount(o.upperPath(s.ParentIDs[0]), "ro"), nil
if _, ok := labels[label.OverlayfsVolatileOpt]; ok {
overlayOptions = append(overlayOptions, "volatile")
}

lowerPaths := make([]string, 0, 8)
Expand All @@ -862,7 +854,12 @@ func (o *snapshotter) mountRemote(ctx context.Context, labels map[string]string,
}
lowerPaths = append(lowerPaths, lowerPathNydus)

if s.Kind == snapshots.KindView {
if s.Kind == snapshots.KindActive {
overlayOptions = append(overlayOptions,
fmt.Sprintf("workdir=%s", o.workPath(s.ID)),
fmt.Sprintf("upperdir=%s", o.upperPath(s.ID)),
)
} else if s.Kind == snapshots.KindView {
lowerPathNormal, err := o.lowerPath(s.ID)
if err != nil {
return nil, errors.Wrapf(err, "failed to locate overlay lowerdir for view snapshot")
Expand Down

0 comments on commit 0da2966

Please sign in to comment.