mirror of
https://github.com/aljazceru/kata-containers.git
synced 2025-12-26 18:44:47 +01:00
VMCache is a new function that creates VMs as caches before using it. It helps speed up new container creation. The function consists of a server and some clients communicating through Unix socket. The protocol is gRPC in protocols/cache/cache.proto. The VMCache server will create some VMs and cache them by factory cache. It will convert the VM to gRPC format and transport it when gets requestion from clients. Factory grpccache is the VMCache client. It will request gRPC format VM and convert it back to a VM. If VMCache function is enabled, kata-runtime will request VM from factory grpccache when it creates a new sandbox. VMCache has two options. vm_cache_number specifies the number of caches of VMCache: unspecified or == 0 --> VMCache is disabled > 0 --> will be set to the specified number vm_cache_endpoint specifies the address of the Unix socket. This commit just includes the core and the client of VMCache. Currently, VM cache still cannot work with VM templating and vsock. And just support qemu. Fixes: #52 Signed-off-by: Hui Zhu <teawater@hyper.sh>
117 lines
2.5 KiB
Go
117 lines
2.5 KiB
Go
// Copyright (c) 2016 Intel Corporation
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
|
|
package virtcontainers
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"os"
|
|
|
|
"github.com/kata-containers/runtime/virtcontainers/store"
|
|
"github.com/kata-containers/runtime/virtcontainers/types"
|
|
)
|
|
|
|
type mockHypervisor struct {
|
|
mockPid int
|
|
}
|
|
|
|
func (m *mockHypervisor) capabilities() types.Capabilities {
|
|
return types.Capabilities{}
|
|
}
|
|
|
|
func (m *mockHypervisor) hypervisorConfig() HypervisorConfig {
|
|
return HypervisorConfig{}
|
|
}
|
|
|
|
func (m *mockHypervisor) createSandbox(ctx context.Context, id string, hypervisorConfig *HypervisorConfig, store *store.VCStore) error {
|
|
err := hypervisorConfig.valid()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (m *mockHypervisor) startSandbox(timeout int) error {
|
|
return nil
|
|
}
|
|
|
|
func (m *mockHypervisor) stopSandbox() error {
|
|
return nil
|
|
}
|
|
|
|
func (m *mockHypervisor) pauseSandbox() error {
|
|
return nil
|
|
}
|
|
|
|
func (m *mockHypervisor) resumeSandbox() error {
|
|
return nil
|
|
}
|
|
|
|
func (m *mockHypervisor) saveSandbox() error {
|
|
return nil
|
|
}
|
|
|
|
func (m *mockHypervisor) addDevice(devInfo interface{}, devType deviceType) error {
|
|
return nil
|
|
}
|
|
|
|
func (m *mockHypervisor) hotplugAddDevice(devInfo interface{}, devType deviceType) (interface{}, error) {
|
|
switch devType {
|
|
case cpuDev:
|
|
return devInfo.(uint32), nil
|
|
case memoryDev:
|
|
memdev := devInfo.(*memoryDevice)
|
|
return memdev.sizeMB, nil
|
|
}
|
|
return nil, nil
|
|
}
|
|
|
|
func (m *mockHypervisor) hotplugRemoveDevice(devInfo interface{}, devType deviceType) (interface{}, error) {
|
|
switch devType {
|
|
case cpuDev:
|
|
return devInfo.(uint32), nil
|
|
case memoryDev:
|
|
return 0, nil
|
|
}
|
|
return nil, nil
|
|
}
|
|
|
|
func (m *mockHypervisor) getSandboxConsole(sandboxID string) (string, error) {
|
|
return "", nil
|
|
}
|
|
|
|
func (m *mockHypervisor) resizeMemory(memMB uint32, memorySectionSizeMB uint32) (uint32, error) {
|
|
return 0, nil
|
|
}
|
|
func (m *mockHypervisor) resizeVCPUs(cpus uint32) (uint32, uint32, error) {
|
|
return 0, 0, nil
|
|
}
|
|
|
|
func (m *mockHypervisor) disconnect() {
|
|
}
|
|
|
|
func (m *mockHypervisor) getThreadIDs() (*threadIDs, error) {
|
|
vcpus := []int{os.Getpid()}
|
|
return &threadIDs{vcpus}, nil
|
|
}
|
|
|
|
func (m *mockHypervisor) cleanup() error {
|
|
return nil
|
|
}
|
|
|
|
func (m *mockHypervisor) pid() int {
|
|
return m.mockPid
|
|
}
|
|
|
|
func (m *mockHypervisor) fromGrpc(ctx context.Context, hypervisorConfig *HypervisorConfig, store *store.VCStore, j []byte) error {
|
|
return errors.New("mockHypervisor is not supported by VM cache")
|
|
}
|
|
|
|
func (m *mockHypervisor) toGrpc() ([]byte, error) {
|
|
return nil, errors.New("firecracker is not supported by VM cache")
|
|
}
|