diff --git a/src/common/assoc_mgr.c b/src/common/assoc_mgr.c index 74b9279e66c6368965c5ef9b54d8682557651cba..2838bea673a83254d926652af11302666138a5a4 100644 --- a/src/common/assoc_mgr.c +++ b/src/common/assoc_mgr.c @@ -4470,25 +4470,28 @@ extern int assoc_mgr_update_tres(slurmdb_update_object_t *update, bool locked) slurmdb_tres_rec_t *object = NULL; ListIterator itr = NULL; + List tmp_list = assoc_mgr_tres_list; + bool changed = false, freeit = false; int rc = SLURM_SUCCESS; assoc_mgr_lock_t locks = { NO_LOCK, NO_LOCK, NO_LOCK, NO_LOCK, WRITE_LOCK, NO_LOCK, NO_LOCK }; if (!locked) assoc_mgr_lock(&locks); - if (!assoc_mgr_tres_list) { - if (!locked) - assoc_mgr_unlock(&locks); - return SLURM_SUCCESS; + + if (!tmp_list) { + tmp_list = list_create(slurmdb_destroy_tres_rec); + freeit = true; } - itr = list_iterator_create(assoc_mgr_tres_list); + itr = list_iterator_create(tmp_list); while ((object = list_pop(update->objects))) { list_iterator_reset(itr); while ((rec = list_next(itr))) { if (object->id == rec->id) break; } - switch(update->type) { + + switch (update->type) { case SLURMDB_ADD_TRES: if (rec) { //rc = SLURM_ERROR; @@ -4499,8 +4502,9 @@ extern int assoc_mgr_update_tres(slurmdb_update_object_t *update, bool locked) "This should never happen."); break; } - list_append(assoc_mgr_tres_list, object); + list_append(tmp_list, object); object = NULL; + changed = true; break; default: break; @@ -4509,6 +4513,15 @@ extern int assoc_mgr_update_tres(slurmdb_update_object_t *update, bool locked) slurmdb_destroy_tres_rec(object); } list_iterator_destroy(itr); + if (changed) { + /* We want to run this on the assoc_mgr_tres_list, but we need + * to make a tmp variable since _post_tres_list will set + * assoc_mgr_tres_list for us. + */ + _post_tres_list(tmp_list, list_count(tmp_list)); + } else if (freeit) + FREE_NULL_LIST(tmp_list); + if (!locked) assoc_mgr_unlock(&locks); return rc; diff --git a/src/slurmctld/controller.c b/src/slurmctld/controller.c index 816904868d75b18749aa19fb1063b472fa24ddd0..099e7775a15ce92fa1bbfd4143864452a0189e6d 100644 --- a/src/slurmctld/controller.c +++ b/src/slurmctld/controller.c @@ -1330,6 +1330,7 @@ static int _init_tres(void) List char_list; List add_list = NULL; slurmdb_tres_rec_t *tres_rec; + slurmdb_update_object_t update_object; if (!temp_char) { error("No tres defined, this should never happen"); @@ -1340,6 +1341,12 @@ static int _init_tres(void) slurm_addto_char_list(char_list, temp_char); xfree(temp_char); + if (!association_based_accounting) { + memset(&update_object, 0, sizeof(slurmdb_update_object_t)); + update_object.type = SLURMDB_ADD_TRES; + update_object.objects = list_create(slurmdb_destroy_tres_rec); + } + while ((temp_char = list_pop(char_list))) { tres_rec = xmalloc(sizeof(slurmdb_tres_rec_t)); @@ -1376,10 +1383,23 @@ static int _init_tres(void) xfree(tres_rec); } - if (!tres_rec->id && - (assoc_mgr_fill_in_tres(acct_db_conn, tres_rec, - ACCOUNTING_ENFORCE_TRES, NULL, 0) - != SLURM_SUCCESS)) { + if (!association_based_accounting) { + if (!tres_rec->id) + fatal("Unless running with a database you " + "can only run with certain TRES, " + "%s%s%s is not one of them. " + "Either set up " + "a database preferably with a slurmdbd " + "or remove this TRES from your " + "configuration.", + tres_rec->type, tres_rec->name ? "/" : "", + tres_rec->name ? tres_rec->name : ""); + list_append(update_object.objects, tres_rec); + } else if (!tres_rec->id && + assoc_mgr_fill_in_tres( + acct_db_conn, tres_rec, + ACCOUNTING_ENFORCE_TRES, NULL, 0) + != SLURM_SUCCESS) { if (!add_list) add_list = list_create( slurmdb_destroy_tres_rec); @@ -1404,6 +1424,11 @@ static int _init_tres(void) FREE_NULL_LIST(add_list); } + if (!association_based_accounting) { + assoc_mgr_update_tres(&update_object, false); + list_destroy(update_object.objects); + } + return SLURM_SUCCESS; }