From 655afec5b4651cba6f5214e531d0f23411f9dbf9 Mon Sep 17 00:00:00 2001
From: Morris Jette <jette@schedmd.com>
Date: Tue, 25 Oct 2011 10:42:27 -0700
Subject: [PATCH] Add functions to get a job's GRES allocation value by name

Patch by Stephen Trofinoff, CSCS.
---
 src/common/gres.c | 34 ++++++++++++++++++++++++++++++++++
 src/common/gres.h | 13 ++++++++++++-
 2 files changed, 46 insertions(+), 1 deletion(-)

diff --git a/src/common/gres.c b/src/common/gres.c
index 7debdd3581d..c1e2ecc7116 100644
--- a/src/common/gres.c
+++ b/src/common/gres.c
@@ -3265,6 +3265,40 @@ static void _job_state_log(void *gres_data, uint32_t job_id, char *gres_name)
 	}
 }
 
+/*
+ * Extract from the job record's gres_list the count of allocated resources of
+ * 	the named gres gres typee.
+ * IN job_gres_list  - job record's gres_list.
+ * IN gres_name_type - the name of the gres type to retrieve the associated
+ *	value from.
+ * RET The value associated with the gres type or NO_VAL if not found.
+ */
+extern uint32_t gres_plugin_get_job_value_by_type(List job_gres_list,
+						  char *gres_name_type)
+{
+	uint32_t gres_val, gres_name_type_id;
+	ListIterator  job_gres_iter;
+	gres_state_t *job_gres_ptr;
+
+	if (job_gres_list == NULL)
+		return NO_VAL;
+
+	gres_name_type_id = _build_id(gres_name_type);
+	gres_val = NO_VAL;
+
+	job_gres_iter = list_iterator_create(job_gres_list);
+	while ((job_gres_ptr = (gres_state_t *) list_next(job_gres_iter))) {
+		if (job_gres_ptr->plugin_id == gres_name_type_id) {
+			gres_val = ((gres_job_state_t*)
+				   (job_gres_ptr->gres_data))->gres_cnt_alloc;
+			break;
+		}
+	}
+	list_iterator_destroy(job_gres_iter);
+
+	return gres_val;
+}
+
 /*
  * Log a job's current gres state
  * IN gres_list - generated by gres_plugin_job_state_validate()
diff --git a/src/common/gres.h b/src/common/gres.h
index 130b6b00844..fd53b264970 100644
--- a/src/common/gres.h
+++ b/src/common/gres.h
@@ -421,6 +421,18 @@ extern void gres_plugin_job_merge(List from_job_gres_list,
   */
 extern void gres_plugin_job_set_env(char ***job_env_ptr, List job_gres_list);
 
+
+/*
+ * Extract from the job record's gres_list the count of allocated resources of
+ * 	the named gres gres typee.
+ * IN job_gres_list  - job record's gres_list.
+ * IN gres_name_type - the name of the gres type to retrieve the associated
+ *	value from.
+ * RET The value associated with the gres type or NO_VAL if not found.
+ */
+extern uint32_t gres_plugin_get_job_value_by_type(List job_gres_list,
+						  char *gres_name_type);
+
 /*
  * Log a job's current gres state
  * IN gres_list - generated by gres_plugin_job_state_validate()
@@ -540,5 +552,4 @@ extern int gres_plugin_step_alloc(List step_gres_list, List job_gres_list,
  */
 extern int gres_plugin_step_dealloc(List step_gres_list, List job_gres_list,
 				    uint32_t job_id, uint32_t step_id);
-
 #endif /* !_GRES_H */
-- 
GitLab