diff options
author | Rahat Mahmood <rahat@google.com> | 2021-04-05 16:00:17 -0700 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2021-04-05 16:06:11 -0700 |
commit | 88f198c2a9da1bac9726db18af4e7615aaa65476 (patch) | |
tree | b3be2c4c001ff6899197c6e380178bf4c1dd9726 /pkg/sentry/fsimpl/cgroupfs/cgroupfs.go | |
parent | 2d9095c7a669ad2632f12de8d0918f8bf48b499e (diff) |
Allow default control values to be set for cgroupfs.
PiperOrigin-RevId: 366891806
Diffstat (limited to 'pkg/sentry/fsimpl/cgroupfs/cgroupfs.go')
-rw-r--r-- | pkg/sentry/fsimpl/cgroupfs/cgroupfs.go | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/pkg/sentry/fsimpl/cgroupfs/cgroupfs.go b/pkg/sentry/fsimpl/cgroupfs/cgroupfs.go index 3d4005fd8..6061bace2 100644 --- a/pkg/sentry/fsimpl/cgroupfs/cgroupfs.go +++ b/pkg/sentry/fsimpl/cgroupfs/cgroupfs.go @@ -94,6 +94,14 @@ var SupportedMountOptions = []string{"all", "cpu", "cpuacct", "cpuset", "memory" // +stateify savable type FilesystemType struct{} +// InternalData contains internal data passed in to the cgroupfs mount via +// vfs.GetFilesystemOptions.InternalData. +// +// +stateify savable +type InternalData struct { + DefaultControlValues map[string]int64 +} + // filesystem implements vfs.FilesystemImpl. // // +stateify savable @@ -218,13 +226,19 @@ func (fsType FilesystemType) GetFilesystem(ctx context.Context, vfsObj *vfs.Virt fs.MaxCachedDentries = maxCachedDentries fs.VFSFilesystem().Init(vfsObj, &fsType, fs) + var defaults map[string]int64 + if opts.InternalData != nil { + ctx.Debugf("cgroupfs.FilesystemType.GetFilesystem: default control values: %v", defaults) + defaults = opts.InternalData.(*InternalData).DefaultControlValues + } + for _, ty := range wantControllers { var c controller switch ty { case controllerMemory: - c = newMemoryController(fs) + c = newMemoryController(fs, defaults) case controllerCPU: - c = newCPUController(fs) + c = newCPUController(fs, defaults) case controllerCPUAcct: c = newCPUAcctController(fs) case controllerCPUSet: @@ -235,6 +249,12 @@ func (fsType FilesystemType) GetFilesystem(ctx context.Context, vfsObj *vfs.Virt fs.controllers = append(fs.controllers, c) } + if len(defaults) != 0 { + // Internal data is always provided at sentry startup and unused values + // indicate a problem with the sandbox config. Fail fast. + panic(fmt.Sprintf("cgroupfs.FilesystemType.GetFilesystem: unknown internal mount data: %v", defaults)) + } + // Controllers usually appear in alphabetical order when displayed. Sort it // here now, so it never needs to be sorted elsewhere. sort.Slice(fs.controllers, func(i, j int) bool { return fs.controllers[i].Type() < fs.controllers[j].Type() }) |