mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-04 11:06:21 +00:00
virtcontainers: storage: Separate storage interface from implementations
The storage implementation of filesystem was in the same file where the resource storage interface was declared. It's more proper to separate implementations and interface into different files. Fixes #633 Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
parent
26f0430a7c
commit
8b20c3f26d
@ -112,49 +112,6 @@ var runStoragePath = filepath.Join("/run", storagePathSuffix, sandboxPathSuffix)
|
|||||||
// It will contain all guest vm sockets and shared mountpoints.
|
// It will contain all guest vm sockets and shared mountpoints.
|
||||||
var RunVMStoragePath = filepath.Join("/run", storagePathSuffix, vmPathSuffix)
|
var RunVMStoragePath = filepath.Join("/run", storagePathSuffix, vmPathSuffix)
|
||||||
|
|
||||||
// resourceStorage is the virtcontainers resources (configuration, state, etc...)
|
|
||||||
// storage interface.
|
|
||||||
// The default resource storage implementation is filesystem.
|
|
||||||
type resourceStorage interface {
|
|
||||||
// Create all resources for a sandbox
|
|
||||||
createAllResources(ctx context.Context, sandbox *Sandbox) error
|
|
||||||
|
|
||||||
// Resources URIs functions return both the URI
|
|
||||||
// for the actual resource and the URI base.
|
|
||||||
containerURI(sandboxID, containerID string, resource sandboxResource) (string, string, error)
|
|
||||||
sandboxURI(sandboxID string, resource sandboxResource) (string, string, error)
|
|
||||||
|
|
||||||
// Sandbox resources
|
|
||||||
storeSandboxResource(sandboxID string, resource sandboxResource, data interface{}) error
|
|
||||||
deleteSandboxResources(sandboxID string, resources []sandboxResource) error
|
|
||||||
fetchSandboxConfig(sandboxID string) (SandboxConfig, error)
|
|
||||||
fetchSandboxState(sandboxID string) (State, error)
|
|
||||||
fetchSandboxNetwork(sandboxID string) (NetworkNamespace, error)
|
|
||||||
storeSandboxNetwork(sandboxID string, networkNS NetworkNamespace) error
|
|
||||||
fetchSandboxDevices(sandboxID string) ([]api.Device, error)
|
|
||||||
storeSandboxDevices(sandboxID string, devices []api.Device) error
|
|
||||||
|
|
||||||
// Hypervisor resources
|
|
||||||
fetchHypervisorState(sandboxID string, state interface{}) error
|
|
||||||
storeHypervisorState(sandboxID string, state interface{}) error
|
|
||||||
|
|
||||||
// Agent resources
|
|
||||||
fetchAgentState(sandboxID string, state interface{}) error
|
|
||||||
storeAgentState(sandboxID string, state interface{}) error
|
|
||||||
|
|
||||||
// Container resources
|
|
||||||
storeContainerResource(sandboxID, containerID string, resource sandboxResource, data interface{}) error
|
|
||||||
deleteContainerResources(sandboxID, containerID string, resources []sandboxResource) error
|
|
||||||
fetchContainerConfig(sandboxID, containerID string) (ContainerConfig, error)
|
|
||||||
fetchContainerState(sandboxID, containerID string) (State, error)
|
|
||||||
fetchContainerProcess(sandboxID, containerID string) (Process, error)
|
|
||||||
storeContainerProcess(sandboxID, containerID string, process Process) error
|
|
||||||
fetchContainerMounts(sandboxID, containerID string) ([]Mount, error)
|
|
||||||
storeContainerMounts(sandboxID, containerID string, mounts []Mount) error
|
|
||||||
fetchContainerDevices(sandboxID, containerID string) ([]ContainerDevice, error)
|
|
||||||
storeContainerDevices(sandboxID, containerID string, devices []ContainerDevice) error
|
|
||||||
}
|
|
||||||
|
|
||||||
// filesystem is a resourceStorage interface implementation for a local filesystem.
|
// filesystem is a resourceStorage interface implementation for a local filesystem.
|
||||||
type filesystem struct {
|
type filesystem struct {
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
@ -246,17 +203,6 @@ func (fs *filesystem) storeFile(file string, data interface{}) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TypedDevice is used as an intermediate representation for marshalling
|
|
||||||
// and unmarshalling Device implementations.
|
|
||||||
type TypedDevice struct {
|
|
||||||
Type string
|
|
||||||
|
|
||||||
// Data is assigned the Device object.
|
|
||||||
// This being declared as RawMessage prevents it from being marshalled/unmarshalled.
|
|
||||||
// We do that explicitly depending on Type.
|
|
||||||
Data json.RawMessage
|
|
||||||
}
|
|
||||||
|
|
||||||
// storeDeviceIDFile is used to marshal and store device IDs to disk.
|
// storeDeviceIDFile is used to marshal and store device IDs to disk.
|
||||||
func (fs *filesystem) storeDeviceIDFile(file string, data interface{}) error {
|
func (fs *filesystem) storeDeviceIDFile(file string, data interface{}) error {
|
||||||
if file == "" {
|
if file == "" {
|
67
virtcontainers/resource_storage.go
Normal file
67
virtcontainers/resource_storage.go
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
// Copyright (c) 2018 Intel Corporation
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
//
|
||||||
|
|
||||||
|
package virtcontainers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
|
"github.com/kata-containers/runtime/virtcontainers/device/api"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TypedDevice is used as an intermediate representation for marshalling
|
||||||
|
// and unmarshalling Device implementations.
|
||||||
|
type TypedDevice struct {
|
||||||
|
Type string
|
||||||
|
|
||||||
|
// Data is assigned the Device object.
|
||||||
|
// This being declared as RawMessage prevents it from being marshalled/unmarshalled.
|
||||||
|
// We do that explicitly depending on Type.
|
||||||
|
Data json.RawMessage
|
||||||
|
}
|
||||||
|
|
||||||
|
// resourceStorage is the virtcontainers resources (configuration, state, etc...)
|
||||||
|
// storage interface.
|
||||||
|
// The default resource storage implementation is filesystem.
|
||||||
|
type resourceStorage interface {
|
||||||
|
// Create all resources for a sandbox
|
||||||
|
createAllResources(ctx context.Context, sandbox *Sandbox) error
|
||||||
|
|
||||||
|
// Resources URIs functions return both the URI
|
||||||
|
// for the actual resource and the URI base.
|
||||||
|
containerURI(sandboxID, containerID string, resource sandboxResource) (string, string, error)
|
||||||
|
sandboxURI(sandboxID string, resource sandboxResource) (string, string, error)
|
||||||
|
|
||||||
|
// Sandbox resources
|
||||||
|
storeSandboxResource(sandboxID string, resource sandboxResource, data interface{}) error
|
||||||
|
deleteSandboxResources(sandboxID string, resources []sandboxResource) error
|
||||||
|
fetchSandboxConfig(sandboxID string) (SandboxConfig, error)
|
||||||
|
fetchSandboxState(sandboxID string) (State, error)
|
||||||
|
fetchSandboxNetwork(sandboxID string) (NetworkNamespace, error)
|
||||||
|
storeSandboxNetwork(sandboxID string, networkNS NetworkNamespace) error
|
||||||
|
fetchSandboxDevices(sandboxID string) ([]api.Device, error)
|
||||||
|
storeSandboxDevices(sandboxID string, devices []api.Device) error
|
||||||
|
|
||||||
|
// Hypervisor resources
|
||||||
|
fetchHypervisorState(sandboxID string, state interface{}) error
|
||||||
|
storeHypervisorState(sandboxID string, state interface{}) error
|
||||||
|
|
||||||
|
// Agent resources
|
||||||
|
fetchAgentState(sandboxID string, state interface{}) error
|
||||||
|
storeAgentState(sandboxID string, state interface{}) error
|
||||||
|
|
||||||
|
// Container resources
|
||||||
|
storeContainerResource(sandboxID, containerID string, resource sandboxResource, data interface{}) error
|
||||||
|
deleteContainerResources(sandboxID, containerID string, resources []sandboxResource) error
|
||||||
|
fetchContainerConfig(sandboxID, containerID string) (ContainerConfig, error)
|
||||||
|
fetchContainerState(sandboxID, containerID string) (State, error)
|
||||||
|
fetchContainerProcess(sandboxID, containerID string) (Process, error)
|
||||||
|
storeContainerProcess(sandboxID, containerID string, process Process) error
|
||||||
|
fetchContainerMounts(sandboxID, containerID string) ([]Mount, error)
|
||||||
|
storeContainerMounts(sandboxID, containerID string, mounts []Mount) error
|
||||||
|
fetchContainerDevices(sandboxID, containerID string) ([]ContainerDevice, error)
|
||||||
|
storeContainerDevices(sandboxID, containerID string, devices []ContainerDevice) error
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user