Skip to content

Commit

Permalink
RDMA/core: Add interface to read device namespace sharing mode
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Parav Pandit authored and Jason Gunthorpe committed Mar 28, 2019
1 parent 37eeab5 commit cb7e0e1
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
1 change: 1 addition & 0 deletions drivers/infiniband/core/core_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ struct pkey_index_qp_list {
};

extern const struct attribute_group ib_dev_attr_group;
extern bool ib_devices_shared_netns;

int ib_device_register_sysfs(struct ib_device *device);
void ib_device_unregister_sysfs(struct ib_device *device);
Expand Down
2 changes: 1 addition & 1 deletion drivers/infiniband/core/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ static DEFINE_XARRAY_FLAGS(rdma_nets, XA_FLAGS_ALLOC);
*/
static DECLARE_RWSEM(rdma_nets_rwsem);

static bool ib_devices_shared_netns = true;
bool ib_devices_shared_netns = true;
module_param_named(netns_mode, ib_devices_shared_netns, bool, 0444);
MODULE_PARM_DESC(netns_mode,
"Share device among net namespaces; default=1 (shared)");
Expand Down
32 changes: 32 additions & 0 deletions drivers/infiniband/core/nldev.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ static const struct nla_policy nldev_policy[RDMA_NLDEV_ATTR_MAX] = {
[RDMA_NLDEV_ATTR_RES_CTXN] = { .type = NLA_U32 },
[RDMA_NLDEV_ATTR_LINK_TYPE] = { .type = NLA_NUL_STRING,
.len = RDMA_NLDEV_ATTR_ENTRY_STRLEN },
[RDMA_NLDEV_SYS_ATTR_NETNS_MODE] = { .type = NLA_U8 },
};

static int put_driver_name_print_type(struct sk_buff *msg, const char *name,
Expand Down Expand Up @@ -1312,6 +1313,34 @@ static int nldev_dellink(struct sk_buff *skb, struct nlmsghdr *nlh,
return 0;
}

static int nldev_get_sys_get_dumpit(struct sk_buff *skb,
struct netlink_callback *cb)
{
struct nlattr *tb[RDMA_NLDEV_ATTR_MAX];
struct nlmsghdr *nlh;
int err;

err = nlmsg_parse(cb->nlh, 0, tb, RDMA_NLDEV_ATTR_MAX - 1,
nldev_policy, NULL);
if (err)
return err;

nlh = nlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq,
RDMA_NL_GET_TYPE(RDMA_NL_NLDEV,
RDMA_NLDEV_CMD_SYS_GET),
0, 0);

err = nla_put_u8(skb, RDMA_NLDEV_SYS_ATTR_NETNS_MODE,
(u8)ib_devices_shared_netns);
if (err) {
nlmsg_cancel(skb, nlh);
return err;
}

nlmsg_end(skb, nlh);
return skb->len;
}

static const struct rdma_nl_cbs nldev_cb_table[RDMA_NLDEV_NUM_OPS] = {
[RDMA_NLDEV_CMD_GET] = {
.doit = nldev_get_doit,
Expand Down Expand Up @@ -1357,6 +1386,9 @@ static const struct rdma_nl_cbs nldev_cb_table[RDMA_NLDEV_NUM_OPS] = {
.doit = nldev_res_get_pd_doit,
.dump = nldev_res_get_pd_dumpit,
},
[RDMA_NLDEV_CMD_SYS_GET] = {
.dump = nldev_get_sys_get_dumpit,
},
};

void __init nldev_init(void)
Expand Down
9 changes: 8 additions & 1 deletion include/uapi/rdma/rdma_netlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,8 @@ enum rdma_nldev_command {

RDMA_NLDEV_CMD_PORT_GET, /* can dump */

/* 6 - 8 are free to use */
RDMA_NLDEV_CMD_SYS_GET, /* can dump */
/* 7 - 8 are free to use */

RDMA_NLDEV_CMD_RES_GET = 9, /* can dump */

Expand Down Expand Up @@ -472,6 +473,12 @@ enum rdma_nldev_attr {
*/
RDMA_NLDEV_ATTR_LINK_TYPE, /* string */

/*
* net namespace mode for rdma subsystem:
* either shared or exclusive among multiple net namespaces.
*/
RDMA_NLDEV_SYS_ATTR_NETNS_MODE, /* u8 */

/*
* Always the end
*/
Expand Down

0 comments on commit cb7e0e1

Please sign in to comment.