From 968d525ad04053b8d5a982717da12c19cd1e3629 Mon Sep 17 00:00:00 2001
From: Danny Auble <da@llnl.gov>
Date: Thu, 3 Sep 2009 18:05:43 +0000
Subject: [PATCH] added functionality for a global qos_list so we don't have to
 continually query the db.  We also added start of ability to add preempt.  No
 checks are there yet.

---
 src/sacctmgr/account_functions.c     | 29 +++++--------
 src/sacctmgr/association_functions.c | 19 +++------
 src/sacctmgr/cluster_functions.c     | 20 +++------
 src/sacctmgr/common.c                | 17 ++++----
 src/sacctmgr/file_functions.c        | 29 ++++++-------
 src/sacctmgr/problem_functions.c     |  7 ----
 src/sacctmgr/qos_functions.c         | 63 ++++++++++++++++++----------
 src/sacctmgr/sacctmgr.c              |  3 ++
 src/sacctmgr/sacctmgr.h              |  1 +
 src/sacctmgr/user_functions.c        | 34 ++++++---------
 10 files changed, 99 insertions(+), 123 deletions(-)

diff --git a/src/sacctmgr/account_functions.c b/src/sacctmgr/account_functions.c
index 427bf1e36ab..e9369dd9d25 100644
--- a/src/sacctmgr/account_functions.c
+++ b/src/sacctmgr/account_functions.c
@@ -47,7 +47,6 @@ static int _set_cond(int *start, int argc, char *argv[],
 	int a_set = 0;
 	int u_set = 0;
 	int end = 0;
-	List qos_list = NULL;
 	acct_association_cond_t *assoc_cond = NULL;
 	int command_len = 0;
 	int option = 0;
@@ -275,12 +274,12 @@ static int _set_cond(int *start, int argc, char *argv[],
 					list_create(slurm_destroy_char);
 			}
 			
-			if(!qos_list) {
-				qos_list = acct_storage_g_get_qos(
+			if(!g_qos_list) {
+				g_qos_list = acct_storage_g_get_qos(
 					db_conn, my_uid, NULL);
 			}
 
-			if(addto_qos_char_list(assoc_cond->qos_list, qos_list,
+			if(addto_qos_char_list(assoc_cond->qos_list, g_qos_list,
 					       argv[i]+end, option))
 				a_set = 1;
 			else
@@ -293,9 +292,6 @@ static int _set_cond(int *start, int argc, char *argv[],
 		}
 	}
 
-	if(qos_list)
-		list_destroy(qos_list);
-
 	(*start) = i;
 
 	if(u_set && a_set)
@@ -318,7 +314,6 @@ static int _set_rec(int *start, int argc, char *argv[],
 	int u_set = 0;
 	int a_set = 0;
 	int end = 0;
-	List qos_list = NULL;
 	int command_len = 0;
 	int option = 0;
 
@@ -487,12 +482,12 @@ static int _set_rec(int *start, int argc, char *argv[],
 				assoc->qos_list = 
 					list_create(slurm_destroy_char);
 						
-			if(!qos_list) 
-				qos_list = acct_storage_g_get_qos(
+			if(!g_qos_list) 
+				g_qos_list = acct_storage_g_get_qos(
 					db_conn, my_uid, NULL);
 
 			if(addto_qos_char_list(assoc->qos_list,
-					       qos_list, argv[i]+end, option))
+					       g_qos_list, argv[i]+end, option))
 				a_set = 1;
 			else
 				exit_code = 1;
@@ -506,9 +501,6 @@ static int _set_rec(int *start, int argc, char *argv[],
 
 	(*start) = i;
 
-	if(qos_list)
-		list_destroy(qos_list);
-
 	if(u_set && a_set)
 		return 3;
 	else if(a_set)
@@ -915,8 +907,7 @@ extern int sacctmgr_list_account(int argc, char *argv[])
 	acct_account_rec_t *acct = NULL;
 	acct_association_rec_t *assoc = NULL;
 	char *object;
-	List qos_list = NULL;
-
+	
 	int field_count = 0;
 
 	print_field_t *field = NULL;
@@ -1331,8 +1322,8 @@ extern int sacctmgr_list_account(int argc, char *argv[])
 							 field_count));
 						break;
 					case PRINT_QOS:
-						if(!qos_list) {
-							qos_list = 
+						if(!g_qos_list) {
+							g_qos_list = 
 								acct_storage_g_get_qos(
 									db_conn,
 									my_uid,
@@ -1340,7 +1331,7 @@ extern int sacctmgr_list_account(int argc, char *argv[])
 						}
 						field->print_routine(
 							field,
-							qos_list,
+							g_qos_list,
 							assoc->qos_list,
 							(curr_inx == 
 							 field_count));
diff --git a/src/sacctmgr/association_functions.c b/src/sacctmgr/association_functions.c
index 91ab83aa971..01f3c5f64d9 100644
--- a/src/sacctmgr/association_functions.c
+++ b/src/sacctmgr/association_functions.c
@@ -47,7 +47,6 @@ static int _set_cond(int *start, int argc, char *argv[],
 {
 	int i, end = 0;
 	int set = 0;
-	List qos_list = NULL;
 	int command_len = 0;
 	int option = 0;
 	for (i=(*start); i<argc; i++) {
@@ -274,12 +273,12 @@ static int _set_cond(int *start, int argc, char *argv[],
 					list_create(slurm_destroy_char);
 			}
 			
-			if(!qos_list) {
-				qos_list = acct_storage_g_get_qos(
+			if(!g_qos_list) {
+				g_qos_list = acct_storage_g_get_qos(
 					db_conn, my_uid, NULL);
 			}
 			
-			if(addto_qos_char_list(assoc_cond->qos_list, qos_list,
+			if(addto_qos_char_list(assoc_cond->qos_list, g_qos_list,
 					       argv[i]+end, option))
 				set = 1;
 			else
@@ -297,8 +296,6 @@ static int _set_cond(int *start, int argc, char *argv[],
 			fprintf(stderr, " Unknown condition: %s\n", argv[i]);
 		}
 	}
-	if(qos_list)
-		list_destroy(qos_list);
 
 	(*start) = i;
 
@@ -319,7 +316,6 @@ extern int sacctmgr_list_association(int argc, char *argv[])
 	char *object = NULL;
 	char *print_acct = NULL, *last_cluster = NULL;
 	List tree_list = NULL;
-	List qos_list = NULL;
 
 	int field_count = 0;
 
@@ -735,12 +731,12 @@ extern int sacctmgr_list_association(int argc, char *argv[])
 						     (curr_inx == field_count));
 				break;
 			case PRINT_QOS:
-				if(!qos_list) 
-					qos_list = acct_storage_g_get_qos(
+				if(!g_qos_list) 
+					g_qos_list = acct_storage_g_get_qos(
 						db_conn, my_uid, NULL);
 				
 				field->print_routine(field,
-						     qos_list,
+						     g_qos_list,
 						     assoc->qos_list,
 						     (curr_inx == field_count));
 				break;
@@ -771,9 +767,6 @@ extern int sacctmgr_list_association(int argc, char *argv[])
 		printf("\n");
 	}
 
-	if(qos_list)
-		list_destroy(qos_list);
-
 	if(tree_list) 
 		list_destroy(tree_list);
 			
diff --git a/src/sacctmgr/cluster_functions.c b/src/sacctmgr/cluster_functions.c
index 807275b3336..6f4d9e439cf 100644
--- a/src/sacctmgr/cluster_functions.c
+++ b/src/sacctmgr/cluster_functions.c
@@ -115,7 +115,6 @@ static int _set_rec(int *start, int argc, char *argv[],
 	int i, mins;
 	int set = 0;
 	int end = 0;
-	List qos_list = NULL;
 	int command_len = 0;
 	int option = 0;
 
@@ -236,12 +235,12 @@ static int _set_rec(int *start, int argc, char *argv[],
 				assoc->qos_list = 
 					list_create(slurm_destroy_char);
 						
-			if(!qos_list) 
-				qos_list = acct_storage_g_get_qos(
+			if(!g_qos_list) 
+				g_qos_list = acct_storage_g_get_qos(
 					db_conn, my_uid, NULL);
 						
 			if(addto_qos_char_list(assoc->qos_list,
-					       qos_list, argv[i]+end, option))
+					       g_qos_list, argv[i]+end, option))
 				set = 1;
 			else
 				exit_code = 1;
@@ -254,9 +253,6 @@ static int _set_rec(int *start, int argc, char *argv[],
 	}
 	(*start) = i;
 
-	if(qos_list)
-		list_destroy(qos_list);
-
 	return set;
 
 }
@@ -420,7 +416,6 @@ extern int sacctmgr_list_cluster(int argc, char *argv[])
 	ListIterator itr2 = NULL;
 	acct_cluster_rec_t *cluster = NULL;
 	char *object;
-	List qos_list = NULL;
 
 	int field_count = 0;
 
@@ -786,12 +781,12 @@ extern int sacctmgr_list_cluster(int argc, char *argv[])
 				break;
 				
 			case PRINT_QOS:
-				if(!qos_list) 
-					qos_list = acct_storage_g_get_qos(
+				if(!g_qos_list) 
+					g_qos_list = acct_storage_g_get_qos(
 						db_conn, my_uid, NULL);
 				
 				field->print_routine(field,
-						     qos_list,
+						     g_qos_list,
 						     assoc->qos_list,
 						     (curr_inx == field_count));
 				break;
@@ -818,9 +813,6 @@ extern int sacctmgr_list_cluster(int argc, char *argv[])
 		printf("\n");
 	}
 
-	if(qos_list)
-		list_destroy(qos_list);
-
 	list_iterator_destroy(itr2);
 	list_iterator_destroy(itr);
 	list_destroy(cluster_list);
diff --git a/src/sacctmgr/common.c b/src/sacctmgr/common.c
index df8dc589600..a55664a2df0 100644
--- a/src/sacctmgr/common.c
+++ b/src/sacctmgr/common.c
@@ -1168,26 +1168,25 @@ extern void sacctmgr_print_assoc_limits(acct_association_rec_t *assoc)
 	}
 
 	if(assoc->qos_list) {
-		List qos_list = acct_storage_g_get_qos(db_conn, my_uid, NULL);
-		char *temp_char = get_qos_complete_str(qos_list,
+		if(!g_qos_list)
+			g_qos_list = 
+				acct_storage_g_get_qos(db_conn, my_uid, NULL);
+		char *temp_char = get_qos_complete_str(g_qos_list,
 						       assoc->qos_list);
 		if(temp_char) {		
 			printf("  QOS           = %s\n", temp_char);
 			xfree(temp_char);
 		}
-		if(qos_list)
-			list_destroy(qos_list);
 	} 
 }
 
 extern void sacctmgr_print_qos_limits(acct_qos_rec_t *qos)
 {
-	List qos_list = NULL;
 	if(!qos)
 		return;
 
-	if(qos->preempt_list)
-		qos_list = acct_storage_g_get_qos(db_conn, my_uid, NULL);
+	if(qos->preempt_list && !g_qos_list)
+		g_qos_list = acct_storage_g_get_qos(db_conn, my_uid, NULL);
 
 	if(qos->job_flags)
 		printf("  JobFlags       = %s", qos->job_flags);
@@ -1265,7 +1264,7 @@ extern void sacctmgr_print_qos_limits(acct_qos_rec_t *qos)
 	}
 
 	if(qos->preempt_list) {
-		char *temp_char = get_qos_complete_str(qos_list,
+		char *temp_char = get_qos_complete_str(g_qos_list,
 						       qos->preempt_list);
 		if(temp_char) {		
 			printf("  Preempt        = %s\n", temp_char);
@@ -1278,8 +1277,6 @@ extern void sacctmgr_print_qos_limits(acct_qos_rec_t *qos)
 	else if(qos->priority != NO_VAL) 
 		printf("  Priority       = %d\n", qos->priority);
 
-	if(qos_list)
-		list_destroy(qos_list);
 }
 
 extern int sort_coord_list(acct_coord_rec_t *coord_a, acct_coord_rec_t *coord_b)
diff --git a/src/sacctmgr/file_functions.c b/src/sacctmgr/file_functions.c
index 8499020fb61..8c3956d071c 100644
--- a/src/sacctmgr/file_functions.c
+++ b/src/sacctmgr/file_functions.c
@@ -111,8 +111,6 @@ typedef enum {
 	MOD_USER
 } sacctmgr_mod_type_t;
 
-static List qos_list = NULL;
-
 static int _init_sacctmgr_file_opts(sacctmgr_file_opts_t *file_opts)
 {
 	if(!file_opts)
@@ -495,12 +493,12 @@ static sacctmgr_file_opts_t *_parse_options(char *options)
 					list_create(slurm_destroy_char);
 			}
 			
-			if(!qos_list) {
-				qos_list = acct_storage_g_get_qos(
+			if(!g_qos_list) {
+				g_qos_list = acct_storage_g_get_qos(
 					db_conn, my_uid, NULL);
 			}
 
-			addto_qos_char_list(file_opts->qos_list, qos_list,
+			addto_qos_char_list(file_opts->qos_list, g_qos_list,
 					    option, option2);
 		} else if (!strncasecmp (sub, "WCKeys",
 					 MAX(command_len, 2))) {
@@ -843,9 +841,13 @@ static int _print_out_assoc(List assoc_list, bool user, bool add)
 						     assoc->partition);
 				break;
 			case PRINT_QOS:
+				if(!g_qos_list) 
+					g_qos_list = acct_storage_g_get_qos(
+						db_conn, my_uid, NULL);
+	
 				field->print_routine(
 					field,
-					qos_list,
+					g_qos_list,
 					assoc->qos_list);
 				break;
 			case PRINT_USER:
@@ -1093,7 +1095,7 @@ static int _mod_assoc(sacctmgr_file_opts_t *file_opts,
 		list_iterator_destroy(new_qos_itr);
 		list_iterator_destroy(now_qos_itr);
 		if(mod_assoc.qos_list && list_count(mod_assoc.qos_list))
-			new_qos = get_qos_complete_str(qos_list,
+			new_qos = get_qos_complete_str(g_qos_list,
 						       mod_assoc.qos_list);
 		if(new_qos) {
 			xstrfmtcat(my_info, 
@@ -1108,7 +1110,7 @@ static int _mod_assoc(sacctmgr_file_opts_t *file_opts,
 			mod_assoc.qos_list = NULL;
 		}
 	} else if(file_opts->qos_list && list_count(file_opts->qos_list)) {
-		char *new_qos = get_qos_complete_str(qos_list,
+		char *new_qos = get_qos_complete_str(g_qos_list,
 						     file_opts->qos_list);
 		
 		if(new_qos) {
@@ -1867,11 +1869,6 @@ static int _print_file_acct_hierarchical_rec_childern(FILE *fd,
 extern int print_file_add_limits_to_line(char **line,
 					 acct_association_rec_t *assoc)
 {
-	static List qos_list = NULL; /* This is a leak, since we never
-				      * free it, but we don't
-				      * really care since this isn't a
-				      * deamon.
-				      */
 	if(!assoc)
 		return SLURM_ERROR;
 
@@ -1918,11 +1915,11 @@ extern int print_file_add_limits_to_line(char **line,
 
 	if(assoc->qos_list && list_count(assoc->qos_list)) {
 		char *temp_char = NULL;
-		if(!qos_list) 
-			qos_list = acct_storage_g_get_qos(
+		if(!g_qos_list) 
+			g_qos_list = acct_storage_g_get_qos(
 				db_conn, my_uid, NULL);
 		
-		temp_char = get_qos_complete_str(qos_list, assoc->qos_list);
+		temp_char = get_qos_complete_str(g_qos_list, assoc->qos_list);
 		xstrfmtcat(*line, ":QOS='%s'", temp_char);
 		xfree(temp_char);
 	}
diff --git a/src/sacctmgr/problem_functions.c b/src/sacctmgr/problem_functions.c
index 1c39597bb60..fc954ab1573 100644
--- a/src/sacctmgr/problem_functions.c
+++ b/src/sacctmgr/problem_functions.c
@@ -46,7 +46,6 @@ static int _set_cond(int *start, int argc, char *argv[],
 {
 	int i, end = 0;
 	int set = 0;
-	List qos_list = NULL;
 	int command_len = 0;
 	int option = 0;
 	for (i=(*start); i<argc; i++) {
@@ -121,8 +120,6 @@ static int _set_cond(int *start, int argc, char *argv[],
 			fprintf(stderr, " Unknown condition: %s\n", argv[i]);
 		}
 	}
-	if(qos_list)
-		list_destroy(qos_list);
 
 	(*start) = i;
 
@@ -141,7 +138,6 @@ extern int sacctmgr_list_problem(int argc, char *argv[])
 	ListIterator itr2 = NULL;
 	char *object = NULL;
 	List tree_list = NULL;
-	List qos_list = NULL;
 
 	int field_count = 0;
 
@@ -297,9 +293,6 @@ extern int sacctmgr_list_problem(int argc, char *argv[])
 		printf("\n");
 	}
 
-	if(qos_list)
-		list_destroy(qos_list);
-
 	if(tree_list) 
 		list_destroy(tree_list);
 			
diff --git a/src/sacctmgr/qos_functions.c b/src/sacctmgr/qos_functions.c
index 413b73c0757..56053935038 100644
--- a/src/sacctmgr/qos_functions.c
+++ b/src/sacctmgr/qos_functions.c
@@ -136,7 +136,7 @@ static int _set_cond(int *start, int argc, char *argv[],
 }
 
 static int _set_rec(int *start, int argc, char *argv[],
-		    List qos_list,
+		    List name_list,
 		    acct_qos_rec_t *qos)
 {
 	int i, mins;
@@ -166,8 +166,8 @@ static int _set_rec(int *start, int argc, char *argv[],
 		} else if(!end
 			  || !strncasecmp (argv[i], "Name",
 					   MAX(command_len, 1))) {
-			if(qos_list) 
-				slurm_addto_char_list(qos_list, argv[i]+end);
+			if(name_list) 
+				slurm_addto_char_list(name_list, argv[i]+end);
 		} else if (!strncasecmp (argv[i], "Description",
 					 MAX(command_len, 1))) {
 			if(!qos->description)
@@ -290,12 +290,12 @@ static int _set_rec(int *start, int argc, char *argv[],
 				qos->preempt_list = 
 					list_create(slurm_destroy_char);
 						
-			if(!qos_list) 
-				qos_list = acct_storage_g_get_qos(
+			if(!g_qos_list) 
+				g_qos_list = acct_storage_g_get_qos(
 					db_conn, my_uid, NULL);
 						
 			if(addto_qos_char_list(qos->preempt_list,
-					       qos_list, argv[i]+end, option))
+					       g_qos_list, argv[i]+end, option))
 				set = 1;
 			else
 				exit_code = 1;
@@ -338,7 +338,6 @@ extern int sacctmgr_add_qos(int argc, char *argv[])
 	char *description = NULL;
 	char *name = NULL;
 	List qos_list = NULL;
-	List local_qos_list = NULL;
 	char *qos_str = NULL;
 
 	init_acct_qos_rec(start_qos);
@@ -364,16 +363,18 @@ extern int sacctmgr_add_qos(int argc, char *argv[])
 		return SLURM_SUCCESS;
 	} 
 
-
-	local_qos_list = acct_storage_g_get_qos(db_conn, my_uid, NULL);
-
-	if(!local_qos_list) {
-		exit_code=1;
-		fprintf(stderr, " Problem getting qos's from database.  "
-		       "Contact your admin.\n");
-		list_destroy(name_list);
-		xfree(description);
-		return SLURM_ERROR;
+	if(!g_qos_list) {
+		g_qos_list = acct_storage_g_get_qos(db_conn, my_uid, NULL);
+		
+		if(!g_qos_list) {
+			exit_code=1;
+			fprintf(stderr, " Problem getting qos's "
+				"from database.  "
+				"Contact your admin.\n");
+			list_destroy(name_list);
+			xfree(description);
+			return SLURM_ERROR;
+		}
 	}
 
 	qos_list = list_create(destroy_acct_qos_rec);
@@ -381,7 +382,7 @@ extern int sacctmgr_add_qos(int argc, char *argv[])
 	itr = list_iterator_create(name_list);
 	while((name = list_next(itr))) {
 		qos = NULL;
-		if(!sacctmgr_find_qos_from_list(local_qos_list, name)) {
+		if(!sacctmgr_find_qos_from_list(g_qos_list, name)) {
 			qos = xmalloc(sizeof(acct_qos_rec_t));
 			qos->name = xstrdup(name);
 			if(start_qos->description) 
@@ -407,6 +408,9 @@ extern int sacctmgr_add_qos(int argc, char *argv[])
 			if(start_qos->job_flags)
 				qos->job_flags = start_qos->job_flags;
 
+			qos->preempt_list =
+				copy_char_list(start_qos->preempt_list);
+
 			qos->priority = start_qos->priority;
 
 			qos->usage_factor = start_qos->usage_factor;
@@ -416,7 +420,6 @@ extern int sacctmgr_add_qos(int argc, char *argv[])
 		}
 	}
 	list_iterator_destroy(itr);
-	list_destroy(local_qos_list);
 	list_destroy(name_list);
 	
 	if(!list_count(qos_list)) {
@@ -487,7 +490,6 @@ extern int sacctmgr_list_qos(int argc, char *argv[])
 		PRINT_ID,
 		PRINT_NAME,
 		PRINT_JOBF,
-		PRINT_PRIO,
 		PRINT_GRPCM,
 		PRINT_GRPC,
 		PRINT_GRPJ,
@@ -500,6 +502,8 @@ extern int sacctmgr_list_qos(int argc, char *argv[])
 		PRINT_MAXN,
 		PRINT_MAXS,
 		PRINT_MAXW,
+		PRINT_PREE,
+		PRINT_PRIO,
 		PRINT_UF,
 	};
 
@@ -516,7 +520,7 @@ extern int sacctmgr_list_qos(int argc, char *argv[])
 		list_destroy(format_list);		
 		return SLURM_ERROR;
 	} else if(!list_count(format_list)) {
-		slurm_addto_char_list(format_list, "N,Prio,JobF,"
+		slurm_addto_char_list(format_list, "N,Prio,Pree,"
 				      "GrpJ,GrpN,GrpS,MaxJ,MaxN,MaxS,MaxW");
 	}
 
@@ -623,8 +627,14 @@ extern int sacctmgr_list_qos(int argc, char *argv[])
 			field->name = xstrdup("Name");
 			field->len = 10;
 			field->print_routine = print_fields_str;
+		} else if(!strncasecmp("Preempt", object,
+				       MAX(command_len, 3))) {
+			field->type = PRINT_PREE;
+			field->name = xstrdup("Preempt");
+			field->len = 10;
+			field->print_routine = sacctmgr_print_qos_bitstr;
 		} else if(!strncasecmp("Priority", object,
-				       MAX(command_len, 1))) {
+				       MAX(command_len, 3))) {
 			field->type = PRINT_PRIO;
 			field->name = xstrdup("Priority");
 			field->len = 10;
@@ -757,6 +767,15 @@ extern int sacctmgr_list_qos(int argc, char *argv[])
 					field, qos->name,
 					(curr_inx == field_count));
 				break;
+			case PRINT_PREE:
+				if(!g_qos_list) 
+					g_qos_list = acct_storage_g_get_qos(
+						db_conn, my_uid, NULL);
+
+				field->print_routine(
+					field, g_qos_list, qos->preempt_bitstr,
+					(curr_inx == field_count));
+				break;
 			case PRINT_PRIO:
 				field->print_routine(
 					field, qos->priority,
diff --git a/src/sacctmgr/sacctmgr.c b/src/sacctmgr/sacctmgr.c
index b42016e46c6..c28bb65c59b 100644
--- a/src/sacctmgr/sacctmgr.c
+++ b/src/sacctmgr/sacctmgr.c
@@ -56,6 +56,7 @@ int rollback_flag;       /* immediate execute=1, else = 0 */
 int with_assoc_flag = 0;
 void *db_conn = NULL;
 uint32_t my_uid = 0;
+List g_qos_list = NULL;
 
 static void	_add_it (int argc, char *argv[]);
 static void	_archive_it (int argc, char *argv[]);
@@ -228,6 +229,8 @@ main (int argc, char *argv[])
 		exit_code = local_exit_code;
 	acct_storage_g_close_connection(&db_conn);
 	slurm_acct_storage_fini();
+	if(g_qos_list)
+		list_destroy(g_qos_list);
 	exit(exit_code);
 }
 
diff --git a/src/sacctmgr/sacctmgr.h b/src/sacctmgr/sacctmgr.h
index d106c74f56d..f54b3ddfbf2 100644
--- a/src/sacctmgr/sacctmgr.h
+++ b/src/sacctmgr/sacctmgr.h
@@ -98,6 +98,7 @@ extern int with_assoc_flag;/* show acct/user associations flag */
 extern int readonly_flag; /* make it so you can only run list commands */
 extern void *db_conn;
 extern uint32_t my_uid;
+extern List g_qos_list;
 
 extern int sacctmgr_add_association(int argc, char *argv[]);
 extern int sacctmgr_add_user(int argc, char *argv[]);
diff --git a/src/sacctmgr/user_functions.c b/src/sacctmgr/user_functions.c
index fd8c03840c8..2dca63a7389 100644
--- a/src/sacctmgr/user_functions.c
+++ b/src/sacctmgr/user_functions.c
@@ -48,7 +48,6 @@ static int _set_cond(int *start, int argc, char *argv[],
 	int u_set = 0;
 	int a_set = 0;
 	int end = 0;
-	List qos_list = NULL;
 	acct_association_cond_t *assoc_cond = NULL;
 	int command_len = 0;
 	int option = 0;
@@ -290,13 +289,13 @@ static int _set_cond(int *start, int argc, char *argv[],
 					list_create(slurm_destroy_char);
 			}
 			
-			if(!qos_list) {
-				qos_list = acct_storage_g_get_qos(
+			if(!g_qos_list) {
+				g_qos_list = acct_storage_g_get_qos(
 					db_conn, my_uid, NULL);
 			}
 
 			addto_qos_char_list(assoc_cond->qos_list,
-					    qos_list, argv[i]+end, option);
+					    g_qos_list, argv[i]+end, option);
 			u_set = 1;
 		} else {
 			exit_code=1;
@@ -306,9 +305,6 @@ static int _set_cond(int *start, int argc, char *argv[],
 		}		
 	}	
 
-	if(qos_list)
-		list_destroy(qos_list);
-
 	(*start) = i;
 
 	if(u_set && a_set)
@@ -329,7 +325,6 @@ static int _set_rec(int *start, int argc, char *argv[],
 	int u_set = 0;
 	int a_set = 0;
 	int end = 0;
-	List qos_list = NULL;
 	int command_len = 0;
 	int option = 0;
 
@@ -492,12 +487,12 @@ static int _set_rec(int *start, int argc, char *argv[],
 				assoc->qos_list = 
 					list_create(slurm_destroy_char);
 						
-			if(!qos_list) 
-				qos_list = acct_storage_g_get_qos(
+			if(!g_qos_list) 
+				g_qos_list = acct_storage_g_get_qos(
 					db_conn, my_uid, NULL);
 						
 			if(addto_qos_char_list(assoc->qos_list,
-					       qos_list, argv[i]+end, option))
+					       g_qos_list, argv[i]+end, option))
 				a_set = 1;
 			else
 				exit_code = 1;
@@ -511,9 +506,6 @@ static int _set_rec(int *start, int argc, char *argv[],
 
 	(*start) = i;
 
-	if(qos_list)
-		list_destroy(qos_list);
-
 	if(u_set && a_set)
 		return 3;
 	else if(u_set)
@@ -674,7 +666,6 @@ extern int sacctmgr_add_user(int argc, char *argv[])
 	acct_association_cond_t *assoc_cond = NULL;
 	acct_wckey_rec_t *wckey = NULL;
 	acct_wckey_cond_t *wckey_cond = NULL;
-	List qos_list = NULL;
 	acct_admin_level_t admin_level = ACCT_ADMIN_NOTSET;
 	char *name = NULL, *account = NULL, *cluster = NULL, *partition = NULL;
 	int partition_set = 0;
@@ -861,11 +852,11 @@ extern int sacctmgr_add_user(int argc, char *argv[])
 				start_assoc.qos_list = 
 					list_create(slurm_destroy_char);
 			
-			if(!qos_list) 
-				qos_list = acct_storage_g_get_qos(
+			if(!g_qos_list) 
+				g_qos_list = acct_storage_g_get_qos(
 					db_conn, my_uid, NULL);
 			
-			if(addto_qos_char_list(start_assoc.qos_list, qos_list,
+			if(addto_qos_char_list(start_assoc.qos_list, g_qos_list,
 					       argv[i]+end, option))
 				limit_set = 1;
 			else
@@ -1484,7 +1475,6 @@ extern int sacctmgr_list_user(int argc, char *argv[])
 	acct_user_rec_t *user = NULL;
 	acct_association_rec_t *assoc = NULL;
 	char *object;
-	List qos_list = NULL;
 
 	print_field_t *field = NULL;
 	int field_count = 0;
@@ -1930,8 +1920,8 @@ extern int sacctmgr_list_user(int argc, char *argv[])
 							 field_count));
 						break;
 					case PRINT_QOS:
-						if(!qos_list) {
-							qos_list = 
+						if(!g_qos_list) {
+							g_qos_list = 
 								acct_storage_g_get_qos(
 									db_conn,
 									my_uid,
@@ -1939,7 +1929,7 @@ extern int sacctmgr_list_user(int argc, char *argv[])
 						}
 						field->print_routine(
 							field,
-							qos_list,
+							g_qos_list,
 							assoc->qos_list,
 							(curr_inx == 
 							 field_count));
-- 
GitLab