From 837be271ba9cb4fc8cb2eaa96be519f3d10a01d4 Mon Sep 17 00:00:00 2001
From: Morris Jette <jette@schedmd.com>
Date: Tue, 22 Nov 2011 09:45:24 -0800
Subject: [PATCH] Fix for fatal error managing GRES. Patch by Carles Fenoy,
 BSC.

---
 NEWS                | 1 +
 doc/html/team.shtml | 1 +
 src/common/gres.c   | 6 ++++++
 3 files changed, 8 insertions(+)

diff --git a/NEWS b/NEWS
index 318874e4cd0..e665a68a91e 100644
--- a/NEWS
+++ b/NEWS
@@ -21,6 +21,7 @@ documents those changes that are of interest to users and admins.
  -- Avoid orphan job step if slurmctld is down when a job step completes.
  -- Fix Lua link order, patch from Pär Andersson, NSC.
  -- Set SLURM_CPUS_PER_TASK=1 when user specifies --cpus-per-task=1.
+ -- Fix for fatal error managing GRES. Patch by Carles Fenoy, BSC.
 
 * Changes in SLURM 2.3.1
 ========================
diff --git a/doc/html/team.shtml b/doc/html/team.shtml
index f0ad3cac7aa..4a1b1d07e0e 100644
--- a/doc/html/team.shtml
+++ b/doc/html/team.shtml
@@ -27,6 +27,7 @@ organizations. The current SLURM development staff includes: </p>
 <li>Gilles Civario (Bull)</li>
 <li>Chuck Clouston (Bull)</li>
 <li>Yuri D'Elia (Center for Biomedicine, EURAC Research, Italy)</li>
+<li>Carles Fenoy (Barcelona Supercomputer Center, Spain)</li>
 <li>Joseph Donaghy (LLNL)</li>
 <li>Chris Dunlap (LLNL)</li>
 <li>Joey Ekstrom (LLNL/Bringham Young University)</li>
diff --git a/src/common/gres.c b/src/common/gres.c
index c1e2ecc7116..a0e4523e322 100644
--- a/src/common/gres.c
+++ b/src/common/gres.c
@@ -2509,6 +2509,12 @@ extern uint32_t _job_test(void *job_gres_data, void *node_gres_data,
 		return NO_VAL;
 	} else if (job_gres_ptr->gres_cnt_alloc && node_gres_ptr->topo_cnt) {
 		/* Need to determine which specific CPUs can be used */
+		gres_avail = node_gres_ptr->gres_cnt_avail;
+		if (!use_total_gres)
+			gres_avail -= node_gres_ptr->gres_cnt_alloc;
+		if (job_gres_ptr->gres_cnt_alloc > gres_avail)
+			return (uint32_t) 0;	/* insufficient, gres to use */
+
 		if (cpu_bitmap) {
 			cpus_ctld = cpu_end_bit - cpu_start_bit + 1;
 			if (cpus_ctld < 1) {
-- 
GitLab