From bd099fbda95eff462f93e20889da00db99a938da Mon Sep 17 00:00:00 2001 From: ChengyuZhu6 Date: Mon, 4 Sep 2023 13:18:23 +0800 Subject: [PATCH] runtime: extend SharedFile to support mutiple storage devices To enhance the construction and administration of `Katavirtualvolume` storages, this commit expands the 'sharedFile' structure to manage both rootfs storages(`containerStorages`) including `Katavirtualvolume` and other data volumes storages(`volumeStorages`). NOTE: `volumeStorages` is intended for future extensions to support Kubernetes data volumes. Currently, `KataVirtualVolume` is exclusively employed for container rootfs, hence only `containerStorages` is actively utilized. Signed-off-by: ChengyuZhu6 --- src/runtime/virtcontainers/fs_share.go | 5 +++-- src/runtime/virtcontainers/fs_share_linux.go | 17 +++++++++-------- src/runtime/virtcontainers/kata_agent.go | 13 +++++++++---- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/runtime/virtcontainers/fs_share.go b/src/runtime/virtcontainers/fs_share.go index b5000291cc..3df08368ea 100644 --- a/src/runtime/virtcontainers/fs_share.go +++ b/src/runtime/virtcontainers/fs_share.go @@ -21,8 +21,9 @@ var fsShareTracingTags = map[string]string{ // SharedFile represents the outcome of a host filesystem sharing // operation. type SharedFile struct { - storage *grpc.Storage - guestPath string + containerStorages []*grpc.Storage + volumeStorages []*grpc.Storage + guestPath string } type FilesystemSharer interface { diff --git a/src/runtime/virtcontainers/fs_share_linux.go b/src/runtime/virtcontainers/fs_share_linux.go index 5bafb9e403..97e893fdda 100644 --- a/src/runtime/virtcontainers/fs_share_linux.go +++ b/src/runtime/virtcontainers/fs_share_linux.go @@ -455,13 +455,14 @@ func (f *FilesystemShare) shareRootFilesystemWithNydus(ctx context.Context, c *C f.Logger().Infof("Nydus rootfs info: %#v\n", rootfs) return &SharedFile{ - storage: rootfs, - guestPath: rootfsGuestPath, + containerStorages: []*grpc.Storage{rootfs}, + guestPath: rootfsGuestPath, }, nil } // func (c *Container) shareRootfs(ctx context.Context) (*grpc.Storage, string, error) { func (f *FilesystemShare) ShareRootFilesystem(ctx context.Context, c *Container) (*SharedFile, error) { + if c.rootFs.Type == NydusRootFSType { return f.shareRootFilesystemWithNydus(ctx, c) } @@ -470,13 +471,13 @@ func (f *FilesystemShare) ShareRootFilesystem(ctx context.Context, c *Container) if HasOptionPrefix(c.rootFs.Options, annotations.FileSystemLayer) { path := filepath.Join("/run/kata-containers", c.id, "rootfs") return &SharedFile{ - storage: &grpc.Storage{ + containerStorages: []*grpc.Storage{{ MountPoint: path, Source: "none", Fstype: c.rootFs.Type, Driver: kataOverlayDevType, Options: c.rootFs.Options, - }, + }}, guestPath: path, }, nil } @@ -541,8 +542,8 @@ func (f *FilesystemShare) ShareRootFilesystem(ctx context.Context, c *Container) } return &SharedFile{ - storage: rootfsStorage, - guestPath: rootfsGuestPath, + containerStorages: []*grpc.Storage{rootfsStorage}, + guestPath: rootfsGuestPath, }, nil } @@ -556,8 +557,8 @@ func (f *FilesystemShare) ShareRootFilesystem(ctx context.Context, c *Container) } return &SharedFile{ - storage: nil, - guestPath: rootfsGuestPath, + containerStorages: nil, + guestPath: rootfsGuestPath, }, nil } diff --git a/src/runtime/virtcontainers/kata_agent.go b/src/runtime/virtcontainers/kata_agent.go index c17e7f080f..3194ec6e84 100644 --- a/src/runtime/virtcontainers/kata_agent.go +++ b/src/runtime/virtcontainers/kata_agent.go @@ -1258,12 +1258,17 @@ func (k *kataAgent) createContainer(ctx context.Context, sandbox *Sandbox, c *Co return nil, err } - if sharedRootfs.storage != nil { + if sharedRootfs.containerStorages != nil { // Add rootfs to the list of container storage. - // We only need to do this for block based rootfs, as we + ctrStorages = append(ctrStorages, sharedRootfs.containerStorages...) + } + + if sharedRootfs.volumeStorages != nil { + // Add volumeStorages to the list of container storage. + // We only need to do this for KataVirtualVolume based rootfs, as we // want the agent to mount it into the right location - // (kataGuestSharedDir/ctrID/ - ctrStorages = append(ctrStorages, sharedRootfs.storage) + + ctrStorages = append(ctrStorages, sharedRootfs.volumeStorages...) } ociSpec := c.GetPatchedOCISpec()