From 452ae1a863ccb817b430cf1f9739cfe6fc146aea Mon Sep 17 00:00:00 2001
From: Danny Auble <da@llnl.gov>
Date: Wed, 19 Jan 2011 23:17:11 +0000
Subject: [PATCH] -- BLUEGENE - This fixes a race condition with dynamic mode
 to make it so we copy the booted and job list of blocks before trying to
 create.

---
 NEWS                                          |  2 +-
 .../select/bluegene/plugin/bg_job_place.c     | 29 ++++++++++++++-----
 .../select/bluegene/plugin/dynamic_block.c    |  7 +++--
 3 files changed, 27 insertions(+), 11 deletions(-)

diff --git a/NEWS b/NEWS
index a0932a9baa2..6ceaa08bd0e 100644
--- a/NEWS
+++ b/NEWS
@@ -42,7 +42,7 @@ documents those changes that are of interest to users and admins.
  -- BLUEGENE - more robust checking for states when freeing blocks.
  -- Added correct files to the slurm.spec file for correct perl api rpm
     creation.
-
+ 
 * Changes in SLURM 2.2.0
 ========================
  -- Change format of Duration field in "scontrol show reservation" output from
diff --git a/src/plugins/select/bluegene/plugin/bg_job_place.c b/src/plugins/select/bluegene/plugin/bg_job_place.c
index 71ebf6f8f4f..126ab37aa29 100644
--- a/src/plugins/select/bluegene/plugin/bg_job_place.c
+++ b/src/plugins/select/bluegene/plugin/bg_job_place.c
@@ -729,6 +729,7 @@ static int _dynamically_request(List block_list, int *blocks_added,
 	List list_of_lists = NULL;
 	List temp_list = NULL;
 	List new_blocks = NULL;
+	List job_list = NULL, booted_list = NULL;
 	ListIterator itr = NULL;
 	int rc = SLURM_ERROR;
 	int create_try = 0;
@@ -746,20 +747,28 @@ static int _dynamically_request(List block_list, int *blocks_added,
 	if (SELECT_IS_PREEMPT_SET(query_mode)
 	    && SELECT_IS_CHECK_FULL_SET(query_mode)) {
 		list_append(list_of_lists, block_list);
-	} else if (user_req_nodes)
-		list_append(list_of_lists, bg_lists->job_running);
-	else {
+	} else if (user_req_nodes) {
+		slurm_mutex_lock(&block_state_mutex);
+		job_list = copy_bg_list(bg_lists->job_running);
+		list_append(list_of_lists, job_list);
+		slurm_mutex_unlock(&block_state_mutex);
+	} else {
+		slurm_mutex_lock(&block_state_mutex);
 		list_append(list_of_lists, block_list);
 		if (list_count(block_list) != list_count(bg_lists->booted)) {
-			list_append(list_of_lists, bg_lists->booted);
+			booted_list = copy_bg_list(bg_lists->booted);
+			list_append(list_of_lists, booted_list);
 			if (list_count(bg_lists->booted)
-			    != list_count(bg_lists->job_running))
-				list_append(list_of_lists,
-					    bg_lists->job_running);
+			    != list_count(bg_lists->job_running)) {
+				job_list = copy_bg_list(bg_lists->job_running);
+				list_append(list_of_lists, job_list);
+			}
 		} else if (list_count(block_list)
 			   != list_count(bg_lists->job_running)) {
-			list_append(list_of_lists, bg_lists->job_running);
+			job_list = copy_bg_list(bg_lists->job_running);
+			list_append(list_of_lists, job_list);
 		}
+		slurm_mutex_unlock(&block_state_mutex);
 	}
 	itr = list_iterator_create(list_of_lists);
 	while ((temp_list = (List)list_next(itr))) {
@@ -838,6 +847,10 @@ static int _dynamically_request(List block_list, int *blocks_added,
 
 	if (list_of_lists)
 		list_destroy(list_of_lists);
+	if (job_list)
+		list_destroy(job_list);
+	if (booted_list)
+		list_destroy(booted_list);
 
 	return rc;
 }
diff --git a/src/plugins/select/bluegene/plugin/dynamic_block.c b/src/plugins/select/bluegene/plugin/dynamic_block.c
index 8c17f5601ae..de672cb3004 100644
--- a/src/plugins/select/bluegene/plugin/dynamic_block.c
+++ b/src/plugins/select/bluegene/plugin/dynamic_block.c
@@ -75,11 +75,15 @@ extern List create_dynamic_block(List block_list,
 	}
 	memset(&blockreq, 0, sizeof(blockreq_t));
 
-	slurm_mutex_lock(&block_state_mutex);
 	if (my_block_list) {
 		reset_ba_system(track_down_nodes);
 		itr = list_iterator_create(my_block_list);
 		while ((bg_record = list_next(itr))) {
+			if (bg_record->magic != BLOCK_MAGIC) {
+				error("got a block with bad magic");
+				list_remove(itr);
+				continue;
+			}
 			if (bg_record->free_cnt) {
 				if (bg_conf->slurm_debug_flags
 				    & DEBUG_FLAG_BG_PICK) {
@@ -402,7 +406,6 @@ finished:
 	if (results)
 		list_destroy(results);
 	errno = rc;
-	slurm_mutex_unlock(&block_state_mutex);
 
 	return new_blocks;
 }
-- 
GitLab