Commit 8be565e6 authored by Leon Romanovsky's avatar Leon Romanovsky Committed by Jason Gunthorpe

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: default avatarLeon Romanovsky <leonro@mellanox.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
parent f732e713
...@@ -943,6 +943,17 @@ static const struct nldev_fill_res_entry fill_entries[RDMA_RESTRACK_MAX] = { ...@@ -943,6 +943,17 @@ static const struct nldev_fill_res_entry fill_entries[RDMA_RESTRACK_MAX] = {
}, },
}; };
static bool is_visible_in_pid_ns(struct rdma_restrack_entry *res)
{
/*
* 1. Kern resources should be visible in init name space only
* 2. Present only resources visible in the current namespace
*/
if (rdma_is_kernel_res(res))
return task_active_pid_ns(current) == &init_pid_ns;
return task_active_pid_ns(current) == task_active_pid_ns(res->task);
}
static int res_get_common_dumpit(struct sk_buff *skb, static int res_get_common_dumpit(struct sk_buff *skb,
struct netlink_callback *cb, struct netlink_callback *cb,
enum rdma_restrack_type res_type) enum rdma_restrack_type res_type)
...@@ -1007,16 +1018,7 @@ static int res_get_common_dumpit(struct sk_buff *skb, ...@@ -1007,16 +1018,7 @@ static int res_get_common_dumpit(struct sk_buff *skb,
if (idx < start) if (idx < start)
goto next; goto next;
if ((rdma_is_kernel_res(res) && if (!is_visible_in_pid_ns(res))
task_active_pid_ns(current) != &init_pid_ns) ||
(!rdma_is_kernel_res(res) && task_active_pid_ns(current) !=
task_active_pid_ns(res->task)))
/*
* 1. Kern resources should be visible in init
* namspace only
* 2. Present only resources visible in the current
* namespace
*/
goto next; goto next;
if (!rdma_restrack_get(res)) if (!rdma_restrack_get(res))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment