1 /*****************************************************************************\ 2 * slurmdb_defs.h - definitions used by slurmdb api 3 ****************************************************************************** 4 * Copyright (C) 2010 Lawrence Livermore National Security. 5 * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 6 * Written by Danny Auble da@llnl.gov, et. al. 7 * CODE-OCEC-09-009. All rights reserved. 8 * 9 * This file is part of Slurm, a resource management program. 10 * For details, see <https://slurm.schedmd.com/>. 11 * Please also read the included file: DISCLAIMER. 12 * 13 * Slurm is free software; you can redistribute it and/or modify it under 14 * the terms of the GNU General Public License as published by the Free 15 * Software Foundation; either version 2 of the License, or (at your option) 16 * any later version. 17 * 18 * In addition, as a special exception, the copyright holders give permission 19 * to link the code of portions of this program with the OpenSSL library under 20 * certain conditions as described in each individual source file, and 21 * distribute linked combinations including the two. You must obey the GNU 22 * General Public License in all respects for all of the code used other than 23 * OpenSSL. If you modify file(s) with this exception, you may extend this 24 * exception to your version of the file(s), but you are not obligated to do 25 * so. If you do not wish to do so, delete this exception statement from your 26 * version. If you delete this exception statement from all source files in 27 * the program, then also delete it here. 28 * 29 * Slurm is distributed in the hope that it will be useful, but WITHOUT ANY 30 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 31 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 32 * details. 33 * 34 * You should have received a copy of the GNU General Public License along 35 * with Slurm; if not, write to the Free Software Foundation, Inc., 36 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 37 \*****************************************************************************/ 38 #ifndef _SLURMDB_DEFS_H 39 #define _SLURMDB_DEFS_H 40 41 #include "slurm/slurmdb.h" 42 43 /* Defined purge macros */ 44 #define SLURMDB_PURGE_GET_UNITS(_X) \ 45 (_X & SLURMDB_PURGE_BASE) 46 #define SLURMDB_PURGE_ARCHIVE_SET(_X) \ 47 (_X != NO_VAL && _X & SLURMDB_PURGE_ARCHIVE) 48 #define SLURMDB_PURGE_IN_HOURS(_X) \ 49 (_X != NO_VAL && _X & SLURMDB_PURGE_HOURS) 50 #define SLURMDB_PURGE_IN_DAYS(_X) \ 51 (_X != NO_VAL && _X & SLURMDB_PURGE_DAYS) 52 #define SLURMDB_PURGE_IN_MONTHS(_X) \ 53 (_X != NO_VAL && _X & SLURMDB_PURGE_MONTHS) 54 55 /* This is used to point out constants that exist in the 56 * TRES records. This should be the same order as 57 * the enum pointing out the order in the array that is defined in 58 * src/slurmctld/slurmctld.h. If this changes please also update 59 * src/plugins/accounting_storage/filetxt/accounting_storage_filetxt.c 60 * acct_storage_p_get_tres() to reflect things as it is static. 61 */ 62 typedef enum { 63 TRES_CPU = 1, 64 TRES_MEM, 65 TRES_ENERGY, 66 TRES_NODE, 67 TRES_BILLING, 68 TRES_FS_DISK, 69 TRES_VMEM, 70 TRES_PAGES, 71 TRES_STATIC_CNT 72 } tres_types_t; 73 74 /* These #defines are for the tres_str functions below and should be 75 * sent when flags are allowed in the functions. 76 */ 77 #define TRES_STR_FLAG_NONE 0x00000000 /* No flags, meaning by 78 * default the string 79 * will contain -1 and 80 * be unique honoring 81 * the first value found 82 * in an incoming string */ 83 #define TRES_STR_FLAG_ONLY_CONCAT 0x00000001 /* Only concat the 84 * string, this will 85 * most likely trump the 86 * other flags below. */ 87 #define TRES_STR_FLAG_REPLACE 0x00000002 /* Replace previous count 88 * values found, if this 89 * is not set duplicate 90 * entries will be skipped. */ 91 #define TRES_STR_FLAG_REMOVE 0x00000004 /* If -1 entries are 92 * found remove them, by 93 * default they will be 94 * added to the string 95 */ 96 #define TRES_STR_FLAG_SORT_ID 0x00000008 /* sort string by ID */ 97 #define TRES_STR_FLAG_SIMPLE 0x00000010 /* make a simple string */ 98 #define TRES_STR_FLAG_COMMA1 0x00000020 /* make a first char a comma */ 99 #define TRES_STR_FLAG_NO_NULL 0x00000040 /* return blank string 100 * instead of NULL */ 101 #define TRES_STR_CONVERT_UNITS 0x00000080 /* Convert number units */ 102 #define TRES_STR_FLAG_SUM 0x00000100 /* Sum entries of the same type 103 * ignoring -1 */ 104 #define TRES_STR_FLAG_MAX 0x00000200 /* Set Max value from entries of 105 * the same type ignoring -1 */ 106 #define TRES_STR_FLAG_MIN 0x00000400 /* Set Min value from entries of 107 * the same type ignoring -1 */ 108 #define TRES_STR_FLAG_ALLOW_REAL 0x00000800 /* Allow all counts (even zero) 109 * unless INFINITE64 or NO_VAL64 */ 110 #define TRES_STR_FLAG_BYTES 0x00000800 /* Convertable Usage in Bytes */ 111 112 typedef struct { 113 slurmdb_cluster_rec_t *cluster_rec; 114 int preempt_cnt; 115 time_t start_time; 116 } local_cluster_rec_t; 117 118 extern slurmdb_job_rec_t *slurmdb_create_job_rec(); 119 extern slurmdb_step_rec_t *slurmdb_create_step_rec(); 120 extern slurmdb_assoc_usage_t *slurmdb_create_assoc_usage(int tres_cnt); 121 extern slurmdb_qos_usage_t *slurmdb_create_qos_usage(int tres_cnt); 122 123 extern char *slurmdb_cluster_fed_states_str(uint32_t states); 124 extern uint32_t str_2_cluster_fed_states(char *states); 125 extern char *slurmdb_federation_flags_str(uint32_t flags); 126 extern uint32_t str_2_federation_flags(char *flags, int option); 127 extern char *slurmdb_job_flags_str(uint32_t flags); 128 extern uint32_t str_2_job_flags(char *flags); 129 extern char *slurmdb_qos_str(List qos_list, uint32_t level); 130 extern uint32_t str_2_slurmdb_qos(List qos_list, char *level); 131 extern char *slurmdb_qos_flags_str(uint32_t flags); 132 extern uint32_t str_2_qos_flags(char *flags, int option); 133 extern char *slurmdb_res_flags_str(uint32_t flags); 134 extern uint32_t str_2_res_flags(char *flags, int option); 135 extern char *slurmdb_res_type_str(slurmdb_resource_type_t type); 136 137 extern char *slurmdb_admin_level_str(slurmdb_admin_level_t level); 138 extern slurmdb_admin_level_t str_2_slurmdb_admin_level(char *level); 139 140 /* The next three functions have pointers to assoc_list so do not 141 * destroy assoc_list before using the list returned from this function. 142 */ 143 extern List slurmdb_get_hierarchical_sorted_assoc_list(List assoc_list, 144 bool use_lft); 145 extern List slurmdb_get_acct_hierarchical_rec_list(List assoc_list); 146 extern List slurmdb_get_acct_hierarchical_rec_list_no_lft(List assoc_list); 147 148 /* This reorders the list into a alphabetical hierarchy. 149 IN/OUT: assoc_list 150 */ 151 extern void slurmdb_sort_hierarchical_assoc_list(List assoc_list, bool use_lft); 152 153 /* IN/OUT: tree_list a list of slurmdb_print_tree_t's */ 154 extern char *slurmdb_tree_name_get(char *name, char *parent, List tree_list); 155 156 extern int set_qos_bitstr_from_string(bitstr_t *valid_qos, char *names); 157 extern int set_qos_bitstr_from_list(bitstr_t *valid_qos, List qos_list); 158 extern char *get_qos_complete_str_bitstr(List qos_list, bitstr_t *valid_qos); 159 extern char *get_qos_complete_str(List qos_list, List num_qos_list); 160 161 extern char *get_classification_str(uint16_t classification); 162 extern uint16_t str_2_classification(char *classification); 163 164 extern const char *rollup_interval_to_string(int interval); 165 166 extern char *slurmdb_problem_str_get(uint16_t problem); 167 extern uint16_t str_2_slurmdb_problem(char *problem); 168 169 extern void log_assoc_rec(slurmdb_assoc_rec_t *assoc_ptr, List qos_list); 170 171 extern int slurmdb_report_set_start_end_time(time_t *start, time_t *end); 172 173 extern uint32_t slurmdb_parse_purge(char *string); 174 extern char *slurmdb_purge_string(uint32_t purge, char *string, int len, 175 bool with_archive); 176 extern int slurmdb_addto_qos_char_list(List char_list, List qos_list, 177 char *names, int option); 178 extern int slurmdb_send_accounting_update(List update_list, char *cluster, 179 char *host, uint16_t port, 180 uint16_t rpc_version); 181 extern slurmdb_report_cluster_rec_t *slurmdb_cluster_rec_2_report( 182 slurmdb_cluster_rec_t *cluster); 183 184 /* OUT: job_id_str - filled in with the id of the job/array 185 * RET: job_id_str */ 186 extern char *slurmdb_get_selected_step_id( 187 char *job_id_str, int len, 188 slurmdb_selected_step_t *selected_step); 189 /* OUT: out - copy grp/max/qos limits from in 190 * IN: in - what to copy from 191 */ 192 extern void slurmdb_copy_assoc_rec_limits(slurmdb_assoc_rec_t *out, 193 slurmdb_assoc_rec_t *in); 194 extern void slurmdb_copy_cluster_rec(slurmdb_cluster_rec_t *out, 195 slurmdb_cluster_rec_t *in); 196 extern void slurmdb_copy_federation_rec(slurmdb_federation_rec_t *out, 197 slurmdb_federation_rec_t *in); 198 extern void slurmdb_copy_qos_rec_limits(slurmdb_qos_rec_t *out, 199 slurmdb_qos_rec_t *in); 200 extern slurmdb_tres_rec_t *slurmdb_copy_tres_rec(slurmdb_tres_rec_t *tres); 201 extern List slurmdb_copy_tres_list(List tres); 202 extern List slurmdb_diff_tres_list(List tres_list_old, List tres_list_new); 203 extern char *slurmdb_tres_string_combine_lists( 204 List tres_list_old, List tres_list_new); 205 /* make a tres_string from a given list 206 * IN tres - list of slurmdb_tres_rec_t's 207 * IN flags - see the TRES_STR_FLAGS above 208 * Meaningful flags are TRES_STR_FLAG_SIMPLE 209 * TRES_STR_FLAG_COMMA1 210 * RET char * of tres_str 211 */ 212 extern char *slurmdb_make_tres_string(List tres, uint32_t flags); 213 extern char *slurmdb_format_tres_str( 214 char *tres_in, List full_tres_list, bool simple); 215 /* 216 * Comparator used for sorting tres by id 217 * 218 * returns: -1 tres_a < tres_b 0: tres_a == tres_b 1: tres_a > tres_b 219 * 220 */ 221 extern int slurmdb_sort_tres_by_id_asc(void *v1, void *v2); 222 223 /* Used to turn a tres string into a list containing 224 * slurmdb_tres_rec_t's with only id's and counts filled in, no 225 * formatted types or names. 226 * 227 * IN/OUT: tres_list - list created from the simple tres string 228 * IN : tres - simple string you want convert 229 * IN : flags - see the TRES_STR_FLAGS above 230 * Meaningful flags are TRES_STR_FLAG_REPLACE 231 * TRES_STR_FLAG_REMOVE 232 * TRES_STR_FLAG_SORT_ID 233 */ 234 extern void slurmdb_tres_list_from_string( 235 List *tres_list, char *tres, uint32_t flags); 236 237 /* combine a name array and count array into a string */ 238 extern char *slurmdb_make_tres_string_from_arrays(char **tres_names, 239 uint64_t *tres_cnts, 240 uint32_t tres_cnt, 241 uint32_t flags); 242 243 extern char *slurmdb_make_tres_string_from_simple( 244 char *tres_in, List full_tres_list, int spec_unit, 245 uint32_t convert_flags, uint32_t tres_str_flags, char *nodes); 246 247 /* Used to combine 2 different TRES strings together 248 * 249 * IN/OUT: tres_str_old - original simple tres string 250 * IN : tres_str_new - string you want added 251 * IN : flags - see the TRES_STR_FLAGS above 252 * Meaningful flags are TRES_STR_FLAG_ONLY_CONCAT 253 * TRES_STR_FLAG_REPLACE 254 * TRES_STR_FLAG_REMOVE 255 * TRES_STR_FLAG_SORT_ID 256 * TRES_STR_FLAG_SIMPLE 257 * TRES_STR_FLAG_COMMA1 258 * TRES_STR_FLAG_NO_NULL 259 * RET : new tres_str_old - the new string (also sent out) 260 */ 261 extern char *slurmdb_combine_tres_strings( 262 char **tres_str_old, char *tres_str_new, uint32_t flags); 263 extern slurmdb_tres_rec_t *slurmdb_find_tres_in_string( 264 char *tres_str_in, int id); 265 extern uint64_t slurmdb_find_tres_count_in_string(char *tres_str_in, int id); 266 extern int slurmdb_find_qos_in_list_by_name(void *x, void *key); 267 extern int slurmdb_find_qos_in_list(void *x, void *key); 268 extern int slurmdb_find_selected_step_in_list(void *x, void *key); 269 extern int slurmdb_find_assoc_in_list(void *x, void *key); 270 extern int slurmdb_find_update_object_in_list(void *x, void *key); 271 extern int slurmdb_find_tres_in_list(void *x, void *key); 272 extern int slurmdb_find_tres_in_list_by_count(void *x, void *key); 273 extern int slurmdb_find_tres_in_list_by_type(void *x, void *key); 274 extern int slurmdb_find_cluster_in_list(void *x, void *key); 275 extern int slurmdb_find_cluster_accting_tres_in_list(void *x, void *key); 276 extern int slurmdb_add_cluster_accounting_to_tres_list( 277 slurmdb_cluster_accounting_rec_t *accting, 278 List *tres); 279 extern int slurmdb_add_accounting_to_tres_list( 280 slurmdb_accounting_rec_t *accting, 281 List *tres); 282 extern int slurmdb_add_time_from_count_to_tres_list( 283 slurmdb_tres_rec_t *tres_in, List *tres, time_t elapsed); 284 extern int slurmdb_sum_accounting_list( 285 slurmdb_cluster_accounting_rec_t *accting, 286 List *total_tres_acct); 287 extern void slurmdb_transfer_acct_list_2_tres( 288 List accounting_list, List *tres); 289 extern void slurmdb_transfer_tres_time( 290 List *tres_list_out, char *tres_str, int elapsed); 291 292 extern int slurmdb_get_tres_base_unit(char *tres_type); 293 extern char *slurmdb_ave_tres_usage(char *tres_string, int tasks); 294 295 /* Setup cluster rec with plugin_id that indexes into select list */ 296 extern int slurmdb_setup_cluster_rec(slurmdb_cluster_rec_t *cluster_rec); 297 298 extern void slurmdb_job_cond_def_start_end(slurmdb_job_cond_t *job_cond); 299 extern int slurmdb_job_sort_by_submit_time(void *v1, void *v2); 300 301 #endif 302