Skip to content

Commit

Permalink
snapshot: Introduce a function to prepare KataVirtualVolume
Browse files Browse the repository at this point in the history
Introduce a function to prepare KataVirtualVolume for both guest pull image
and host sharing image modes to eliminate redundant code.

Signed-off-by: ChengyuZhu6 <[email protected]>
  • Loading branch information
ChengyuZhu6 committed Dec 7, 2023
1 parent 685b708 commit 7ead21f
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions snapshot/mount_option.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,37 @@ func (o *snapshotter) mountWithTarfsVolume(rafs rafs.Rafs, blobID string) ([]str
return []string{}, nil
}

func (o *snapshotter) prepareKataVirtualVolume(blockType, source, volumeType, fsType string, options []string, labels map[string]string) (string, error) {
volume := &KataVirtualVolume{
VolumeType: volumeType,
Source: source,
FSType: fsType,
Options: options,
}
if blockType == label.NydusImageBlockInfo || blockType == label.NydusLayerBlockInfo {
dmverityInfo := labels[blockType]
if len(dmverityInfo) > 0 {
dmverity, err := parseTarfsDmVerityInfo(dmverityInfo)
if err != nil {
return "", err
}
volume.DmVerity = &dmverity
}
} else if blockType == label.NydusProxyMode {
volume.ImagePull = &ImagePullVolume{Metadata: labels}
}

if !volume.Validate() {
return "", errors.Errorf("got invalid kata volume, %v", volume)
}
info, err := EncodeKataVirtualVolumeToBase64(*volume)
if err != nil {
return "", errors.Errorf("failed to encoding Kata Volume info %v", volume)
}
opt := fmt.Sprintf("%s=%s", KataVirtualVolumeOptionName, info)
return opt, nil
}

func parseTarfsDmVerityInfo(info string) (DmVerityInfo, error) {
var dataBlocks, hashOffset uint64
var rootHash string
Expand Down

0 comments on commit 7ead21f

Please sign in to comment.