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
This commit is contained in:
Nicolas Lacasse 2018-08-22 10:05:56 -07:00 committed by Shentubot
parent 3c5ec25f1c
commit 8d318aac55
1 changed files with 16 additions and 16 deletions

View File

@ -398,7 +398,18 @@ func (d *Dirent) MountRoot() *Dirent {
return mountRoot 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 { if d.frozen {
// Already frozen. // Already frozen.
return return
@ -419,21 +430,6 @@ func (d *Dirent) freeze() {
d.flush() 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 // descendantOf returns true if the receiver dirent is equal to, or a
// descendant of, the argument dirent. // 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 // reasons, so we flush all references on the replaced node and
// its children. // its children.
replaced.Inode.Watches.Unpin(replaced) replaced.Inode.Watches.Unpin(replaced)
replaced.mu.Lock()
replaced.flush() replaced.flush()
replaced.mu.Unlock()
} }
if err := renamed.Inode.Rename(ctx, oldParent, renamed, newParent, newName); err != nil { 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() renamed.dropExtendedReference()
// Same as replaced.flush above. // Same as replaced.flush above.
renamed.mu.Lock()
renamed.flush() renamed.flush()
renamed.mu.Unlock()
return nil return nil
} }