Whamcloud - gitweb
LU-7845 lnet: check if ni is in current net namespace
[fs/lustre-release.git] / lnet / lnet / config.c
index 4f338cc..93ab8ba 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2012, 2014, Intel Corporation.
+ * Copyright (c) 2012, 2015, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -35,6 +35,8 @@
  */
 
 #define DEBUG_SUBSYSTEM S_LNET
+#include <linux/nsproxy.h>
+#include <net/net_namespace.h>
 #include <lnet/lib-lnet.h>
 
 /* tmp struct for parsing routes */
@@ -108,11 +110,19 @@ lnet_ni_free(struct lnet_ni *ni)
        if (ni->ni_cpts != NULL)
                cfs_expr_list_values_free(ni->ni_cpts, ni->ni_ncpts);
 
+       if (ni->ni_lnd_tunables != NULL)
+               LIBCFS_FREE(ni->ni_lnd_tunables, sizeof(*ni->ni_lnd_tunables));
+
        for (i = 0; i < LNET_MAX_INTERFACES &&
                    ni->ni_interfaces[i] != NULL; i++) {
                LIBCFS_FREE(ni->ni_interfaces[i],
                            strlen(ni->ni_interfaces[i]) + 1);
        }
+
+       /* release reference to net namespace */
+       if (ni->ni_net_ns != NULL)
+               put_net(ni->ni_net_ns);
+
        LIBCFS_FREE(ni, sizeof(*ni));
 }
 
@@ -174,6 +184,13 @@ lnet_ni_alloc(__u32 net, struct cfs_expr_list *el, struct list_head *nilist)
 
        /* LND will fill in the address part of the NID */
        ni->ni_nid = LNET_MKNID(net, 0);
+
+       /* Store net namespace in which current ni is being created */
+       if (current->nsproxy->net_ns != NULL)
+               ni->ni_net_ns = get_net(current->nsproxy->net_ns);
+       else
+               ni->ni_net_ns = NULL;
+
        ni->ni_last_alive = cfs_time_current_sec();
        list_add_tail(&ni->ni_list, nilist);
        return ni;
@@ -479,7 +496,7 @@ lnet_str2tbs_sep(struct list_head *tbs, char *str)
                        ltb = lnet_new_text_buf(nob);
                        if (ltb == NULL) {
                                lnet_free_text_bufs(&pending);
-                               return -1;
+                               return -ENOMEM;
                        }
 
                         for (i = 0; i < nob; i++)
@@ -612,7 +629,7 @@ lnet_str2tbs_expand(struct list_head *tbs, char *str)
 
  failed:
        lnet_free_text_bufs(&pending);
-       return -1;
+       return -EINVAL;
 }
 
 static int
@@ -646,7 +663,7 @@ lnet_parse_priority(char *str, unsigned int *priority, char **token)
                /* Update the caller's token pointer so it treats the found
                   priority as the token to report in the error message. */
                *token += sep - str + 1;
-               return -1;
+               return -EINVAL;
        }
 
        CDEBUG(D_NET, "gateway %s, priority %d, nob %d\n", str, *priority, nob);
@@ -676,7 +693,7 @@ lnet_parse_route (char *str, int *im_a_router)
        char             *token = str;
        int               ntokens = 0;
        int               myrc = -1;
-       unsigned int      hops;
+       __u32             hops;
        int               got_hops = 0;
        unsigned int      priority = 0;
 
@@ -759,8 +776,10 @@ lnet_parse_route (char *str, int *im_a_router)
                }
        }
 
+       /* if there are no hops set then we want to flag this value as
+        * unset since hops is an optional parameter */
        if (!got_hops)
-               hops = 1;
+               hops = LNET_UNDEFINED_HOPS;
 
        LASSERT(!list_empty(&nets));
        LASSERT(!list_empty(&gateways));