static List _build_tres_list(char *tres_str) { List tres_list = NULL; ListIterator iter; slurmdb_tres_rec_t *tres; slurmdb_tres_cond_t cond; char *tres_tmp = NULL, *tres_tmp2 = NULL, *save_ptr = NULL, *tok; memset(&cond, 0, sizeof(slurmdb_tres_cond_t)); tres_list = acct_storage_g_get_tres(db_conn, my_uid, &cond); if (!tres_list) { fatal("Problem getting TRES data: %m"); exit(1); } iter = list_iterator_create(tres_list); while ((tres = list_next(iter))) { if (tres_str) { tres_tmp = xstrdup(tres_str); xstrfmtcat(tres_tmp2, "%s%s%s", tres->type, tres->name ? "/" : "", tres->name ? tres->name : ""); tok = strtok_r(tres_tmp, ",", &save_ptr); while (tok) { if (!xstrcasecmp(tres_tmp2, tok)) break; tok = strtok_r(NULL, ",", &save_ptr); } if (!tok) /* Not found */ tres->id = NO_VAL; /* Skip this TRES */ xfree(tres_tmp2); xfree(tres_tmp); } else if (tres->id != TRES_CPU) { tres->id = NO_VAL; /* Skip this TRES */ } } list_iterator_destroy(iter); return tres_list; }
/* sacctmgr_list_tres() */ int sacctmgr_list_tres(int argc, char **argv) { List tres_list; ListIterator itr; ListIterator itr2; List format_list; List print_fields_list; slurmdb_tres_cond_t cond; slurmdb_tres_rec_t *tres; int field_count; print_field_t *field; format_list = list_create(slurm_destroy_char); /* Append to the format list the fields * we want to print, these are the data structure * members of the type returned by slurmdbd */ slurm_addto_char_list(format_list, "Type,Name%15,ID"); if (exit_code) { FREE_NULL_LIST(format_list); return SLURM_ERROR; } /* Process the format list creating a list of * print field_t structures */ print_fields_list = sacctmgr_process_format_list(format_list); FREE_NULL_LIST(format_list); /* Call slurmdbd to get all tres with not * condition */ memset(&cond, 0, sizeof(slurmdb_tres_cond_t)); tres_list = acct_storage_g_get_tres(db_conn, my_uid, &cond); itr = list_iterator_create(tres_list); itr2 = list_iterator_create(print_fields_list); print_fields_header(print_fields_list); field_count = list_count(print_fields_list); /* For each tres prints the data structure members */ while ((tres = list_next(itr))) { while ((field = list_next(itr2))) { switch (field->type) { case PRINT_NAME: field->print_routine(field, tres->name, field_count); break; case PRINT_ID: field->print_routine(field, tres->id, field_count); break; case PRINT_TYPE: field->print_routine(field, tres->type, field_count); break; } } list_iterator_reset(itr2); printf("\n"); } list_iterator_destroy(itr); list_iterator_destroy(itr2); FREE_NULL_LIST(tres_list); FREE_NULL_LIST(print_fields_list); return 0; }