Skip to content

Commit b4c598a

Browse files
Leon Romanovskyrleon
Leon Romanovsky
authored andcommitted
RDMA/netlink: Implement nldev device dumpit calback
This patch adds the ability to return all available devices together with their properties. Signed-off-by: Leon Romanovsky <[email protected]> Reviewed-by: Steve Wise <[email protected]>
1 parent 6c80b41 commit b4c598a

File tree

1 file changed

+63
-1
lines changed

1 file changed

+63
-1
lines changed

drivers/infiniband/core/nldev.c

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,75 @@
3030
* POSSIBILITY OF SUCH DAMAGE.
3131
*/
3232

33+
#include <net/netlink.h>
3334
#include <rdma/rdma_netlink.h>
3435

3536
#include "core_priv.h"
3637

38+
static const struct nla_policy nldev_policy[RDMA_NLDEV_ATTR_MAX] = {
39+
[RDMA_NLDEV_ATTR_DEV_INDEX] = { .type = NLA_U32 },
40+
[RDMA_NLDEV_ATTR_DEV_NAME] = { .type = NLA_NUL_STRING,
41+
.len = IB_DEVICE_NAME_MAX - 1},
42+
[RDMA_NLDEV_ATTR_PORT_INDEX] = { .type = NLA_U32 },
43+
};
44+
45+
static int fill_dev_info(struct sk_buff *msg, struct ib_device *device)
46+
{
47+
if (nla_put_u32(msg, RDMA_NLDEV_ATTR_DEV_INDEX, device->index))
48+
return -EMSGSIZE;
49+
if (nla_put_string(msg, RDMA_NLDEV_ATTR_DEV_NAME, device->name))
50+
return -EMSGSIZE;
51+
if (nla_put_u32(msg, RDMA_NLDEV_ATTR_PORT_INDEX, rdma_end_port(device)))
52+
return -EMSGSIZE;
53+
return 0;
54+
}
55+
56+
static int _nldev_get_dumpit(struct ib_device *device,
57+
struct sk_buff *skb,
58+
struct netlink_callback *cb,
59+
unsigned int idx)
60+
{
61+
int start = cb->args[0];
62+
struct nlmsghdr *nlh;
63+
64+
if (idx < start)
65+
return 0;
66+
67+
nlh = nlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq,
68+
RDMA_NL_GET_TYPE(RDMA_NL_NLDEV, RDMA_NLDEV_CMD_GET),
69+
0, NLM_F_MULTI);
70+
71+
if (fill_dev_info(skb, device)) {
72+
nlmsg_cancel(skb, nlh);
73+
goto out;
74+
}
75+
76+
nlmsg_end(skb, nlh);
77+
78+
idx++;
79+
80+
out: cb->args[0] = idx;
81+
return skb->len;
82+
}
83+
84+
static int nldev_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb)
85+
{
86+
/*
87+
* There is no need to take lock, because
88+
* we are relying on ib_core's lists_rwsem
89+
*/
90+
return ib_enum_all_devs(_nldev_get_dumpit, skb, cb);
91+
}
92+
93+
static const struct rdma_nl_cbs nldev_cb_table[] = {
94+
[RDMA_NLDEV_CMD_GET] = {
95+
.dump = nldev_get_dumpit,
96+
},
97+
};
98+
3799
void __init nldev_init(void)
38100
{
39-
rdma_nl_register(RDMA_NL_NLDEV, NULL);
101+
rdma_nl_register(RDMA_NL_NLDEV, nldev_cb_table);
40102
}
41103

42104
void __exit nldev_exit(void)

0 commit comments

Comments
 (0)