Whamcloud - gitweb
LU-9679 lnet: use LIST_HEAD() for local lists.
[fs/lustre-release.git] / lnet / lnet / config.c
index 2394f39..9559975 100644 (file)
@@ -381,7 +381,6 @@ lnet_net_alloc(__u32 net_id, struct list_head *net_list)
 
        net->net_id = net_id;
        net->net_last_alive = ktime_get_real_seconds();
-       net->net_state = LNET_NET_STATE_INIT;
 
        /* initialize global paramters to undefiend */
        net->net_tunables.lct_peer_timeout = -1;
@@ -480,10 +479,10 @@ lnet_ni_alloc_common(struct lnet_net *net, char *iface)
        ni->ni_nid = LNET_MKNID(net->net_id, 0);
 
        /* Store net namespace in which current ni is being created */
-       if (current->nsproxy->net_ns != NULL)
+       if (current->nsproxy && current->nsproxy->net_ns)
                ni->ni_net_ns = get_net(current->nsproxy->net_ns);
        else
-               ni->ni_net_ns = NULL;
+               ni->ni_net_ns = get_net(&init_net);
 
        ni->ni_state = LNET_NI_STATE_INIT;
        list_add_tail(&ni->ni_netlist, &net->net_ni_added);
@@ -902,31 +901,14 @@ lnet_free_text_bufs(struct list_head *tbs)
        }
 }
 
-void
-lnet_print_text_bufs(struct list_head *tbs)
-{
-       struct list_head *tmp;
-       struct lnet_text_buf  *ltb;
-
-       list_for_each(tmp, tbs) {
-               ltb = list_entry(tmp, struct lnet_text_buf, ltb_list);
-
-               CDEBUG(D_WARNING, "%s\n", ltb->ltb_text);
-       }
-
-       CDEBUG(D_WARNING, "%d allocated\n", lnet_tbnob);
-}
-
 static int
 lnet_str2tbs_sep(struct list_head *tbs, char *str)
 {
-       struct list_head  pending;
-       char             *sep;
-       int               nob;
-       int               i;
-       struct lnet_text_buf  *ltb;
-
-       INIT_LIST_HEAD(&pending);
+       LIST_HEAD(pending);
+       char *sep;
+       int nob;
+       int i;
+       struct lnet_text_buf *ltb;
 
        /* Split 'str' into separate commands */
        for (;;) {
@@ -1004,7 +986,7 @@ static int
 lnet_str2tbs_expand(struct list_head *tbs, char *str)
 {
        char              num[16];
-       struct list_head  pending;
+       LIST_HEAD(pending);
        char             *sep;
        char             *sep2;
        char             *parsed;
@@ -1016,8 +998,6 @@ lnet_str2tbs_expand(struct list_head *tbs, char *str)
        int               nob;
        int               scanned;
 
-       INIT_LIST_HEAD(&pending);
-
        sep = strchr(str, '[');
        if (sep == NULL)                        /* nothing to expand */
                return 0;
@@ -1127,10 +1107,10 @@ static int
 lnet_parse_route (char *str, int *im_a_router)
 {
        /* static scratch buffer OK (single threaded) */
-       static char       cmd[LNET_SINGLE_TEXTBUF_NOB];
+       static char cmd[LNET_SINGLE_TEXTBUF_NOB];
 
-       struct list_head  nets;
-       struct list_head  gateways;
+       LIST_HEAD(nets);
+       LIST_HEAD(gateways);
        struct list_head *tmp1;
        struct list_head *tmp2;
        __u32             net;
@@ -1145,9 +1125,6 @@ lnet_parse_route (char *str, int *im_a_router)
        int               got_hops = 0;
        unsigned int      priority = 0;
 
-       INIT_LIST_HEAD(&gateways);
-       INIT_LIST_HEAD(&nets);
-
        /* save a copy of the string for error messages */
        strncpy(cmd, str, sizeof(cmd));
        cmd[sizeof(cmd) - 1] = '\0';
@@ -1292,13 +1269,11 @@ lnet_parse_route_tbs(struct list_head *tbs, int *im_a_router)
 int
 lnet_parse_routes (char *routes, int *im_a_router)
 {
-       struct list_head tbs;
-       int              rc = 0;
+       LIST_HEAD(tbs);
+       int rc = 0;
 
        *im_a_router = 0;
 
-       INIT_LIST_HEAD(&tbs);
-
        if (lnet_str2tbs_sep(&tbs, routes) < 0) {
                CERROR("Error parsing routes\n");
                rc = -EINVAL;
@@ -1313,7 +1288,7 @@ lnet_parse_routes (char *routes, int *im_a_router)
 static int
 lnet_match_network_token(char *token, int len, __u32 *ipaddrs, int nip)
 {
-       struct list_head list = LIST_HEAD_INIT(list);
+       LIST_HEAD(list);
        int             rc;
        int             i;
 
@@ -1491,9 +1466,9 @@ lnet_match_networks (char **networksp, char *ip2nets, __u32 *ipaddrs, int nip)
        static char       networks[LNET_SINGLE_TEXTBUF_NOB];
        static char       source[LNET_SINGLE_TEXTBUF_NOB];
 
-       struct list_head  raw_entries;
-       struct list_head  matched_nets;
-       struct list_head  current_nets;
+       LIST_HEAD(raw_entries);
+       LIST_HEAD(matched_nets);
+       LIST_HEAD(current_nets);
        struct list_head *t;
        struct list_head *t2;
        struct lnet_text_buf  *tb;
@@ -1505,15 +1480,12 @@ lnet_match_networks (char **networksp, char *ip2nets, __u32 *ipaddrs, int nip)
        int               dup;
        int               rc;
 
-       INIT_LIST_HEAD(&raw_entries);
        if (lnet_str2tbs_sep(&raw_entries, ip2nets) < 0) {
                CERROR("Error parsing ip2nets\n");
                LASSERT(lnet_tbnob == 0);
                return -EINVAL;
        }
 
-       INIT_LIST_HEAD(&matched_nets);
-       INIT_LIST_HEAD(&current_nets);
        networks[0] = 0;
        count = 0;
        len = 0;
@@ -1575,12 +1547,11 @@ lnet_match_networks (char **networksp, char *ip2nets, __u32 *ipaddrs, int nip)
                list_for_each_safe(t, t2, &current_nets) {
                        tb = list_entry(t, struct lnet_text_buf, ltb_list);
 
-                       list_del(&tb->ltb_list);
-                       list_add_tail(&tb->ltb_list, &matched_nets);
+                       list_move_tail(&tb->ltb_list, &matched_nets);
 
-                       len += snprintf(networks + len, sizeof(networks) - len,
-                                       "%s%s", (len == 0) ? "" : ",",
-                                       tb->ltb_text);
+                       len += scnprintf(networks + len, sizeof(networks) - len,
+                                        "%s%s", (len == 0) ? "" : ",",
+                                        tb->ltb_text);
 
                        if (len >= sizeof(networks)) {
                                CERROR("Too many matched networks\n");
@@ -1604,16 +1575,30 @@ lnet_match_networks (char **networksp, char *ip2nets, __u32 *ipaddrs, int nip)
        *networksp = networks;
        return count;
 }
-
-int lnet_inet_enumerate(struct lnet_inetdev **dev_list)
+/*
+ * kernel 5.3: commit ef11db3310e272d3d8dbe8739e0770820dd20e52
+ * added in_dev_for_each_ifa_rtnl and in_dev_for_each_ifa_rcu
+ * and removed for_ifa and endfor_ifa.
+ * Use the _rntl variant as the current locking is rtnl.
+ */
+#ifdef in_dev_for_each_ifa_rtnl
+#define DECLARE_CONST_IN_IFADDR(ifa)           const struct in_ifaddr *ifa
+#define endfor_ifa(in_dev)
+#else
+#define DECLARE_CONST_IN_IFADDR(ifa)
+#define in_dev_for_each_ifa_rtnl(ifa, in_dev)  for_ifa((in_dev))
+#endif
+
+int lnet_inet_enumerate(struct lnet_inetdev **dev_list, struct net *ns)
 {
        struct lnet_inetdev *ifaces = NULL;
        struct net_device *dev;
        int nalloc = 0;
        int nip = 0;
+       DECLARE_CONST_IN_IFADDR(ifa);
 
        rtnl_lock();
-       for_each_netdev(&init_net, dev) {
+       for_each_netdev(ns, dev) {
                int flags = dev_get_flags(dev);
                struct in_device *in_dev;
                int node_id;
@@ -1638,7 +1623,7 @@ int lnet_inet_enumerate(struct lnet_inetdev **dev_list)
                node_id = dev_to_node(&dev->dev);
                cpt = cfs_cpt_of_node(lnet_cpt_table(), node_id);
 
-               for_ifa(in_dev) {
+               in_dev_for_each_ifa_rtnl(ifa, in_dev) {
                        if (nip >= nalloc) {
                                struct lnet_inetdev *tmp;
 
@@ -1686,7 +1671,10 @@ lnet_parse_ip2nets (char **networksp, char *ip2nets)
        int        rc;
        int i;
 
-       nip = lnet_inet_enumerate(&ifaces);
+       if (current->nsproxy && current->nsproxy->net_ns)
+               nip = lnet_inet_enumerate(&ifaces, current->nsproxy->net_ns);
+       else
+               nip = lnet_inet_enumerate(&ifaces, &init_net);
        if (nip < 0) {
                if (nip != -ENOENT) {
                        LCONSOLE_ERROR_MSG(0x117,