mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-09-05 10:50:18 +00:00
runtime: support to create VirtualVolume rootfs storages
1) Creating storage for all `io.katacontainers.volume=` messages in rootFs.Options, and then aggregates all storages into `containerStorages`. 2) Creating storage for other data volumes and push them into `volumeStorages`. Signed-off-by: ChengyuZhu6 <chengyu.zhu@intel.com>
This commit is contained in:
@@ -130,7 +130,7 @@ func CreateSandbox(ctx context.Context, vci vc.VC, ociSpec specs.Spec, runtimeCo
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !rootFs.Mounted && len(sandboxConfig.Containers) == 1 {
|
if !rootFs.Mounted && len(sandboxConfig.Containers) == 1 {
|
||||||
if rootFs.Source != "" {
|
if rootFs.Source != "" && !vc.HasOptionPrefix(rootFs.Options, vc.VirtualVolumePrefix) {
|
||||||
realPath, err := ResolvePath(rootFs.Source)
|
realPath, err := ResolvePath(rootFs.Source)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, vc.Process{}, err
|
return nil, vc.Process{}, err
|
||||||
|
@@ -15,6 +15,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
@@ -26,6 +27,7 @@ import (
|
|||||||
"github.com/kata-containers/kata-containers/src/runtime/pkg/katautils/katatrace"
|
"github.com/kata-containers/kata-containers/src/runtime/pkg/katautils/katatrace"
|
||||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols/grpc"
|
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols/grpc"
|
||||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/annotations"
|
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/annotations"
|
||||||
|
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types"
|
||||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/utils"
|
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -460,9 +462,55 @@ func (f *FilesystemShare) shareRootFilesystemWithNydus(ctx context.Context, c *C
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handleVirtualVolume processes all `io.katacontainers.volume=` messages in rootFs.Options,
|
||||||
|
// creating storage, and then aggregates all storages into an array.
|
||||||
|
func handleVirtualVolume(c *Container) ([]*grpc.Storage, string, error) {
|
||||||
|
var volumes []*grpc.Storage
|
||||||
|
var volumeType string
|
||||||
|
|
||||||
|
for _, o := range c.rootFs.Options {
|
||||||
|
if strings.HasPrefix(o, VirtualVolumePrefix) {
|
||||||
|
virtVolume, err := types.ParseKataVirtualVolume(strings.TrimPrefix(o, VirtualVolumePrefix))
|
||||||
|
if err != nil {
|
||||||
|
return nil, "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
volumeType = virtVolume.VolumeType
|
||||||
|
var vol *grpc.Storage
|
||||||
|
vol, err = handleVirtualVolumeStorageObject(c, "", virtVolume)
|
||||||
|
if err != nil {
|
||||||
|
return nil, "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
if vol != nil {
|
||||||
|
volumes = append(volumes, vol)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return volumes, volumeType, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *FilesystemShare) shareRootFilesystemWithVirtualVolume(ctx context.Context, c *Container) (*SharedFile, error) {
|
||||||
|
guestPath := filepath.Join("/run/kata-containers/", c.id, c.rootfsSuffix)
|
||||||
|
rootFsStorages, _, err := handleVirtualVolume(c)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &SharedFile{
|
||||||
|
containerStorages: rootFsStorages,
|
||||||
|
guestPath: guestPath,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
// func (c *Container) shareRootfs(ctx context.Context) (*grpc.Storage, string, error) {
|
// func (c *Container) shareRootfs(ctx context.Context) (*grpc.Storage, string, error) {
|
||||||
func (f *FilesystemShare) ShareRootFilesystem(ctx context.Context, c *Container) (*SharedFile, error) {
|
func (f *FilesystemShare) ShareRootFilesystem(ctx context.Context, c *Container) (*SharedFile, error) {
|
||||||
|
|
||||||
|
if HasOptionPrefix(c.rootFs.Options, VirtualVolumePrefix) {
|
||||||
|
return f.shareRootFilesystemWithVirtualVolume(ctx, c)
|
||||||
|
}
|
||||||
|
|
||||||
if c.rootFs.Type == NydusRootFSType {
|
if c.rootFs.Type == NydusRootFSType {
|
||||||
return f.shareRootFilesystemWithNydus(ctx, c)
|
return f.shareRootFilesystemWithNydus(ctx, c)
|
||||||
}
|
}
|
||||||
|
@@ -91,6 +91,7 @@ var (
|
|||||||
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/"
|
||||||
|
defaultKataGuestVirtualVolumedir = "/run/kata-containers/virtual-volumes/"
|
||||||
mountGuestTag = "kataShared"
|
mountGuestTag = "kataShared"
|
||||||
defaultKataGuestSandboxDir = "/run/kata-containers/sandbox/"
|
defaultKataGuestSandboxDir = "/run/kata-containers/sandbox/"
|
||||||
type9pFs = "9p"
|
type9pFs = "9p"
|
||||||
@@ -1200,6 +1201,10 @@ func (k *kataAgent) appendDevices(deviceList []*grpc.Device, c *Container) []*gr
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if strings.HasPrefix(dev.ContainerPath, defaultKataGuestVirtualVolumedir) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
switch device.DeviceType() {
|
switch device.DeviceType() {
|
||||||
case config.DeviceBlock:
|
case config.DeviceBlock:
|
||||||
kataDevice = k.appendBlockDevice(dev, device, c)
|
kataDevice = k.appendBlockDevice(dev, device, c)
|
||||||
|
Reference in New Issue
Block a user