1 /*****************************************************************************\ 2 * proc_args.h - helper functions for command argument processing 3 ***************************************************************************** 4 * Copyright (C) 2007 Hewlett-Packard Development Company, L.P. 5 * Written by Christopher Holmes <cholmes@hp.com>, who borrowed heavily 6 * from existing Slurm source code, particularly src/srun/opt.c 7 * 8 * This file is part of Slurm, a resource management program. 9 * For details, see <https://slurm.schedmd.com/>. 10 * Please also read the included file: DISCLAIMER. 11 * 12 * Slurm is free software; you can redistribute it and/or modify it under 13 * the terms of the GNU General Public License as published by the Free 14 * Software Foundation; either version 2 of the License, or (at your option) 15 * any later version. 16 * 17 * In addition, as a special exception, the copyright holders give permission 18 * to link the code of portions of this program with the OpenSSL library under 19 * certain conditions as described in each individual source file, and 20 * distribute linked combinations including the two. You must obey the GNU 21 * General Public License in all respects for all of the code used other than 22 * OpenSSL. If you modify file(s) with this exception, you may extend this 23 * exception to your version of the file(s), but you are not obligated to do 24 * so. If you do not wish to do so, delete this exception statement from your 25 * version. If you delete this exception statement from all source files in 26 * the program, then also delete it here. 27 * 28 * Slurm is distributed in the hope that it will be useful, but WITHOUT ANY 29 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 30 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 31 * details. 32 * 33 * You should have received a copy of the GNU General Public License along 34 * with Slurm; if not, write to the Free Software Foundation, Inc., 35 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 36 \*****************************************************************************/ 37 38 #ifndef _PROC_ARGS_H 39 #define _PROC_ARGS_H 40 41 #include <sys/types.h> 42 #include <unistd.h> 43 44 #include "src/common/macros.h" /* true and false */ 45 #include "src/common/env.h" 46 47 /* convert task state ID to equivalent string */ 48 extern char *format_task_dist_states(task_dist_states_t t); 49 50 /* print this version of Slurm */ 51 void print_slurm_version(void); 52 53 /* print the available gres options */ 54 void print_gres_help(void); 55 56 /* set distribution type strings from distribution type const */ 57 void set_distribution(task_dist_states_t distribution, 58 char **dist, char **lllp_dist); 59 60 /* verify the requested distribution type */ 61 task_dist_states_t verify_dist_type(const char *arg, uint32_t *plane_size); 62 63 /* return command name from its full path name */ 64 char *base_name(const char *command); 65 66 /* 67 * str_to_mbytes(): verify that arg is numeric with optional "K", "M", "G" 68 * or "T" at end and return the number in mega-bytes. Default units are MB. 69 */ 70 uint64_t str_to_mbytes(const char *arg); 71 72 /* 73 * str_to_mbytes2(): verify that arg is numeric with optional "K", "M", "G" 74 * or "T" at end and return the number in mega-bytes. Default units are GB 75 * if ???, otherwise MB. 76 */ 77 uint64_t str_to_mbytes2(const char *arg); 78 79 /* 80 * Reverse the above conversion. Returns an xmalloc()'d string. 81 */ 82 extern char *mbytes2_to_str(uint64_t mbytes); 83 84 /* verify that a node count in arg is of a known form (count or min-max) */ 85 bool verify_node_count(const char *arg, int *min_nodes, int *max_nodes); 86 87 /* verify a node list is valid based on the dist and task count given */ 88 bool verify_node_list(char **node_list_pptr, enum task_dist_states dist, 89 int task_count); 90 91 /* 92 * get either 1 or 2 integers for a resource count in the form of either 93 * (count, min-max, or '*') 94 * A partial error message is passed in via the 'what' param. 95 * IN arg - argument 96 * IN what - variable name (for errors) 97 * OUT min - first number 98 * OUT max - maximum value if specified, NULL if don't care 99 * IN isFatal - if set, exit on error 100 * RET true if valid 101 */ 102 bool get_resource_arg_range(const char *arg, const char *what, int* min, 103 int *max, bool isFatal); 104 105 /* verify resource counts from a complex form of: X, X:X, X:X:X or X:X:X:X */ 106 bool verify_socket_core_thread_count(const char *arg, int *min_sockets, 107 int *min_cores, int *min_threads, 108 cpu_bind_type_t *cpu_bind_type); 109 110 /* verify a hint and convert it into the implied settings */ 111 bool verify_hint(const char *arg, int *min_sockets, int *min_cores, 112 int *min_threads, int *ntasks_per_core, 113 cpu_bind_type_t *cpu_bind_type); 114 115 /* parse the mail type */ 116 uint16_t parse_mail_type(const char *arg); 117 118 /* print the mail type */ 119 char *print_mail_type(const uint16_t type); 120 121 /* 122 * search PATH to confirm the location and access mode of the given command 123 * IN cwd - current working directory 124 * IN cmd - command to execute 125 * IN check_cwd_last - if true, search cwd after PATH is checked 126 * - if false, search cwd for the command first 127 * IN access_mode - required access rights of cmd 128 * IN test_exec - if false, do not confirm access mode of cmd if full path 129 * RET full path of cmd or NULL if not found 130 */ 131 char *search_path(char *cwd, char *cmd, bool check_cwd_last, int access_mode, 132 bool test_exec); 133 134 /* helper function for printing options */ 135 char *print_commandline(const int script_argc, char **script_argv); 136 137 /* Translate a signal option string "--signal=<int>[@<time>]" into 138 * it's warn_signal and warn_time components. 139 * RET 0 on success, -1 on failure */ 140 int get_signal_opts(char *optarg, uint16_t *warn_signal, uint16_t *warn_time, 141 uint16_t *warn_flags); 142 /* Return an xmalloc()'d string representing the original cmdline args */ 143 extern char *signal_opts_to_cmdline(uint16_t warn_signal, uint16_t warn_time, 144 uint16_t warn_flags); 145 146 /* Convert a signal name to it's numeric equivalent. 147 * Return 0 on failure */ 148 int sig_name2num(const char *signal_name); 149 /* Return an xmalloc()'d string reversing the above conversion */ 150 extern char *sig_num2name(int signal); 151 152 /* 153 * parse_uint16/32/64 - Convert ascii string to a 16/32/64 bit unsigned int. 154 * IN aval - ascii string. 155 * IN/OUT ival - 16/32/64 bit pointer. 156 * RET 0 if no error, 1 otherwise. 157 */ 158 extern int parse_uint16(char *aval, uint16_t *ival); 159 extern int parse_uint32(char *aval, uint32_t *ival); 160 extern int parse_uint64(char *aval, uint64_t *ival); 161 162 /* Get a decimal integer from arg 163 * IN name - command line name 164 * IN val - command line argument value 165 * IN positive - true if number needs to be greater than 0 166 * RET Returns the integer on success, exits program on failure. 167 */ 168 extern int parse_int(const char *name, const char *val, bool positive); 169 170 171 /* print_db_notok() - Print an error message about slurmdbd 172 * is unreachable or wrong cluster name. 173 * IN cname - char * cluster name 174 * IN isenv - bool cluster name from env or from command line option. 175 */ 176 extern void print_db_notok(const char *cname, bool isenv); 177 178 /* 179 * parse_resv_flags() used to parse the Flags= option. It handles 180 * daily, weekly, static_alloc, part_nodes, and maint, optionally 181 * preceded by + or -, separated by a comma but no spaces. 182 * 183 * flagstr IN - reservation flag string 184 * msg IN - string to append to error message (e.g. function name) 185 * resv_msg_ptr IN/OUT - sets flags and times in ptr. 186 * RET equivalent reservation flag bits 187 */ 188 extern uint64_t parse_resv_flags(const char *flagstr, const char *msg, 189 resv_desc_msg_t *resv_msg_ptr); 190 191 extern uint16_t parse_compress_type(const char *arg); 192 193 extern int validate_acctg_freq(char *acctg_freq); 194 195 /* 196 * Format a tres_per_* argument 197 * dest OUT - resulting string 198 * prefix IN - TRES type (e.g. "gpu") 199 * src IN - user input, can include multiple comma-separated specifications 200 */ 201 extern void xfmt_tres(char **dest, char *prefix, char *src); 202 203 /* 204 * Format a tres_freq argument 205 * dest OUT - resulting string 206 * prefix IN - TRES type (e.g. "gpu") 207 * src IN - user input 208 */ 209 extern void xfmt_tres_freq(char **dest, char *prefix, char *src); 210 211 #endif /* !_PROC_ARGS_H */ 212