From nobody Thu Sep 11 01:49:16 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D15AC315D34; Wed, 10 Sep 2025 14:39:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757515146; cv=none; b=f99u2QWa8MoX5zYCQyIE8mvQFDVAw6UxrSy+6iyLUmndedEMjmVGW8sBy6iSLpELVKQJbfRs9H7MywzMOS7W8PbbwpnqRaGWIoyWSjMMjS99v7rl50NdZpI51cpxMl2ko+pklxvKN5CCfmxdtCOQ5LJd51cYhheeIFJ+wfLmd6Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757515146; c=relaxed/simple; bh=oRiUykJBQlga5zzzIWDVy4MBnAL3DsvpFayNB03RaHE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=P8zGtLKmO7/gyZwHyL9Rd8feph/k8/6fZZCYQ+MqehbrAVb0jjA4H5FvWXXHYV1VUTT4OkqDMuY5kkhtH9DSm/d++CxeiXXRCik64BD3JKYGUXqt2EJZ7vAfyrUxSBbT/gz7ebYSk+gWvSZoYO+tdI1XnkAhtoAckyyLIGlRP2Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TFZGoyG/; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TFZGoyG/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 45032C4CEFB; Wed, 10 Sep 2025 14:39:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1757515145; bh=oRiUykJBQlga5zzzIWDVy4MBnAL3DsvpFayNB03RaHE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=TFZGoyG/GiHUMR8YVToC8GQ1OzLSta6G7n5Awy2McTrAlN/O060DW1PkblGtmiqwD oV+CVvgTzE0qDfswWMZ6o7NDzFx48qSPIB8efED+62Wpzj62CK/c7QA8xMqEfMDuXk ZJ+O+QK9Wvb3clsNCV9/hSOKq3YZEyD50GJ95O0LFlrnd+N0Yjm0NY7p5miBUDcEzg F1+6HgdaV0nItBn6Zzd3C/0HAT1x/wQNYCOZuYz71nzgDwCgqagH52tf7pkY9p81gE Ujuu1HR4a/fVa8eR64Hb9i3M2KhBFEV3ndUiqS+uUKJBtPcanhra0OKm4GT0umqXop ecXBij+QenReA== From: Christian Brauner Date: Wed, 10 Sep 2025 16:37:05 +0200 Subject: [PATCH 20/32] net: support iterator Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250910-work-namespace-v1-20-4dd56e7359d8@kernel.org> References: <20250910-work-namespace-v1-0-4dd56e7359d8@kernel.org> In-Reply-To: <20250910-work-namespace-v1-0-4dd56e7359d8@kernel.org> To: Jan Kara , Amir Goldstein , linux-fsdevel@vger.kernel.org Cc: Josef Bacik , Jeff Layton , Mike Yuan , =?utf-8?q?Zbigniew_J=C4=99drzejewski-Szmek?= , Lennart Poettering , Daan De Meyer , Aleksa Sarai , Alexander Viro , Jens Axboe , Tejun Heo , Johannes Weiner , =?utf-8?q?Michal_Koutn=C3=BD?= , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Chuck Lever , linux-nfs@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, netdev@vger.kernel.org, Christian Brauner X-Mailer: b4 0.14.3-dev-385fa X-Developer-Signature: v=1; a=openpgp-sha256; l=2327; i=brauner@kernel.org; h=from:subject:message-id; bh=oRiUykJBQlga5zzzIWDVy4MBnAL3DsvpFayNB03RaHE=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMWQc7OWQrLYIdJ/EVht1x/1xW/KhAN/VDWJ537N9lTM39 laV7XHqKGVhEONikBVTZHFoNwmXW85TsdkoUwNmDisTyBAGLk4BmMgrbkaGtxdWRqu8mHdJZlLM Tof79ZNXtQv9ObT794GW75FLL+qdPsvIsDBWrOH32jnsXExxN/w5Gos48yNq1c8uOmQm7fYi2u4 3KwA= X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Support the generic namespace iterator and lookup infrastructure to support file handles for namespaces. The network namespace has a separate list with different lifetime rules which we can just leave in tact. We have a similar concept for mount namespaces as well where it is on two differenet lists for different purposes. Signed-off-by: Christian Brauner --- include/net/net_namespace.h | 1 + net/core/net_namespace.c | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h index 025a7574b275..42075748dff1 100644 --- a/include/net/net_namespace.h +++ b/include/net/net_namespace.h @@ -11,6 +11,7 @@ #include #include #include +#include =20 #include #include diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c index dafb3d947043..b85e303400be 100644 --- a/net/core/net_namespace.c +++ b/net/core/net_namespace.c @@ -20,6 +20,7 @@ #include #include #include +#include =20 #include #include @@ -445,7 +446,7 @@ static __net_init int setup_net(struct net *net) LIST_HEAD(net_exit_list); int error =3D 0; =20 - net->net_cookie =3D atomic64_inc_return(&net_aligned_data.net_cookie); + net->net_cookie =3D ns_tree_gen_id(&net->ns); =20 list_for_each_entry(ops, &pernet_list, list) { error =3D ops_init(ops, net); @@ -455,6 +456,7 @@ static __net_init int setup_net(struct net *net) down_write(&net_rwsem); list_add_tail_rcu(&net->list, &net_namespace_list); up_write(&net_rwsem); + ns_tree_add_raw(net); out: return error; =20 @@ -675,8 +677,10 @@ static void cleanup_net(struct work_struct *work) =20 /* Don't let anyone else find us. */ down_write(&net_rwsem); - llist_for_each_entry(net, net_kill_list, cleanup_list) + llist_for_each_entry(net, net_kill_list, cleanup_list) { + ns_tree_remove(net); list_del_rcu(&net->list); + } /* Cache last net. After we unlock rtnl, no one new net * added to net_namespace_list can assign nsid pointer * to a net from net_kill_list (see peernet2id_alloc()). --=20 2.47.3