diff options
author | Googler <noreply@google.com> | 2019-02-13 12:06:20 -0800 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2019-02-13 12:07:34 -0800 |
commit | 7aaa6cf22594cfc7eff2070191c0077bfd58046a (patch) | |
tree | f67f13952444ba3f66ca61e7c5be2c672e03aa48 /pkg/sentry/fs/tmpfs | |
parent | 2c7488454e7fcbf98c00bcdceb70cb8e2fa98c96 (diff) |
Internal change.
PiperOrigin-RevId: 233802562
Change-Id: I40e1b13fd571daaf241b00f8df4bcedd034dc3f1
Diffstat (limited to 'pkg/sentry/fs/tmpfs')
-rw-r--r-- | pkg/sentry/fs/tmpfs/BUILD | 1 | ||||
-rw-r--r-- | pkg/sentry/fs/tmpfs/inode_file.go | 13 |
2 files changed, 14 insertions, 0 deletions
diff --git a/pkg/sentry/fs/tmpfs/BUILD b/pkg/sentry/fs/tmpfs/BUILD index bf5b68869..9570c71e5 100644 --- a/pkg/sentry/fs/tmpfs/BUILD +++ b/pkg/sentry/fs/tmpfs/BUILD @@ -15,6 +15,7 @@ go_library( visibility = ["//pkg/sentry:internal"], deps = [ "//pkg/abi/linux", + "//pkg/metric", "//pkg/sentry/context", "//pkg/sentry/device", "//pkg/sentry/fs", diff --git a/pkg/sentry/fs/tmpfs/inode_file.go b/pkg/sentry/fs/tmpfs/inode_file.go index 2505e2c69..ef5e67dda 100644 --- a/pkg/sentry/fs/tmpfs/inode_file.go +++ b/pkg/sentry/fs/tmpfs/inode_file.go @@ -18,6 +18,7 @@ import ( "io" "sync" + "gvisor.googlesource.com/gvisor/pkg/metric" "gvisor.googlesource.com/gvisor/pkg/sentry/context" "gvisor.googlesource.com/gvisor/pkg/sentry/fs" "gvisor.googlesource.com/gvisor/pkg/sentry/fs/fsutil" @@ -29,6 +30,12 @@ import ( "gvisor.googlesource.com/gvisor/pkg/sentry/usermem" ) +var ( + opensRO = metric.MustCreateNewUint64Metric("/in_memory_file/opens_ro", false /* sync */, "Number of times an in-memory file was opened in read-only mode.") + opensW = metric.MustCreateNewUint64Metric("/in_memory_file/opens_w", false /* sync */, "Number of times an in-memory file was opened in write mode.") + reads = metric.MustCreateNewUint64Metric("/in_memory_file/reads", false /* sync */, "Number of in-memory file reads.") +) + // fileInodeOperations implements fs.InodeOperations for a regular tmpfs file. // These files are backed by FrameRegions allocated from a platform.Memory, // and may be directly mapped. @@ -116,6 +123,11 @@ func (*fileInodeOperations) Rename(ctx context.Context, oldParent *fs.Inode, old // GetFile implements fs.InodeOperations.GetFile. func (f *fileInodeOperations) GetFile(ctx context.Context, d *fs.Dirent, flags fs.FileFlags) (*fs.File, error) { + if flags.Write { + opensW.Increment() + } else if flags.Read { + opensRO.Increment() + } flags.Pread = true flags.Pwrite = true return fs.NewFile(ctx, d, flags, ®ularFileOperations{iops: f}), nil @@ -237,6 +249,7 @@ func (*fileInodeOperations) StatFS(context.Context) (fs.Info, error) { } func (f *fileInodeOperations) read(ctx context.Context, dst usermem.IOSequence, offset int64) (int64, error) { + reads.Increment() // Zero length reads for tmpfs are no-ops. if dst.NumBytes() == 0 { return 0, nil |