* 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/
*/
#define DEBUG_SUBSYSTEM S_LNET
+#include <linux/nsproxy.h>
+#include <net/net_namespace.h>
#include <lnet/lib-lnet.h>
/* tmp struct for parsing routes */
#define LNET_MAX_TEXTBUF_NOB (64<<10) /* bound allocation */
#define LNET_SINGLE_TEXTBUF_NOB (4<<10)
-void
+static void
lnet_syntax(char *name, char *str, int offset, int width)
{
static char dots[LNET_SINGLE_TEXTBUF_NOB];
(width < 1) ? 0 : width - 1, dashes);
}
-int
+static int
lnet_issep (char c)
{
switch (c) {
if (ni->ni_cpts != NULL)
cfs_expr_list_values_free(ni->ni_cpts, ni->ni_ncpts);
-#ifndef __KERNEL__
-# ifdef HAVE_LIBPTHREAD
- pthread_mutex_destroy(&ni->ni_lock);
-# endif
-#endif
+ 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));
}
return NULL;
}
-#ifdef __KERNEL__
spin_lock_init(&ni->ni_lock);
-#else
-# ifdef HAVE_LIBPTHREAD
- pthread_mutex_init(&ni->ni_lock, NULL);
-# endif
-#endif
INIT_LIST_HEAD(&ni->ni_cptlist);
ni->ni_refs = cfs_percpt_alloc(lnet_cpt_table(),
sizeof(*ni->ni_refs[0]));
/* 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;
goto failed;
}
- /* Allocate a seperate piece of memory and copy
+ /* Allocate a separate piece of memory and copy
* into it the string, so we don't have
* a depencency on the tokens string. This way we
* can free the tokens at the end of the function.
return -EINVAL;
}
-struct lnet_text_buf *lnet_new_text_buf(int str_len)
+static struct lnet_text_buf *lnet_new_text_buf(int str_len)
{
struct lnet_text_buf *ltb;
int nob;
return ltb;
}
-void
+static void
lnet_free_text_buf(struct lnet_text_buf *ltb)
{
lnet_tbnob -= ltb->ltb_size;
LIBCFS_FREE(ltb, ltb->ltb_size);
}
-void
+static void
lnet_free_text_bufs(struct list_head *tbs)
{
struct lnet_text_buf *ltb;
CDEBUG(D_WARNING, "%d allocated\n", lnet_tbnob);
}
-int
+static int
lnet_str2tbs_sep(struct list_head *tbs, char *str)
{
struct list_head pending;
/* Split 'str' into separate commands */
for (;;) {
/* skip leading whitespace */
- while (cfs_iswhite(*str))
+ while (isspace(*str))
str++;
/* scan for separator or comment */
ltb = lnet_new_text_buf(nob);
if (ltb == NULL) {
lnet_free_text_bufs(&pending);
- return -1;
+ return -ENOMEM;
}
for (i = 0; i < nob; i++)
- if (cfs_iswhite(str[i]))
+ if (isspace(str[i]))
ltb->ltb_text[i] = ' ';
else
ltb->ltb_text[i] = str[i];
return 0;
}
-int
+static int
lnet_expand1tb(struct list_head *list,
char *str, char *sep1, char *sep2,
char *item, int itemlen)
return 0;
}
-int
+static int
lnet_str2tbs_expand(struct list_head *tbs, char *str)
{
char num[16];
failed:
lnet_free_text_bufs(&pending);
- return -1;
+ return -EINVAL;
}
-int
+static int
lnet_parse_hops (char *str, unsigned int *hops)
{
int len = strlen(str);
#define LNET_PRIORITY_SEPARATOR (':')
-int
+static int
lnet_parse_priority(char *str, unsigned int *priority, char **token)
{
int nob;
/* 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);
return 0;
}
-int
+static int
lnet_parse_route (char *str, int *im_a_router)
{
/* static scratch buffer OK (single threaded) */
char *token = str;
int ntokens = 0;
int myrc = -1;
- unsigned int hops;
+ __u32 hops;
int got_hops = 0;
unsigned int priority = 0;
sep = str;
for (;;) {
/* scan for token start */
- while (cfs_iswhite(*sep))
+ while (isspace(*sep))
sep++;
if (*sep == 0) {
if (ntokens < (got_hops ? 3 : 2))
token = sep++;
/* scan for token end */
- while (*sep != 0 && !cfs_iswhite(*sep))
+ while (*sep != 0 && !isspace(*sep))
sep++;
if (*sep != 0)
*sep++ = 0;
}
}
+ /* 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));
return myrc;
}
-int
+static int
lnet_parse_route_tbs(struct list_head *tbs, int *im_a_router)
{
struct lnet_text_buf *ltb;
return rc;
}
-int
+static int
lnet_match_network_token(char *token, int len, __u32 *ipaddrs, int nip)
{
struct list_head list = LIST_HEAD_INIT(list);
for (rc = i = 0; !rc && i < nip; i++)
rc = cfs_ip_addr_match(ipaddrs[i], &list);
- cfs_ip_addr_free(&list);
+ cfs_expr_list_free_list(&list);
return rc;
}
-int
+static int
lnet_match_network_tokens(char *net_entry, __u32 *ipaddrs, int nip)
{
static char tokens[LNET_SINGLE_TEXTBUF_NOB];
sep = tokens;
for (;;) {
/* scan for token start */
- while (cfs_iswhite(*sep))
+ while (isspace(*sep))
sep++;
if (*sep == 0)
break;
token = sep++;
/* scan for token end */
- while (*sep != 0 && !cfs_iswhite(*sep))
+ while (*sep != 0 && !isspace(*sep))
sep++;
if (*sep != 0)
*sep++ = 0;
return 1;
}
-__u32
+static __u32
lnet_netspec2net(char *netspec)
{
char *bracket = strchr(netspec, '(');
return net;
}
-int
+static int
lnet_splitnets(char *source, struct list_head *nets)
{
int offset = 0;
}
}
-int
+static int
lnet_match_networks (char **networksp, char *ip2nets, __u32 *ipaddrs, int nip)
{
static char networks[LNET_SINGLE_TEXTBUF_NOB];
return count;
}
-#ifdef __KERNEL__
-void
+static void
lnet_ipaddr_free_enumeration(__u32 *ipaddrs, int nip)
{
LIBCFS_FREE(ipaddrs, nip * sizeof(*ipaddrs));
}
-int
+static int
lnet_ipaddr_enumerate (__u32 **ipaddrsp)
{
int up;
__u32 *ipaddrs2;
int nip;
char **ifnames;
- int nif = libcfs_ipif_enumerate(&ifnames);
+ int nif = lnet_ipif_enumerate(&ifnames);
int i;
int rc;
LIBCFS_ALLOC(ipaddrs, nif * sizeof(*ipaddrs));
if (ipaddrs == NULL) {
CERROR("Can't allocate ipaddrs[%d]\n", nif);
- libcfs_ipif_free_enumeration(ifnames, nif);
+ lnet_ipif_free_enumeration(ifnames, nif);
return -ENOMEM;
}
if (!strcmp(ifnames[i], "lo"))
continue;
- rc = libcfs_ipif_query(ifnames[i], &up,
+ rc = lnet_ipif_query(ifnames[i], &up,
&ipaddrs[nip], &netmask);
if (rc != 0) {
CWARN("Can't query interface %s: %d\n",
nip++;
}
- libcfs_ipif_free_enumeration(ifnames, nif);
+ lnet_ipif_free_enumeration(ifnames, nif);
if (nip == nif) {
*ipaddrsp = ipaddrs;
int
lnet_parse_ip2nets (char **networksp, char *ip2nets)
{
- __u32 *ipaddrs;
+ __u32 *ipaddrs = NULL;
int nip = lnet_ipaddr_enumerate(&ipaddrs);
int rc;
return 0;
}
-
-int
-lnet_set_ip_niaddr (lnet_ni_t *ni)
-{
- __u32 net = LNET_NIDNET(ni->ni_nid);
- char **names;
- int n;
- __u32 ip;
- __u32 netmask;
- int up;
- int i;
- int rc;
-
- /* Convenience for LNDs that use the IP address of a local interface as
- * the local address part of their NID */
-
- if (ni->ni_interfaces[0] != NULL) {
-
- CLASSERT (LNET_MAX_INTERFACES > 1);
-
- if (ni->ni_interfaces[1] != NULL) {
- CERROR("Net %s doesn't support multiple interfaces\n",
- libcfs_net2str(net));
- return -EPERM;
- }
-
- rc = libcfs_ipif_query(ni->ni_interfaces[0],
- &up, &ip, &netmask);
- if (rc != 0) {
- CERROR("Net %s can't query interface %s: %d\n",
- libcfs_net2str(net), ni->ni_interfaces[0], rc);
- return -EPERM;
- }
-
- if (!up) {
- CERROR("Net %s can't use interface %s: it's down\n",
- libcfs_net2str(net), ni->ni_interfaces[0]);
- return -ENETDOWN;
- }
-
- ni->ni_nid = LNET_MKNID(net, ip);
- return 0;
- }
-
- n = libcfs_ipif_enumerate(&names);
- if (n <= 0) {
- CERROR("Net %s can't enumerate interfaces: %d\n",
- libcfs_net2str(net), n);
- return 0;
- }
-
- for (i = 0; i < n; i++) {
- if (!strcmp(names[i], "lo")) /* skip the loopback IF */
- continue;
-
- rc = libcfs_ipif_query(names[i], &up, &ip, &netmask);
-
- if (rc != 0) {
- CWARN("Net %s can't query interface %s: %d\n",
- libcfs_net2str(net), names[i], rc);
- continue;
- }
-
- if (!up) {
- CWARN("Net %s ignoring interface %s (down)\n",
- libcfs_net2str(net), names[i]);
- continue;
- }
-
- libcfs_ipif_free_enumeration(names, n);
- ni->ni_nid = LNET_MKNID(net, ip);
- return 0;
- }
-
- CERROR("Net %s can't find any interfaces\n", libcfs_net2str(net));
- libcfs_ipif_free_enumeration(names, n);
- return -ENOENT;
-}
-EXPORT_SYMBOL(lnet_set_ip_niaddr);
-
-#endif