[lustre-devel] [PATCH 21/27] lnet: simplify lnet_ni_add_interface

James Simmons jsimmons at infradead.org
Sun Jun 13 16:11:31 PDT 2021


From: Olaf Faaland <faaland1 at llnl.gov>

Remove an unnecessary counter and move the comment before
the relevant code.  Improve error messages.

WC-bug-id: https://jira.whamcloud.com/browse/LU-14665
Lustre-commit: b77a6d86936c32bb ("LU-14665 lnet: simplify lnet_ni_add_interface")
Signed-off-by: Olaf Faaland <faaland1 at llnl.gov>
Reviewed-on: https://review.whamcloud.com/43525
Reviewed-by: Serguei Smirnov <ssmirnov at whamcloud.com>
Reviewed-by: Neil Brown <neilb at suse.de>
Reviewed-by: Oleg Drokin <green at whamcloud.com>
Signed-off-by: James Simmons <jsimmons at infradead.org>
---
 net/lnet/lnet/config.c | 27 +++++++++++----------------
 1 file changed, 11 insertions(+), 16 deletions(-)

diff --git a/net/lnet/lnet/config.c b/net/lnet/lnet/config.c
index 5f4b90b..0117611 100644
--- a/net/lnet/lnet/config.c
+++ b/net/lnet/lnet/config.c
@@ -369,31 +369,26 @@ struct lnet_net *
 static int
 lnet_ni_add_interface(struct lnet_ni *ni, char *iface)
 {
-	int niface = 0;
-
 	if (!ni)
 		return -ENOMEM;
 
-	/* 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.
-	 * The newly allocated ni_interface[] can be
-	 * freed when freeing the NI */
-	if (ni->ni_interface)
-		niface++;
-
-	if (niface >= 1) {
-		LCONSOLE_ERROR_MSG(0x115, "Too many interfaces "
-				   "for net %s\n",
-				   libcfs_net2str(LNET_NIDNET(ni->ni_nid)));
+	if (ni->ni_interface) {
+		LCONSOLE_ERROR_MSG(0x115, "%s: interface %s already set for net %s: rc = %d\n",
+				   iface, ni->ni_interface,
+				   libcfs_net2str(LNET_NIDNET(ni->ni_nid)),
+				   -EINVAL);
 		return -EINVAL;
 	}
 
+	/* Allocate memory for the interface, so the code parsing input into
+	 * tokens and adding interfaces can free the input safely.
+	 * ni->ni_interface is freed in lnet_ni_free().
+	 */
 	ni->ni_interface = kstrdup(iface, GFP_KERNEL);
 
 	if (!ni->ni_interface) {
-		CERROR("Can't allocate net interface name\n");
+		CERROR("%s: cannot allocate net interface name: rc = %d\n",
+		       iface, -ENOMEM);
 		return -ENOMEM;
 	}
 
-- 
1.8.3.1



More information about the lustre-devel mailing list