From 8d318aac553240d4b5044f0ca70bff3e58cf60f3 Mon Sep 17 00:00:00 2001 From: Nicolas Lacasse Date: Wed, 22 Aug 2018 10:05:56 -0700 Subject: 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 --- pkg/sentry/fs/dirent.go | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'pkg/sentry/fs') 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 } -- cgit v1.2.3