diff options
author | Zyad A. Ali <zyad.ali.me@gmail.com> | 2021-07-30 22:16:36 +0200 |
---|---|---|
committer | Zyad A. Ali <zyad.ali.me@gmail.com> | 2021-09-28 20:43:52 +0200 |
commit | 583e18501ee8ee263295edd6f5ccf30d0278d854 (patch) | |
tree | aae4368ef7633b0f0ea2709b1ca6e80b650dddf8 /pkg/sentry/fsimpl/mqfs | |
parent | 7df562d47337b29e6ac53c06c120cd4d88dd5da3 (diff) |
Use one mutex for both Registry and RegistryImpl.
Updates #136
Diffstat (limited to 'pkg/sentry/fsimpl/mqfs')
-rw-r--r-- | pkg/sentry/fsimpl/mqfs/BUILD | 1 | ||||
-rw-r--r-- | pkg/sentry/fsimpl/mqfs/registry.go | 18 |
2 files changed, 3 insertions, 16 deletions
diff --git a/pkg/sentry/fsimpl/mqfs/BUILD b/pkg/sentry/fsimpl/mqfs/BUILD index ef843015d..e1a38686b 100644 --- a/pkg/sentry/fsimpl/mqfs/BUILD +++ b/pkg/sentry/fsimpl/mqfs/BUILD @@ -35,7 +35,6 @@ go_library( "//pkg/sentry/kernel/ipc", "//pkg/sentry/kernel/mq", "//pkg/sentry/vfs", - "//pkg/sync", "//pkg/usermem", "//pkg/waiter", ], diff --git a/pkg/sentry/fsimpl/mqfs/registry.go b/pkg/sentry/fsimpl/mqfs/registry.go index ea1f2981c..2c9c79f01 100644 --- a/pkg/sentry/fsimpl/mqfs/registry.go +++ b/pkg/sentry/fsimpl/mqfs/registry.go @@ -23,18 +23,17 @@ import ( "gvisor.dev/gvisor/pkg/sentry/kernel/auth" "gvisor.dev/gvisor/pkg/sentry/kernel/mq" "gvisor.dev/gvisor/pkg/sentry/vfs" - "gvisor.dev/gvisor/pkg/sync" ) // RegistryImpl implements mq.RegistryImpl. It implements the interface using // the message queue filesystem, and is provided to mq.Registry at // initialization. // +// RegistryImpl is not thread-safe, so it is the responsibility of the user +// (the containing mq.Registry) to protect using a lock. +// // +stateify savable type RegistryImpl struct { - // mu protects all fields below. - mu sync.Mutex - // root is the root dentry of the mq filesystem. Its main usage is to // retreive the root inode, which we use to add, remove, and lookup message // queues. @@ -82,9 +81,6 @@ 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) { - r.mu.Lock() - defer r.mu.Unlock() - inode, err := r.lookup(ctx, name) if err != nil { return nil, false, nil @@ -106,9 +102,6 @@ func (r *RegistryImpl) Get(ctx context.Context, name string, access mq.AccessTyp // New implements mq.RegistryImpl.New. func (r *RegistryImpl) New(ctx context.Context, name string, q *mq.Queue, access mq.AccessType, block bool, perm linux.FileMode, flags uint32) (*vfs.FileDescription, error) { - r.mu.Lock() - defer r.mu.Unlock() - root := r.root.Inode().(*rootInode) qInode := r.fs.newQueueInode(ctx, auth.CredentialsFromContext(ctx), q, perm).(*queueInode) err := root.Insert(name, qInode) @@ -120,9 +113,6 @@ func (r *RegistryImpl) New(ctx context.Context, name string, q *mq.Queue, access // Unlink implements mq.RegistryImpl.Unlink. func (r *RegistryImpl) Unlink(ctx context.Context, name string) error { - r.mu.Lock() - defer r.mu.Unlock() - creds := auth.CredentialsFromContext(ctx) if err := r.root.Inode().CheckPermissions(ctx, creds, vfs.MayWrite|vfs.MayExec); err != nil { return err @@ -142,8 +132,6 @@ func (r *RegistryImpl) Destroy(ctx context.Context) { } // lookup retreives a kernfs.Inode using a name. -// -// Precondition: r.mu must be held. func (r *RegistryImpl) lookup(ctx context.Context, name string) (kernfs.Inode, error) { inode := r.root.Inode().(*rootInode) lookup, err := inode.Lookup(ctx, name) |