On 9/25/2018 3:16 PM, Jason Gunthorpe wrote: > On Thu, Sep 13, 2018 at 12:16:20PM -0700, Steve Wise wrote: >> Add support for new LINK messages to allow adding and deleting rdma >> interfaces. This will be used initially for soft rdma drivers which >> instantiate device instances dynamically by the admin specifying a netdev >> device to use. The rdma_rxe module will be the first user of these >> messages. >> >> The design is modeled after RTNL_NEWLINK/DELLINK: rdma drivers >> register with the rdma core if they provide link add/delete functions. >> Each driver registers with a unique "type" string, that is used to >> dispatch messages coming from user space. A new RDMA_NLDEV_ATTR is >> defined for the "type" string. User mode will pass 3 attributes in a >> NEWLINK message: RDMA_NLDEV_ATTR_IBDEV_NAME for the desired rdma device >> name to be created, RDMA_NLDEV_ATTR_LINK_TYPE for the "type" of link >> being added, and RDMA_NLDEV_ATTR_NDEV_NAME for the net_device interface >> to use for this link. The DELLINK message will contain the IBDEV_NAME >> and LINK_TYPE attributes. >> >> Signed-off-by: Steve Wise <swise@xxxxxxxxxxxxxxxxxxxxx> >> drivers/infiniband/core/nldev.c | 113 +++++++++++++++++++++++++++++++++++++++ >> include/rdma/rdma_netlink.h | 11 ++++ >> include/uapi/rdma/rdma_netlink.h | 9 ++++ >> 3 files changed, 133 insertions(+) >> >> diff --git a/drivers/infiniband/core/nldev.c b/drivers/infiniband/core/nldev.c >> index 0385ab438320..d107b982c210 100644 >> +++ b/drivers/infiniband/core/nldev.c >> @@ -33,6 +33,7 @@ >> #include <linux/module.h> >> #include <linux/pid.h> >> #include <linux/pid_namespace.h> >> +#include <linux/mutex.h> >> #include <net/netlink.h> >> #include <rdma/rdma_cm.h> >> #include <rdma/rdma_netlink.h> >> @@ -107,6 +108,8 @@ >> [RDMA_NLDEV_ATTR_DRIVER_U32] = { .type = NLA_U32 }, >> [RDMA_NLDEV_ATTR_DRIVER_S64] = { .type = NLA_S64 }, >> [RDMA_NLDEV_ATTR_DRIVER_U64] = { .type = NLA_U64 }, >> + [RDMA_NLDEV_ATTR_LINK_TYPE] = { .type = NLA_NUL_STRING, >> + .len = IFNAMSIZ }, >> }; >> >> static int put_driver_name_print_type(struct sk_buff *msg, const char *name, >> @@ -1072,6 +1075,110 @@ static int nldev_res_get_pd_dumpit(struct sk_buff *skb, >> return res_get_common_dumpit(skb, cb, RDMA_RESTRACK_PD); >> } >> >> +static LIST_HEAD(link_ops); >> +static DEFINE_MUTEX(link_ops_mutex); >> + >> +void rdma_link_register(struct rdma_link_ops *ops) >> +{ >> + mutex_lock(&link_ops_mutex); >> + list_add(&ops->list, &link_ops); > > Make sure the name is unique > The function name? >> + mutex_unlock(&link_ops_mutex); >> +} >> +EXPORT_SYMBOL(rdma_link_register); >> + >> +void rdma_link_unregister(struct rdma_link_ops *ops) >> +{ >> + mutex_lock(&link_ops_mutex); >> + list_del_init(&ops->list); >> + mutex_unlock(&link_ops_mutex); >> +} >> +EXPORT_SYMBOL(rdma_link_unregister); >> + >> +static const struct rdma_link_ops *link_ops_get(const char *type) >> +{ >> + const struct rdma_link_ops *ops; >> + >> + mutex_lock(&link_ops_mutex); >> + list_for_each_entry(ops, &link_ops, list) { >> + if (!strncmp(ops->type, type, IFNAMSIZ)) > > Why strncmp here? Both strings should be null terminated. > ok. >> + goto out; >> + } >> + ops = NULL; > > This should trigger module automatic loading and try again. > > Ie call > > request_module("rdma-link-%s", type); > > And rxe should provide that symbol as a module-alias. > > See the similar code in netdev, ie MODULE_ALIAS_RTNL_LINK and the > request_module calls Hmm, I'll look into this. Thanks!