static void _process_uw(List user_list, slurmdb_wckey_rec_t *wckey) { slurmdb_report_user_rec_t *slurmdb_report_user = NULL; struct passwd *passwd_ptr = NULL; uid_t uid = NO_VAL; passwd_ptr = getpwnam(wckey->user); if (passwd_ptr) uid = passwd_ptr->pw_uid; /* In this report we are using the slurmdb_report user structure to store the information we want since it is already available and will do pretty much what we want. */ slurmdb_report_user = xmalloc(sizeof(slurmdb_report_user_rec_t)); slurmdb_report_user->name = xstrdup(wckey->user); slurmdb_report_user->uid = uid; slurmdb_report_user->acct = xstrdup(wckey->name); list_append(user_list, slurmdb_report_user); /* get the amount of time this wckey used during the time we are looking at */ slurmdb_transfer_acct_list_2_tres(wckey->accounting_list, &slurmdb_report_user->tres_list); }
static void _process_wu(List assoc_list, slurmdb_wckey_rec_t *wckey) { slurmdb_report_assoc_rec_t *slurmdb_report_assoc = NULL, *parent_assoc = NULL; ListIterator itr = NULL; /* find the parent */ itr = list_iterator_create(assoc_list); while((parent_assoc = list_next(itr))) { if (!parent_assoc->user && !xstrcmp(parent_assoc->acct, wckey->name)) break; } list_iterator_destroy(itr); if (!parent_assoc) { parent_assoc = xmalloc(sizeof(slurmdb_report_assoc_rec_t)); list_append(assoc_list, parent_assoc); parent_assoc->acct = xstrdup(wckey->name); } /* now add one for the user */ slurmdb_report_assoc = xmalloc(sizeof(slurmdb_report_assoc_rec_t)); list_append(assoc_list, slurmdb_report_assoc); slurmdb_report_assoc->acct = xstrdup(wckey->name); slurmdb_report_assoc->user = xstrdup(wckey->user); /* get the amount of time this wckey used during the time we are looking at */ slurmdb_transfer_acct_list_2_tres(wckey->accounting_list, &slurmdb_report_assoc->tres_list); slurmdb_transfer_acct_list_2_tres(wckey->accounting_list, &parent_assoc->tres_list); }
static void _process_au(List assoc_list, slurmdb_assoc_rec_t *assoc) { slurmdb_report_assoc_rec_t *slurmdb_report_assoc = xmalloc(sizeof(slurmdb_report_assoc_rec_t)); list_append(assoc_list, slurmdb_report_assoc); slurmdb_report_assoc->acct = xstrdup(assoc->acct); slurmdb_report_assoc->cluster = xstrdup(assoc->cluster); slurmdb_report_assoc->parent_acct = xstrdup(assoc->parent_acct); slurmdb_report_assoc->user = xstrdup(assoc->user); /* get the amount of time this assoc used during the time we are looking at */ slurmdb_transfer_acct_list_2_tres(assoc->accounting_list, &slurmdb_report_assoc->tres_list); }
static void _process_ua(List user_list, slurmdb_assoc_rec_t *assoc) { ListIterator itr = NULL; slurmdb_report_user_rec_t *slurmdb_report_user = NULL; /* make sure we add all associations to this user rec because we could have some in partitions which would create another record otherwise */ itr = list_iterator_create(user_list); while((slurmdb_report_user = list_next(itr))) { if (!xstrcmp(slurmdb_report_user->name, assoc->user) && !xstrcmp(slurmdb_report_user->acct, assoc->acct)) break; } list_iterator_destroy(itr); if (!slurmdb_report_user) { struct passwd *passwd_ptr = NULL; uid_t uid = NO_VAL; passwd_ptr = getpwnam(assoc->user); if (passwd_ptr) uid = passwd_ptr->pw_uid; /* In this report we are using the slurmdb_report user structure to store the information we want since it is already available and will do pretty much what we want. */ slurmdb_report_user = xmalloc(sizeof(slurmdb_report_user_rec_t)); slurmdb_report_user->name = xstrdup(assoc->user); slurmdb_report_user->uid = uid; slurmdb_report_user->acct = xstrdup(assoc->acct); list_append(user_list, slurmdb_report_user); } /* get the amount of time this assoc used during the time we are looking at */ slurmdb_transfer_acct_list_2_tres(assoc->accounting_list, &slurmdb_report_user->tres_list); }
extern List slurmdb_report_user_top_usage(void *db_conn, slurmdb_user_cond_t *user_cond, bool group_accounts) { List cluster_list = NULL; ListIterator itr = NULL; ListIterator itr2 = NULL; ListIterator itr3 = NULL; ListIterator cluster_itr = NULL; slurmdb_cluster_cond_t cluster_cond; List user_list = NULL; List usage_cluster_list = NULL; char *object = NULL; int exit_code = 0; slurmdb_user_rec_t *user = NULL; slurmdb_cluster_rec_t *cluster = NULL; slurmdb_assoc_rec_t *assoc = NULL; slurmdb_report_user_rec_t *slurmdb_report_user = NULL; slurmdb_report_cluster_rec_t *slurmdb_report_cluster = NULL; uid_t my_uid = getuid(); bool delete_user_cond = 0, delete_assoc_cond = 0, delete_cluster_list = 0; time_t start_time, end_time; if (!user_cond) { delete_user_cond = 1; user_cond = xmalloc(sizeof(slurmdb_user_cond_t)); } if (!user_cond->assoc_cond) { delete_assoc_cond = 1; user_cond->assoc_cond = xmalloc(sizeof(slurmdb_assoc_cond_t)); } if (!user_cond->assoc_cond->cluster_list) { delete_cluster_list = 1; user_cond->assoc_cond->cluster_list = list_create(slurm_destroy_char); } user_cond->with_deleted = 1; user_cond->with_assocs = 1; user_cond->assoc_cond->with_usage = 1; user_cond->assoc_cond->without_parent_info = 1; /* This needs to be done on some systems to make sure assoc_cond isn't messed up. This has happened on some 64 bit machines and this is here to be on the safe side. */ start_time = user_cond->assoc_cond->usage_start; end_time = user_cond->assoc_cond->usage_end; slurmdb_report_set_start_end_time(&start_time, &end_time); user_cond->assoc_cond->usage_start = start_time; user_cond->assoc_cond->usage_end = end_time; user_list = acct_storage_g_get_users(db_conn, my_uid, user_cond); if (!user_list) { exit_code=1; fprintf(stderr, " Problem with user query.\n"); goto end_it; } /* We have to get the clusters here or we will be unable to get the correct total time for the cluster if associations are not enforced. */ slurmdb_init_cluster_cond(&cluster_cond, 0); cluster_cond.with_usage = 1; cluster_cond.with_deleted = 1; cluster_cond.usage_end = user_cond->assoc_cond->usage_end; cluster_cond.usage_start = user_cond->assoc_cond->usage_start; cluster_cond.cluster_list = user_cond->assoc_cond->cluster_list; usage_cluster_list = acct_storage_g_get_clusters( db_conn, my_uid, &cluster_cond); if (!usage_cluster_list) { exit_code=1; fprintf(stderr, " Problem with cluster query.\n"); goto end_it; } cluster_list = list_create(slurmdb_destroy_report_cluster_rec); itr = list_iterator_create(usage_cluster_list); while((cluster = list_next(itr))) { /* check to see if this cluster is around during the time we are looking at */ if (!cluster->accounting_list || !list_count(cluster->accounting_list)) continue; slurmdb_report_cluster = slurmdb_cluster_rec_2_report(cluster); list_append(cluster_list, slurmdb_report_cluster); slurmdb_report_cluster->user_list = list_create(slurmdb_destroy_report_user_rec); } list_iterator_destroy(itr); list_destroy(usage_cluster_list); itr = list_iterator_create(user_list); cluster_itr = list_iterator_create(cluster_list); while((user = list_next(itr))) { struct passwd *passwd_ptr = NULL; if (!user->assoc_list || !list_count(user->assoc_list)) continue; passwd_ptr = getpwnam(user->name); if (passwd_ptr) user->uid = passwd_ptr->pw_uid; else user->uid = (uint32_t)NO_VAL; itr2 = list_iterator_create(user->assoc_list); while((assoc = list_next(itr2))) { if (!assoc->accounting_list || !list_count(assoc->accounting_list)) continue; while((slurmdb_report_cluster = list_next(cluster_itr))) { if (!strcmp(slurmdb_report_cluster->name, assoc->cluster)) { ListIterator user_itr = NULL; if (!group_accounts) { slurmdb_report_user = NULL; goto new_user; } user_itr = list_iterator_create( slurmdb_report_cluster-> user_list); while((slurmdb_report_user = list_next(user_itr))) { if (slurmdb_report_user->uid != NO_VAL) { if (slurmdb_report_user-> uid == user->uid) break; } else if (slurmdb_report_user-> name && !strcasecmp( slurmdb_report_user-> name, user->name)) break; } list_iterator_destroy(user_itr); new_user: if (!slurmdb_report_user) { slurmdb_report_user = xmalloc( sizeof (slurmdb_report_user_rec_t)); slurmdb_report_user->name = xstrdup(assoc->user); slurmdb_report_user->uid = user->uid; slurmdb_report_user->acct_list = list_create (slurm_destroy_char); list_append(slurmdb_report_cluster-> user_list, slurmdb_report_user); } break; } } if (!slurmdb_report_cluster) { error("This cluster '%s' hasn't " "registered yet, but we have jobs " "that ran?", assoc->cluster); slurmdb_report_cluster = xmalloc(sizeof(slurmdb_report_cluster_rec_t)); list_append(cluster_list, slurmdb_report_cluster); slurmdb_report_cluster->name = xstrdup(assoc->cluster); slurmdb_report_cluster->user_list = list_create(slurmdb_destroy_report_user_rec); slurmdb_report_user = xmalloc(sizeof(slurmdb_report_user_rec_t)); slurmdb_report_user->name = xstrdup(assoc->user); slurmdb_report_user->uid = user->uid; slurmdb_report_user->acct_list = list_create(slurm_destroy_char); list_append(slurmdb_report_cluster->user_list, slurmdb_report_user); } list_iterator_reset(cluster_itr); itr3 = list_iterator_create( slurmdb_report_user->acct_list); while((object = list_next(itr3))) { if (!strcmp(object, assoc->acct)) break; } list_iterator_destroy(itr3); if (!object) list_append(slurmdb_report_user->acct_list, xstrdup(assoc->acct)); slurmdb_transfer_acct_list_2_tres( assoc->accounting_list, &slurmdb_report_user->tres_list); } list_iterator_destroy(itr2); } list_iterator_destroy(itr); list_iterator_destroy(cluster_itr); end_it: if (delete_cluster_list) { list_destroy(user_cond->assoc_cond->cluster_list); user_cond->assoc_cond->cluster_list = NULL; } if (delete_assoc_cond) { slurmdb_destroy_assoc_cond(user_cond->assoc_cond); user_cond->assoc_cond = NULL; } if (delete_user_cond) { slurmdb_destroy_user_cond(user_cond); user_cond = NULL; } if (user_list) { list_destroy(user_list); user_list = NULL; } if (exit_code) { if (cluster_list) { list_destroy(cluster_list); cluster_list = NULL; } } return cluster_list; }