mirror of https://github.com/torvalds/linux.git
selftests/namespaces: fourth listns() test
Test listns() with LISTNS_CURRENT_USER. List namespaces owned by current user namespace. Link: https://patch.msgid.link/20251029-work-namespace-nstree-listns-v4-42-2e6f823ebdc0@kernel.org Tested-by: syzbot@syzkaller.appspotmail.com Reviewed-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Christian Brauner <brauner@kernel.org>
This commit is contained in:
parent
46909d1343
commit
abac8de3e5
|
|
@ -168,4 +168,37 @@ TEST(listns_pagination)
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Test listns() with LISTNS_CURRENT_USER.
|
||||
* List namespaces owned by current user namespace.
|
||||
*/
|
||||
TEST(listns_current_user)
|
||||
{
|
||||
struct ns_id_req req = {
|
||||
.size = sizeof(req),
|
||||
.spare = 0,
|
||||
.ns_id = 0,
|
||||
.ns_type = 0,
|
||||
.spare2 = 0,
|
||||
.user_ns_id = LISTNS_CURRENT_USER,
|
||||
};
|
||||
__u64 ns_ids[100];
|
||||
ssize_t ret;
|
||||
|
||||
ret = sys_listns(&req, ns_ids, ARRAY_SIZE(ns_ids), 0);
|
||||
if (ret < 0) {
|
||||
if (errno == ENOSYS)
|
||||
SKIP(return, "listns() not supported");
|
||||
TH_LOG("listns failed: %s (errno=%d)", strerror(errno), errno);
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
ASSERT_GE(ret, 0);
|
||||
|
||||
/* Should find at least the initial namespaces if we're in init_user_ns */
|
||||
TH_LOG("Found %zd namespaces owned by current user namespace", ret);
|
||||
|
||||
for (ssize_t i = 0; i < ret; i++)
|
||||
TH_LOG(" [%zd] ns_id: %llu", i, (unsigned long long)ns_ids[i]);
|
||||
}
|
||||
|
||||
TEST_HARNESS_MAIN
|
||||
|
|
|
|||
Loading…
Reference in New Issue