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 <chengyu.zhu@intel.com>
This commit is contained in:
ChengyuZhu6 2023-09-04 13:18:23 +08:00
parent e4f33ac141
commit bd099fbda9
3 changed files with 21 additions and 14 deletions

View File

@ -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 {

View File

@ -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
}

View File

@ -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()