summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/fs/dirent.go
diff options
context:
space:
mode:
authorNicolas Lacasse <nlacasse@google.com>2018-08-22 10:05:56 -0700
committerShentubot <shentubot@google.com>2018-08-22 10:07:01 -0700
commit8d318aac553240d4b5044f0ca70bff3e58cf60f3 (patch)
treee5003124a4ec9aa9ee772818e67ceed67d8f2d89 /pkg/sentry/fs/dirent.go
parent3c5ec25f1cfb08b73c68c5bb12609cf7915c3025 (diff)
fs: Hold Dirent.mu when calling Dirent.flush().
As required by the contract in Dirent.flush(). Also inline Dirent.freeze() into Dirent.Freeze(), since it is only called from there. PiperOrigin-RevId: 209783626 Change-Id: Ie6de4533d93dd299ffa01dabfa257c9cc259b1f4
Diffstat (limited to 'pkg/sentry/fs/dirent.go')
-rw-r--r--pkg/sentry/fs/dirent.go32
1 files changed, 16 insertions, 16 deletions
diff --git a/pkg/sentry/fs/dirent.go b/pkg/sentry/fs/dirent.go
index 4d3aeaf41..71ef3336e 100644
--- a/pkg/sentry/fs/dirent.go
+++ b/pkg/sentry/fs/dirent.go
@@ -398,7 +398,18 @@ func (d *Dirent) MountRoot() *Dirent {
return mountRoot
}
-func (d *Dirent) freeze() {
+// Freeze prevents this dirent from walking to more nodes. Freeze is applied
+// recursively to all children.
+//
+// If this particular Dirent represents a Virtual node, then Walks and Creates
+// may proceed as before.
+//
+// Freeze can only be called before the application starts running, otherwise
+// the root it might be out of sync with the application root if modified by
+// sys_chroot.
+func (d *Dirent) Freeze() {
+ d.mu.Lock()
+ defer d.mu.Unlock()
if d.frozen {
// Already frozen.
return
@@ -419,21 +430,6 @@ func (d *Dirent) freeze() {
d.flush()
}
-// Freeze prevents this dirent from walking to more nodes. Freeze is applied
-// recursively to all children.
-//
-// If this particular Dirent represents a Virtual node, then Walks and Creates
-// may proceed as before.
-//
-// Freeze can only be called before the application starts running, otherwise
-// the root it might be out of sync with the application root if modified by
-// sys_chroot.
-func (d *Dirent) Freeze() {
- d.mu.Lock()
- defer d.mu.Unlock()
- d.freeze()
-}
-
// descendantOf returns true if the receiver dirent is equal to, or a
// descendant of, the argument dirent.
//
@@ -1586,7 +1582,9 @@ func Rename(ctx context.Context, root *Dirent, oldParent *Dirent, oldName string
// reasons, so we flush all references on the replaced node and
// its children.
replaced.Inode.Watches.Unpin(replaced)
+ replaced.mu.Lock()
replaced.flush()
+ replaced.mu.Unlock()
}
if err := renamed.Inode.Rename(ctx, oldParent, renamed, newParent, newName); err != nil {
@@ -1637,7 +1635,9 @@ func Rename(ctx context.Context, root *Dirent, oldParent *Dirent, oldName string
renamed.dropExtendedReference()
// Same as replaced.flush above.
+ renamed.mu.Lock()
renamed.flush()
+ renamed.mu.Unlock()
return nil
}