mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Simplify vfs.NewDisconnectedMount signature and callpoints.
vfs.NewDisconnectedMount has no error paths. Its much prettier without the error return value. Also simplify MountDisconnected which would immediately drop the refs taken by NewDisconnectedMount. Instead make it directly call newMount. PiperOrigin-RevId: 405767966
This commit is contained in:
@@ -71,10 +71,7 @@ func NewRegistryImpl(ctx context.Context, vfsObj *vfs.VirtualFilesystem, creds *
|
||||
var dentry kernfs.Dentry
|
||||
dentry.InitRoot(&fs.Filesystem, fs.newRootInode(ctx, creds))
|
||||
|
||||
mount, err := vfsObj.NewDisconnectedMount(vfsfs, dentry.VFSDentry(), &vfs.MountOptions{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mount := vfsObj.NewDisconnectedMount(vfsfs, dentry.VFSDentry(), &vfs.MountOptions{})
|
||||
|
||||
return &RegistryImpl{
|
||||
root: &dentry,
|
||||
|
||||
@@ -314,10 +314,7 @@ func clonePrivateMount(vfsObj *vfs.VirtualFilesystem, vd vfs.VirtualDentry, forc
|
||||
if forceReadOnly {
|
||||
opts.ReadOnly = true
|
||||
}
|
||||
newmnt, err := vfsObj.NewDisconnectedMount(oldmnt.Filesystem(), vd.Dentry(), &opts)
|
||||
if err != nil {
|
||||
return vfs.VirtualDentry{}, err
|
||||
}
|
||||
newmnt := vfsObj.NewDisconnectedMount(oldmnt.Filesystem(), vd.Dentry(), &opts)
|
||||
// Take a reference on the dentry which will be owned by the returned
|
||||
// VirtualDentry.
|
||||
d := vd.Dentry()
|
||||
|
||||
@@ -418,10 +418,7 @@ func (k *Kernel) Init(args InitKernelArgs) error {
|
||||
return fmt.Errorf("failed to create pipefs filesystem: %v", err)
|
||||
}
|
||||
defer pipeFilesystem.DecRef(ctx)
|
||||
pipeMount, err := k.vfs.NewDisconnectedMount(pipeFilesystem, nil, &vfs.MountOptions{})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create pipefs mount: %v", err)
|
||||
}
|
||||
pipeMount := k.vfs.NewDisconnectedMount(pipeFilesystem, nil, &vfs.MountOptions{})
|
||||
k.pipeMount = pipeMount
|
||||
|
||||
tmpfsFilesystem, tmpfsRoot, err := tmpfs.NewFilesystem(ctx, &k.vfs, auth.NewRootCredentials(k.rootUserNamespace))
|
||||
@@ -430,22 +427,14 @@ func (k *Kernel) Init(args InitKernelArgs) error {
|
||||
}
|
||||
defer tmpfsFilesystem.DecRef(ctx)
|
||||
defer tmpfsRoot.DecRef(ctx)
|
||||
shmMount, err := k.vfs.NewDisconnectedMount(tmpfsFilesystem, tmpfsRoot, &vfs.MountOptions{})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create tmpfs mount: %v", err)
|
||||
}
|
||||
k.shmMount = shmMount
|
||||
k.shmMount = k.vfs.NewDisconnectedMount(tmpfsFilesystem, tmpfsRoot, &vfs.MountOptions{})
|
||||
|
||||
socketFilesystem, err := sockfs.NewFilesystem(&k.vfs)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create sockfs filesystem: %v", err)
|
||||
}
|
||||
defer socketFilesystem.DecRef(ctx)
|
||||
socketMount, err := k.vfs.NewDisconnectedMount(socketFilesystem, nil, &vfs.MountOptions{})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create sockfs mount: %v", err)
|
||||
}
|
||||
k.socketMount = socketMount
|
||||
k.socketMount = k.vfs.NewDisconnectedMount(socketFilesystem, nil, &vfs.MountOptions{})
|
||||
|
||||
k.socketsVFS2 = make(map[*vfs.FileDescription]*SocketRecord)
|
||||
|
||||
|
||||
@@ -178,12 +178,12 @@ func (vfs *VirtualFilesystem) NewMountNamespace(ctx context.Context, creds *auth
|
||||
// (which may be nil). The new Mount is not associated with any MountNamespace
|
||||
// and is not connected to any other Mounts. References are taken on fs and
|
||||
// root.
|
||||
func (vfs *VirtualFilesystem) NewDisconnectedMount(fs *Filesystem, root *Dentry, opts *MountOptions) (*Mount, error) {
|
||||
func (vfs *VirtualFilesystem) NewDisconnectedMount(fs *Filesystem, root *Dentry, opts *MountOptions) *Mount {
|
||||
fs.IncRef()
|
||||
if root != nil {
|
||||
root.IncRef()
|
||||
}
|
||||
return newMount(vfs, fs, root, nil /* mntns */, opts), nil
|
||||
return newMount(vfs, fs, root, nil /* mntns */, opts)
|
||||
}
|
||||
|
||||
// MountDisconnected creates a Filesystem configured by the given arguments,
|
||||
@@ -201,9 +201,7 @@ func (vfs *VirtualFilesystem) MountDisconnected(ctx context.Context, creds *auth
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer root.DecRef(ctx)
|
||||
defer fs.DecRef(ctx)
|
||||
return vfs.NewDisconnectedMount(fs, root, opts)
|
||||
return newMount(vfs, fs, root, nil /* mntns */, opts), nil
|
||||
}
|
||||
|
||||
// ConnectMountAt connects mnt at the path represented by target.
|
||||
|
||||
@@ -150,12 +150,7 @@ func (vfs *VirtualFilesystem) Init(ctx context.Context) error {
|
||||
}
|
||||
anonfs.vfsfs.Init(vfs, &anonFilesystemType{}, &anonfs)
|
||||
defer anonfs.vfsfs.DecRef(ctx)
|
||||
anonMount, err := vfs.NewDisconnectedMount(&anonfs.vfsfs, nil, &MountOptions{})
|
||||
if err != nil {
|
||||
// We should not be passing any MountOptions that would cause
|
||||
// construction of this mount to fail.
|
||||
panic(fmt.Sprintf("VirtualFilesystem.Init: anonfs mount failed: %v", err))
|
||||
}
|
||||
anonMount := vfs.NewDisconnectedMount(&anonfs.vfsfs, nil, &MountOptions{})
|
||||
vfs.anonMount = anonMount
|
||||
|
||||
return nil
|
||||
|
||||
@@ -411,11 +411,7 @@ func New(args Args) (*Loader, error) {
|
||||
return nil, fmt.Errorf("failed to create hostfs filesystem: %w", err)
|
||||
}
|
||||
defer hostFilesystem.DecRef(k.SupervisorContext())
|
||||
hostMount, err := k.VFS().NewDisconnectedMount(hostFilesystem, nil, &vfs.MountOptions{})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create hostfs mount: %w", err)
|
||||
}
|
||||
k.SetHostMount(hostMount)
|
||||
k.SetHostMount(k.VFS().NewDisconnectedMount(hostFilesystem, nil, &vfs.MountOptions{}))
|
||||
}
|
||||
|
||||
eid := execID{cid: args.ID}
|
||||
|
||||
+1
-4
@@ -769,10 +769,7 @@ func (c *containerMounter) mountSharedSubmountVFS2(ctx context.Context, conf *co
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
newMnt, err := c.k.VFS().NewDisconnectedMount(source.vfsMount.Filesystem(), source.vfsMount.Root(), opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
newMnt := c.k.VFS().NewDisconnectedMount(source.vfsMount.Filesystem(), source.vfsMount.Root(), opts)
|
||||
defer newMnt.DecRef(ctx)
|
||||
|
||||
root := mns.Root()
|
||||
|
||||
Reference in New Issue
Block a user