1
1

* fix ompi_ifaddrtoname to return the correct error code (it was returning

OMPI_ERROR if it found something and OMPI_SUCCESS otherwise).  Also
  look for INADDR_NONE instead of INADDR_ANY as the return from inet_addr()
* add convinience function ompi_ifislocal to quickly test if a given
  hostname or IP address (in dotted-quad form) is a local address
* don't ssh to the local machine, but fork() / exec() the bootproxy directly
  if ompi_ifislocal returns true *AND* there is no username specified
  for the given host
* remove the llm hack to translate localhost -> local machine name

This commit was SVN r3450.
Этот коммит содержится в:
Brian Barrett 2004-10-31 19:01:53 +00:00
родитель 4e67bf4646
Коммит fc8a7868e7
6 изменённых файлов: 184 добавлений и 38 удалений

Просмотреть файл

@ -99,13 +99,7 @@ parse_line(int first, mca_llm_base_hostfile_node_t *node)
int ret; int ret;
if (MCA_LLM_BASE_STRING == first) { if (MCA_LLM_BASE_STRING == first) {
/* don't allow localhost or 127.0.0.1 */ strncpy(node->hostname, mca_llm_base_string, MAXHOSTNAMELEN);
if ((strncmp("localhost", mca_llm_base_string, strlen("localhost")) == 0) ||
(strcmp("127.0.0.1", mca_llm_base_string) == 0)) {
gethostname(node->hostname, MAXHOSTNAMELEN);
} else {
strncpy(node->hostname, mca_llm_base_string, MAXHOSTNAMELEN);
}
node->given_count = 1; node->given_count = 1;
} else { } else {
parse_error(); parse_error();

Просмотреть файл

@ -34,6 +34,7 @@
#include "mca/ns/base/base.h" #include "mca/ns/base/base.h"
#include "util/proc_info.h" #include "util/proc_info.h"
#include "util/show_help.h" #include "util/show_help.h"
#include "util/if.h"
/* /*
* Internal constants * Internal constants
@ -306,7 +307,7 @@ internal_spawn_proc(mca_pcm_rsh_module_t *me,
int cmdc = 0; int cmdc = 0;
char *printable = NULL; char *printable = NULL;
int stderr_is_error = me->ignore_stderr == 0 ? 1 : 0; int stderr_is_error = me->ignore_stderr == 0 ? 1 : 0;
char *username = NULL; char *start_username = NULL;
int ret; int ret;
pid_t pid; pid_t pid;
FILE *fp; FILE *fp;
@ -314,37 +315,43 @@ internal_spawn_proc(mca_pcm_rsh_module_t *me,
int i; int i;
char *tmp; char *tmp;
bool high_qos = (0 != (me->constraints & OMPI_RTE_SPAWN_HIGH_QOS)); bool high_qos = (0 != (me->constraints & OMPI_RTE_SPAWN_HIGH_QOS));
bool is_local;
start_node = (mca_llm_base_hostfile_node_t*) ompi_list_get_first(hostlist); start_node = (mca_llm_base_hostfile_node_t*) ompi_list_get_first(hostlist);
start_username = mca_pcm_base_get_username(start_node);
/* /* add all the startup stuff if needed */
* Check to see if we need to do the .profile thing is_local = ompi_ifislocal(start_node->hostname) &&
*/ start_username == NULL;
ret = internal_need_profile(me, start_node, stderr_is_error,
&needs_profile);
if (OMPI_SUCCESS != ret) {
goto cleanup;
}
/* if (!is_local) {
* Build up start array /*
*/ * Check to see if we need to do the .profile thing
*/
ret = internal_need_profile(me, start_node, stderr_is_error,
&needs_profile);
if (OMPI_SUCCESS != ret) {
goto cleanup;
}
/* build up the rsh command part */ /*
cmdv = ompi_argv_split(me->rsh_agent, ' '); * Build up start array
cmdc = ompi_argv_count(cmdv); */
ompi_argv_append(&cmdc, &cmdv, start_node->hostname); /* build up the rsh command part */
username = mca_pcm_base_get_username(start_node); cmdv = ompi_argv_split(me->rsh_agent, ' ');
if (NULL != username) { cmdc = ompi_argv_count(cmdv);
ompi_argv_append(&cmdc, &cmdv, "-l");
ompi_argv_append(&cmdc, &cmdv, username);
}
/* add the start of .profile thing if required */ ompi_argv_append(&cmdc, &cmdv, start_node->hostname);
if (needs_profile) { if (NULL != start_username) {
ompi_argv_append(&cmdc, &cmdv, "( ! [ -e ./.profile ] || . ./.profile;"); ompi_argv_append(&cmdc, &cmdv, "-l");
ompi_argv_append(&cmdc, &cmdv, start_username);
}
/* add the start of .profile thing if required */
if (needs_profile) {
ompi_argv_append(&cmdc, &cmdv, "( ! [ -e ./.profile ] || . ./.profile;");
}
} }
/* build the command to start */ /* build the command to start */
@ -374,7 +381,7 @@ internal_spawn_proc(mca_pcm_rsh_module_t *me,
} }
/* add the end of the .profile thing if required */ /* add the end of the .profile thing if required */
if (needs_profile) { if (!is_local && needs_profile) {
ompi_argv_append(&cmdc, &cmdv, ")"); ompi_argv_append(&cmdc, &cmdv, ")");
} }
@ -464,7 +471,7 @@ proc_cleanup:
/* free up everything we used on the way */ /* free up everything we used on the way */
if (NULL != printable) free(printable); if (NULL != printable) free(printable);
if (NULL != cmd0) free(cmd0); if (NULL != cmd0) free(cmd0);
if (NULL != username) free(username); if (NULL != start_username) free(start_username);
ompi_argv_free(cmdv); ompi_argv_free(cmdv);
cmdv = NULL; cmdv = NULL;
cmdc = 0; cmdc = 0;

Просмотреть файл

@ -365,11 +365,11 @@ int ompi_ifaddrtoname(const char* if_addr, char* if_name, int length)
if(rc != OMPI_SUCCESS) if(rc != OMPI_SUCCESS)
return rc; return rc;
if(inaddr == INADDR_ANY) { if(inaddr == INADDR_NONE) {
h = gethostbyname(if_addr); h = gethostbyname(if_addr);
if(h == 0) { if(h == 0) {
ompi_output(0,"ompi_ifaddrtoname: unable to resolve %s\n", if_addr); ompi_output(0,"ompi_ifaddrtoname: unable to resolve %s\n", if_addr);
return OMPI_ERROR; return OMPI_ERR_NOT_FOUND;
} }
memcpy(&inaddr, h->h_addr, sizeof(inaddr)); memcpy(&inaddr, h->h_addr, sizeof(inaddr));
} }
@ -379,10 +379,10 @@ int ompi_ifaddrtoname(const char* if_addr, char* if_name, int length)
intf = (ompi_if_t*)ompi_list_get_next(intf)) { intf = (ompi_if_t*)ompi_list_get_next(intf)) {
if(intf->if_addr.sin_addr.s_addr == inaddr) { if(intf->if_addr.sin_addr.s_addr == inaddr) {
strncpy(if_name, intf->if_name, length); strncpy(if_name, intf->if_name, length);
return OMPI_ERROR; return OMPI_SUCCESS;
} }
} }
return OMPI_SUCCESS; return OMPI_ERR_NOT_FOUND;
} }
/* /*
@ -516,3 +516,17 @@ int ompi_ifindextoname(int if_index, char* if_name, int length)
} }
return OMPI_ERROR; return OMPI_ERROR;
} }
bool
ompi_ifislocal(char *hostname)
{
const int len = 100;
char addrname[len - 1];
int ret;
ret = ompi_ifaddrtoname(hostname, addrname, len);
if (OMPI_SUCCESS == ret) return true;
return false;
}

Просмотреть файл

@ -88,6 +88,15 @@ OMPI_DECLSPEC int ompi_ifindextoaddr(int if_index, struct sockaddr*, int);
* @param size (IN) Interface address buffer size * @param size (IN) Interface address buffer size
*/ */
OMPI_DECLSPEC int ompi_ifindextomask(int if_index, struct sockaddr*, int); OMPI_DECLSPEC int ompi_ifindextomask(int if_index, struct sockaddr*, int);
/**
* Determine if given hostname / IP address is a local address
*
* @param hostname (IN) Hostname (or stringified IP address)
* @return true if \c hostname is local, false otherwise
*/
OMPI_DECLSPEC bool ompi_ifislocal(char *hostname);
#if defined(c_plusplus) || defined(__cplusplus) #if defined(c_plusplus) || defined(__cplusplus)
} }
#endif #endif

Просмотреть файл

@ -7,6 +7,7 @@ AM_CPPFLAGS = -I$(top_srcdir)/test/support -DOMPI_ENABLE_DEBUG_OVERRIDE=1 -g
noinst_PROGRAMS = \ noinst_PROGRAMS = \
ompi_numtostr \ ompi_numtostr \
ompi_if \
ompi_pack \ ompi_pack \
ompi_os_path \ ompi_os_path \
ompi_sys_info \ ompi_sys_info \
@ -20,6 +21,12 @@ ompi_numtostr_LDADD = \
$(top_builddir)/test/support/libsupport.la $(top_builddir)/test/support/libsupport.la
ompi_numtostr_DEPENDENCIES = $(ompi_numtostr_LDADD) ompi_numtostr_DEPENDENCIES = $(ompi_numtostr_LDADD)
ompi_if_SOURCES = ompi_if.c
ompi_if_LDADD = \
$(top_builddir)/src/libmpi.la \
$(top_builddir)/test/support/libsupport.la
ompi_if_DEPENDENCIES = $(ompi_if_LDADD)
ompi_argv_SOURCES = ompi_argv.c ompi_argv_SOURCES = ompi_argv.c
ompi_argv_LDADD = \ ompi_argv_LDADD = \
$(top_builddir)/src/libmpi.la \ $(top_builddir)/src/libmpi.la \

115
test/util/ompi_if.c Обычный файл
Просмотреть файл

@ -0,0 +1,115 @@
/*
* $HEADER$
*/
#include "ompi_config.h"
#if 0
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#endif
#include "runtime/runtime.h"
#include "util/if.h"
#include "support.h"
#include "util/bufpack.h"
#include "include/constants.h"
static bool
test_ifaddrtoname(char *addr)
{
int ret;
char addrname[100];
int len = 99;
ret = ompi_ifaddrtoname(addr, addrname, len);
if (ret == OMPI_SUCCESS) {
return true;
} else {
return false;
}
}
int
main(int argc, char *argv[])
{
char hostname[MAXHOSTNAMELEN];
ompi_init(argc, argv);
test_init("ompi_if");
/* 127.0.0.1 */
if (test_ifaddrtoname("127.0.0.1")) {
test_success();
} else {
test_failure("ifaddrtoname test failed for 127.0.0.1");
}
if (ompi_ifislocal("127.0.0.1")) {
test_success();
} else {
test_failure("ifislocal test failed for 127.0.0.1");
}
/* localhost */
if (test_ifaddrtoname("localhost")) {
test_success();
} else {
test_failure("ifaddrtoname test failed for localhost");
}
if (ompi_ifislocal("localhost")) {
test_success();
} else {
test_failure("ifislocal test failed for localhost");
}
/* 0.0.0.0 */
if (test_ifaddrtoname("0.0.0.0")) {
test_failure("ifaddrtoname test failed for 0.0.0.0");
} else {
test_success();
}
if (ompi_ifislocal("0.0.0.0")) {
test_failure("ompi_ifislocal test failed for 0.0.0.0");
} else {
test_success();
}
/* foo.example.com */
if (test_ifaddrtoname("foo.example.com")) {
test_failure("ifaddrtoname test failed for foo.example.com");
} else {
test_success();
}
if (ompi_ifislocal("foo.example.com")) {
test_failure("ifislocal test failed for foo.example.com");
} else {
test_success();
}
/* local host name */
gethostname(hostname, MAXHOSTNAMELEN);
if (test_ifaddrtoname(hostname)) {
test_success();
} else {
test_failure("ifaddrtoname test failed for local host name");
}
if (ompi_ifislocal(hostname)) {
test_success();
} else {
test_failure("ifislocal test failed for local host name");
}
test_finalize();
ompi_finalize();
return 0;
}