From 3eeb9aea28fe5cca44ff105f85c0f9ffb6b7bd67 Mon Sep 17 00:00:00 2001
From: Moe Jette <jette1@llnl.gov>
Date: Mon, 23 Jun 2008 20:57:56 +0000
Subject: [PATCH] Add support for Hostname and NodeHostname in slurm.conf being
 fully qualified     domain names (by Vijay Ramasubramanian, University of
 Maryland).

---
 NEWS                       |  2 ++
 doc/man/man5/slurm.conf.5  | 14 +++++++---
 src/common/read_config.c   | 55 ++++++++++++++++++++++++++++++++++++++
 src/common/read_config.h   | 15 ++++++++++-
 src/common/stepd_api.c     |  8 ++++--
 src/scontrol/scontrol.c    |  5 ++++
 src/slurmd/slurmd/slurmd.c |  9 ++++++-
 src/sview/popups.c         | 18 ++++++++-----
 src/sview/sview.c          |  3 ++-
 9 files changed, 113 insertions(+), 16 deletions(-)

diff --git a/NEWS b/NEWS
index 91deb23a0a8..29b0ea90491 100644
--- a/NEWS
+++ b/NEWS
@@ -45,6 +45,8 @@ documents those changes that are of interest to users and admins.
     later change in the partition's limits. NOTE: Not reported by
     "scontrol show config" to avoid changing RPCs. It will be reported in 
     SLURM version 1.4.
+ -- Add support for Hostname and NodeHostname in slurm.conf being fully qualified 
+    domain names (by Vijay Ramasubramanian, University of Maryland).
 
 * Changes in SLURM 1.3.3
 ========================
diff --git a/doc/man/man5/slurm.conf.5 b/doc/man/man5/slurm.conf.5
index c6713b408df..7ceb2880714 100644
--- a/doc/man/man5/slurm.conf.5
+++ b/doc/man/man5/slurm.conf.5
@@ -1,4 +1,5 @@
 .TH "slurm.conf" "5" "June 2008" "slurm.conf 1.3" "Slurm configuration file"
+
 .SH "NAME"
 slurm.conf \- Slurm configuration file 
 .SH "DESCRIPTION"
@@ -1257,9 +1258,11 @@ The node configuration specified the following information:
 \fBNodeName\fR
 Name that SLURM uses to refer to a node (or base partition for 
 BlueGene systems). 
-Typically this would be the string that "/bin/hostname \-s" 
-returns, however it may be an arbitrary string if 
-\fBNodeHostname\fR is specified.
+Typically this would be the string that "/bin/hostname \-s" returns.
+It may also be the fully qualified domane name as returned by "/bin/hostname \-f"
+(e.g. "foo1.bar.com"), although that may prevent use of hostlist expressions
+(the numeric portion in brackets must be at the end of the string).
+It may also be an arbitrary string if \fBNodeHostname\fR is specified.
 If the \fBNodeName\fR is "DEFAULT", the values specified 
 with that record will apply to subsequent node specifications   
 unless explicitly set to other values in that node record or 
@@ -1272,7 +1275,10 @@ considered adjacent in the computer.
 
 .TP
 \fBNodeHostname\fR
-The string that "/bin/hostname \-s" returns. 
+Typically this would be the string that "/bin/hostname \-s" returns. 
+It may also be the fully qualified domain name as returned by "/bin/hostname \-f"
+(e.g. "foo1.bar.com"), although that may prevent use of hostlist expressions
+(the numeric portion in brackets must be at the end of the string).
 A node range expression can be used to specify a set of nodes.
 If an expression is used, the number of nodes identified by 
 \fBNodeHostname\fR on a line in the configuration file must 
diff --git a/src/common/read_config.c b/src/common/read_config.c
index ed638c46755..90598831f03 100644
--- a/src/common/read_config.c
+++ b/src/common/read_config.c
@@ -3,6 +3,7 @@
  *****************************************************************************
  *  Copyright (C) 2002-2007 The Regents of the University of California.
  *  Copyright (C) 2008 Lawrence Livermore National Security.
+ *  Portions Copyright (C) 2008 Vijay Ramasubramanian.
  *  Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
  *  Written by Morris Jette <jette1@llnl.gov>.
  *  LLNL-CODE-402394.
@@ -43,6 +44,7 @@
 #include <assert.h>
 #include <ctype.h>
 #include <errno.h>
+#include <netdb.h>
 #include <pwd.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -67,6 +69,7 @@
 #include "src/common/parse_config.h"
 #include "src/common/parse_time.h"
 #include "src/common/slurm_selecttype_info.h"
+#include "src/common/util-net.h"
 
 /* Instantiation of the "extern slurm_ctl_conf_t slurmcltd_conf"
  * found in slurmctld.h */
@@ -928,6 +931,58 @@ extern char *slurm_conf_get_nodename(const char *node_hostname)
 	return NULL;
 }
 
+/*
+ * slurm_conf_get_aliased_nodename - Return the NodeName for the
+ * complete hostname string returned by gethostname if there is
+ * such a match, otherwise iterate through any aliases returned
+ * by get_host_by_name
+ */
+extern char *slurm_conf_get_aliased_nodename()
+{
+	char hostname_full[1024];
+	int error_code;
+	char *nodename;
+
+	error_code = gethostname(hostname_full, sizeof(hostname_full));
+	/* we shouldn't have any problem here since by the time
+	 * this function has been called, gethostname_short,
+	 * which invokes gethostname, has probably already been called
+	 * successfully, so just return NULL if something weird
+	 * happens at this point
+	 */
+	if (error_code)
+		return NULL;
+
+	nodename = slurm_conf_get_nodename(hostname_full);
+	/* if the full hostname did not match a nodename */
+	if (nodename == NULL) {
+		/* use get_host_by_name; buffer sizes, semantics, etc.
+		 * copied from slurm_protocol_socket_implementation.c
+		 */
+		struct hostent * he = NULL;
+		char * h_buf[4096];
+		int h_err;
+
+		he = get_host_by_name(hostname_full, (void *)&h_buf,
+				      sizeof(h_buf), &h_err);
+		if (he != NULL) {
+			unsigned int i = 0;
+			/* check the "official" host name first */
+			nodename = slurm_conf_get_nodename(he->h_name);
+			while ((nodename == NULL) &&
+			       (he->h_aliases[i] != NULL)) {
+				/* the "official" name still didn't match --
+				 * iterate through the aliases */
+				nodename =
+				     slurm_conf_get_nodename(he->h_aliases[i]);
+				i++;
+			}
+		}
+	}
+
+	return nodename;
+}
+
 /*
  * slurm_conf_get_port - Return the port for a given NodeName
  */
diff --git a/src/common/read_config.h b/src/common/read_config.h
index a06485ecb6f..cddc90068df 100644
--- a/src/common/read_config.h
+++ b/src/common/read_config.h
@@ -2,7 +2,9 @@
  *  read_config.h - definitions for reading the overall slurm configuration 
  *  file
  *****************************************************************************
- *  Copyright (C) 2002-2006 The Regents of the University of California.
+ *  Copyright (C) 2002-2007 The Regents of the University of California.
+ *  Copyright (C) 2008 Lawrence Livermore National Security.
+ *  Portions Copyright (C) 2008 Vijay Ramasubramanian.
  *  Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
  *  Written by Morris Mette <jette1@llnl.gov>.
  *  LLNL-CODE-402394.
@@ -267,6 +269,17 @@ extern char *slurm_conf_get_hostname(const char *node_name);
  */
 extern char *slurm_conf_get_nodename(const char *node_hostname);
 
+/*
+ * slurm_conf_get_aliased_nodename - Return the NodeName matching an alias
+ * of the local hostname
+ *
+ * Returned string was allocated with xmalloc(), and must be freed by
+ * the caller using xfree().
+ *
+ * NOTE: Caller must NOT be holding slurm_conf_lock().
+ */
+extern char *slurm_conf_get_aliased_nodename(void);
+
 /*
  * slurm_conf_get_port - Return the port for a given NodeName
  *
diff --git a/src/common/stepd_api.c b/src/common/stepd_api.c
index 159a2047f69..88e163cc43a 100644
--- a/src/common/stepd_api.c
+++ b/src/common/stepd_api.c
@@ -2,7 +2,9 @@
  *  src/common/stepd_api.c - slurmstepd message API
  *  $Id$
  *****************************************************************************
- *  Copyright (C) 2005 The Regents of the University of California.
+ *  Copyright (C) 2005-2007 The Regents of the University of California.
+ *  Copyright (C) 2008 Lawrence Livermore National Security.
+ *  Portions Copyright (C) 2008 Vijay Ramasubramanian
  *  Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
  *  Written by Christopher Morrone <morrone2@llnl.gov>
  *  LLNL-CODE-402394.
@@ -169,7 +171,9 @@ _guess_nodename()
 		return NULL;
 
 	nodename = slurm_conf_get_nodename(host);
-	if (nodename == NULL) /* no match?  lets try localhost */
+	if (nodename == NULL)
+		nodename = slurm_conf_get_aliased_nodename();
+	if (nodename == NULL) /* if no match, try localhost */
 		nodename = slurm_conf_get_nodename("localhost");
 
 	return nodename;
diff --git a/src/scontrol/scontrol.c b/src/scontrol/scontrol.c
index 6ccb4f5a417..9106ba5164e 100644
--- a/src/scontrol/scontrol.c
+++ b/src/scontrol/scontrol.c
@@ -3,6 +3,8 @@
  *	provides interface to read, write, update, and configurations.
  *****************************************************************************
  *  Copyright (C) 2002-2007 The Regents of the University of California.
+ *  Copyright (C) 2008 Lawrence Livermore National Security.
+ *  Portions Copyright (C) 2008 Vijay Ramasubramanian.
  *  Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
  *  Written by Morris Jette <jette1@llnl.gov>
  *  LLNL-CODE-402394.
@@ -419,6 +421,9 @@ _print_daemons (void)
 	if ((n = slurm_conf_get_nodename(me))) {
 		d = 1;
 		xfree(n);
+	} else if ((n = slurm_conf_get_aliased_nodename())) {
+		d = 1;
+		xfree(n);
 	} else if ((n = slurm_conf_get_nodename("localhost"))) {
 		d = 1;
 		xfree(n);
diff --git a/src/slurmd/slurmd/slurmd.c b/src/slurmd/slurmd/slurmd.c
index f736d5f0a85..e02697f002d 100644
--- a/src/slurmd/slurmd/slurmd.c
+++ b/src/slurmd/slurmd/slurmd.c
@@ -2,7 +2,9 @@
  *  src/slurmd/slurmd/slurmd.c - main slurm node server daemon
  *  $Id$
  *****************************************************************************
- *  Copyright (C) 2002-2006 The Regents of the University of California.
+ *  Copyright (C) 2002-2007 The Regents of the University of California.
+ *  Copyright (C) 2008 Lawrence Livermore National Security.
+ *  Portions Copyright (C) 2008 Vijay Ramasubramanian.
  *  Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
  *  Written by Mark Grondona <mgrondona@llnl.gov>.
  *  LLNL-CODE-402394.
@@ -582,6 +584,11 @@ _read_config()
 	/* node_name may already be set from a command line parameter */
 	if (conf->node_name == NULL)
 		conf->node_name = slurm_conf_get_nodename(conf->hostname);
+	/* if we didn't match the form of the hostname already
+	 * stored in conf->hostname, check to see if we match any
+	 * valid aliases */
+	if (conf->node_name == NULL)
+		conf->node_name = slurm_conf_get_aliased_nodename();
 	if (conf->node_name == NULL)
 		conf->node_name = slurm_conf_get_nodename("localhost");
 	if (conf->node_name == NULL)
diff --git a/src/sview/popups.c b/src/sview/popups.c
index f4861202278..89c0aaf2616 100644
--- a/src/sview/popups.c
+++ b/src/sview/popups.c
@@ -1,7 +1,9 @@
 /****************************************************************************\
  *  popups.c - put different popup displays here
  *****************************************************************************
- *  Copyright (C) 2002-2006 The Regents of the University of California.
+ *  Copyright (C) 2002-2007 The Regents of the University of California.
+ *  Copyright (C) 2008 Lawrence Livermore National Security.
+ *  Portions Copyright (C) 2008 Vijay Ramasubramanian
  *  Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
  *  Written by Danny Auble <da@llnl.gov>, et. al.
  *  LLNL-CODE-402394.
@@ -627,13 +629,15 @@ extern void create_daemon_popup(GtkAction *action, gpointer user_data)
 	}
 	slurm_conf_unlock();
 
-	if ((n = slurm_conf_get_nodename(me))) {
-		d = 1;
+	if ((n = slurm_conf_get_nodename(me))) {
+		d = 1;
+		xfree(n);
+	} else if ((n = slurm_conf_get_aliased_nodename())) {
+		d = 1;
+		xfree(n);
+	} else if ((n = slurm_conf_get_nodename("localhost"))) {
+		d = 1;
 		xfree(n);
-	} else if ((n = slurm_conf_get_nodename("localhost"))) {
-		d = 1;
-		xfree(n);
-	}
 	if (actld && ctld)
 		add_display_treestore_line(update, treestore, &iter, 
 					   "Slurmctld", "1");
diff --git a/src/sview/sview.c b/src/sview/sview.c
index f277da11570..74979e6ba51 100644
--- a/src/sview/sview.c
+++ b/src/sview/sview.c
@@ -1,7 +1,8 @@
 /****************************************************************************\
  *  sview.c - main for sview
  *****************************************************************************
- *  Copyright (C) 2002-2006 The Regents of the University of California.
+ *  Copyright (C) 2002-2007 The Regents of the University of California.
+ *  Copyright (C) 2008 Lawrence Livermore National Security.
  *  Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
  *  Written by Danny Auble <da@llnl.gov>, et. al.
  *  LLNL-CODE-402394.
-- 
GitLab