summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/fs/inotify_watch.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/sentry/fs/inotify_watch.go')
-rw-r--r--pkg/sentry/fs/inotify_watch.go12
1 files changed, 7 insertions, 5 deletions
diff --git a/pkg/sentry/fs/inotify_watch.go b/pkg/sentry/fs/inotify_watch.go
index ff6ec6e3e..8904ef544 100644
--- a/pkg/sentry/fs/inotify_watch.go
+++ b/pkg/sentry/fs/inotify_watch.go
@@ -16,6 +16,7 @@ package fs
import (
"sync"
+ "sync/atomic"
"gvisor.googlesource.com/gvisor/pkg/abi/linux"
)
@@ -33,9 +34,6 @@ type Watch struct {
// Descriptor for this watch. This is unique across an inotify instance.
wd int32
- // Events being monitored via this watch.
- mask uint32
-
// The inode being watched. Note that we don't directly hold a reference on
// this inode. Instead we hold a reference on the dirent(s) containing the
// inode, which we record in pins.
@@ -48,6 +46,10 @@ type Watch struct {
// mu protects the fields below.
mu sync.Mutex `state:"nosave"`
+ // Events being monitored via this watch. Must be accessed atomically,
+ // writes are protected by mu.
+ mask uint32
+
// pins is the set of dirents this watch is currently pinning in memory by
// holding a reference to them. See Pin()/Unpin().
pins map[*Dirent]bool
@@ -62,7 +64,7 @@ func (w *Watch) ID() uint64 {
// should continue to be be notified of events after the target has been
// unlinked.
func (w *Watch) NotifyParentAfterUnlink() bool {
- return w.mask&linux.IN_EXCL_UNLINK == 0
+ return atomic.LoadUint32(&w.mask)&linux.IN_EXCL_UNLINK == 0
}
// isRenameEvent returns true if eventMask describes a rename event.
@@ -73,7 +75,7 @@ func isRenameEvent(eventMask uint32) bool {
// Notify queues a new event on this watch.
func (w *Watch) Notify(name string, events uint32, cookie uint32) {
unmaskableBits := ^uint32(0) &^ linux.IN_ALL_EVENTS
- effectiveMask := unmaskableBits | w.mask
+ effectiveMask := unmaskableBits | atomic.LoadUint32(&w.mask)
matchedEvents := effectiveMask & events
if matchedEvents == 0 {