[mpich-commits] [mpich] MPICH primary repository branch, master, updated. v3.1b1-46-g885bf73

mysql vizuser noreply at mpich.org
Mon Sep 23 11:54:38 CDT 2013


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "MPICH primary repository".

The branch, master has been updated
       via  885bf732074b5fab25cb0c14c9ce25e62b8f8d82 (commit)
      from  66d87263f13b6c388b1702b4deeb84bf1376d28e (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.mpich.org/mpich.git/commitdiff/885bf732074b5fab25cb0c14c9ce25e62b8f8d82

commit 885bf732074b5fab25cb0c14c9ce25e62b8f8d82
Author: Pavan Balaji <balaji at mcs.anl.gov>
Date:   Wed Sep 11 22:00:39 2013 -0500

    Cleanup multiple aspects of the is_local lookup.
    
    1. Cleanup check for local IPs.  We check to see if the host IP
    matches that of the list of local IP addresses.  If it does, it's a
    local host.
    
    2. Do not try to detect remotely accessible nodes.  Our logic for
    identifying whether a node is remotely accessible is quite primitive
    and hacky.  It doesn't serve any real purpose either.  This patch
    deletes that code.
    
    3. Cleanup the is_local lookup function.  If getifaddrs and inet_ntop
    are available, try to detect local processes.  If they aren't there,
    simply return non-local.  In this case, the launcher will fall back to
    using a remote launch even for local processes.  Bad, but workable.
    
    4. Make the hostname lookups more comprehensive, by matching the local
    hostname and the IP address the local hostname resolves to as well.
    This works well when the /etc/hosts file contains an IP address match
    that is not a part of the network addresses.  In this case, the
    hostname IP lookup will give that IP address, but it will not match
    any of the local network IP addresses.
    
    Signed-off-by: Ken Raffenetti <raffenet at mcs.anl.gov>

diff --git a/src/pm/hydra/include/hydra.h b/src/pm/hydra/include/hydra.h
index c7cc78f..e17b8c8 100644
--- a/src/pm/hydra/include/hydra.h
+++ b/src/pm/hydra/include/hydra.h
@@ -596,7 +596,6 @@ HYD_status HYDU_sock_set_nonblock(int fd);
 HYD_status HYDU_sock_forward_stdio(int in, int out, int *closed);
 HYD_status HYDU_sock_get_iface_ip(char *iface, char **ip);
 HYD_status HYDU_sock_is_local(char *host, int *is_local);
-HYD_status HYDU_sock_remote_access(char *host, int *remote_access);
 HYD_status
 HYDU_sock_create_and_listen_portstr(char *iface, char *hostname, char *port_range,
                                     char **port_str,
diff --git a/src/pm/hydra/ui/mpich/mpiexec.c b/src/pm/hydra/ui/mpich/mpiexec.c
index 34c9763..0e80405 100644
--- a/src/pm/hydra/ui/mpich/mpiexec.c
+++ b/src/pm/hydra/ui/mpich/mpiexec.c
@@ -272,21 +272,15 @@ int main(int argc, char **argv)
     /* If the user didn't specify a local hostname, try to find one in
      * the list of nodes passed to us */
     if (HYD_server_info.localhost == NULL) {
-        /* See if the node list contains a remotely accessible localhost */
+        /* See if the node list contains a localhost */
         for (node = HYD_server_info.node_list; node; node = node->next) {
-            int is_local, remote_access;
+            int is_local;
 
             status = HYDU_sock_is_local(node->hostname, &is_local);
             HYDU_ERR_POP(status, "unable to check if %s is local\n", node->hostname);
 
-            if (is_local) {
-                status = HYDU_sock_remote_access(node->hostname, &remote_access);
-                HYDU_ERR_POP(status, "unable to check if %s is remotely accessible\n",
-                             node->hostname);
-
-                if (remote_access)
-                    break;
-            }
+            if (is_local)
+                break;
         }
 
         if (node)
diff --git a/src/pm/hydra/utils/sock/sock.c b/src/pm/hydra/utils/sock/sock.c
index 3a772c4..56cd7c7 100644
--- a/src/pm/hydra/utils/sock/sock.c
+++ b/src/pm/hydra/utils/sock/sock.c
@@ -488,134 +488,131 @@ HYD_status HYDU_sock_get_iface_ip(char *iface, char **ip)
     goto fn_exit;
 }
 
+#if defined(HAVE_GETIFADDRS) && defined (HAVE_INET_NTOP)
 HYD_status HYDU_sock_is_local(char *host, int *is_local)
 {
     struct hostent *ht;
-    char *ip1 = NULL, *ip2 = NULL;
-    char buf1[INET_ADDRSTRLEN];
+    char *host_ip = NULL, *local_ip = NULL, *lhost_ip = NULL;
+    char lhost[MAX_HOSTNAME_LEN];
     struct sockaddr_in sa;
-
-#if defined(HAVE_GETIFADDRS)
     struct ifaddrs *ifaddr, *ifa;
-#endif /* HAVE_GETIFADDRS */
-
-#if defined (HAVE_INET_NTOP)
-    int remote_access;
-#endif /* HAVE_INET_NTOP */
-
+    char buf[INET_ADDRSTRLEN];
     HYD_status status = HYD_SUCCESS;
 
     *is_local = 0;
 
-    /* If we are unable to resolve the remote host name, it need not
-     * be an error. It could mean that the user is using an alias for
-     * the hostname (e.g., an ssh config alias) */
-    if ((ht = gethostbyname(host)) == NULL)
+    /* Algorithm used:
+     *
+     * 1. Find the local host name
+     *    - If "host" matches the local host name, return.
+     * 2. Find the IP address associated with "host" and the IP the local host
+     *    resolves to.
+     *    - If these IPs match, return.
+     * 3. Find all local network IP addresses
+     *    - If the "host" IP address matches any of the local network IP
+     *      addresses, return.
+     */
+
+
+    /* STEP 1: If "host" matches the local host name, return */
+    if (gethostname(lhost, MAX_HOSTNAME_LEN) < 0) {
+        HYDU_ERR_SETANDJUMP(status, HYD_INTERNAL_ERROR, "gethostname returned an error\n");
+    }
+    else if (!strcmp(lhost, host)) {
+        *is_local = 1;
         goto fn_exit;
+    }
+
+
+    /* STEP 2: If the IP address associated with "host" and the IP address local
+     * host resolves to match, return */
+
+    if ((ht = gethostbyname(lhost)) == NULL) {
+        HYDU_ERR_SETANDJUMP(status, HYD_INTERNAL_ERROR, "gethostbyname error on %s: %s\n",
+                            lhost, hstrerror(h_errno));
+    }
 
     memset((char *) &sa, 0, sizeof(struct sockaddr_in));
     memcpy(&sa.sin_addr, ht->h_addr_list[0], ht->h_length);
 
-#if defined HAVE_INET_NTOP
-    ip1 = HYDU_strdup((char *) inet_ntop(AF_INET, (const void *) &sa.sin_addr, buf1,
-                                         MAX_HOSTNAME_LEN));
-    HYDU_ASSERT(ip1, status);
+    /* Find the IP address of the host */
+    lhost_ip = HYDU_strdup((char *) inet_ntop(AF_INET, (const void *) &sa.sin_addr, buf,
+                                              MAX_HOSTNAME_LEN));
+    HYDU_ASSERT(lhost_ip, status);
+
+    /* If we are unable to resolve the remote host name, it need not be an
+     * error. It could mean that the user is using an alias for the hostname
+     * (e.g., an ssh config alias) */
+    if ((ht = gethostbyname(host)) == NULL)
+        goto fn_exit;
+
+    memset((char *) &sa, 0, sizeof(struct sockaddr_in));
+    memcpy(&sa.sin_addr, ht->h_addr_list[0], ht->h_length);
 
-    status = HYDU_sock_remote_access(ip1, &remote_access);
-    HYDU_ERR_POP(status, "unable to check if the IP is remotely accessible\n");
+    /* Find the IP address of the host */
+    host_ip = HYDU_strdup((char *) inet_ntop(AF_INET, (const void *) &sa.sin_addr, buf,
+                                             MAX_HOSTNAME_LEN));
+    HYDU_ASSERT(host_ip, status);
 
-    if (!remote_access) {
+    /* See if the IP address of the hostname we got matches the IP address
+     * to which the local host resolves */
+    if (!strcmp(lhost_ip, host_ip)) {
         *is_local = 1;
         goto fn_exit;
     }
-#else
-    goto fn_exit;
-#endif /* HAVE_INET_NTOP */
 
-#if defined(HAVE_GETIFADDRS)
-    /* Got the interface name; let's query for the IP address */
+
+    /* STEP 3: Find all local IP addresses and try to match the host IP
+     * with it. */
+
     if (getifaddrs(&ifaddr) == -1)
         HYDU_ERR_SETANDJUMP(status, HYD_INTERNAL_ERROR, "getifaddrs failed\n");
 
+    /* Find the IP addresses of all local interfaces */
     for (ifa = ifaddr; ifa; ifa = ifa->ifa_next) {
         if (ifa->ifa_addr && ifa->ifa_addr->sa_family == AF_INET) {
-            struct sockaddr_in *sa_ptr;
+            struct sockaddr_in *sa_ptr = (struct sockaddr_in *) ifa->ifa_addr;
 
-            sa_ptr = (struct sockaddr_in *) ifa->ifa_addr;
+            local_ip = HYDU_strdup((char *)
+                                   inet_ntop(AF_INET, (const void *) &(sa_ptr->sin_addr), buf,
+                                             MAX_HOSTNAME_LEN));
+            HYDU_ASSERT(local_ip, status);
 
-#if defined HAVE_INET_NTOP
-            {
-                char buf2[INET_ADDRSTRLEN];
-
-                ip2 = HYDU_strdup((char *)
-                                  inet_ntop(AF_INET, (const void *) &(sa_ptr->sin_addr), buf2,
-                                            MAX_HOSTNAME_LEN));
-                HYDU_ASSERT(ip2, status);
-            }
-#endif /* HAVE_INET_NTOP */
-
-            if (!strcmp(ip1, ip2)) {
+            /* STEP 3: For each local IP address, see if it matches the "host"
+             * IP address */
+            if (!strcmp(host_ip, local_ip)) {
                 *is_local = 1;
                 freeifaddrs(ifaddr);
                 goto fn_exit;
             }
 
-            HYDU_FREE(ip2);
-            ip2 = NULL;
+            HYDU_FREE(local_ip);
+            local_ip = NULL;
         }
     }
 
     freeifaddrs(ifaddr);
-#endif
 
   fn_exit:
-    if (ip1)
-        HYDU_FREE(ip1);
-    if (ip2)
-        HYDU_FREE(ip2);
+    if (host_ip)
+        HYDU_FREE(host_ip);
+    if (local_ip)
+        HYDU_FREE(local_ip);
+    if (lhost_ip)
+        HYDU_FREE(lhost_ip);
     return status;
 
   fn_fail:
     goto fn_exit;
 }
-
-HYD_status HYDU_sock_remote_access(char *host, int *remote_access)
-{
-    struct hostent *ht;
-    char *ip = NULL, buf[INET_ADDRSTRLEN];
-    struct sockaddr_in sa;
-    HYD_status status = HYD_SUCCESS;
-
-    if ((ht = gethostbyname(host))) {
-        memset((char *) &sa, 0, sizeof(struct sockaddr_in));
-        memcpy(&sa.sin_addr, ht->h_addr_list[0], ht->h_length);
-
-#if defined HAVE_INET_NTOP
-        ip = HYDU_strdup((char *) inet_ntop(AF_INET, (const void *) &sa.sin_addr, buf,
-                                            MAX_HOSTNAME_LEN));
-        HYDU_ASSERT(ip, status);
 #else
-        ip = HYDU_strdup(host);
-#endif
-    }
-    else {
-        ip = HYDU_strdup(host);
-    }
-
-    /* FIXME: Comparing the hostname to "127.*" does not seem like a
-     * good way of checking if a hostname is remotely accessible */
-    if (!MPL_strncmp(ip, "127.", strlen("127.")))
-        *remote_access = 0;
-    else
-        *remote_access = 1;
-
-  fn_exit:
-    HYDU_FREE(ip);
-    return status;
+HYD_status HYDU_sock_is_local(char *host, int *is_local)
+{
+    *is_local = 0;
 
-  fn_fail:
-    goto fn_exit;
+    return HYD_SUCCESS;
 }
+#endif /* HAVE_GETIFADDRS && HAVE_INET_NTOP */
 
 HYD_status
 HYDU_sock_create_and_listen_portstr(char *iface, char *hostname, char *port_range,

-----------------------------------------------------------------------

Summary of changes:
 src/pm/hydra/include/hydra.h    |    1 -
 src/pm/hydra/ui/mpich/mpiexec.c |   14 +---
 src/pm/hydra/utils/sock/sock.c  |  161 +++++++++++++++++++--------------------
 3 files changed, 83 insertions(+), 93 deletions(-)


hooks/post-receive
-- 
MPICH primary repository


More information about the commits mailing list