summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorgVisor bot <gvisor-bot@google.com>2021-10-26 19:03:21 +0000
committergVisor bot <gvisor-bot@google.com>2021-10-26 19:03:21 +0000
commit1cf8a412c893de6e20562d01fbdb086f5778d77e (patch)
tree9d86c5a1c14dc1a5a85307ace8649449666e08d7
parented29acdbd826b3250f757ed11ee8b1b355b2f724 (diff)
parent763d7e6e396d8d4c67d650e02bd2350b22606ada (diff)
Merge release-20211019.0-40-g763d7e6e3 (automated)
-rw-r--r--pkg/sentry/fsimpl/mqfs/mqfs.go5
-rw-r--r--pkg/sentry/fsimpl/mqfs/mqfs_state_autogen.go32
-rw-r--r--pkg/sentry/fsimpl/mqfs/registry.go23
-rw-r--r--pkg/sentry/fsimpl/mqfs/root.go9
-rw-r--r--pkg/sentry/vfs/filesystem_type.go2
5 files changed, 13 insertions, 58 deletions
diff --git a/pkg/sentry/fsimpl/mqfs/mqfs.go b/pkg/sentry/fsimpl/mqfs/mqfs.go
index c2b53c9d0..9b3704217 100644
--- a/pkg/sentry/fsimpl/mqfs/mqfs.go
+++ b/pkg/sentry/fsimpl/mqfs/mqfs.go
@@ -75,6 +75,7 @@ func (ft FilesystemType) GetFilesystem(ctx context.Context, vfsObj *vfs.VirtualF
impl.fs.MaxCachedDentries = maxCachedDentries
impl.fs.VFSFilesystem().IncRef()
+ impl.root.IncRef()
return impl.fs.VFSFilesystem(), impl.root.VFSDentry(), nil
}
@@ -100,10 +101,6 @@ func maxCachedDentries(ctx context.Context, mopts map[string]string) (_ uint64,
type filesystem struct {
kernfs.Filesystem
devMinor uint32
-
- // root is the filesystem's root dentry. Since we take a reference on it in
- // GetFilesystem, we should release it when the fs is released.
- root *kernfs.Dentry
}
// Release implements vfs.FilesystemImpl.Release.
diff --git a/pkg/sentry/fsimpl/mqfs/mqfs_state_autogen.go b/pkg/sentry/fsimpl/mqfs/mqfs_state_autogen.go
index d6154efc3..32905c2cb 100644
--- a/pkg/sentry/fsimpl/mqfs/mqfs_state_autogen.go
+++ b/pkg/sentry/fsimpl/mqfs/mqfs_state_autogen.go
@@ -35,7 +35,6 @@ func (fs *filesystem) StateFields() []string {
return []string{
"Filesystem",
"devMinor",
- "root",
}
}
@@ -46,7 +45,6 @@ func (fs *filesystem) StateSave(stateSinkObject state.Sink) {
fs.beforeSave()
stateSinkObject.Save(0, &fs.Filesystem)
stateSinkObject.Save(1, &fs.devMinor)
- stateSinkObject.Save(2, &fs.root)
}
func (fs *filesystem) afterLoad() {}
@@ -55,7 +53,6 @@ func (fs *filesystem) afterLoad() {}
func (fs *filesystem) StateLoad(stateSourceObject state.Source) {
stateSourceObject.Load(0, &fs.Filesystem)
stateSourceObject.Load(1, &fs.devMinor)
- stateSourceObject.Load(2, &fs.root)
}
func (q *queueInode) StateTypeName() string {
@@ -170,7 +167,6 @@ func (i *rootInode) StateFields() []string {
"InodeNotSymlink",
"InodeTemporary",
"OrderedChildren",
- "implStatFS",
"locks",
}
}
@@ -187,8 +183,7 @@ func (i *rootInode) StateSave(stateSinkObject state.Sink) {
stateSinkObject.Save(4, &i.InodeNotSymlink)
stateSinkObject.Save(5, &i.InodeTemporary)
stateSinkObject.Save(6, &i.OrderedChildren)
- stateSinkObject.Save(7, &i.implStatFS)
- stateSinkObject.Save(8, &i.locks)
+ stateSinkObject.Save(7, &i.locks)
}
func (i *rootInode) afterLoad() {}
@@ -202,29 +197,7 @@ func (i *rootInode) StateLoad(stateSourceObject state.Source) {
stateSourceObject.Load(4, &i.InodeNotSymlink)
stateSourceObject.Load(5, &i.InodeTemporary)
stateSourceObject.Load(6, &i.OrderedChildren)
- stateSourceObject.Load(7, &i.implStatFS)
- stateSourceObject.Load(8, &i.locks)
-}
-
-func (i *implStatFS) StateTypeName() string {
- return "pkg/sentry/fsimpl/mqfs.implStatFS"
-}
-
-func (i *implStatFS) StateFields() []string {
- return []string{}
-}
-
-func (i *implStatFS) beforeSave() {}
-
-// +checklocksignore
-func (i *implStatFS) StateSave(stateSinkObject state.Sink) {
- i.beforeSave()
-}
-
-func (i *implStatFS) afterLoad() {}
-
-// +checklocksignore
-func (i *implStatFS) StateLoad(stateSourceObject state.Source) {
+ stateSourceObject.Load(7, &i.locks)
}
func (r *rootInodeRefs) StateTypeName() string {
@@ -258,6 +231,5 @@ func init() {
state.Register((*queueFD)(nil))
state.Register((*RegistryImpl)(nil))
state.Register((*rootInode)(nil))
- state.Register((*implStatFS)(nil))
state.Register((*rootInodeRefs)(nil))
}
diff --git a/pkg/sentry/fsimpl/mqfs/registry.go b/pkg/sentry/fsimpl/mqfs/registry.go
index c8fbe4d33..e470ffadc 100644
--- a/pkg/sentry/fsimpl/mqfs/registry.go
+++ b/pkg/sentry/fsimpl/mqfs/registry.go
@@ -57,16 +57,19 @@ func NewRegistryImpl(ctx context.Context, vfsObj *vfs.VirtualFilesystem, creds *
return nil, err
}
- var dentry kernfs.Dentry
fs := &filesystem{
devMinor: devMinor,
- root: &dentry,
}
fs.VFSFilesystem().Init(vfsObj, &FilesystemType{}, fs)
vfsfs := fs.VFSFilesystem()
+ // NewDisconnectedMount will obtain a ref on dentry and vfsfs which is
+ // transferred to mount. vfsfs was initiated with 1 ref already. So get rid
+ // of the extra ref.
+ defer vfsfs.DecRef(ctx)
+ // dentry is initialized with 1 ref which is transferred to fs.
+ var dentry kernfs.Dentry
dentry.InitRoot(&fs.Filesystem, fs.newRootInode(ctx, creds))
- defer vfsfs.DecRef(ctx) // NewDisconnectedMount will obtain a ref on success.
mount, err := vfsObj.NewDisconnectedMount(vfsfs, dentry.VFSDentry(), &vfs.MountOptions{})
if err != nil {
@@ -82,7 +85,7 @@ func NewRegistryImpl(ctx context.Context, vfsObj *vfs.VirtualFilesystem, creds *
// Get implements mq.RegistryImpl.Get.
func (r *RegistryImpl) Get(ctx context.Context, name string, access mq.AccessType, block bool, flags uint32) (*vfs.FileDescription, bool, error) {
- inode, err := r.lookup(ctx, name)
+ inode, err := r.root.Inode().(*rootInode).Lookup(ctx, name)
if err != nil {
return nil, false, nil
}
@@ -120,7 +123,7 @@ func (r *RegistryImpl) Unlink(ctx context.Context, name string) error {
}
root := r.root.Inode().(*rootInode)
- inode, err := r.lookup(ctx, name)
+ inode, err := root.Lookup(ctx, name)
if err != nil {
return err
}
@@ -133,16 +136,6 @@ func (r *RegistryImpl) Destroy(ctx context.Context) {
r.mount.DecRef(ctx)
}
-// lookup retreives a kernfs.Inode using a name.
-func (r *RegistryImpl) lookup(ctx context.Context, name string) (kernfs.Inode, error) {
- inode := r.root.Inode().(*rootInode)
- lookup, err := inode.Lookup(ctx, name)
- if err != nil {
- return nil, err
- }
- return lookup, nil
-}
-
// newFD returns a new file description created using the given queue and inode.
func (r *RegistryImpl) newFD(q *mq.Queue, inode *queueInode, access mq.AccessType, block bool, flags uint32) (*vfs.FileDescription, error) {
view, err := mq.NewView(q, access, block)
diff --git a/pkg/sentry/fsimpl/mqfs/root.go b/pkg/sentry/fsimpl/mqfs/root.go
index 37b5749fb..922e669e2 100644
--- a/pkg/sentry/fsimpl/mqfs/root.go
+++ b/pkg/sentry/fsimpl/mqfs/root.go
@@ -34,7 +34,6 @@ type rootInode struct {
kernfs.InodeNotSymlink
kernfs.InodeTemporary
kernfs.OrderedChildren
- implStatFS
locks vfs.FileLocks
}
@@ -77,13 +76,7 @@ func (*rootInode) SetStat(context.Context, *vfs.Filesystem, *auth.Credentials, v
return linuxerr.EPERM
}
-// implStatFS provides an implementation of kernfs.Inode.StatFS for message
-// queues to be embedded in inodes.
-//
-// +stateify savable
-type implStatFS struct{}
-
// StatFS implements kernfs.Inode.StatFS.
-func (*implStatFS) StatFS(context.Context, *vfs.Filesystem) (linux.Statfs, error) {
+func (*rootInode) StatFS(context.Context, *vfs.Filesystem) (linux.Statfs, error) {
return vfs.GenericStatFS(linux.MQUEUE_MAGIC), nil
}
diff --git a/pkg/sentry/vfs/filesystem_type.go b/pkg/sentry/vfs/filesystem_type.go
index 9d54cc4ed..70d6eb85e 100644
--- a/pkg/sentry/vfs/filesystem_type.go
+++ b/pkg/sentry/vfs/filesystem_type.go
@@ -28,7 +28,7 @@ import (
type FilesystemType interface {
// GetFilesystem returns a Filesystem configured by the given options,
// along with its mount root. A reference is taken on the returned
- // Filesystem and Dentry.
+ // Filesystem and Dentry whose ownership is transferred to the caller.
GetFilesystem(ctx context.Context, vfsObj *VirtualFilesystem, creds *auth.Credentials, source string, opts GetFilesystemOptions) (*Filesystem, *Dentry, error)
// Name returns the name of this FilesystemType.