mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Take Mount reference in VFS.connectLocked.
Updates #179 PiperOrigin-RevId: 314563830
This commit is contained in:
@@ -39,8 +39,8 @@ Mount references are held by:
|
||||
- Mount: Each referenced Mount holds a reference on its parent, which is the
|
||||
mount containing its mount point.
|
||||
|
||||
- VirtualFilesystem: A reference is held on each Mount that has not been
|
||||
umounted.
|
||||
- VirtualFilesystem: A reference is held on each Mount that has been connected
|
||||
to a mount point, but not yet umounted.
|
||||
|
||||
MountNamespace and FileDescription references are held by users of VFS. The
|
||||
expectation is that each `kernel.Task` holds a reference on its corresponding
|
||||
|
||||
+14
-2
@@ -265,8 +265,8 @@ func (vfs *VirtualFilesystem) MountAt(ctx context.Context, creds *auth.Credentia
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer mnt.DecRef()
|
||||
if err := vfs.ConnectMountAt(ctx, creds, mnt, target); err != nil {
|
||||
mnt.DecRef()
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
@@ -394,8 +394,15 @@ func (vfs *VirtualFilesystem) umountRecursiveLocked(mnt *Mount, opts *umountRecu
|
||||
// references held by vd.
|
||||
//
|
||||
// Preconditions: vfs.mountMu must be locked. vfs.mounts.seq must be in a
|
||||
// writer critical section. d.mu must be locked. mnt.parent() == nil.
|
||||
// writer critical section. d.mu must be locked. mnt.parent() == nil, i.e. mnt
|
||||
// must not already be connected.
|
||||
func (vfs *VirtualFilesystem) connectLocked(mnt *Mount, vd VirtualDentry, mntns *MountNamespace) {
|
||||
if checkInvariants {
|
||||
if mnt.parent() != nil {
|
||||
panic("VFS.connectLocked called on connected mount")
|
||||
}
|
||||
}
|
||||
mnt.IncRef() // dropped by callers of umountRecursiveLocked
|
||||
mnt.storeKey(vd)
|
||||
if vd.mount.children == nil {
|
||||
vd.mount.children = make(map[*Mount]struct{})
|
||||
@@ -420,6 +427,11 @@ func (vfs *VirtualFilesystem) connectLocked(mnt *Mount, vd VirtualDentry, mntns
|
||||
// writer critical section. mnt.parent() != nil.
|
||||
func (vfs *VirtualFilesystem) disconnectLocked(mnt *Mount) VirtualDentry {
|
||||
vd := mnt.loadKey()
|
||||
if checkInvariants {
|
||||
if vd.mount != nil {
|
||||
panic("VFS.disconnectLocked called on disconnected mount")
|
||||
}
|
||||
}
|
||||
mnt.storeKey(VirtualDentry{})
|
||||
delete(vd.mount.children, mnt)
|
||||
atomic.AddUint32(&vd.dentry.mounts, math.MaxUint32) // -1
|
||||
|
||||
Reference in New Issue
Block a user