summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/vfs
diff options
context:
space:
mode:
authorAyush Ranjan <ayushranjan@google.com>2021-10-26 16:57:12 -0700
committergVisor bot <gvisor-bot@google.com>2021-10-26 17:00:07 -0700
commit7b8f19dc76a9fecbf4d2e5f43a47c6d47d53e100 (patch)
tree632c24c56d874298eb2cca543ec5e5aee01df30f /pkg/sentry/vfs
parentf54a25c1f03e705f2fb65be7389ddeb37bc5e64e (diff)
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
Diffstat (limited to 'pkg/sentry/vfs')
-rw-r--r--pkg/sentry/vfs/mount.go8
-rw-r--r--pkg/sentry/vfs/vfs.go7
2 files changed, 4 insertions, 11 deletions
diff --git a/pkg/sentry/vfs/mount.go b/pkg/sentry/vfs/mount.go
index 05a416775..9ab9a8fca 100644
--- a/pkg/sentry/vfs/mount.go
+++ b/pkg/sentry/vfs/mount.go
@@ -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.
diff --git a/pkg/sentry/vfs/vfs.go b/pkg/sentry/vfs/vfs.go
index 1b2a668c0..9c1ee549a 100644
--- a/pkg/sentry/vfs/vfs.go
+++ b/pkg/sentry/vfs/vfs.go
@@ -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