From 819005cc25452b07cadce102a4b13845ecb7ca85 Mon Sep 17 00:00:00 2001
From: Moe Jette <jette1@llnl.gov>
Date: Fri, 17 Apr 2009 23:26:57 +0000
Subject: [PATCH] Add support for scontrol show part <name> for a switch or
 node name.

---
 doc/man/man1/scontrol.1  |  4 ++++
 slurm/slurm.h.in         | 11 +++++++++++
 src/scontrol/info_node.c | 38 +++++++++++++++++++++++++++++++++++++-
 3 files changed, 52 insertions(+), 1 deletion(-)

diff --git a/doc/man/man1/scontrol.1 b/doc/man/man1/scontrol.1
index 23300753706..68478f44e80 100644
--- a/doc/man/man1/scontrol.1
+++ b/doc/man/man1/scontrol.1
@@ -225,6 +225,10 @@ entity: the configuration parameter name, job ID, node name, partition name,
 reservation name, or job step ID for \fIconfig\fP, \fIjob\fP, \fInode\fP, 
 \fIpartition\fP, or \fIstep\fP respectively. 
 For an \fIENTITY\fP of \fItopology\fP, the \fIID\fP may be a node or switch name.
+If one node name is specified, all switches connected to that node (and 
+their parent switches) will be shown.
+If more than one node name is specified, only switches that connect to all 
+named nodes will be shown.
 \fIhostnames\fP takes an optional hostlist expression as input and 
 writes a list of individual host names to standard output (one per 
 line). If no hostlist expression is supplied, the contents of the 
diff --git a/slurm/slurm.h.in b/slurm/slurm.h.in
index 3a45c22fa1e..168de324157 100644
--- a/slurm/slurm.h.in
+++ b/slurm/slurm.h.in
@@ -1999,6 +1999,17 @@ extern void slurm_free_topo_info_msg PARAMS(( topo_info_response_msg_t *msg ));
 extern void slurm_print_topo_info_msg PARAMS(( 
 	FILE * out, topo_info_response_msg_t *topo_info_msg_ptr, int one_liner )) ;
 
+/*
+ * slurm_print_topo_record - output information about a specific Slurm topology
+ *	record based upon message as loaded using slurm_load_topo
+ * IN out - file to write to
+ * IN topo_ptr - an individual switch information record pointer
+ * IN one_liner - print as a single line if not zero
+ * RET out - char * containing formatted output (must be freed after call)
+ *	   NULL is returned on failure.
+ */
+extern void slurm_print_topo_record PARAMS((FILE * out, topo_info_t *topo_ptr, 
+				    int one_liner ));
 /*****************************************************************************\
  *	SLURM PARTITION CONFIGURATION READ/PRINT/UPDATE FUNCTIONS
 \*****************************************************************************/
diff --git a/src/scontrol/info_node.c b/src/scontrol/info_node.c
index 4ea71376e98..29e117e3464 100644
--- a/src/scontrol/info_node.c
+++ b/src/scontrol/info_node.c
@@ -192,6 +192,8 @@ scontrol_print_node_list (char *node_list)
 extern void	scontrol_print_topo (char *node_list)
 {
 	static topo_info_response_msg_t *topo_info_msg = NULL;
+	int i, match, match_cnt = 0;
+	hostset_t hs;
 
 	if ((topo_info_msg == NULL) &&
 	    slurm_load_topo(&topo_info_msg)) {
@@ -199,5 +201,39 @@ extern void	scontrol_print_topo (char *node_list)
 		return;
 	}
 
-	slurm_print_topo_info_msg(stdout, topo_info_msg, one_liner);
+	if ((node_list == NULL) || (node_list[0] == '\0')) {
+		slurm_print_topo_info_msg(stdout, topo_info_msg, one_liner);
+		return;
+	}
+
+	/* Search for matching switch name */
+	for (i=0; i<topo_info_msg->record_count; i++) {
+		if (strcmp(topo_info_msg->topo_array[i].name, node_list))
+			continue;
+		slurm_print_topo_record(stdout, &topo_info_msg->topo_array[i], 
+					one_liner);
+		return;
+	}
+
+	/* Search for matching node name */
+	for (i=0; i<topo_info_msg->record_count; i++) {
+		if ((topo_info_msg->topo_array[i].nodes == NULL) ||
+		    (topo_info_msg->topo_array[i].nodes[0] == '\0')) 
+			continue;
+		hs = hostset_create(topo_info_msg->topo_array[i].nodes);
+		if (hs == NULL)
+			fatal("hostset_create: memory allocation failure");
+		match = hostset_within(hs, node_list);
+		hostset_destroy(hs);
+		if (!match)
+			continue;
+		match_cnt++;
+		slurm_print_topo_record(stdout, &topo_info_msg->topo_array[i], 
+					one_liner);
+	}
+
+	if (match_cnt == 0) {
+		error("Topology information contains no switch or "
+		      "node named %s", node_list);
+	}
 }
-- 
GitLab