diff --git a/contribs/perlapi/libslurm-perl/Slurm.xs b/contribs/perlapi/libslurm-perl/Slurm.xs index 7bde7dc493bb71da6bba5614a5d270aee64e665b..8c83a9df1f261136a4fe7c4ac8c20a3d1e858102 100644 --- a/contribs/perlapi/libslurm-perl/Slurm.xs +++ b/contribs/perlapi/libslurm-perl/Slurm.xs @@ -20,13 +20,6 @@ extern void slurm_api_clear_config(void); slurm_xfree((void **)&(__p), __FILE__, __LINE__, "") extern void slurm_xfree(void **, const char *, int, const char *); -extern int slurm_hostlist_count(hostlist_t hl); -extern int slurm_hostlist_push(hostlist_t hl, const char *hosts); -extern int slurm_hostlist_push_host(hostlist_t hl, const char *host); -extern int slurm_hostlist_find(hostlist_t hl, const char *hostname); -extern size_t slurm_hostlist_ranged_string(hostlist_t hl, size_t n, char *buf); -extern void slurm_hostlist_uniq(hostlist_t hl); - struct slurm { node_info_msg_t *node_info_msg; partition_info_msg_t *part_info_msg; @@ -753,14 +746,19 @@ slurm_get_triggers(slurm_t self) ################################################################## MODULE=Slurm PACKAGE=Slurm::Hostlist PREFIX=slurm_hostlist_ +int +slurm_hostlist_count(hostlist_t hl = NULL) + OUTPUT: + RETVAL + hostlist_t slurm_hostlist_create(char* hostlist) int -slurm_hostlist_count(hostlist_t hl = NULL) +slurm_hostlist_find(hostlist_t hl = NULL, char* hostname) OUTPUT: RETVAL - + int slurm_hostlist_push(hostlist_t hl = NULL, char* hosts) OUTPUT: @@ -771,8 +769,17 @@ slurm_hostlist_push_host(hostlist_t hl = NULL, char* host) OUTPUT: RETVAL -int -slurm_hostlist_find(hostlist_t hl = NULL, char* hostname) +char* +slurm_hostlist_ranged_string(hostlist_t hl = NULL) + PREINIT: + size_t size = 1024; + int rc = 0; + CODE: + Newz(0, RETVAL, size, char); + while((rc = slurm_hostlist_ranged_string(hl, size, RETVAL)) == -1) { + size *= 2; + Renew(RETVAL, size, char); + } OUTPUT: RETVAL @@ -791,20 +798,6 @@ slurm_hostlist_shift(hostlist_t hl = NULL) OUTPUT: RETVAL -char* -slurm_hostlist_ranged_string(hostlist_t hl = NULL) - PREINIT: - size_t size = 1024; - int rc = 0; - CODE: - Newz(0, RETVAL, size, char); - while((rc = slurm_hostlist_ranged_string(hl, size, RETVAL)) == -1) { - size *= 2; - Renew(RETVAL, size, char); - } - OUTPUT: - RETVAL - void slurm_hostlist_uniq(hostlist_t hl = NULL) CODE: diff --git a/slurm/slurm.h.in b/slurm/slurm.h.in index a9f39cbf19ddc978693af437fb698c5bcd95155d..f464f0507e82ba9d33ccf1235fb0469cee2a8b54 100644 --- a/slurm/slurm.h.in +++ b/slurm/slurm.h.in @@ -2380,6 +2380,64 @@ extern int slurm_checkpoint_tasks PARAMS(( uint32_t job_id, uint16_t step_id, */ extern hostlist_t slurm_hostlist_create PARAMS(( const char *hostlist )); +/* slurm_hostlist_count(): + * + * Return the number of hosts in hostlist hl. + */ +extern int slurm_hostlist_count PARAMS((hostlist_t hl)); + +/* + * slurm_hostlist_destroy(): + * + * Destroy a hostlist object. Frees all memory allocated to the hostlist. + */ +extern void slurm_hostlist_destroy PARAMS(( hostlist_t hl )); + +/* slurm_hostlist_find(): + * + * Searches hostlist hl for the first host matching hostname + * and returns position in list if found. + * + * Returns -1 if host is not found. + * + */ +extern int slurm_hostlist_find PARAMS((hostlist_t hl, const char *hostname)); + +/* slurm_hostlist_push(): + * + * push a string representation of hostnames onto a hostlist. + * + * The hosts argument may take the same form as in slurm_hostlist_create() + * + * Returns the number of hostnames inserted into the list, + * or 0 on failure. + */ +extern int slurm_hostlist_push PARAMS((hostlist_t hl, const char *hosts)); + +/* slurm_hostlist_push_host(): + * + * Push a single host onto the hostlist hl. + * This function is more efficient than slurm_hostlist_push() for a single + * hostname, since the argument does not need to be checked for ranges. + * + * return value is 1 for success, 0 for failure. + */ +extern int slurm_hostlist_push_host PARAMS((hostlist_t hl, const char *host)); + +/* slurm_hostlist_ranged_string(): + * + * Write the string representation of the hostlist hl into buf, + * writing at most n chars. Returns the number of bytes written, + * or -1 if truncation occurred. + * + * The result will be NULL terminated. + * + * slurm_hostlist_ranged_string() will write a bracketed hostlist representation + * where possible. + */ +extern size_t slurm_hostlist_ranged_string PARAMS((hostlist_t hl, + size_t n, char *buf)); + /* * slurm_hostlist_shift(): * @@ -2391,12 +2449,12 @@ extern hostlist_t slurm_hostlist_create PARAMS(( const char *hostlist )); */ extern char * slurm_hostlist_shift PARAMS(( hostlist_t hl )); -/* - * slurm_hostlist_destroy(): +/* slurm_hostlist_uniq(): * - * Destroy a hostlist object. Frees all memory allocated to the hostlist. + * Sort the hostlist hl and remove duplicate entries. + * */ -extern void slurm_hostlist_destroy PARAMS(( hostlist_t hl )); +extern void slurm_hostlist_uniq PARAMS((hostlist_t hl)); /*****************************************************************************\ * SLURM TRIGGER FUNCTIONS diff --git a/src/api/Makefile.am b/src/api/Makefile.am index ef5543cba7a976fd49cb2b9a8be8bb74b413208e..2b31344aad7f648aad5bfad756998475ef3ed8f0 100644 --- a/src/api/Makefile.am +++ b/src/api/Makefile.am @@ -78,6 +78,7 @@ slurmapi_src = \ partition_info.c \ reservation_info.c \ signal.c \ + slurm_hostlist.c \ slurm_pmi.c slurm_pmi.h \ step_ctx.c step_ctx.h \ step_io.c step_io.h \ diff --git a/src/api/Makefile.in b/src/api/Makefile.in index 95e789421db0e908790bc1ba7b046810b890e808..21115e913add3ab7603ee6967c7ff664b468f479 100644 --- a/src/api/Makefile.in +++ b/src/api/Makefile.in @@ -101,9 +101,10 @@ libslurmhelper_la_DEPENDENCIES = $(am__DEPENDENCIES_1) am__objects_1 = allocate.lo allocate_msg.lo cancel.lo checkpoint.lo \ complete.lo config_info.lo init_msg.lo job_info.lo \ job_step_info.lo node_info.lo node_select_info.lo \ - partition_info.lo reservation_info.lo signal.lo slurm_pmi.lo \ - step_ctx.lo step_io.lo step_launch.lo pmi_server.lo submit.lo \ - suspend.lo triggers.lo reconfigure.lo update_config.lo + partition_info.lo reservation_info.lo signal.lo \ + slurm_hostlist.lo slurm_pmi.lo step_ctx.lo step_io.lo \ + step_launch.lo pmi_server.lo submit.lo suspend.lo triggers.lo \ + reconfigure.lo update_config.lo am_libslurmhelper_la_OBJECTS = $(am__objects_1) libslurmhelper_la_OBJECTS = $(am_libslurmhelper_la_OBJECTS) PROGRAMS = $(noinst_PROGRAMS) @@ -378,6 +379,7 @@ slurmapi_src = \ partition_info.c \ reservation_info.c \ signal.c \ + slurm_hostlist.c \ slurm_pmi.c slurm_pmi.h \ step_ctx.c step_ctx.h \ step_io.c step_io.h \ @@ -544,6 +546,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/reconfigure.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/reservation_info.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/signal.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/slurm_hostlist.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/slurm_pmi.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/step_ctx.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/step_io.Plo@am__quote@ diff --git a/src/api/slurm_hostlist.c b/src/api/slurm_hostlist.c new file mode 100644 index 0000000000000000000000000000000000000000..bc1bd7ffdf961cf4aab5d293d792bdae28ee5dae --- /dev/null +++ b/src/api/slurm_hostlist.c @@ -0,0 +1,96 @@ +/****************************************************************************\ + * slurm_hostname.c - wrapper functions to allow for systems that + * don't allow strong alias' + ***************************************************************************** + * Copyright (C) 2009 Lawrence Livermore National Security. + * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). + * Written by Danny Auble <da@llnl.gov>. + * LLNL-CODE-402394. + * + * This file is part of SLURM, a resource management program. + * For details, see <https://computing.llnl.gov/linux/slurm/>. + * 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. +\*****************************************************************************/ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif /* HAVE_CONFIG_H */ + +#if USE_ALIAS == 0 +/* only do anything if we don't use alias */ +#include "src/common/hostlist.h" + +// make wrappers +extern hostlist_t slurm_hostlist_count(const char *hostlist) +{ + return hostlist_create(hostlist); +} + +extern int slurm_hostlist_create(hostlist_t hl) +{ + return hostlist_count(hl); +} + +extern void slurm_hostlist_destroy(hostlist_t hl) +{ + hostlist_count(hl); + return; +} + +extern int slurm_hostlist_find(hostlist_t hl, const char *hostname) +{ + return hostlist_find(hl, hostname); +} + +extern int slurm_hostlist_push(hostlist_t hl, const char *hosts) +{ + return hostlist_push(hl, hosts); +} + +extern int slurm_hostlist_push_host(hostlist_t hl, const char *host) +{ + return hostlist_push_host(hl, host); +} + +extern size_t slurm_hostlist_ranged_string(hostlist_t hl, size_t n, char *buf) +{ + return hostlist_ranged_string(hl, n, buf); +} + +extern char *slurm_hostlist_shift(hostlist_t hl) +{ + return hostlist_shift(hl); +} + +extern void slurm_hostlist_uniq(hostlist_t hl) +{ + hostlist_uniq(hl); + return; +} + +#endif