Commit 1e609160 authored by Pavan Balaji's avatar Pavan Balaji
Browse files

[svn-r3997] Move the base utilities and types into a hydra_base.h header and common

utilities to a hydra_utils.h header. These do not depend on any other
part of the code and can be used in any process/function.
parent f08ec24d
......@@ -5,7 +5,7 @@
*/
#include "hydra.h"
#include "hydra_mem.h"
#include "hydra_utils.h"
#include "bsci.h"
#include "bscu.h"
......
......@@ -5,9 +5,7 @@
*/
#include "hydra.h"
#include "hydra_sock.h"
#include "hydra_mem.h"
#include "hydra_launch.h"
#include "hydra_utils.h"
#include "bsci.h"
#include "bscu.h"
......
......@@ -8,7 +8,7 @@
#define BSCU_H_INCLUDED
#include "hydra.h"
#include "hydra_sig.h"
#include "hydra_utils.h"
#include "bsci.h"
HYD_Status HYD_BSCU_Wait_for_completion(void);
......
......@@ -5,7 +5,7 @@
*/
#include "hydra.h"
#include "hydra_sig.h"
#include "hydra_utils.h"
#include "bsci.h"
#include "bscu.h"
......
......@@ -5,7 +5,7 @@
*/
#include "hydra.h"
#include "hydra_mem.h"
#include "hydra_utils.h"
#include "bsci.h"
#include "bscu.h"
......
......@@ -5,7 +5,7 @@
*/
#include "hydra.h"
#include "hydra_dbg.h"
#include "hydra_utils.h"
#include "csi.h"
#include "pmci.h"
#include "bsci.h"
......
......@@ -5,7 +5,7 @@
*/
#include "hydra.h"
#include "hydra_sock.h"
#include "hydra_utils.h"
#include "csi.h"
#include "pmci.h"
#include "demux.h"
......
......@@ -5,8 +5,7 @@
*/
#include "hydra.h"
#include "hydra_sock.h"
#include "hydra_mem.h"
#include "hydra_utils.h"
#include "demux.h"
static int num_cb_fds = 0;
......
......@@ -8,77 +8,8 @@
#define HYDRA_H_INCLUDED
#include <stdio.h>
#include "mpibase.h"
#include "hydra_config.h"
#if defined HAVE_UNISTD_H
#include <unistd.h>
#endif /* HAVE_UNISTD_H */
#if defined HAVE_STDLIB_H
#include <stdlib.h>
#endif /* HAVE_STDLIB_H */
#if defined HAVE_STRING_H
#include <string.h>
#endif /* HAVE_STRING_H */
#if defined HAVE_STRINGS_H
#include <strings.h>
#endif /* HAVE_STRINGS_H */
#if defined HAVE_STDARG_H
#include <stdarg.h>
#endif /* HAVE_STDARG_H */
#if defined HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif /* HAVE_SYS_TYPES_H */
#include <errno.h>
/* FIXME: Is time.h available everywhere? We should probably have
* multiple timer options like MPICH2. */
#include <time.h>
#include "mpimem.h"
#if defined MAXHOSTNAMELEN
#define MAX_HOSTNAME_LEN MAXHOSTNAMELEN
#else
#define MAX_HOSTNAME_LEN 256
#endif /* MAXHOSTNAMELEN */
#if defined MANUAL_EXTERN_ENVIRON
extern char **environ;
#endif /* MANUAL_EXTERN_ENVIRON */
typedef enum {
HYD_SUCCESS = 0,
HYD_NO_MEM,
HYD_SOCK_ERROR,
HYD_INVALID_PARAM,
HYD_INTERNAL_ERROR
} HYD_Status;
#define HYD_STDOUT (1)
#define HYD_STDIN (2)
typedef unsigned short HYD_Event_t;
#define HYD_TMPBUF_SIZE (64 * 1024)
#define HYD_EXEC_ARGS 200
typedef struct HYD_Env {
char *env_name;
char *env_value;
struct HYD_Env *next;
} HYD_Env_t;
typedef enum {
HYD_ENV_PROP_UNSET,
HYD_ENV_PROP_ALL,
HYD_ENV_PROP_NONE,
HYD_ENV_PROP_LIST
} HYD_Env_prop_t;
#include "hydra_base.h"
#include "hydra_utils.h"
struct HYD_Handle_ {
int debug;
......@@ -109,43 +40,7 @@ struct HYD_Handle_ {
int exec_proc_count;
char *exec[HYD_EXEC_ARGS];
struct HYD_Partition_list {
char *name;
int proc_count;
char **mapping; /* Can be core IDs or something else */
/*
* The boot-strap server is expected to start a single
* executable on the first possible node and return a
* single PID. This executable could be a PM proxy that
* will launch the actual application on the rest of the
* partition list.
*
* Possible hacks:
*
* 1. If the process manager needs more proxies within
* this same list, it can use different group
* IDs. Each group ID will have its own proxy.
*
* 2. If no proxy is needed, the PM can split this list
* into one element per process. The boot-strap
* server itself does not distinguish a proxy from
* the application executable, so it will not require
* any changes.
*
* 3. One proxy per physical node means that each
* partition will have a different group ID.
*/
int group_id; /* Assumed to be in ascending order */
int group_rank; /* Rank within the group */
int pid;
int out;
int err;
int exit_status;
char *args[HYD_EXEC_ARGS];
struct HYD_Partition_list *next;
} *partition;
struct HYD_Partition_list *partition;
/* Local environment */
HYD_Env_t *user_env;
......@@ -185,62 +80,4 @@ typedef struct HYD_Handle_ HYD_Handle;
*/
extern HYD_Handle handle;
#if !defined COMPILER_ACCEPTS_VA_ARGS
#define HYDU_Print printf
#else
#define HYDU_Print(...) \
{ \
int i; \
for (i = 0; i < HYDU_Dbg_depth; i++) \
printf(" "); \
printf(__VA_ARGS__); \
}
#endif /* COMPILER_ACCEPTS_VA_ARGS */
#if !defined ENABLE_DEBUG
#define HYDU_FUNC_ENTER()
#define HYDU_FUNC_EXIT()
#elif defined COMPILER_ACCEPTS_FUNC
#define HYDU_FUNC_ENTER() \
{ \
HYDU_Print("Entering function %s\n", __func__); \
HYDU_Dbg_depth++; \
}
#define HYDU_FUNC_EXIT() \
{ \
HYDU_Print("Exiting function %s\n", __func__); \
HYDU_Dbg_depth--; \
}
#else
#define HYDU_FUNC_ENTER() \
{ \
HYDU_Dbg_depth++; \
}
#define HYDU_FUNC_EXIT() \
{ \
HYDU_Dbg_depth--; \
}
#endif
#if !defined COMPILER_ACCEPTS_VA_ARGS
#define HYDU_Error_printf MPIU_Error_printf
#elif defined COMPILER_ACCEPTS_FUNC && defined __LINE__
#define HYDU_Error_printf(...) \
{ \
fprintf(stderr, "%s (%d): ", __func__, __LINE__); \
MPIU_Error_printf(__VA_ARGS__); \
}
#elif defined __FILE__ && defined __LINE__
#define HYDU_Error_printf(...) \
{ \
fprintf(stderr, "%s (%d): ", __FILE__, __LINE__); \
MPIU_Error_printf(__VA_ARGS__); \
}
#else
#define HYDU_Error_printf(...) \
{ \
MPIU_Error_printf(__VA_ARGS__); \
}
#endif
#endif /* HYDRA_H_INCLUDED */
/* -*- Mode: C; c-basic-offset:4 ; -*- */
/*
* (C) 2008 by Argonne National Laboratory.
* See COPYRIGHT in top-level directory.
*/
#ifndef HYDRA_BASE_H_INCLUDED
#define HYDRA_BASE_H_INCLUDED
#include <stdio.h>
#include "mpibase.h"
#include "hydra_config.h"
#if defined HAVE_UNISTD_H
#include <unistd.h>
#endif /* HAVE_UNISTD_H */
#if defined HAVE_STDLIB_H
#include <stdlib.h>
#endif /* HAVE_STDLIB_H */
#if defined HAVE_STRING_H
#include <string.h>
#endif /* HAVE_STRING_H */
#if defined HAVE_STRINGS_H
#include <strings.h>
#endif /* HAVE_STRINGS_H */
#if defined HAVE_STDARG_H
#include <stdarg.h>
#endif /* HAVE_STDARG_H */
#if defined HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif /* HAVE_SYS_TYPES_H */
#include <errno.h>
/* FIXME: Is time.h available everywhere? We should probably have
* multiple timer options like MPICH2. */
#include <time.h>
#include "mpimem.h"
#if defined MAXHOSTNAMELEN
#define MAX_HOSTNAME_LEN MAXHOSTNAMELEN
#else
#define MAX_HOSTNAME_LEN 256
#endif /* MAXHOSTNAMELEN */
#if defined MANUAL_EXTERN_ENVIRON
extern char **environ;
#endif /* MANUAL_EXTERN_ENVIRON */
typedef enum {
HYD_SUCCESS = 0,
HYD_NO_MEM,
HYD_SOCK_ERROR,
HYD_INVALID_PARAM,
HYD_INTERNAL_ERROR
} HYD_Status;
#define HYD_STDOUT (1)
#define HYD_STDIN (2)
typedef unsigned short HYD_Event_t;
#define HYD_TMPBUF_SIZE (64 * 1024)
#define HYD_EXEC_ARGS 200
typedef struct HYD_Env {
char *env_name;
char *env_value;
struct HYD_Env *next;
} HYD_Env_t;
typedef enum {
HYD_ENV_PROP_UNSET,
HYD_ENV_PROP_ALL,
HYD_ENV_PROP_NONE,
HYD_ENV_PROP_LIST
} HYD_Env_prop_t;
#if !defined COMPILER_ACCEPTS_VA_ARGS
#define HYDU_Print printf
#else
#define HYDU_Print(...) \
{ \
int i; \
for (i = 0; i < HYDU_Dbg_depth; i++) \
printf(" "); \
printf(__VA_ARGS__); \
}
#endif /* COMPILER_ACCEPTS_VA_ARGS */
#if !defined ENABLE_DEBUG
#define HYDU_FUNC_ENTER()
#define HYDU_FUNC_EXIT()
#elif defined COMPILER_ACCEPTS_FUNC
#define HYDU_FUNC_ENTER() \
{ \
HYDU_Print("Entering function %s\n", __func__); \
HYDU_Dbg_depth++; \
}
#define HYDU_FUNC_EXIT() \
{ \
HYDU_Print("Exiting function %s\n", __func__); \
HYDU_Dbg_depth--; \
}
#else
#define HYDU_FUNC_ENTER() \
{ \
HYDU_Dbg_depth++; \
}
#define HYDU_FUNC_EXIT() \
{ \
HYDU_Dbg_depth--; \
}
#endif
#if !defined COMPILER_ACCEPTS_VA_ARGS
#define HYDU_Error_printf MPIU_Error_printf
#elif defined COMPILER_ACCEPTS_FUNC && defined __LINE__
#define HYDU_Error_printf(...) \
{ \
fprintf(stderr, "%s (%d): ", __func__, __LINE__); \
MPIU_Error_printf(__VA_ARGS__); \
}
#elif defined __FILE__ && defined __LINE__
#define HYDU_Error_printf(...) \
{ \
fprintf(stderr, "%s (%d): ", __FILE__, __LINE__); \
MPIU_Error_printf(__VA_ARGS__); \
}
#else
#define HYDU_Error_printf(...) \
{ \
MPIU_Error_printf(__VA_ARGS__); \
}
#endif
#endif /* HYDRA_BASE_H_INCLUDED */
/* -*- Mode: C; c-basic-offset:4 ; -*- */
/*
* (C) 2008 by Argonne National Laboratory.
* See COPYRIGHT in top-level directory.
*/
#ifndef HYDRA_DBG_H_INCLUDED
#define HYDRA_DBG_H_INCLUDED
#include "hydra.h"
#endif /* HYDRA_DBG_H_INCLUDED */
/* -*- Mode: C; c-basic-offset:4 ; -*- */
/*
* (C) 2008 by Argonne National Laboratory.
* See COPYRIGHT in top-level directory.
*/
#ifndef HYDRA_ENV_H_INCLUDED
#define HYDRA_ENV_H_INCLUDED
#include "hydra.h"
HYD_Status HYDU_Env_global_list(HYD_Env_t ** env_list);
HYD_Env_t *HYDU_Env_dup(HYD_Env_t env);
HYD_Env_t *HYDU_Env_listdup(HYD_Env_t * env);
HYD_Status HYDU_Env_create(HYD_Env_t ** env, char *env_name, char *env_value);
HYD_Status HYDU_Env_free(HYD_Env_t * env);
HYD_Status HYDU_Env_free_list(HYD_Env_t * env);
HYD_Env_t *HYDU_Env_found_in_list(HYD_Env_t * env_list, HYD_Env_t env);
HYD_Status HYDU_Env_add_to_list(HYD_Env_t ** env_list, HYD_Env_t env);
HYD_Status HYDU_Env_putenv(HYD_Env_t env);
#endif /* HYDRA_ENV_H_INCLUDED */
/* -*- Mode: C; c-basic-offset:4 ; -*- */
/*
* (C) 2008 by Argonne National Laboratory.
* See COPYRIGHT in top-level directory.
*/
#ifndef HYDRA_LAUNCH_H_INCLUDED
#define HYDRA_LAUNCH_H_INCLUDED
#include "hydra.h"
HYD_Status HYDU_Append_env(HYD_Env_t * env_list, char **client_arg, int id);
HYD_Status HYDU_Append_exec(char **exec, char **client_arg);
HYD_Status HYDU_Append_wdir(char **client_arg, char *wdir);
HYD_Status HYDU_Allocate_Partition(struct HYD_Partition_list **partition);
HYD_Status HYDU_Create_process(char **client_arg, int *in, int *out, int *err, int *pid);
HYD_Status HYDU_Dump_args(char **args);
#endif /* HYDRA_LAUNCH_H_INCLUDED */
/* -*- Mode: C; c-basic-offset:4 ; -*- */
/*
* (C) 2008 by Argonne National Laboratory.
* See COPYRIGHT in top-level directory.
*/
#ifndef HYDRA_MEM_H_INCLUDED
#define HYDRA_MEM_H_INCLUDED
#include "hydra.h"
#define HYDU_NUM_JOIN_STR 100
#define HYDU_MALLOC(p, type, size, status) \
{ \
(p) = (type) MPIU_Malloc((size)); \
if ((p) == NULL) { \
HYDU_Error_printf("failed trying to allocate %d bytes\n", (size)); \
(status) = HYD_NO_MEM; \
goto fn_fail; \
} \
}
#define HYDU_FREE(p) \
{ \
MPIU_Free(p); \
}
#define HYDU_STRDUP(src, dest, type, status) \
{ \
(dest) = (type) MPIU_Strdup((src)); \
if ((p) == NULL) { \
HYDU_Error_printf("failed duping string %s\n", (src)); \
(status) = HYD_INTERNAL_ERROR; \
goto fn_fail; \
} \
}
#define HYDU_PRINT_ARGS(str) \
{ \
int i; \
for (i = 0; (str) != NULL && (str)[i] != NULL; i++) \
printf("%s ", (str)[i]); \
printf("\n"); \
}
#define HYDU_STR_ALLOC_AND_JOIN(strlist, strjoin, status) \
{ \
int len = 0, i, count; \
for (i = 0; (strlist)[i] != NULL; i++) \
len += strlen((strlist)[i]); \
HYDU_MALLOC((strjoin), char *, len + 1, (status)); \
count = 0; \
(strjoin)[0] = 0; \
for (i = 0; (strlist)[i] != NULL; i++) { \
MPIU_Snprintf((strjoin) + count, len - count + 1, "%s", (strlist)[i]); \
count += strlen((strlist)[i]); \
} \
}
#define HYDU_Int_to_str(x, str, status) \
{ \
int len = 1, max = 10, y; \
if ((x) < 0) { \
len++; \
y = -(x); \
} \
else \
y = (x); \
while (y >= max) { \
len++; \
max *= 10; \
} \
(str) = (char *) MPIU_Malloc(len + 1); \
if ((str) == NULL) { \
HYDU_Error_printf("failed trying to allocate %d bytes\n", len + 1); \
(status) = HYD_NO_MEM; \
goto fn_fail; \
} \
MPIU_Snprintf((str), len + 1, "%d", (x)); \
}
#endif /* HYDRA_MEM_H_INCLUDED */
/* -*- Mode: C; c-basic-offset:4 ; -*- */
/*
* (C) 2008 by Argonne National Laboratory.
* See COPYRIGHT in top-level directory.
*/
#ifndef HYDRA_SIG_H_INCLUDED
#define HYDRA_SIG_H_INCLUDED
#ifdef NEEDS_POSIX_FOR_SIGACTION
#define _POSIX_SOURCE
#endif
#include <sys/wait.h>
#if defined(USE_SIGNAL) || defined(USE_SIGACTION)
#include <signal.h>
#else
#error no signal choice
#endif
#ifdef NEEDS_STRSIGNAL_DECL
extern char *strsignal(int);
#endif
#include "hydra.h"
HYD_Status HYDU_Set_signal(int signum, void (*handler) (int));
#endif /* HYDRA_SIG_H_INCLUDED */
/* -*- Mode: C; c-basic-offset:4 ; -*- */
/*
* (C) 2008 by Argonne National Laboratory.
* See COPYRIGHT in top-level directory.
*/
#ifndef HYDRA_SOCKS_H_INCLUDED
#define HYDRA_SOCKS_H_INCLUDED
#include "hydra.h"
#include <poll.h>
#include <fcntl.h>
#include <netdb.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#if !defined size_t
#define size_t unsigned int
#endif /* size_t */
HYD_Status HYDU_Sock_listen(int *listen_fd, char *port_range, uint16_t * port);
HYD_Status HYDU_Sock_connect(const char *host, uint16_t port, int *fd);
HYD_Status HYDU_Sock_accept(int listen_fd, int *fd);
HYD_Status HYDU_Sock_readline(int fd, char *buf, int maxlen, int *linelen);
HYD_Status HYDU_Sock_read(int fd, char *buf, int maxlen, int *count);
HYD_Status HYDU_Sock_writeline(int fd, char *buf, int maxsize);
HYD_Status HYDU_Sock_write(int fd, char *buf, int maxsize);
HYD_Status HYDU_Sock_set_nonblock(int fd);
HYD_Status HYDU_Sock_set_cloexec(int fd);
HYD_Status HYDU_Sock_stdout_cb(int fd, HYD_Event_t events, int stdout_fd, int *closed);
HYD_Status HYDU_Sock_stdin_cb(int fd, HYD_Event_t events, char *buf, int *buf_count,
int *buf_offset, int *closed);
#endif /* HYDRA_SOCKS_H_INCLUDED */
/* -*- Mode: C; c-basic-offset:4 ; -*- */
/*
* (C) 2008 by Argonne National Laboratory.
* See COPYRIGHT in top-level directory.
*/
#ifndef HYDRA_UTILS_H_INCLUDED
#define HYDRA_UTILS_H_INCLUDED
#include "hydra_base.h"