mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-09-06 03:10:07 +00:00
runtime: redefine and add functions to handle VirtualVolume to storage
1) Extract function `handleBlockVolume` to create Storage only. 2) Add functions to handle KataVirtualVolume device and construct corresponding storages. Signed-off-by: ChengyuZhu6 <chengyu.zhu@intel.com>
This commit is contained in:
@@ -89,6 +89,7 @@ var (
|
|||||||
remoteRequestTimeout = 300 * time.Second
|
remoteRequestTimeout = 300 * time.Second
|
||||||
customRequestTimeoutKey = customRequestTimeoutKeyType(struct{}{})
|
customRequestTimeoutKey = customRequestTimeoutKeyType(struct{}{})
|
||||||
errorMissingOCISpec = errors.New("Missing OCI specification")
|
errorMissingOCISpec = errors.New("Missing OCI specification")
|
||||||
|
defaultKataGuestVirtualVolumedir = "/run/kata-containers/virtual-volumes/"
|
||||||
defaultKataHostSharedDir = "/run/kata-containers/shared/sandboxes/"
|
defaultKataHostSharedDir = "/run/kata-containers/shared/sandboxes/"
|
||||||
defaultKataGuestSharedDir = "/run/kata-containers/shared/containers/"
|
defaultKataGuestSharedDir = "/run/kata-containers/shared/containers/"
|
||||||
defaultKataGuestNydusRootDir = "/run/kata-containers/shared/"
|
defaultKataGuestNydusRootDir = "/run/kata-containers/shared/"
|
||||||
@@ -109,6 +110,7 @@ var (
|
|||||||
kataVfioPciDevType = "vfio-pci" // VFIO device to used as VFIO in the container
|
kataVfioPciDevType = "vfio-pci" // VFIO device to used as VFIO in the container
|
||||||
kataVfioPciGuestKernelDevType = "vfio-pci-gk" // VFIO device for consumption by the guest kernel
|
kataVfioPciGuestKernelDevType = "vfio-pci-gk" // VFIO device for consumption by the guest kernel
|
||||||
kataVfioApDevType = "vfio-ap"
|
kataVfioApDevType = "vfio-ap"
|
||||||
|
kataDmVerityBlkDevType = "dmverity"
|
||||||
sharedDir9pOptions = []string{"trans=virtio,version=9p2000.L,cache=mmap", "nodev"}
|
sharedDir9pOptions = []string{"trans=virtio,version=9p2000.L,cache=mmap", "nodev"}
|
||||||
sharedDirVirtioFSOptions = []string{}
|
sharedDirVirtioFSOptions = []string{}
|
||||||
sharedDirVirtioFSDaxOptions = "dax"
|
sharedDirVirtioFSDaxOptions = "dax"
|
||||||
@@ -1544,14 +1546,36 @@ func (k *kataAgent) handleLocalStorage(mounts []specs.Mount, sandboxID string, r
|
|||||||
return localStorages, nil
|
return localStorages, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// handleDeviceBlockVolume handles volume that is block device file
|
// Add the source block type to DriverOptions in the volume with dm-verity
|
||||||
// and DeviceBlock type.
|
func handleDmVerityBlockVolume(driverType, source string, verityInfo *types.DmVerityInfo, vol *grpc.Storage) (*grpc.Storage, error) {
|
||||||
func (k *kataAgent) handleDeviceBlockVolume(c *Container, m Mount, device api.Device) (*grpc.Storage, error) {
|
no, err := json.Marshal(verityInfo)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
vol.Driver = kataDmVerityBlkDevType
|
||||||
|
vol.DriverOptions = append(vol.DriverOptions, "verity_info="+string(no))
|
||||||
|
switch driverType {
|
||||||
|
case kataNvdimmDevType:
|
||||||
|
vol.DriverOptions = append(vol.DriverOptions, "source_type=pmem")
|
||||||
|
case kataBlkCCWDevType:
|
||||||
|
vol.DriverOptions = append(vol.DriverOptions, "source_type=virtio_ccw")
|
||||||
|
case kataBlkDevType:
|
||||||
|
vol.DriverOptions = append(vol.DriverOptions, "source_type=virtio_pci")
|
||||||
|
case kataMmioBlkDevType:
|
||||||
|
vol.DriverOptions = append(vol.DriverOptions, "source_type=virtio_mmio")
|
||||||
|
case kataSCSIDevType:
|
||||||
|
vol.DriverOptions = append(vol.DriverOptions, "source_type=scsi")
|
||||||
|
}
|
||||||
|
vol.Options = []string{"ro"}
|
||||||
|
vol.MountPoint = filepath.Join(defaultKataGuestVirtualVolumedir, "verity", verityInfo.Hash)
|
||||||
|
return vol, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func handleBlockVolume(c *Container, device api.Device) (*grpc.Storage, error) {
|
||||||
vol := &grpc.Storage{}
|
vol := &grpc.Storage{}
|
||||||
|
|
||||||
blockDrive, ok := device.GetDeviceInfo().(*config.BlockDrive)
|
blockDrive, ok := device.GetDeviceInfo().(*config.BlockDrive)
|
||||||
if !ok || blockDrive == nil {
|
if !ok || blockDrive == nil {
|
||||||
k.Logger().Error("malformed block drive")
|
|
||||||
return nil, fmt.Errorf("malformed block drive")
|
return nil, fmt.Errorf("malformed block drive")
|
||||||
}
|
}
|
||||||
switch {
|
switch {
|
||||||
@@ -1576,6 +1600,47 @@ func (k *kataAgent) handleDeviceBlockVolume(c *Container, m Mount, device api.De
|
|||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("Unknown block device driver: %s", c.sandbox.config.HypervisorConfig.BlockDeviceDriver)
|
return nil, fmt.Errorf("Unknown block device driver: %s", c.sandbox.config.HypervisorConfig.BlockDeviceDriver)
|
||||||
}
|
}
|
||||||
|
return vol, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// handleVirtualVolumeStorageObject handles KataVirtualVolume that is block device file.
|
||||||
|
func handleVirtualVolumeStorageObject(c *Container, blockDeviceId string, virtVolume *types.KataVirtualVolume) (*grpc.Storage, error) {
|
||||||
|
var vol *grpc.Storage
|
||||||
|
if virtVolume.VolumeType == types.KataVirtualVolumeImageRawBlockType || virtVolume.VolumeType == types.KataVirtualVolumeLayerRawBlockType {
|
||||||
|
device := c.sandbox.devManager.GetDeviceByID(blockDeviceId)
|
||||||
|
if device == nil {
|
||||||
|
return nil, fmt.Errorf("Failed to find device by id (id=%s) in handleVirtualVolumeStorageObject", blockDeviceId)
|
||||||
|
}
|
||||||
|
var err error
|
||||||
|
vol, err = handleBlockVolume(c, device)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
filename := b64.URLEncoding.EncodeToString([]byte(vol.Source))
|
||||||
|
vol.MountPoint = filepath.Join(defaultKataGuestVirtualVolumedir, filename)
|
||||||
|
|
||||||
|
//convert block storage to dmverity storage if dm-verity info is available
|
||||||
|
if virtVolume.DmVerity != nil {
|
||||||
|
vol, err = handleDmVerityBlockVolume(vol.Driver, virtVolume.Source, virtVolume.DmVerity, vol)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if virtVolume.VolumeType == types.KataVirtualVolumeImageGuestPullType {
|
||||||
|
///TODO implement the logic with pulling image in the guest.
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return vol, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// handleDeviceBlockVolume handles volume that is block device file
|
||||||
|
// and DeviceBlock type.
|
||||||
|
func (k *kataAgent) handleDeviceBlockVolume(c *Container, m Mount, device api.Device) (*grpc.Storage, error) {
|
||||||
|
vol, err := handleBlockVolume(c, device)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
vol.MountPoint = m.Destination
|
vol.MountPoint = m.Destination
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user