Skip to content

Commit

Permalink
Update all tools/libs to use fi_hostlist.[ch]
Browse files Browse the repository at this point in the history
  • Loading branch information
chu11 committed Jan 13, 2017
1 parent 363168a commit e3f4570
Show file tree
Hide file tree
Showing 16 changed files with 241 additions and 239 deletions.
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

* common/miscutil/fi_hostlist.h, common/miscutil/fi_hostlist.c:
New files. Wrapper around hostlist.[ch].

* Update all tools to use fi_hostlist.[ch].

2017-01-13 Albert Chu <[email protected]>

Expand Down
54 changes: 27 additions & 27 deletions common/toolcommon/pstdout.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

#include "pstdout.h"
#include "cbuf.h"
#include "hostlist.h"
#include "fi_hostlist.h"
#include "list.h"

/* max hostrange size is typically 16 bytes
Expand Down Expand Up @@ -109,7 +109,7 @@ struct pstdout_state {
int pstdout_errnum = PSTDOUT_ERR_SUCCESS;

struct pstdout_consolidated_data {
hostlist_t h;
fi_hostlist_t h;
char *output;
};

Expand Down Expand Up @@ -146,7 +146,7 @@ _pstdout_consolidated_data_create(const char *hostname, const char *output)
cdata->h = NULL;
cdata->output = NULL;

if (!(cdata->h = hostlist_create(hostname)))
if (!(cdata->h = fi_hostlist_create(hostname)))
{
pstdout_errnum = PSTDOUT_ERR_OUTMEM;
goto cleanup;
Expand All @@ -164,7 +164,7 @@ _pstdout_consolidated_data_create(const char *hostname, const char *output)
if (cdata)
{
if (cdata->h)
hostlist_destroy(cdata->h);
fi_hostlist_destroy(cdata->h);
free(cdata->output);
free(cdata);
}
Expand All @@ -180,7 +180,7 @@ _pstdout_consolidated_data_destroy(void *x)

cdata = (struct pstdout_consolidated_data *)x;
if (cdata->h)
hostlist_destroy(cdata->h);
fi_hostlist_destroy(cdata->h);
free(cdata->output);
free(cdata);
}
Expand All @@ -201,8 +201,8 @@ _pstdout_consolidated_data_compare(void *x, void *y)
assert(cdataX->h);
assert(cdataY->h);

h_countX = hostlist_count(cdataX->h);
h_countY = hostlist_count(cdataY->h);
h_countX = fi_hostlist_count(cdataX->h);
h_countY = fi_hostlist_count(cdataY->h);

if (h_countX < h_countY)
return -1;
Expand Down Expand Up @@ -450,7 +450,7 @@ pstdout_get_fanout(void)
int
pstdout_hostnames_count(const char *hostnames)
{
hostlist_t h = NULL;
fi_hostlist_t h = NULL;
int count = 0;
int rv = -1;

Expand All @@ -460,13 +460,13 @@ pstdout_hostnames_count(const char *hostnames)
return -1;
}

if (!(h = hostlist_create(hostnames)))
if (!(h = fi_hostlist_create(hostnames)))
{
pstdout_errnum = PSTDOUT_ERR_OUTMEM;
goto cleanup;
}

if (!(count = hostlist_count(h)))
if (!(count = fi_hostlist_count(h)))
{
if (pstdout_debug_flags & PSTDOUT_DEBUG_STANDARD)
fprintf(stderr, "hostnames count == 0\n");
Expand All @@ -477,7 +477,7 @@ pstdout_hostnames_count(const char *hostnames)
rv = count;
cleanup:
if (h)
hostlist_destroy(h);
fi_hostlist_destroy(h);
return rv;
}

Expand Down Expand Up @@ -990,10 +990,10 @@ _pstdout_output_buffer_data(pstdout_state_t pstate,
}
else
{
if (!hostlist_push(cdata->h, pstate->hostname))
if (!fi_hostlist_push(cdata->h, pstate->hostname))
{
if (pstdout_debug_flags & PSTDOUT_DEBUG_STANDARD)
fprintf(stderr, "hostlist_push: %s\n", strerror(errno));
fprintf(stderr, "fi_hostlist_push: %s\n", strerror(errno));
pstdout_errnum = PSTDOUT_ERR_INTERNAL;
goto cleanup;
}
Expand Down Expand Up @@ -1190,11 +1190,11 @@ _pstdout_output_consolidated(FILE *stream,
char hbuf[PSTDOUT_BUFLEN + 1];

memset(hbuf, '\0', PSTDOUT_BUFLEN + 1);
hostlist_sort(cdata->h);
if (hostlist_ranged_string(cdata->h, PSTDOUT_BUFLEN, hbuf) < 0)
fi_hostlist_sort(cdata->h);
if (fi_hostlist_ranged_string(cdata->h, PSTDOUT_BUFLEN, hbuf) < 0)
{
if (pstdout_debug_flags & PSTDOUT_DEBUG_STANDARD)
fprintf(stderr, "hostlist_ranged_string: %s\n", strerror(errno));
fprintf(stderr, "fi_hostlist_ranged_string: %s\n", strerror(errno));
pstdout_errnum = PSTDOUT_ERR_INTERNAL;
goto cleanup;
}
Expand Down Expand Up @@ -1313,7 +1313,7 @@ _pstdout_sigint(int s)
if ((rc = pthread_mutex_lock(&pstdout_states_mutex)))
{
if (pstdout_debug_flags & PSTDOUT_DEBUG_STANDARD)
fprintf(stderr, "hostlist_ranged_string: %s\n", strerror(rc));
fprintf(stderr, "fi_hostlist_ranged_string: %s\n", strerror(rc));
}

if (list_for_each(pstdout_states, _pstdout_sigint_finish_output, NULL) < 0)
Expand All @@ -1332,8 +1332,8 @@ pstdout_launch(const char *hostnames, Pstdout_Thread pstdout_func, void *arg)
struct pstdout_thread_data **tdata = NULL;
struct pstdout_state pstate;
unsigned int pstate_init = 0;
hostlist_iterator_t hitr = NULL;
hostlist_t h = NULL;
fi_hostlist_iterator_t hitr = NULL;
fi_hostlist_t h = NULL;
int h_count = 0;
char *host = NULL;
int exit_code = -1;
Expand Down Expand Up @@ -1374,12 +1374,12 @@ pstdout_launch(const char *hostnames, Pstdout_Thread pstdout_func, void *arg)
goto cleanup;
}

if (!(h = hostlist_create(hostnames)))
if (!(h = fi_hostlist_create(hostnames)))
{
pstdout_errnum = PSTDOUT_ERR_OUTMEM;
goto cleanup;
}
h_count = hostlist_count(h);
h_count = fi_hostlist_count(h);

/* Sanity check */
if (h_count <= 0)
Expand Down Expand Up @@ -1411,7 +1411,7 @@ pstdout_launch(const char *hostnames, Pstdout_Thread pstdout_func, void *arg)
}
sighandler_set++;

if (!(hitr = hostlist_iterator_create(h)))
if (!(hitr = fi_hostlist_iterator_create(h)))
{
pstdout_errnum = PSTDOUT_ERR_OUTMEM;
goto cleanup;
Expand All @@ -1425,7 +1425,7 @@ pstdout_launch(const char *hostnames, Pstdout_Thread pstdout_func, void *arg)
memset(tdata, '\0', sizeof(struct pstdout_thread_data *) * h_count);

i = 0;
while ((host = hostlist_next(hitr)))
while ((host = fi_hostlist_next(hitr)))
{
if (!(tdata[i] = (struct pstdout_thread_data *)malloc(sizeof(struct pstdout_thread_data))))
{
Expand Down Expand Up @@ -1463,10 +1463,10 @@ pstdout_launch(const char *hostnames, Pstdout_Thread pstdout_func, void *arg)
}
host = NULL;

hostlist_iterator_destroy(hitr);
fi_hostlist_iterator_destroy(hitr);
hitr = NULL;

hostlist_destroy(h);
fi_hostlist_destroy(h);
h = NULL;

/* Launch threads up to fanout */
Expand Down Expand Up @@ -1565,9 +1565,9 @@ pstdout_launch(const char *hostnames, Pstdout_Thread pstdout_func, void *arg)
free(tdata);
}
if (hitr)
hostlist_iterator_destroy(hitr);
fi_hostlist_iterator_destroy(hitr);
if (h)
hostlist_destroy(h);
fi_hostlist_destroy(h);
free(host);
if ((rc = pthread_mutex_unlock(&pstdout_launch_mutex)))
{
Expand Down
44 changes: 22 additions & 22 deletions common/toolcommon/tool-hostrange-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,21 @@
#include <ipmidetect.h>

#include "freeipmi-portability.h"
#include "hostlist.h"
#include "fi_hostlist.h"
#include "pstdout.h"
#include "tool-hostrange-common.h"

#define HOSTLIST_BUFLEN 1024
#define FI_HOSTLIST_BUFLEN 1024

static int
eliminate_nodes (char **hosts)
{
hostlist_t hl = NULL;
hostlist_t hlnew = NULL;
hostlist_iterator_t hitr = NULL;
fi_hostlist_t hl = NULL;
fi_hostlist_t hlnew = NULL;
fi_hostlist_iterator_t hitr = NULL;
ipmidetect_t id = NULL;
char *host = NULL;
char hostbuf[HOSTLIST_BUFLEN + 1];
char hostbuf[FI_HOSTLIST_BUFLEN + 1];
int rv = -1;

assert (hosts);
Expand Down Expand Up @@ -73,31 +73,31 @@ eliminate_nodes (char **hosts)
goto cleanup;
}

if (!(hl = hostlist_create (*hosts)))
if (!(hl = fi_hostlist_create (*hosts)))
{
fprintf (stderr,
"hostlist_create: %s\n",
"fi_hostlist_create: %s\n",
strerror (errno));
goto cleanup;
}

if (!(hlnew = hostlist_create (*hosts)))
if (!(hlnew = fi_hostlist_create (*hosts)))
{
fprintf (stderr,
"hostlist_create: %s\n",
"fi_hostlist_create: %s\n",
strerror (errno));
goto cleanup;
}

if (!(hitr = hostlist_iterator_create (hl)))
if (!(hitr = fi_hostlist_iterator_create (hl)))
{
fprintf (stderr,
"hostlist_iterator_create: %s\n",
"fi_hostlist_iterator_create: %s\n",
strerror (errno));
goto cleanup;
}

while ((host = hostlist_next (hitr)))
while ((host = fi_hostlist_next (hitr)))
{
int ret;

Expand All @@ -113,24 +113,24 @@ eliminate_nodes (char **hosts)
}

if (!ret)
hostlist_delete (hlnew, host);
fi_hostlist_delete (hlnew, host);

free (host);
}
host = NULL;

if (!hostlist_count (hlnew))
if (!fi_hostlist_count (hlnew))
{
rv = 0;
goto cleanup;
}

memset (hostbuf, '\0', HOSTLIST_BUFLEN + 1);
memset (hostbuf, '\0', FI_HOSTLIST_BUFLEN + 1);

if (hostlist_ranged_string (hlnew, HOSTLIST_BUFLEN, hostbuf) < 0)
if (fi_hostlist_ranged_string (hlnew, FI_HOSTLIST_BUFLEN, hostbuf) < 0)
{
fprintf (stderr,
"hostlist_ranged_string: truncation\n");
"fi_hostlist_ranged_string: truncation\n");
goto cleanup;
}

Expand All @@ -141,16 +141,16 @@ eliminate_nodes (char **hosts)
goto cleanup;
}

rv = hostlist_count (hlnew);
rv = fi_hostlist_count (hlnew);
cleanup:
if (id)
ipmidetect_handle_destroy (id);
if (hitr)
hostlist_iterator_destroy (hitr);
fi_hostlist_iterator_destroy (hitr);
if (hl)
hostlist_destroy (hl);
fi_hostlist_destroy (hl);
if (hlnew)
hostlist_destroy (hlnew);
fi_hostlist_destroy (hlnew);
free (host);
return (rv);
}
Expand Down
10 changes: 5 additions & 5 deletions ipmidetect/ipmidetect-argp.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
#include "freeipmi-portability.h"
#include "error.h"
#include "fd.h"
#include "hostlist.h"
#include "fi_hostlist.h"

const char *argp_program_version =
"ipmidetect - " PACKAGE_VERSION "\n"
Expand Down Expand Up @@ -107,7 +107,7 @@ _push_inputted_nodes (struct ipmidetect_arguments *cmd_args,
if (strchr (nodes, '.'))
err_exit ("nodes must be listed in short hostname format");

if (!hostlist_push (cmd_args->inputted_nodes, nodes))
if (!fi_hostlist_push (cmd_args->inputted_nodes, nodes))
err_exit ("nodes improperly formatted");
}

Expand Down Expand Up @@ -185,7 +185,7 @@ cmdline_parse (int key, char *arg, struct argp_state *state)
_read_nodes_from_stdin (cmd_args);
else
_push_inputted_nodes (cmd_args, arg);
hostlist_uniq (cmd_args->inputted_nodes);
fi_hostlist_uniq (cmd_args->inputted_nodes);
break;
case ARGP_KEY_END:
break;
Expand All @@ -208,8 +208,8 @@ ipmidetect_argp_parse (int argc, char **argv, struct ipmidetect_arguments *cmd_a
cmd_args->output_type = IPMIDETECT_DETECTED_AND_UNDETECTED_NODES;
cmd_args->output_format = 0;

if (!(cmd_args->inputted_nodes = hostlist_create (NULL)))
err_exit ("hostlist_create");
if (!(cmd_args->inputted_nodes = fi_hostlist_create (NULL)))
err_exit ("fi_hostlist_create");

argp_parse (&cmdline_argp,
argc,
Expand Down
Loading

0 comments on commit e3f4570

Please sign in to comment.