tmpfs: use lockdep mutexes

PiperOrigin-RevId: 449803147
This commit is contained in:
Andrei Vagin
2022-05-19 12:07:37 -07:00
committed by gVisor bot
parent 7db613ab1c
commit 4d4b2b99c8
3 changed files with 38 additions and 6 deletions
+34
View File
@@ -1,5 +1,6 @@
load("//tools:defs.bzl", "go_library", "go_test")
load("//tools/go_generics:defs.bzl", "go_template_instance")
load("//pkg/sync/locking:locking.bzl", "declare_mutex", "declare_rwmutex")
licenses(["notice"])
@@ -37,6 +38,34 @@ go_template_instance(
},
)
declare_mutex(
name = "inode_mutex",
out = "inode_mutex.go",
package = "tmpfs",
prefix = "inode",
)
declare_mutex(
name = "pages_used_mutex",
out = "pages_used_mutex.go",
package = "tmpfs",
prefix = "pagesUsed",
)
declare_mutex(
name = "iter_mutex",
out = "iter_mutex.go",
package = "tmpfs",
prefix = "iter",
)
declare_rwmutex(
name = "filesystem_mutex",
out = "filesystem_mutex.go",
package = "tmpfs",
prefix = "filesystem",
)
go_library(
name = "tmpfs",
srcs = [
@@ -44,9 +73,13 @@ go_library(
"device_file.go",
"directory.go",
"filesystem.go",
"filesystem_mutex.go",
"fstree.go",
"inode_mutex.go",
"inode_refs.go",
"iter_mutex.go",
"named_pipe.go",
"pages_used_mutex.go",
"regular_file.go",
"save_restore.go",
"socket_file.go",
@@ -82,6 +115,7 @@ go_library(
"//pkg/sentry/vfs",
"//pkg/sentry/vfs/memxattr",
"//pkg/sync",
"//pkg/sync/locking",
"//pkg/usermem",
],
)
+1 -2
View File
@@ -21,7 +21,6 @@ import (
"gvisor.dev/gvisor/pkg/errors/linuxerr"
"gvisor.dev/gvisor/pkg/sentry/kernel/auth"
"gvisor.dev/gvisor/pkg/sentry/vfs"
"gvisor.dev/gvisor/pkg/sync"
)
// +stateify savable
@@ -44,7 +43,7 @@ type directory struct {
// (with inode == nil) that represent the iteration position of
// directoryFDs. childList is used to support directoryFD.IterDirents()
// efficiently. childList is protected by iterMu.
iterMu sync.Mutex `state:"nosave"`
iterMu iterMutex `state:"nosave"`
childList dentryList
}
+3 -4
View File
@@ -45,7 +45,6 @@ import (
"gvisor.dev/gvisor/pkg/sentry/usage"
"gvisor.dev/gvisor/pkg/sentry/vfs"
"gvisor.dev/gvisor/pkg/sentry/vfs/memxattr"
"gvisor.dev/gvisor/pkg/sync"
)
// Name is the default filesystem name.
@@ -81,7 +80,7 @@ type filesystem struct {
usage usage.MemoryKind
// mu serializes changes to the Dentry tree.
mu sync.RWMutex `state:"nosave"`
mu filesystemRWMutex `state:"nosave"`
nextInoMinusOne atomicbitops.Uint64 // accessed using atomic memory operations
@@ -95,7 +94,7 @@ type filesystem struct {
// pagesUsed is the pages used out of the tmpfs size.
// pagesUsed is protected by pagesUsedMu.
pagesUsedMu sync.Mutex `state:"nosave"`
pagesUsedMu pagesUsedMutex `state:"nosave"`
pagesUsed uint64
}
@@ -434,7 +433,7 @@ type inode struct {
// Inode metadata. Writing multiple fields atomically requires holding
// mu, othewise atomic operations can be used.
mu sync.Mutex `state:"nosave"`
mu inodeMutex `state:"nosave"`
mode atomicbitops.Uint32 // file type and mode
nlink atomicbitops.Uint32 // protected by filesystem.mu instead of inode.mu
uid atomicbitops.Uint32 // auth.KUID, but stored as raw uint32 for sync/atomic