From 8d5ddc3b4c24c05017f4b679016801b58b63d3bc Mon Sep 17 00:00:00 2001
From: Danny Auble <da@llnl.gov>
Date: Thu, 12 May 2005 23:18:48 +0000
Subject: [PATCH] check usrname on startup make sure thread safe.

---
 src/plugins/select/bluegene/bgl_job_run.c      | 10 ++++++----
 .../select/bluegene/bgl_switch_connections.c   |  1 +
 src/plugins/select/bluegene/bluegene.c         | 18 +++++++++++++++---
 3 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/src/plugins/select/bluegene/bgl_job_run.c b/src/plugins/select/bluegene/bgl_job_run.c
index 74706ef681c..30465db35d5 100644
--- a/src/plugins/select/bluegene/bgl_job_run.c
+++ b/src/plugins/select/bluegene/bgl_job_run.c
@@ -381,10 +381,12 @@ static void _term_agent(bgl_update_t *bgl_update_ptr)
 				xfree(bgl_record->target_name);
 				bgl_record->target_name = xstrdup(USER_NAME);
 			}
-		}
-		if(update_partition_user(bgl_record) == 1) 
-			last_bgl_update = time(NULL);
-			
+		
+			if(update_partition_user(bgl_record) == 1) 
+				last_bgl_update = time(NULL);
+		} else {
+			bgl_record->target_name = xstrdup(USER_NAME);	
+		}	
 		if(bgl_record->state != RM_PARTITION_CONFIGURING) {
 			bgl_record->boot_state = 0;
 			bgl_record->boot_count = 0;
diff --git a/src/plugins/select/bluegene/bgl_switch_connections.c b/src/plugins/select/bluegene/bgl_switch_connections.c
index fe8743859a3..85ad26c0cd2 100644
--- a/src/plugins/select/bluegene/bgl_switch_connections.c
+++ b/src/plugins/select/bluegene/bgl_switch_connections.c
@@ -157,6 +157,7 @@ static int _add_switch_conns(rm_switch_t* curr_switch,
 			}
 		} 
 		conn_num++;
+		//debug("adding %d -> %d",bgl_conn->source, bgl_conn->target);
 	}
 	list_iterator_destroy(itr);
 	if ((rc = rm_set_data(curr_switch, RM_SwitchConnNum, &conn_num)) 
diff --git a/src/plugins/select/bluegene/bluegene.c b/src/plugins/select/bluegene/bluegene.c
index 1c50c70cc4c..c18a02e2e61 100644
--- a/src/plugins/select/bluegene/bluegene.c
+++ b/src/plugins/select/bluegene/bluegene.c
@@ -602,6 +602,7 @@ extern int create_static_partitions(List part_list)
 #else
 	ListIterator itr_found;
 #endif
+	slurm_mutex_lock(&part_state_mutex);
 	reset_pa_system();
 		
 	if(bgl_list) {
@@ -617,12 +618,14 @@ extern int create_static_partitions(List part_list)
 						 bgl_record->conn_type) == SLURM_ERROR) {
 					error("I was unable to make the "
 					      "requested partition.");
+					slurm_mutex_unlock(&part_state_mutex);
 					return SLURM_ERROR;
 				}
 		}
 		list_iterator_destroy(itr);
 	} else {
 		error("create_static_partitions: no bgl_list 1");
+		slurm_mutex_unlock(&part_state_mutex);
 		return SLURM_ERROR;
 	}
 
@@ -651,6 +654,7 @@ extern int create_static_partitions(List part_list)
 				if((rc = configure_partition(bgl_record)) 
 				   == SLURM_ERROR) {
 					list_iterator_destroy(itr);
+					slurm_mutex_unlock(&part_state_mutex);
 					return rc;
 				}
 				print_bgl_record(bgl_record);
@@ -659,6 +663,7 @@ extern int create_static_partitions(List part_list)
 		list_iterator_destroy(itr);
 	} else {
 		error("create_static_partitions: no bgl_list 2");
+		slurm_mutex_unlock(&part_state_mutex);
 		return SLURM_ERROR;
 	}
 #endif
@@ -710,6 +715,7 @@ extern int create_static_partitions(List part_list)
 		list_iterator_destroy(itr);
 	} else {
 		error("create_static_partitions: no bgl_list 3");
+		slurm_mutex_unlock(&part_state_mutex);
 		return SLURM_ERROR;
 	}
 	bgl_record->bgl_part_list = list_create(NULL);			
@@ -731,12 +737,15 @@ extern int create_static_partitions(List part_list)
 			 bgl_record->conn_type) == SLURM_ERROR) {
 		error("I was unable to make the "
 		      "requested partition.");
+		slurm_mutex_unlock(&part_state_mutex);
 		return SLURM_ERROR;
 	}
 	bgl_record->node_use = SELECT_COPROCESSOR_MODE;
 #ifdef HAVE_BGL_FILES
-	if((rc = configure_partition(bgl_record)) == SLURM_ERROR)
+	if((rc = configure_partition(bgl_record)) == SLURM_ERROR) {
+		slurm_mutex_unlock(&part_state_mutex);
 		return rc;
+	}
 	print_bgl_record(bgl_record);
 
 #else
@@ -756,6 +765,7 @@ extern int create_static_partitions(List part_list)
 		list_iterator_destroy(itr);
 	} else {
 		error("create_static_partitions: no bgl_list 4");
+		slurm_mutex_unlock(&part_state_mutex);
 		return SLURM_ERROR;
 	}
 #endif	/* HAVE_BGL_FILES */
@@ -777,9 +787,10 @@ no_total:
 		list_iterator_destroy(itr);
 	} else {
 		error("create_static_partitions: no bgl_list 5");
-	}	
+	}
+	debug("Setting time up");
 	last_bgl_update = time(NULL);
-	rc = SLURM_SUCCESS;
+	slurm_mutex_unlock(&part_state_mutex);
 #ifdef _PRINT_PARTS_AND_EXIT
 	if(bgl_list) {
 		itr = list_iterator_create(bgl_list);
@@ -794,6 +805,7 @@ no_total:
 	}
  	exit(0);
 #endif	/* _PRINT_PARTS_AND_EXIT */
+	rc = SLURM_SUCCESS;
 
 	return rc;
 }
-- 
GitLab