From dcbbd67cacb646838174b5c2a6e7db4e6c212cd5 Mon Sep 17 00:00:00 2001 From: Andrei Vagin Date: Thu, 23 Sep 2021 18:14:10 -0700 Subject: kernel: allow to access Task.netns without taking Task.mu This allows to avoind unnecessary lock-ordering dependencies on task.mu. --- pkg/sentry/kernel/task_net.go | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'pkg/sentry/kernel/task_net.go') diff --git a/pkg/sentry/kernel/task_net.go b/pkg/sentry/kernel/task_net.go index f7711232c..e31e2b2e8 100644 --- a/pkg/sentry/kernel/task_net.go +++ b/pkg/sentry/kernel/task_net.go @@ -20,9 +20,7 @@ import ( // IsNetworkNamespaced returns true if t is in a non-root network namespace. func (t *Task) IsNetworkNamespaced() bool { - t.mu.Lock() - defer t.mu.Unlock() - return !t.netns.IsRoot() + return !t.netns.Load().IsRoot() } // NetworkContext returns the network stack used by the task. NetworkContext @@ -31,14 +29,10 @@ func (t *Task) IsNetworkNamespaced() bool { // TODO(gvisor.dev/issue/1833): Migrate callers of this method to // NetworkNamespace(). func (t *Task) NetworkContext() inet.Stack { - t.mu.Lock() - defer t.mu.Unlock() - return t.netns.Stack() + return t.netns.Load().Stack() } // NetworkNamespace returns the network namespace observed by the task. func (t *Task) NetworkNamespace() *inet.Namespace { - t.mu.Lock() - defer t.mu.Unlock() - return t.netns + return t.netns.Load() } -- cgit v1.2.3