All of lore.kernel.org
 help / color / mirror / Atom feed
From: James Simmons <jsimmons@infradead.org>
To: Andreas Dilger <adilger@whamcloud.com>,
	Oleg Drokin <green@whamcloud.com>, NeilBrown <neilb@suse.de>
Cc: Frank Sehr <fsehr@whamcloud.com>,
	Lustre Development List <lustre-devel@lists.lustre.org>
Subject: [lustre-devel] [PATCH 26/42] lnet: Allow IP specification
Date: Mon, 23 Jan 2023 18:00:39 -0500	[thread overview]
Message-ID: <1674514855-15399-27-git-send-email-jsimmons@infradead.org> (raw)
In-Reply-To: <1674514855-15399-1-git-send-email-jsimmons@infradead.org>

From: Frank Sehr <fsehr@whamcloud.com>

Allows selecting an interface by specifying an IP address in the NID.
All variations of interface and IP address are considered.

1 no interface and no IP address is specified: Select first interface
2 interface and no IP: Select main IP address
3 no interface and IP specified: Select first interface
  that has the IP address
4 interface and IP specified: Verify that interface and IP match

The change does not have any effect on current configurations and
will be active when the changes in lnetctl, YAML or
module parameter are applied.
This patch effects only socklnd component. A macro is defined in
lnet-types.h to check if an IP address is set (IPV4 or IPV6).
Further IPV6 changes are not integrated.

For further reference please read

IP specification in LNet
https://wiki.whamcloud.com/display/LNet/IP+specification+in+LNet

WC-bug-id: https://jira.whamcloud.com/browse/LU-13642
Lustre-commit: 14cdcd61985aa0209 ("LU-13642 lnet: Allow IP specification")
Signed-off-by: Frank Sehr <fsehr@whamcloud.com>
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/47660
Reviewed-by: Neil Brown <neilb@suse.de>
Reviewed-by: Cyril Bordage <cbordage@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Signed-off-by: James Simmons <jsimmons@infradead.org>
---
 include/linux/lnet/lib-lnet.h        |  3 ++
 include/uapi/linux/lnet/lnet-types.h | 37 ++++++++++++-------
 net/lnet/klnds/socklnd/socklnd.c     | 53 +++++++++++++---------------
 net/lnet/lnet/config.c               | 50 ++++++++++++++++++++++++++
 4 files changed, 101 insertions(+), 42 deletions(-)

diff --git a/include/linux/lnet/lib-lnet.h b/include/linux/lnet/lib-lnet.h
index ba68d50e677d..25289f5bba39 100644
--- a/include/linux/lnet/lib-lnet.h
+++ b/include/linux/lnet/lib-lnet.h
@@ -838,6 +838,9 @@ struct lnet_inetdev {
 
 int lnet_inet_enumerate(struct lnet_inetdev **dev_list, struct net *ns,
 			bool v6);
+int lnet_inet_select(struct lnet_ni *ni, struct lnet_inetdev *ifaces,
+		     int num_ifaces);
+
 void lnet_sock_setbuf(struct socket *socket, int txbufsize, int rxbufsize);
 void lnet_sock_getbuf(struct socket *socket, int *txbufsize, int *rxbufsize);
 int lnet_sock_getaddr(struct socket *socket, bool remote,
diff --git a/include/uapi/linux/lnet/lnet-types.h b/include/uapi/linux/lnet/lnet-types.h
index 304add9957ef..8a1d2d749b4b 100644
--- a/include/uapi/linux/lnet/lnet-types.h
+++ b/include/uapi/linux/lnet/lnet-types.h
@@ -90,11 +90,6 @@ static inline __u32 LNET_NIDNET(lnet_nid_t nid)
 	return (nid >> 32) & 0xffffffff;
 }
 
-static inline lnet_nid_t LNET_MKNID(__u32 net, __u32 addr)
-{
-	return (((__u64)net) << 32) | addr;
-}
-
 static inline __u32 LNET_NETNUM(__u32 net)
 {
 	return net & 0xffff;
@@ -110,25 +105,41 @@ static inline __u32 LNET_MKNET(__u32 type, __u32 num)
 	return (type << 16) | num;
 }
 
+static inline lnet_nid_t LNET_MKNID(__u32 net, __u32 addr)
+{
+	return (((__u64)net) << 32) | addr;
+}
+
 /** The lolnd NID (i.e. myself) */
 #define LNET_NID_LO_0 LNET_MKNID(LNET_MKNET(LOLND, 0), 0)
 
 #define LNET_NET_ANY LNET_NIDNET(LNET_NID_ANY)
 
-/* check for address set */
-static inline bool nid_addr_is_set(const struct lnet_nid *nid)
+static inline bool nid_is_nid4(const struct lnet_nid *nid)
 {
-	int sum = 0, i;
+	return NID_ADDR_BYTES(nid) == 4;
+}
 
-	for (i = 0; i < NID_ADDR_BYTES(nid); i++)
-		sum |= nid->nid_addr[i];
+static inline bool nid_is_ipv4(const struct lnet_nid *nid)
+{
+	return NID_ADDR_BYTES(nid) == 4;
+}
 
-	return sum ? true : false;
+static inline bool nid_is_ipv6(const struct lnet_nid *nid)
+{
+	return NID_ADDR_BYTES(nid) == 16;
 }
 
-static inline int nid_is_nid4(const struct lnet_nid *nid)
+/* check for address set */
+static inline bool nid_addr_is_set(const struct lnet_nid *nid)
 {
-	return NID_ADDR_BYTES(nid) == 4;
+	int i;
+
+	for (i = 0; i < NID_ADDR_BYTES(nid); i++)
+		if (nid->nid_addr[i])
+			return true;
+
+	return false;
 }
 
 /* LOLND may not be defined yet, so we cannot use an inline */
diff --git a/net/lnet/klnds/socklnd/socklnd.c b/net/lnet/klnds/socklnd/socklnd.c
index 07e056845b24..0a4fb966f498 100644
--- a/net/lnet/klnds/socklnd/socklnd.c
+++ b/net/lnet/klnds/socklnd/socklnd.c
@@ -2542,8 +2542,7 @@ ksocknal_startup(struct lnet_ni *ni)
 	struct ksock_net *net;
 	struct ksock_interface *ksi = NULL;
 	struct lnet_inetdev *ifaces = NULL;
-	int i = 0;
-	int rc;
+	int rc, if_idx;
 
 	LASSERT(ni->ni_net->net_lnd == &the_ksocklnd);
 
@@ -2555,7 +2554,7 @@ ksocknal_startup(struct lnet_ni *ni)
 
 	net = kzalloc(sizeof(*net), GFP_NOFS);
 	if (!net)
-		goto fail_0;
+		goto out_base;
 
 	net->ksnn_incarnation = ktime_get_real_ns();
 	ni->ni_data = net;
@@ -2564,55 +2563,51 @@ ksocknal_startup(struct lnet_ni *ni)
 
 	rc = lnet_inet_enumerate(&ifaces, ni->ni_net_ns, true);
 	if (rc < 0)
-		goto fail_1;
+		goto out_net;
 
 	ksi = &net->ksnn_interface;
-	/* Use the first discovered interface or look in the list */
-	if (ni->ni_interface) {
-		for (i = 0; i < rc; i++) {
-			if (strcmp(ifaces[i].li_name, ni->ni_interface) == 0)
-				break;
-		}
-		/* ni_interface doesn't contain the interface we want */
-		if (i == rc) {
-			CERROR("ksocklnd: failed to find interface %s\n",
-			       ni->ni_interface);
-			goto fail_1;
-		}
-	} else {
-		rc = lnet_ni_add_interface(ni, ifaces[i].li_name);
+
+	/* Interface and/or IP address is specified otherwise default to
+	 * the first Interface
+	 */
+	if_idx = lnet_inet_select(ni, ifaces, rc);
+	if (if_idx < 0)
+		goto out_net;
+
+	if (!ni->ni_interface) {
+		rc = lnet_ni_add_interface(ni, ifaces[if_idx].li_name);
 		if (rc < 0)
 			CWARN("ksocklnd failed to allocate ni_interface\n");
 	}
 
-	ni->ni_dev_cpt = ifaces[i].li_cpt;
-	ksi->ksni_index = ifaces[i].li_index;
-	if (ifaces[i].li_ipv6) {
+	ni->ni_dev_cpt = ifaces[if_idx].li_cpt;
+	ksi->ksni_index = ifaces[if_idx].li_index;
+	if (ifaces[if_idx].li_ipv6) {
 		struct sockaddr_in6 *sa;
 		sa = (void *)&ksi->ksni_addr;
 		memset(sa, 0, sizeof(*sa));
 		sa->sin6_family = AF_INET6;
-		memcpy(&sa->sin6_addr, ifaces[i].li_ipv6addr,
+		memcpy(&sa->sin6_addr, ifaces[if_idx].li_ipv6addr,
 		       sizeof(struct in6_addr));
 		ni->ni_nid.nid_size = sizeof(struct in6_addr) - 4;
-		memcpy(&ni->ni_nid.nid_addr, ifaces[i].li_ipv6addr,
+		memcpy(&ni->ni_nid.nid_addr, ifaces[if_idx].li_ipv6addr,
 		       sizeof(struct in6_addr));
 	} else {
 		struct sockaddr_in *sa;
 		sa = (void *)&ksi->ksni_addr;
 		memset(sa, 0, sizeof(*sa));
 		sa->sin_family = AF_INET;
-		sa->sin_addr.s_addr = htonl(ifaces[i].li_ipaddr);
-		ksi->ksni_netmask = ifaces[i].li_netmask;
+		sa->sin_addr.s_addr = htonl(ifaces[if_idx].li_ipaddr);
+		ksi->ksni_netmask = ifaces[if_idx].li_netmask;
 		ni->ni_nid.nid_size = 4 - 4;
 		ni->ni_nid.nid_addr[0] = sa->sin_addr.s_addr;
 	}
-	strlcpy(ksi->ksni_name, ifaces[i].li_name, sizeof(ksi->ksni_name));
+	strlcpy(ksi->ksni_name, ifaces[if_idx].li_name, sizeof(ksi->ksni_name));
 
 	/* call it before add it to ksocknal_data.ksnd_nets */
 	rc = ksocknal_net_start_threads(net, ni->ni_cpts, ni->ni_ncpts);
 	if (rc)
-		goto fail_1;
+		goto out_net;
 
 	list_add(&net->ksnn_list, &ksocknal_data.ksnd_nets);
 	net->ksnn_ni = ni;
@@ -2620,9 +2615,9 @@ ksocknal_startup(struct lnet_ni *ni)
 
 	return 0;
 
-fail_1:
+out_net:
 	kfree(net);
-fail_0:
+out_base:
 	if (!ksocknal_data.ksnd_nnets)
 		ksocknal_base_shutdown();
 
diff --git a/net/lnet/lnet/config.c b/net/lnet/lnet/config.c
index 5bfae4e46910..0c4405f0f13b 100644
--- a/net/lnet/lnet/config.c
+++ b/net/lnet/lnet/config.c
@@ -1615,6 +1615,56 @@ int lnet_inet_enumerate(struct lnet_inetdev **dev_list, struct net *ns, bool v6)
 }
 EXPORT_SYMBOL(lnet_inet_enumerate);
 
+int lnet_inet_select(struct lnet_ni *ni,
+		     struct lnet_inetdev *ifaces,
+		     int num_ifaces)
+{
+	bool addr_set = nid_addr_is_set(&ni->ni_nid);
+	int if_idx;
+
+	/* default to first interface if both interface and NID unspecified */
+	if (!ni->ni_interface && !addr_set)
+		return 0;
+
+	for (if_idx = 0; if_idx < num_ifaces; if_idx++) {
+		if (ni->ni_interface &&
+		    strcmp(ni->ni_interface, ifaces[if_idx].li_name) != 0)
+			/* not the specified interface */
+			continue;
+
+		if (!addr_set)
+			/* IP unspecified, use IP of first matching interface */
+			break;
+
+		if (ifaces[if_idx].li_ipv6 &&
+		    nid_is_ipv6(&ni->ni_nid)) {
+			if (memcmp(ni->ni_nid.nid_addr,
+				   ifaces[if_idx].li_ipv6addr,
+				   sizeof(struct in6_addr)) == 0)
+				break;
+		} else if (!ifaces[if_idx].li_ipv6 &&
+			   nid_is_ipv4(&ni->ni_nid)) {
+			if (ni->ni_nid.nid_addr[0] ==
+			    htonl(ifaces[if_idx].li_ipaddr))
+				break;
+		}
+	}
+
+	if (if_idx < num_ifaces)
+		return if_idx;
+
+	if (ni->ni_interface)
+		CERROR("ksocklnd: failed to find interface %s%s%s\n",
+		       ni->ni_interface, addr_set ? "@" : "",
+		       addr_set ? libcfs_nidstr(&ni->ni_nid) : "");
+	else
+		CERROR("ksocklnd: failed to find IP address %s\n",
+		       libcfs_nidstr(&ni->ni_nid));
+
+	return -EINVAL;
+}
+EXPORT_SYMBOL(lnet_inet_select);
+
 int
 lnet_parse_ip2nets(const char **networksp, const char *ip2nets)
 {
-- 
2.27.0

_______________________________________________
lustre-devel mailing list
lustre-devel@lists.lustre.org
http://lists.lustre.org/listinfo.cgi/lustre-devel-lustre.org

  parent reply	other threads:[~2023-01-23 23:34 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-23 23:00 [lustre-devel] [PATCH 00/42] lustre: sync to OpenSFS tree as of Jan 22 2023 James Simmons
2023-01-23 23:00 ` [lustre-devel] [PATCH 01/42] lustre: osc: pack osc_async_page better James Simmons
2023-01-23 23:00 ` [lustre-devel] [PATCH 02/42] lnet: lnet_peer_merge_data to understand large addr James Simmons
2023-01-23 23:00 ` [lustre-devel] [PATCH 03/42] lnet: router_discover - handle large addrs in ping James Simmons
2023-01-23 23:00 ` [lustre-devel] [PATCH 04/42] lnet: Drop LNet message if deadline exceeded James Simmons
2023-01-23 23:00 ` [lustre-devel] [PATCH 05/42] lnet: change lnet_find_best_lpni to handle large NIDs James Simmons
2023-01-23 23:00 ` [lustre-devel] [PATCH 06/42] lustre: ldebugfs: add histogram to stats counter James Simmons
2023-01-23 23:00 ` [lustre-devel] [PATCH 07/42] lustre: llite: wake_up after cl_object_kill James Simmons
2023-01-23 23:00 ` [lustre-devel] [PATCH 08/42] lustre: pcc: use two bits to indicate pcc type for attach James Simmons
2023-01-23 23:00 ` [lustre-devel] [PATCH 09/42] lustre: ldebugfs: make job_stats and rename_stats valid YAML James Simmons
2023-01-23 23:00 ` [lustre-devel] [PATCH 10/42] lustre: misc: fix stats snapshot_time to use wallclock James Simmons
2023-01-23 23:00 ` [lustre-devel] [PATCH 11/42] lustre: pools: force creation of a component without a pool James Simmons
2023-01-23 23:00 ` [lustre-devel] [PATCH 12/42] lustre: sec: reserve flag for fid2path for encrypted files James Simmons
2023-01-23 23:00 ` [lustre-devel] [PATCH 13/42] lustre: llite: update statx size/ctime for fallocate James Simmons
2023-01-23 23:00 ` [lustre-devel] [PATCH 14/42] lustre: ptlrpc: fiemap flexible array James Simmons
2023-01-23 23:00 ` [lustre-devel] [PATCH 15/42] lustre: ptlrpc: Add LCME_FL_PARITY to wirecheck James Simmons
2023-01-23 23:00 ` [lustre-devel] [PATCH 16/42] lnet: selftest: lst read-outside of allocation James Simmons
2023-01-23 23:00 ` [lustre-devel] [PATCH 17/42] lustre: misc: rename lprocfs_stats functions James Simmons
2023-01-23 23:00 ` [lustre-devel] [PATCH 18/42] lustre: osc: Fix possible null pointer James Simmons
2023-01-23 23:00 ` [lustre-devel] [PATCH 19/42] lustre: ptlrpc: NUL terminate long jobid strings James Simmons
2023-01-23 23:00 ` [lustre-devel] [PATCH 20/42] lustre: uapi: remove _GNU_SOURCE dependency in lustre_user.h James Simmons
2023-01-23 23:00 ` [lustre-devel] [PATCH 21/42] lnet: handles unregister/register events James Simmons
2023-01-23 23:00 ` [lustre-devel] [PATCH 22/42] lustre: update version to 2.15.53 James Simmons
2023-01-23 23:00 ` [lustre-devel] [PATCH 23/42] lustre: ptlrpc: don't panic during reconnection James Simmons
2023-01-23 23:00 ` [lustre-devel] [PATCH 24/42] lustre: move to kobj_type default_groups James Simmons
2023-01-23 23:00 ` [lustre-devel] [PATCH 25/42] lnet: increase transaction timeout James Simmons
2023-01-23 23:00 ` James Simmons [this message]
2023-01-23 23:00 ` [lustre-devel] [PATCH 27/42] lustre: obdclass: fix T10PI prototypes James Simmons
2023-01-23 23:00 ` [lustre-devel] [PATCH 28/42] lustre: obdclass: prefer T10 checksum if the target supports it James Simmons
2023-01-23 23:00 ` [lustre-devel] [PATCH 29/42] lustre: llite: remove false outdated comment James Simmons
2023-01-23 23:00 ` [lustre-devel] [PATCH 30/42] lnet: socklnd: clarify error message on timeout James Simmons
2023-01-23 23:00 ` [lustre-devel] [PATCH 31/42] lustre: llite: replace selinux_is_enabled() James Simmons
2023-01-23 23:00 ` [lustre-devel] [PATCH 32/42] lustre: enc: S_ENCRYPTED flag on OST objects for enc files James Simmons
2023-01-23 23:00 ` [lustre-devel] [PATCH 33/42] lnet: asym route inconsistency warning James Simmons
2023-01-23 23:00 ` [lustre-devel] [PATCH 34/42] lnet: o2iblnd: reset hiw proportionally James Simmons
2023-01-23 23:00 ` [lustre-devel] [PATCH 35/42] lnet: libcfs: cfs_hash_for_each_empty optimization James Simmons
2023-01-23 23:00 ` [lustre-devel] [PATCH 36/42] lustre: llite: always enable remote subdir mount James Simmons
2023-01-23 23:00 ` [lustre-devel] [PATCH 37/42] lnet: selftest: migrate LNet selftest group handling to Netlink James Simmons
2023-01-23 23:00 ` [lustre-devel] [PATCH 38/42] lnet: use Netlink to support LNet ping commands James Simmons
2023-01-23 23:00 ` [lustre-devel] [PATCH 39/42] lustre: llite: revert: "llite: clear stale page's uptodate bit" James Simmons
2023-01-23 23:00 ` [lustre-devel] [PATCH 40/42] lnet: validate data sent from user land properly James Simmons
2023-01-23 23:00 ` [lustre-devel] [PATCH 41/42] lnet: modify lnet_inetdev to work with large NIDS James Simmons
2023-01-23 23:00 ` [lustre-devel] [PATCH 42/42] lustre: ldlm: remove obsolete LDLM_FL_SERVER_LOCK James Simmons

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1674514855-15399-27-git-send-email-jsimmons@infradead.org \
    --to=jsimmons@infradead.org \
    --cc=adilger@whamcloud.com \
    --cc=fsehr@whamcloud.com \
    --cc=green@whamcloud.com \
    --cc=lustre-devel@lists.lustre.org \
    --cc=neilb@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.