Skip to content

Commit 8be565e

Browse files
Leon Romanovskyjgunthorpe
authored andcommitted
RDMA/nldev: Factor out the PID namespace check
The PID namespace is going to be used in the .doit callback, so generalize its implementation. Signed-off-by: Leon Romanovsky <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent f732e71 commit 8be565e

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

drivers/infiniband/core/nldev.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,17 @@ static const struct nldev_fill_res_entry fill_entries[RDMA_RESTRACK_MAX] = {
943943
},
944944
};
945945

946+
static bool is_visible_in_pid_ns(struct rdma_restrack_entry *res)
947+
{
948+
/*
949+
* 1. Kern resources should be visible in init name space only
950+
* 2. Present only resources visible in the current namespace
951+
*/
952+
if (rdma_is_kernel_res(res))
953+
return task_active_pid_ns(current) == &init_pid_ns;
954+
return task_active_pid_ns(current) == task_active_pid_ns(res->task);
955+
}
956+
946957
static int res_get_common_dumpit(struct sk_buff *skb,
947958
struct netlink_callback *cb,
948959
enum rdma_restrack_type res_type)
@@ -1007,16 +1018,7 @@ static int res_get_common_dumpit(struct sk_buff *skb,
10071018
if (idx < start)
10081019
goto next;
10091020

1010-
if ((rdma_is_kernel_res(res) &&
1011-
task_active_pid_ns(current) != &init_pid_ns) ||
1012-
(!rdma_is_kernel_res(res) && task_active_pid_ns(current) !=
1013-
task_active_pid_ns(res->task)))
1014-
/*
1015-
* 1. Kern resources should be visible in init
1016-
* namspace only
1017-
* 2. Present only resources visible in the current
1018-
* namespace
1019-
*/
1021+
if (!is_visible_in_pid_ns(res))
10201022
goto next;
10211023

10221024
if (!rdma_restrack_get(res))

0 commit comments

Comments
 (0)