From 132c1367a39eaf9cf12cf8fb116d0cd1a847fa95 Mon Sep 17 00:00:00 2001
From: Nathan Yee <nyee32@schedmd.com>
Date: Fri, 21 Feb 2014 16:46:38 -0800
Subject: [PATCH] Add sview & sinfo support for node version

---
 doc/man/man1/sinfo.1       |  3 ++
 src/sinfo/opts.c           |  6 ++++
 src/sinfo/print.c          | 21 +++++++++++
 src/sinfo/print.h          |  5 ++-
 src/sinfo/sinfo.c          | 74 ++++++++++++++++++++------------------
 src/sinfo/sinfo.h          |  2 ++
 src/sview/front_end_info.c |  8 +++++
 src/sview/node_info.c      | 23 ++++++++++++
 8 files changed, 106 insertions(+), 36 deletions(-)

diff --git a/doc/man/man1/sinfo.1 b/doc/man/man1/sinfo.1
index e3709dcc205..75e432c33f5 100644
--- a/doc/man/man1/sinfo.1
+++ b/doc/man/man1/sinfo.1
@@ -222,6 +222,9 @@ Print the user name of who set the reason a node is unavailable.
 \fB%U\fR
 Print the user name and uid of who set the reason a node is unavailable.
 .TP
+\fB%v\fR
+Print the version of the running slurmd dameon.
+.TP
 \fB%w\fR
 Scheduling weight of the nodes
 .TP
diff --git a/src/sinfo/opts.c b/src/sinfo/opts.c
index bb011bf044e..cae1e3eda5d 100644
--- a/src/sinfo/opts.c
+++ b/src/sinfo/opts.c
@@ -702,6 +702,12 @@ _parse_format( char* format )
 					      field_size,
 					      right_justify,
 					      suffix );
+		} else if (field[0] == 'v') {
+			params.match_flags.version_flag = true;
+			format_add_version( params.format_list,
+					    field_size,
+					    right_justify,
+					    suffix);
 		} else if (field[0] == 'w') {
 			params.match_flags.weight_flag = true;
 			format_add_weight( params.format_list,
diff --git a/src/sinfo/print.c b/src/sinfo/print.c
index 94bde71863c..0c484a3b330 100644
--- a/src/sinfo/print.c
+++ b/src/sinfo/print.c
@@ -1204,6 +1204,27 @@ int _print_max_cpus_per_node(sinfo_data_t * sinfo_data, int width,
 	} else {
 		_print_str("MAX_CPUS_PER_NODE", width, right_justify, true);
 	}
+	if (suffix)
+		printf("%s", suffix);
+	return SLURM_SUCCESS;
+}
 
+int _print_version(sinfo_data_t * sinfo_data, int width,
+		   bool right_justify, char *suffix)
+{
+	if (sinfo_data) {
+		if (sinfo_data->version == NULL) {
+			_print_str("N/A", width, right_justify, true);
+		} else {
+			_print_str(sinfo_data->version, width,
+				   right_justify, true);
+		}
+	} else {
+		_print_str("VERSION", width, right_justify, true);
+	}
+	if (suffix) {
+		printf ("%s", suffix);
+	}
 	return SLURM_SUCCESS;
+
 }
diff --git a/src/sinfo/print.h b/src/sinfo/print.h
index 206910d1f15..4fdb6bcc145 100644
--- a/src/sinfo/print.h
+++ b/src/sinfo/print.h
@@ -148,6 +148,8 @@ void print_sinfo_reservation(reserve_info_msg_t *resv_ptr);
 	format_add_function(list,wid,right,suffix,_print_cpu_load)
 #define format_add_max_cpus_per_node(list,wid,right,suffix) \
 	format_add_function(list,wid,right,suffix,_print_max_cpus_per_node)
+#define format_add_version(list,wid,right,suffix) \
+	format_add_function(list,wid,right,suffix,_print_version)
 
 /*****************************************************************************
  * Print Field Functions
@@ -231,5 +233,6 @@ int _print_cpu_load(sinfo_data_t * node_ptr, int width,
 		    bool right_justify, char *suffix);
 int _print_max_cpus_per_node(sinfo_data_t * sinfo_data, int width,
 			     bool right_justify, char *suffix);
-
+int _print_version(sinfo_data_t * sinfo_data, int width,
+		   bool right_justify, char *suffix);
 #endif
diff --git a/src/sinfo/sinfo.c b/src/sinfo/sinfo.c
index 46af7c3e593..afebcda4c96 100644
--- a/src/sinfo/sinfo.c
+++ b/src/sinfo/sinfo.c
@@ -471,7 +471,7 @@ static int _build_sinfo_data(List sinfo_list,
 	if (params.filtering) {
 		for (j = 0; j < node_msg->record_count; j++) {
 			node_ptr = &(node_msg->node_array[j]);
-		        if (node_ptr->name && _filter_out(node_ptr))
+			if (node_ptr->name && _filter_out(node_ptr))
 				xfree(node_ptr->name);
 		}
 	}
@@ -484,42 +484,42 @@ static int _build_sinfo_data(List sinfo_list,
 		    _strcmp(part_ptr->name, params.partition))
 			continue;
 
-                if (node_msg->record_count == 1) { /* node_name_single */
-                        int pos = -1;
-                        uint16_t subgrp_size = 0;
-                        hostlist_t hl;
+		if (node_msg->record_count == 1) { /* node_name_single */
+			int pos = -1;
+			uint16_t subgrp_size = 0;
+			hostlist_t hl;
 
-                        node_ptr = &(node_msg->node_array[0]);
-                        if ((node_ptr->name == NULL) ||
+			node_ptr = &(node_msg->node_array[0]);
+			if ((node_ptr->name == NULL) ||
 			    (part_ptr->nodes == NULL))
-                                continue;
-                        hl = hostlist_create(part_ptr->nodes);
-                        pos = hostlist_find(hl, node_msg->node_array[0].name);
-                        hostlist_destroy(hl);
-                        if (pos < 0)
-                                continue;
-                        if (select_g_select_nodeinfo_get(
-                                   node_ptr->select_nodeinfo,
-                                   SELECT_NODEDATA_SUBGRP_SIZE,
-                                   0,
-                                   &subgrp_size) == SLURM_SUCCESS
-                            && subgrp_size) {
-                                _handle_subgrps(sinfo_list,
-                                                (uint16_t) j,
-                                                part_ptr,
-                                                node_ptr,
-                                                node_msg->
-                                                node_scaling);
-                        } else {
-                                _insert_node_ptr(sinfo_list,
-                                                 (uint16_t) j,
-                                                 part_ptr,
-                                                 node_ptr,
-                                                 node_msg->
-                                                 node_scaling);
-                        }
-                        continue;
-                }
+				continue;
+			hl = hostlist_create(part_ptr->nodes);
+			pos = hostlist_find(hl, node_msg->node_array[0].name);
+			hostlist_destroy(hl);
+			if (pos < 0)
+				continue;
+			if (select_g_select_nodeinfo_get(
+				   node_ptr->select_nodeinfo,
+				   SELECT_NODEDATA_SUBGRP_SIZE,
+				   0,
+				   &subgrp_size) == SLURM_SUCCESS
+			    && subgrp_size) {
+				_handle_subgrps(sinfo_list,
+						(uint16_t) j,
+						part_ptr,
+						node_ptr,
+						node_msg->
+						node_scaling);
+			} else {
+				_insert_node_ptr(sinfo_list,
+						 (uint16_t) j,
+						 part_ptr,
+						 node_ptr,
+						 node_msg->
+						 node_scaling);
+			}
+			continue;
+		}
 
 		/* Process each partition using a separate thread */
 		build_struct_ptr = xmalloc(sizeof(build_part_info_t));
@@ -745,6 +745,9 @@ static bool _match_node_data(sinfo_data_t *sinfo_ptr, node_info_t *node_ptr)
 	if (params.match_flags.cpu_load_flag &&
 	    (node_ptr->cpu_load        != sinfo_ptr->min_cpu_load))
 		return false;
+	if (params.match_flags.version_flag &&
+	    (node_ptr->version     != sinfo_ptr->version))
+		return false;
 
 
 	return true;
@@ -849,6 +852,7 @@ static void _update_sinfo(sinfo_data_t *sinfo_ptr, node_info_t *node_ptr,
 		sinfo_ptr->max_cpu_load = node_ptr->cpu_load;
 		sinfo_ptr->max_cpus_per_node = sinfo_ptr->part_info->
 					       max_cpus_per_node;
+		sinfo_ptr->version    = node_ptr->version;
 	} else if (hostlist_find(sinfo_ptr->nodes, node_ptr->name) != -1) {
 		/* we already have this node in this record,
 		 * just return, don't duplicate */
diff --git a/src/sinfo/sinfo.h b/src/sinfo/sinfo.h
index 014c926e87f..6d552d77103 100644
--- a/src/sinfo/sinfo.h
+++ b/src/sinfo/sinfo.h
@@ -103,6 +103,7 @@ typedef struct {
 
 	uint32_t max_cpus_per_node;
 
+	char *version;
 	char *features;
 	char *gres;
 	char *reason;
@@ -151,6 +152,7 @@ struct sinfo_match_flags {
 	bool reason_user_flag;
 	bool cpu_load_flag;
 	bool max_cpus_per_node_flag;
+	bool version_flag;
 };
 
 /* Input parameters */
diff --git a/src/sview/front_end_info.c b/src/sview/front_end_info.c
index e9eed6042f9..d8278165722 100644
--- a/src/sview/front_end_info.c
+++ b/src/sview/front_end_info.c
@@ -73,6 +73,7 @@ enum {
 	SORTID_SLURMD_START_TIME,
 	SORTID_STATE,
 	SORTID_UPDATED,
+	SORTID_VERSION,
 	SORTID_CNT
 };
 
@@ -110,6 +111,8 @@ static display_data_t display_data_front_end[] = {
 	 refresh_front_end, create_model_front_end, admin_edit_front_end},
 	{G_TYPE_STRING, SORTID_DENY_USERS, "Deny Users", FALSE, EDIT_NONE,
 	 refresh_front_end, create_model_front_end, admin_edit_front_end},
+	{G_TYPE_STRING, SORTID_VERSION, "Version", FALSE, EDIT_NONE,
+	 refresh_front_end, create_model_front_end, admin_edit_front_end},
 	{G_TYPE_INT, SORTID_COLOR_INX,  NULL, FALSE, EDIT_NONE,
 	 refresh_front_end, create_model_front_end, admin_edit_front_end},
 	{G_TYPE_POINTER, SORTID_NODE_INX,  NULL, FALSE, EDIT_NONE,
@@ -220,6 +223,10 @@ static void _layout_front_end_record(GtkTreeView *treeview,
 						 SORTID_DENY_USERS),
 				   front_end_ptr->deny_users);
 
+	add_display_treestore_line(update, treestore, &iter,
+				   find_col_name(display_data_front_end,
+						 SORTID_VERSION),
+				   front_end_ptr->version);
 }
 
 static void _update_front_end_record(
@@ -250,6 +257,7 @@ static void _update_front_end_record(
 				sview_front_end_info_ptr->slurmd_start_time,
 			   SORTID_STATE,   sview_front_end_info_ptr->state,
 			   SORTID_UPDATED,    1,
+			   SORTID_VERSION, front_end_ptr->version,
 			   -1);
 
 	return;
diff --git a/src/sview/node_info.c b/src/sview/node_info.c
index 084aa54730b..d8e351dff0e 100644
--- a/src/sview/node_info.c
+++ b/src/sview/node_info.c
@@ -69,6 +69,7 @@ enum {
 	SORTID_UPDATED,
 	SORTID_USED_CPUS,
 	SORTID_USED_MEMORY,
+	SORTID_VERSION,
 	SORTID_WEIGHT,
 	SORTID_CNT
 };
@@ -150,6 +151,8 @@ static display_data_t display_data_node[] = {
 	 EDIT_NONE, refresh_node, create_model_node, admin_edit_node},
 	{G_TYPE_STRING, SORTID_CURRENT_WATTS, "Current Watts", FALSE,
 	 EDIT_NONE, refresh_node, create_model_node, admin_edit_node},
+	{G_TYPE_STRING, SORTID_VERSION, "Version", FALSE,
+	 EDIT_NONE, refresh_node, create_model_node, admin_edit_node},
 	{G_TYPE_INT, SORTID_UPDATED, NULL, FALSE, EDIT_NONE, refresh_node,
 	 create_model_node, admin_edit_node},
 	{G_TYPE_NONE, -1, NULL, FALSE, EDIT_NONE}
@@ -197,6 +200,7 @@ static void _layout_node_record(GtkTreeView *treeview,
 	char tmp_current_watts[50];
 	char tmp_base_watts[50];
 	char tmp_consumed_energy[50];
+	char tmp_version[50];
 	char *upper = NULL, *lower = NULL;
 	GtkTreeIter iter;
 	uint16_t err_cpus = 0, alloc_cpus = 0;
@@ -401,6 +405,17 @@ static void _layout_node_record(GtkTreeView *treeview,
 				   find_col_name(display_data_node,
 						 SORTID_CURRENT_WATTS),
 				   tmp_current_watts);
+
+	if (node_ptr->version == NULL) {
+		snprintf(tmp_version, sizeof(tmp_version), "N/A");
+	} else {
+		snprintf(tmp_version, sizeof(tmp_version), "%s",
+			 node_ptr->version);
+	}
+	add_display_treestore_line(update, treestore, &iter,
+				   find_col_name(display_data_node,
+						 SORTID_VERSION),
+				   tmp_version);
 	return;
 }
 
@@ -414,6 +429,7 @@ static void _update_node_record(sview_node_info_t *sview_node_info_ptr,
 	char tmp_mem[20], tmp_used_memory[20];
 	char tmp_used_cpus[20], tmp_cpu_load[20];
 	char tmp_current_watts[50], tmp_base_watts[50], tmp_consumed_energy[50];
+	char tmp_version[50];
 	char *tmp_state_lower, *tmp_state_upper;
 
 
@@ -495,6 +511,12 @@ static void _update_node_record(sview_node_info_t *sview_node_info_ptr,
 	convert_num_unit((float)node_ptr->tmp_disk, tmp_disk, sizeof(tmp_disk),
 			 UNIT_MEGA);
 
+	if (node_ptr->version == NULL) {
+		snprintf(tmp_version, sizeof(tmp_version), "N/A");
+	} else {
+		snprintf(tmp_version, sizeof(tmp_version), "%s",
+			 node_ptr->version);
+	}
 
 	/* Combining these records provides a slight performance improvement */
 	gtk_tree_store_set(treestore, &sview_node_info_ptr->iter_ptr,
@@ -528,6 +550,7 @@ static void _update_node_record(sview_node_info_t *sview_node_info_ptr,
 			   SORTID_THREADS,   node_ptr->threads,
 			   SORTID_USED_CPUS, tmp_used_cpus,
 			   SORTID_USED_MEMORY, tmp_used_memory,
+			   SORTID_VERSION,   tmp_version,
 			   SORTID_WEIGHT,    node_ptr->weight,
 			   SORTID_UPDATED,   1,
 			  -1);
-- 
GitLab