summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorgVisor bot <gvisor-bot@google.com>2021-10-18 22:13:14 +0000
committergVisor bot <gvisor-bot@google.com>2021-10-18 22:13:14 +0000
commit8dfb5f0d9e54a20161b1faef7fbc50a3518d30df (patch)
treef32349b9e0ab81fbc9b5d9f841cea7da53c71c57
parentfaad7f2a97846313a8c6a82366232b25eccaf70f (diff)
parentfa56fbf44e440bbbca710ef1b7cc1d54f862c20e (diff)
Merge release-20211005.0-57-gfa56fbf44 (automated)
-rw-r--r--pkg/sentry/fsimpl/tmpfs/regular_file.go2
-rw-r--r--pkg/sentry/fsimpl/tmpfs/tmpfs.go14
-rw-r--r--pkg/sentry/fsimpl/tmpfs/tmpfs_state_autogen.go14
3 files changed, 25 insertions, 5 deletions
diff --git a/pkg/sentry/fsimpl/tmpfs/regular_file.go b/pkg/sentry/fsimpl/tmpfs/regular_file.go
index 0f2ac6144..453e1aa61 100644
--- a/pkg/sentry/fsimpl/tmpfs/regular_file.go
+++ b/pkg/sentry/fsimpl/tmpfs/regular_file.go
@@ -95,7 +95,7 @@ type regularFile struct {
func (fs *filesystem) newRegularFile(kuid auth.KUID, kgid auth.KGID, mode linux.FileMode, parentDir *directory) *inode {
file := &regularFile{
memFile: fs.mfp.MemoryFile(),
- memoryUsageKind: usage.Tmpfs,
+ memoryUsageKind: fs.usage,
seals: linux.F_SEAL_SEAL,
}
file.inode.init(file, fs, kuid, kgid, linux.S_IFREG|mode, parentDir)
diff --git a/pkg/sentry/fsimpl/tmpfs/tmpfs.go b/pkg/sentry/fsimpl/tmpfs/tmpfs.go
index feafb06e4..f84165aba 100644
--- a/pkg/sentry/fsimpl/tmpfs/tmpfs.go
+++ b/pkg/sentry/fsimpl/tmpfs/tmpfs.go
@@ -41,6 +41,7 @@ import (
"gvisor.dev/gvisor/pkg/sentry/kernel/auth"
"gvisor.dev/gvisor/pkg/sentry/kernel/time"
"gvisor.dev/gvisor/pkg/sentry/pgalloc"
+ "gvisor.dev/gvisor/pkg/sentry/usage"
"gvisor.dev/gvisor/pkg/sentry/vfs"
"gvisor.dev/gvisor/pkg/sentry/vfs/memxattr"
"gvisor.dev/gvisor/pkg/sync"
@@ -74,6 +75,10 @@ type filesystem struct {
// filesystem. Immutable.
mopts string
+ // usage is the memory accounting category under which pages backing
+ // files in this filesystem are accounted.
+ usage usage.MemoryKind
+
// mu serializes changes to the Dentry tree.
mu sync.RWMutex `state:"nosave"`
@@ -106,6 +111,10 @@ type FilesystemOpts struct {
// tmpfs filesystem. This allows tmpfs to "impersonate" other
// filesystems, like ramdiskfs and cgroupfs.
FilesystemType vfs.FilesystemType
+
+ // Usage is the memory accounting category under which pages backing files in
+ // the filesystem are accounted.
+ Usage *usage.MemoryKind
}
// GetFilesystem implements vfs.FilesystemType.GetFilesystem.
@@ -184,11 +193,16 @@ func (fstype FilesystemType) GetFilesystem(ctx context.Context, vfsObj *vfs.Virt
return nil, nil, err
}
clock := time.RealtimeClockFromContext(ctx)
+ memUsage := usage.Tmpfs
+ if tmpfsOpts.Usage != nil {
+ memUsage = *tmpfsOpts.Usage
+ }
fs := filesystem{
mfp: mfp,
clock: clock,
devMinor: devMinor,
mopts: opts.Data,
+ usage: memUsage,
}
fs.vfsfs.Init(vfsObj, newFSType, &fs)
diff --git a/pkg/sentry/fsimpl/tmpfs/tmpfs_state_autogen.go b/pkg/sentry/fsimpl/tmpfs/tmpfs_state_autogen.go
index 6d9f09eef..9a30a69a3 100644
--- a/pkg/sentry/fsimpl/tmpfs/tmpfs_state_autogen.go
+++ b/pkg/sentry/fsimpl/tmpfs/tmpfs_state_autogen.go
@@ -377,6 +377,7 @@ func (fs *filesystem) StateFields() []string {
"clock",
"devMinor",
"mopts",
+ "usage",
"nextInoMinusOne",
"root",
}
@@ -392,8 +393,9 @@ func (fs *filesystem) StateSave(stateSinkObject state.Sink) {
stateSinkObject.Save(2, &fs.clock)
stateSinkObject.Save(3, &fs.devMinor)
stateSinkObject.Save(4, &fs.mopts)
- stateSinkObject.Save(5, &fs.nextInoMinusOne)
- stateSinkObject.Save(6, &fs.root)
+ stateSinkObject.Save(5, &fs.usage)
+ stateSinkObject.Save(6, &fs.nextInoMinusOne)
+ stateSinkObject.Save(7, &fs.root)
}
func (fs *filesystem) afterLoad() {}
@@ -405,8 +407,9 @@ func (fs *filesystem) StateLoad(stateSourceObject state.Source) {
stateSourceObject.Load(2, &fs.clock)
stateSourceObject.Load(3, &fs.devMinor)
stateSourceObject.Load(4, &fs.mopts)
- stateSourceObject.Load(5, &fs.nextInoMinusOne)
- stateSourceObject.Load(6, &fs.root)
+ stateSourceObject.Load(5, &fs.usage)
+ stateSourceObject.Load(6, &fs.nextInoMinusOne)
+ stateSourceObject.Load(7, &fs.root)
}
func (f *FilesystemOpts) StateTypeName() string {
@@ -418,6 +421,7 @@ func (f *FilesystemOpts) StateFields() []string {
"RootFileType",
"RootSymlinkTarget",
"FilesystemType",
+ "Usage",
}
}
@@ -429,6 +433,7 @@ func (f *FilesystemOpts) StateSave(stateSinkObject state.Sink) {
stateSinkObject.Save(0, &f.RootFileType)
stateSinkObject.Save(1, &f.RootSymlinkTarget)
stateSinkObject.Save(2, &f.FilesystemType)
+ stateSinkObject.Save(3, &f.Usage)
}
func (f *FilesystemOpts) afterLoad() {}
@@ -438,6 +443,7 @@ func (f *FilesystemOpts) StateLoad(stateSourceObject state.Source) {
stateSourceObject.Load(0, &f.RootFileType)
stateSourceObject.Load(1, &f.RootSymlinkTarget)
stateSourceObject.Load(2, &f.FilesystemType)
+ stateSourceObject.Load(3, &f.Usage)
}
func (d *dentry) StateTypeName() string {