From nobody Sun Feb 8 18:31:36 2026 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 130922C0294; Wed, 22 Oct 2025 16:09:22 +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=1761149363; cv=none; b=efTIpoZzWuRtngLEWpYaLgwWo1/tkJRrpvxVsc6xIHXgT0p5zf9DWnwHrJPcKAynvR26dxMOm9YEARPRw6CrvcoawIS7tnJm3t8/yOIoNuIaqDtwpH60axHsDrN7aPWqGzvORAFhctv37Pl2aWUCWfOdoYbS0lJ4jugb1f//Mac= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761149363; c=relaxed/simple; bh=gPBGu8BceJ6oHRtyp7iwBf16DUj5zY+HNikOeiNBVYw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=muqCJbh7jPH92qP06wHC0FUENfvsOnyE1i88BAc86Ll1FVVqmzeUkOZLXe3xmNq9OrXNDCyT6Rzo9iMKPLZcXhXJZLoen3QqrJ97G0rICwh6vWK8m0BPxi6sFFKt6H5uryrURbfkpb1Vi0Ckx5o5CXRSU39q0+6eaBv7ApC2V/o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qwpeLoQw; 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="qwpeLoQw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BBD33C4CEE7; Wed, 22 Oct 2025 16:09:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1761149362; bh=gPBGu8BceJ6oHRtyp7iwBf16DUj5zY+HNikOeiNBVYw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=qwpeLoQwHUP+jIbSHho17fazbBhdWrnY8PGq+1hRylkJ62nGHDyDISgaU3DzgVtB2 Mu45jdUNVK/3HfDWYjiuXw5so1XA/mt8y20HxGf871d03AaV4rOY7VVPvqP+UDcEY0 C1vC4L1FWSWkn0Y8zmSgTVU/Rf/ZM6F4aXNjPFxuZn9qdLM/F5UlLaWdiYqusdgV5j HLHiOfMQL5zvgYv43xcIFxBFt57pSsK91yjGULpP9x5Wivvm3xzpQF+ThpNavugtYY UCt1xNgt3dam4l//GaQ5FxWeK+cIUjKwRRO/TAZoksgxr3e0fwGgaFak4t2CvyE0PQ jHpLLi2u5bRUA== From: Christian Brauner Date: Wed, 22 Oct 2025 18:06:15 +0200 Subject: [PATCH v2 37/63] selftests/namespaces: second listns() test 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: <20251022-work-namespace-nstree-listns-v2-37-71a588572371@kernel.org> References: <20251022-work-namespace-nstree-listns-v2-0-71a588572371@kernel.org> In-Reply-To: <20251022-work-namespace-nstree-listns-v2-0-71a588572371@kernel.org> To: linux-fsdevel@vger.kernel.org, Josef Bacik , Jeff Layton Cc: Jann Horn , Mike Yuan , =?utf-8?q?Zbigniew_J=C4=99drzejewski-Szmek?= , Lennart Poettering , Daan De Meyer , Aleksa Sarai , Amir Goldstein , Tejun Heo , Johannes Weiner , Thomas Gleixner , Alexander Viro , Jan Kara , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, bpf@vger.kernel.org, Eric Dumazet , Jakub Kicinski , netdev@vger.kernel.org, Arnd Bergmann , Christian Brauner X-Mailer: b4 0.15-dev-96507 X-Developer-Signature: v=1; a=openpgp-sha256; l=2143; i=brauner@kernel.org; h=from:subject:message-id; bh=gPBGu8BceJ6oHRtyp7iwBf16DUj5zY+HNikOeiNBVYw=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMWT8ZHjW+LXlaP1l/9aAv5zu5RFF7ou+VXKfPbJFa+fsx T1eR+L3dJSyMIhxMciKKbI4tJuEyy3nqdhslKkBM4eVCWQIAxenAExk00RGhqVsy1W5JHcekp/e NqvuidKDt38WO8drbZQ7cTnyUJNNnRkjw5pgM7bJ0wo2+7KKHnTPltxu/eas9ow3Qao6DYumTXq 8lwsA X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 test listns() with type filtering. List only network namespaces. Signed-off-by: Christian Brauner --- tools/testing/selftests/namespaces/listns_test.c | 61 ++++++++++++++++++++= ++++ 1 file changed, 61 insertions(+) diff --git a/tools/testing/selftests/namespaces/listns_test.c b/tools/testi= ng/selftests/namespaces/listns_test.c index cb42827d3dfe..64249502ac49 100644 --- a/tools/testing/selftests/namespaces/listns_test.c +++ b/tools/testing/selftests/namespaces/listns_test.c @@ -54,4 +54,65 @@ TEST(listns_basic_unified) } } =20 +/* + * Test listns() with type filtering. + * List only network namespaces. + */ +TEST(listns_filter_by_type) +{ + struct ns_id_req req =3D { + .size =3D sizeof(req), + .spare =3D 0, + .ns_id =3D 0, + .ns_type =3D CLONE_NEWNET, /* Only network namespaces */ + .spare2 =3D 0, + .user_ns_id =3D 0, + }; + __u64 ns_ids[100]; + ssize_t ret; + + ret =3D sys_listns(&req, ns_ids, ARRAY_SIZE(ns_ids), 0); + if (ret < 0) { + if (errno =3D=3D ENOSYS) + SKIP(return, "listns() not supported"); + TH_LOG("listns failed: %s (errno=3D%d)", strerror(errno), errno); + ASSERT_TRUE(false); + } + ASSERT_GE(ret, 0); + + /* Should find at least init_net */ + ASSERT_GT(ret, 0); + TH_LOG("Found %zd active network namespaces", ret); + + /* Verify we can open each namespace and it's actually a network namespac= e */ + for (ssize_t i =3D 0; i < ret && i < 5; i++) { + struct nsfs_file_handle nsfh =3D { + .ns_id =3D ns_ids[i], + .ns_type =3D CLONE_NEWNET, + .ns_inum =3D 0, + }; + struct file_handle *fh; + int fd; + + fh =3D (struct file_handle *)malloc(sizeof(*fh) + sizeof(nsfh)); + ASSERT_NE(fh, NULL); + fh->handle_bytes =3D sizeof(nsfh); + fh->handle_type =3D 0; + memcpy(fh->f_handle, &nsfh, sizeof(nsfh)); + + fd =3D open_by_handle_at(-10003, fh, O_RDONLY); + free(fh); + + if (fd >=3D 0) { + int ns_type; + /* Verify it's a network namespace via ioctl */ + ns_type =3D ioctl(fd, NS_GET_NSTYPE); + if (ns_type >=3D 0) { + ASSERT_EQ(ns_type, CLONE_NEWNET); + } + close(fd); + } + } +} + TEST_HARNESS_MAIN --=20 2.47.3