Skip to content

Commit cb7e0e1

Browse files
paravmellanoxjgunthorpe
authored andcommitted
RDMA/core: Add interface to read device namespace sharing mode
Add an interface via netlink command to query whether rdma devices are shared among multiple net namespaces or not. When using RDMAtool, it can be queried as, $rdma system show netns netns shared Signed-off-by: Parav Pandit <parav@mellanox.com> Signed-off-by: Leon Romanovsky <leonro@mellanox.com> Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
1 parent 37eeab5 commit cb7e0e1

4 files changed

Lines changed: 42 additions & 2 deletions

File tree

‎drivers/infiniband/core/core_priv.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ struct pkey_index_qp_list {
5555
};
5656

5757
extern const struct attribute_group ib_dev_attr_group;
58+
extern bool ib_devices_shared_netns;
5859

5960
int ib_device_register_sysfs(struct ib_device *device);
6061
void ib_device_unregister_sysfs(struct ib_device *device);

‎drivers/infiniband/core/device.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ static DEFINE_XARRAY_FLAGS(rdma_nets, XA_FLAGS_ALLOC);
127127
*/
128128
static DECLARE_RWSEM(rdma_nets_rwsem);
129129

130-
static bool ib_devices_shared_netns = true;
130+
bool ib_devices_shared_netns = true;
131131
module_param_named(netns_mode, ib_devices_shared_netns, bool, 0444);
132132
MODULE_PARM_DESC(netns_mode,
133133
"Share device among net namespaces; default=1 (shared)");

‎drivers/infiniband/core/nldev.c‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ static const struct nla_policy nldev_policy[RDMA_NLDEV_ATTR_MAX] = {
116116
[RDMA_NLDEV_ATTR_RES_CTXN] = { .type = NLA_U32 },
117117
[RDMA_NLDEV_ATTR_LINK_TYPE] = { .type = NLA_NUL_STRING,
118118
.len = RDMA_NLDEV_ATTR_ENTRY_STRLEN },
119+
[RDMA_NLDEV_SYS_ATTR_NETNS_MODE] = { .type = NLA_U8 },
119120
};
120121

121122
static int put_driver_name_print_type(struct sk_buff *msg, const char *name,
@@ -1312,6 +1313,34 @@ static int nldev_dellink(struct sk_buff *skb, struct nlmsghdr *nlh,
13121313
return 0;
13131314
}
13141315

1316+
static int nldev_get_sys_get_dumpit(struct sk_buff *skb,
1317+
struct netlink_callback *cb)
1318+
{
1319+
struct nlattr *tb[RDMA_NLDEV_ATTR_MAX];
1320+
struct nlmsghdr *nlh;
1321+
int err;
1322+
1323+
err = nlmsg_parse(cb->nlh, 0, tb, RDMA_NLDEV_ATTR_MAX - 1,
1324+
nldev_policy, NULL);
1325+
if (err)
1326+
return err;
1327+
1328+
nlh = nlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq,
1329+
RDMA_NL_GET_TYPE(RDMA_NL_NLDEV,
1330+
RDMA_NLDEV_CMD_SYS_GET),
1331+
0, 0);
1332+
1333+
err = nla_put_u8(skb, RDMA_NLDEV_SYS_ATTR_NETNS_MODE,
1334+
(u8)ib_devices_shared_netns);
1335+
if (err) {
1336+
nlmsg_cancel(skb, nlh);
1337+
return err;
1338+
}
1339+
1340+
nlmsg_end(skb, nlh);
1341+
return skb->len;
1342+
}
1343+
13151344
static const struct rdma_nl_cbs nldev_cb_table[RDMA_NLDEV_NUM_OPS] = {
13161345
[RDMA_NLDEV_CMD_GET] = {
13171346
.doit = nldev_get_doit,
@@ -1357,6 +1386,9 @@ static const struct rdma_nl_cbs nldev_cb_table[RDMA_NLDEV_NUM_OPS] = {
13571386
.doit = nldev_res_get_pd_doit,
13581387
.dump = nldev_res_get_pd_dumpit,
13591388
},
1389+
[RDMA_NLDEV_CMD_SYS_GET] = {
1390+
.dump = nldev_get_sys_get_dumpit,
1391+
},
13601392
};
13611393

13621394
void __init nldev_init(void)

‎include/uapi/rdma/rdma_netlink.h‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,8 @@ enum rdma_nldev_command {
261261

262262
RDMA_NLDEV_CMD_PORT_GET, /* can dump */
263263

264-
/* 6 - 8 are free to use */
264+
RDMA_NLDEV_CMD_SYS_GET, /* can dump */
265+
/* 7 - 8 are free to use */
265266

266267
RDMA_NLDEV_CMD_RES_GET = 9, /* can dump */
267268

@@ -472,6 +473,12 @@ enum rdma_nldev_attr {
472473
*/
473474
RDMA_NLDEV_ATTR_LINK_TYPE, /* string */
474475

476+
/*
477+
* net namespace mode for rdma subsystem:
478+
* either shared or exclusive among multiple net namespaces.
479+
*/
480+
RDMA_NLDEV_SYS_ATTR_NETNS_MODE, /* u8 */
481+
475482
/*
476483
* Always the end
477484
*/

0 commit comments

Comments
 (0)