/*****************************************************************************\ * options.c - option functions for sacct ***************************************************************************** * Copyright (C) 2006-2007 The Regents of the University of California. * Copyright (C) 2008-2009 Lawrence Livermore National Security. * Portions Copyright (C) 2010-2017 SchedMD LLC * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). * Written by Danny Auble . * CODE-OCEC-09-009. All rights reserved. * * This file is part of Slurm, a resource management program. * For details, see . * Please also read the included file: DISCLAIMER. * * Slurm is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free * Software Foundation; either version 2 of the License, or (at your option) * any later version. * * In addition, as a special exception, the copyright holders give permission * to link the code of portions of this program with the OpenSSL library under * certain conditions as described in each individual source file, and * distribute linked combinations including the two. You must obey the GNU * General Public License in all respects for all of the code used other than * OpenSSL. If you modify file(s) with this exception, you may extend this * exception to your version of the file(s), but you are not obligated to do * so. If you do not wish to do so, delete this exception statement from your * version. If you delete this exception statement from all source files in * the program, then also delete it here. * * Slurm is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along * with Slurm; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. \*****************************************************************************/ #include "src/common/parse_time.h" #include "src/common/proc_args.h" #include "src/common/read_config.h" #include "src/common/slurm_time.h" #include "src/common/xstring.h" #include "sacct.h" #include /* getopt_long options, integers but not characters */ #define OPT_LONG_DELIMITER 0x100 #define OPT_LONG_LOCAL 0x101 #define OPT_LONG_NAME 0x102 #define OPT_LONG_NOCONVERT 0x103 #define OPT_LONG_UNITS 0x104 #define OPT_LONG_FEDR 0x105 #define OPT_LONG_WHETJOB 0x106 #define JOB_HASH_SIZE 1000 static void _help_fields_msg(void); static void _help_msg(void); static void _init_params(void); static void _usage(void); List selected_parts = NULL; List selected_steps = NULL; void *acct_db_conn = NULL; List print_fields_list = NULL; ListIterator print_fields_itr = NULL; int field_count = 0; List g_qos_list = NULL; List g_tres_list = NULL; static List _build_cluster_list(slurmdb_federation_rec_t *fed) { slurmdb_cluster_rec_t *cluster; ListIterator iter; List cluster_list; cluster_list = list_create(xfree_ptr); iter = list_iterator_create(fed->cluster_list); while ((cluster = list_next(iter))) (void) slurm_addto_char_list(cluster_list, cluster->name); list_iterator_destroy(iter); return cluster_list; } static void _help_fields_msg(void) { int i; for (i = 0; fields[i].name; i++) { if (i & 3) printf(" "); else if (i) printf("\n"); printf("%-19s", fields[i].name); } printf("\n"); return; } /* returns number of objects added to list */ static int _addto_reason_char_list(List char_list, char *names) { int i = 0, start = 0; uint32_t c; char *name = NULL, *tmp_char = NULL; ListIterator itr = NULL; char quote_c = '\0'; int quote = 0; int count = 0; if (!char_list) { error("No list was given to fill in"); return 0; } itr = list_iterator_create(char_list); if (names) { if (names[i] == '\"' || names[i] == '\'') { quote_c = names[i]; quote = 1; i++; } start = i; while (names[i]) { //info("got %d - %d = %d", i, start, i-start); if (quote && names[i] == quote_c) break; else if (names[i] == '\"' || names[i] == '\'') names[i] = '`'; else if (names[i] == ',') { if ((i-start) > 0) { name = xmalloc((i-start+1)); memcpy(name, names+start, (i-start)); c = job_reason_num(name); if (c == NO_VAL) fatal("unrecognized job reason value %s", name); xfree(name); name = xstrdup_printf("%u", c); while ((tmp_char = list_next(itr))) { if (!xstrcasecmp(tmp_char, name)) break; } if (!tmp_char) { list_append(char_list, name); count++; } else xfree(name); list_iterator_reset(itr); } i++; start = i; if (!names[i]) { info("There is a problem with " "your request. It appears you " "have spaces inside your list."); break; } } i++; } if ((i-start) > 0) { name = xmalloc((i-start)+1); memcpy(name, names+start, (i-start)); c = job_reason_num(name); if (c == NO_VAL) fatal("unrecognized job reason value '%s'", name); xfree(name); name = xstrdup_printf("%u", c); while ((tmp_char = list_next(itr))) { if (!xstrcasecmp(tmp_char, name)) break; } if (!tmp_char) { list_append(char_list, name); count++; } else xfree(name); } } list_iterator_destroy(itr); return count; } static bool _supported_state(uint32_t state_num) { /* Not all state and state flags are accounted */ switch(state_num) { case JOB_PENDING: case JOB_RUNNING: case JOB_SUSPENDED: case JOB_COMPLETE: case JOB_CANCELLED: case JOB_FAILED: case JOB_TIMEOUT: case JOB_NODE_FAIL: case JOB_PREEMPTED: case JOB_BOOT_FAIL: case JOB_DEADLINE: case JOB_OOM: case JOB_REQUEUE: case JOB_RESIZING: case JOB_REVOKED: return true; break; default: return false; break; } } /* returns number of objects added to list */ /* also checks if states are supported by sacct and fatals if not */ static int _addto_state_char_list(List char_list, char *names) { int i = 0, start = 0; uint32_t c; char *name = NULL, *tmp_char = NULL; ListIterator itr = NULL; char quote_c = '\0'; int quote = 0; int count = 0; if (!char_list) { error("No list was given to fill in"); return 0; } itr = list_iterator_create(char_list); if (names) { if (names[i] == '\"' || names[i] == '\'') { quote_c = names[i]; quote = 1; i++; } start = i; while (names[i]) { //info("got %d - %d = %d", i, start, i-start); if (quote && names[i] == quote_c) break; else if (names[i] == '\"' || names[i] == '\'') names[i] = '`'; else if (names[i] == ',') { if ((i-start) > 0) { name = xmalloc((i-start+1)); memcpy(name, names+start, (i-start)); c = job_state_num(name); if (c == NO_VAL) fatal("unrecognized job state value %s", name); if (!_supported_state(c)) fatal("job state %s is not supported / accounted", name); xfree(name); name = xstrdup_printf("%d", c); while ((tmp_char = list_next(itr))) { if (!xstrcasecmp(tmp_char, name)) break; } if (!tmp_char) { list_append(char_list, name); count++; } else xfree(name); list_iterator_reset(itr); } i++; start = i; if (!names[i]) { info("There is a problem with " "your request. It appears you " "have spaces inside your list."); break; } } i++; } if ((i-start) > 0) { name = xmalloc((i-start)+1); memcpy(name, names+start, (i-start)); c = job_state_num(name); if (c == NO_VAL) fatal("unrecognized job state value '%s'", name); if (!_supported_state(c)) fatal("job state %s is not supported / accounted", name); xfree(name); name = xstrdup_printf("%d", c); while ((tmp_char = list_next(itr))) { if (!xstrcasecmp(tmp_char, name)) break; } if (!tmp_char) { list_append(char_list, name); count++; } else xfree(name); } } list_iterator_destroy(itr); return count; } static void _help_msg(void) { printf("\ sacct [