rdma: Autoload netlink client modules
authorJason Gunthorpe <jgunthorpe@obsidianresearch.com>
Mon, 14 Aug 2017 20:57:39 +0000 (14:57 -0600)
committerDoug Ledford <dledford@redhat.com>
Tue, 22 Aug 2017 21:04:22 +0000 (17:04 -0400)
If a message comes in and we do not have the client in the table, then
try to load the module supplying that client using MODULE_ALIAS to find
it.

This duplicates the scheme seen in other netlink muxes (eg nfnetlink).

Signed-off-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
Reviewed-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
drivers/infiniband/core/cma.c
drivers/infiniband/core/device.c
drivers/infiniband/core/iwcm.c
drivers/infiniband/core/netlink.c
drivers/infiniband/core/nldev.c
include/rdma/rdma_netlink.h

index d8edd8b11561aef5224fdbe3e2cfbf65b80a6475..b76de2e2b20950649f5fc65fc0d8333d4efd781c 100644 (file)
@@ -4537,5 +4537,7 @@ static void __exit cma_cleanup(void)
        destroy_workqueue(cma_wq);
 }
 
+MODULE_ALIAS_RDMA_NETLINK(RDMA_NL_RDMA_CM, 1);
+
 module_init(cma_init);
 module_exit(cma_cleanup);
index 91d7cea1a0b9606702390f3dc80d9befadd053fa..fc6be1175183820e34d5d10a48e158402ec95edd 100644 (file)
@@ -1252,5 +1252,7 @@ static void __exit ib_core_cleanup(void)
        destroy_workqueue(ib_wq);
 }
 
+MODULE_ALIAS_RDMA_NETLINK(RDMA_NL_LS, 4);
+
 module_init(ib_core_init);
 module_exit(ib_core_cleanup);
index e33528e102f89a9a2dd639f7e65748e50d49990c..fcf42f6bb82a720bd2971fc030339db068e2ca8d 100644 (file)
@@ -1200,5 +1200,7 @@ static void __exit iw_cm_cleanup(void)
        iwpm_exit(RDMA_NL_IWCM);
 }
 
+MODULE_ALIAS_RDMA_NETLINK(RDMA_NL_IWCM, 2);
+
 module_init(iw_cm_init);
 module_exit(iw_cm_cleanup);
index f782697cf4d819557192c3487c78316de3901f9a..e685148dd3e6c246fdfc75cbc63dc222ccb406a7 100644 (file)
@@ -84,6 +84,15 @@ static bool is_nl_valid(unsigned int type, unsigned int op)
                return false;
 
        cb_table = rdma_nl_types[type].cb_table;
+#ifdef CONFIG_MODULES
+       if (!cb_table) {
+               mutex_unlock(&rdma_nl_mutex);
+               request_module("rdma-netlink-subsys-%d", type);
+               mutex_lock(&rdma_nl_mutex);
+               cb_table = rdma_nl_types[type].cb_table;
+       }
+#endif
+
        if (!cb_table || (!cb_table[op].dump && !cb_table[op].doit))
                return false;
        return true;
index 474022274e09cd53b87d7942cc70a9cd646e9e7e..3ba24c428c3bda48ec8698934f275828754ac19d 100644 (file)
@@ -30,6 +30,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <linux/module.h>
 #include <net/netlink.h>
 #include <rdma/rdma_netlink.h>
 
@@ -320,3 +321,5 @@ void __exit nldev_exit(void)
 {
        rdma_nl_unregister(RDMA_NL_NLDEV);
 }
+
+MODULE_ALIAS_RDMA_NETLINK(RDMA_NL_NLDEV, 5);
index e25bf1988846df869dbb285032fbf201d0dd6864..2d878596b1e07a41f0e7d75b17b269e88646b9fd 100644 (file)
@@ -17,6 +17,18 @@ enum rdma_nl_flags {
        RDMA_NL_ADMIN_PERM      = 1 << 0,
 };
 
+/* Define this module as providing netlink services for NETLINK_RDMA, with
+ * index _index.  Since the client indexes were setup in a uapi header as an
+ * enum and we do no want to change that, the user must supply the expanded
+ * constant as well and the compiler checks they are the same.
+ */
+#define MODULE_ALIAS_RDMA_NETLINK(_index, _val)                                \
+       static inline void __chk_##_index(void)                                \
+       {                                                                      \
+               BUILD_BUG_ON(_index != _val);                                  \
+       }                                                                      \
+       MODULE_ALIAS("rdma-netlink-subsys-" __stringify(_val))
+
 /**
  * Register client in RDMA netlink.
  * @index: Index of the added client