diff options
author | Leon Romanovsky <leonro@mellanox.com> | 2019-01-30 11:48:54 +0100 |
---|---|---|
committer | Jason Gunthorpe <jgg@mellanox.com> | 2019-01-31 05:11:45 +0100 |
commit | 8be565e65fa9f4b1dee96e19bce3ca34e68cc8cb (patch) | |
tree | 28ffaed1b203cce0f2f305afebfbf467a44e965e /drivers | |
parent | RDMA/nldev: Dynamically generate restrack dumpit callbacks (diff) | |
download | linux-8be565e65fa9f4b1dee96e19bce3ca34e68cc8cb.tar.xz linux-8be565e65fa9f4b1dee96e19bce3ca34e68cc8cb.zip |
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 <leonro@mellanox.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/infiniband/core/nldev.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/drivers/infiniband/core/nldev.c b/drivers/infiniband/core/nldev.c index 68b2d7a871cb..e54a79d3f458 100644 --- a/drivers/infiniband/core/nldev.c +++ b/drivers/infiniband/core/nldev.c @@ -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, struct netlink_callback *cb, enum rdma_restrack_type res_type) @@ -1007,16 +1018,7 @@ static int res_get_common_dumpit(struct sk_buff *skb, if (idx < start) goto next; - if ((rdma_is_kernel_res(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 - */ + if (!is_visible_in_pid_ns(res)) goto next; if (!rdma_restrack_get(res)) |