[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r26215 - in gnunet/src: include testbed
From: |
gnunet |
Subject: |
[GNUnet-SVN] r26215 - in gnunet/src: include testbed |
Date: |
Wed, 27 Feb 2013 15:22:24 +0100 |
Author: harsha
Date: 2013-02-27 15:22:24 +0100 (Wed, 27 Feb 2013)
New Revision: 26215
Modified:
gnunet/src/include/gnunet_testbed_service.h
gnunet/src/testbed/gnunet_testbed_mpi_spawn.c
gnunet/src/testbed/testbed_api_hosts.c
Log:
Parsing LoadLeveler allocated hosts and creating testbed hosts from them
Modified: gnunet/src/include/gnunet_testbed_service.h
===================================================================
--- gnunet/src/include/gnunet_testbed_service.h 2013-02-27 14:12:33 UTC (rev
26214)
+++ gnunet/src/include/gnunet_testbed_service.h 2013-02-27 14:22:24 UTC (rev
26215)
@@ -132,6 +132,24 @@
/**
+ * Loads the set of host allocated by the LoadLeveler Job Scheduler. This
+ * function is only available when compiled with support for LoadLeveler and is
+ * used for running on the SuperMUC
+ *
+ * @param cfg the configuration to use as a template while starting a
controller
+ * on any of the loaded hosts. Operation queue sizes specific to a
host
+ * are also read from this configuration handle
+ * @param hosts set to the hosts found in the file; caller must free this if
+ * number of hosts returned is greater than 0
+ * @return number of hosts returned in 'hosts', 0 on error
+ */
+unsigned int
+GNUNET_TESTBED_hosts_load_from_loadleveler (const struct
+ GNUNET_CONFIGURATION_Handle *cfg,
+ struct GNUNET_TESTBED_Host
+ ***hosts);
+
+/**
* Destroy a host handle. Must only be called once everything
* running on that host has been stopped.
*
Modified: gnunet/src/testbed/gnunet_testbed_mpi_spawn.c
===================================================================
--- gnunet/src/testbed/gnunet_testbed_mpi_spawn.c 2013-02-27 14:12:33 UTC
(rev 26214)
+++ gnunet/src/testbed/gnunet_testbed_mpi_spawn.c 2013-02-27 14:22:24 UTC
(rev 26215)
@@ -1,6 +1,7 @@
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_resolver_service.h"
+#include "gnunet_testbed_service.h"
#include <mpi.h>
/**
@@ -22,216 +23,21 @@
GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
/**
- * Log an error message at log-level 'level' that indicates
- * a failure of the command 'cmd' with the message given
- * by gcry_strerror(rc).
- */
-#define LOG_GAI(level, cmd, rc) do { LOG(level, _("`%s' failed at %s:%d with
error: %s\n"), cmd, __FILE__, __LINE__, gai_strerror(rc)); } while(0)
-
-/**
* Global result
*/
static int ret;
/**
- * The array of hostnames
+ * The host list
*/
-static char **hostnames;
+static struct GNUNET_TESTBED_Host **hosts;
/**
- * The array of host's addresses
+ * Number of hosts in the host list
*/
-static char **hostaddrs;
-
-/**
- * The resolution request handles; one per each hostname resolution
- */
-struct GNUNET_RESOLVER_RequestHandle **rhs;
-
-/**
- * Number of hosts in the hostname array
- */
static unsigned int nhosts;
/**
- * Number of addresses in the hostaddr array
- */
-static unsigned int nhostaddrs;
-
-/**
- * Did we connect to the resolver service
- */
-static unsigned int resolver_connected;
-
-/**
- * Task for resolving ips
- */
-static GNUNET_SCHEDULER_TaskIdentifier resolve_task_id;
-
-
-/**
- * Resolves the hostnames array
- *
- * @param cls NULL
- * @param tc the scheduler task context
- */
-static void
-resolve_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
- struct addrinfo hint;
- const struct sockaddr_in *in_addr;
- struct addrinfo *res;
- char *hostip;
- unsigned int host;
- unsigned int rc;
-
- resolve_task_id = GNUNET_SCHEDULER_NO_TASK;
- hint.ai_family = AF_INET; /* IPv4 */
- hint.ai_socktype = 0;
- hint.ai_protocol = 0;
- hint.ai_addrlen = 0;
- hint.ai_addr = NULL;
- hint.ai_canonname = NULL;
- hint.ai_next = NULL;
- hint.ai_flags = AI_NUMERICSERV;
- for (host = 0; host < nhosts; host++)
- {
- res = NULL;
- LOG_DEBUG ("Resolving: %s host\n", hostnames[host]);
- if (0 != (rc = getaddrinfo (hostnames[host], "22", &hint, &res)))
- {
- LOG_GAI (GNUNET_ERROR_TYPE_ERROR, "getaddrinfo", rc);
- ret = GNUNET_SYSERR;
- return;
- }
- GNUNET_assert (NULL != res);
- GNUNET_assert (NULL != res->ai_addr);
- GNUNET_assert (sizeof (struct sockaddr_in) == res->ai_addrlen);
- in_addr = (const struct sockaddr_in *) res->ai_addr;
- hostip = inet_ntoa (in_addr->sin_addr);
- GNUNET_assert (NULL != hostip);
- GNUNET_array_append (hostaddrs, nhostaddrs, GNUNET_strdup (hostip));
- LOG_DEBUG ("%s --> %s\n", hostnames[host], hostaddrs[host]);
- freeaddrinfo (res);
- }
- ret = GNUNET_OK;
-}
-
-
-/**
- * Loads the set of host allocated by the LoadLeveler Job Scheduler. This
- * function is only available when compiled with support for LoadLeveler and is
- * used for running on the SuperMUC
- *
- * @param hostlist set to the hosts found in the file; caller must free this if
- * number of hosts returned is greater than 0
- * @return number of hosts returned in 'hosts', 0 on error
- */
-unsigned int
-get_loadleveler_hosts ()
-{
- const char *hostfile;
- char *buf;
- char *hostname;
- struct addrinfo *ret;
- struct addrinfo hint;
- ssize_t rsize;
- uint64_t size;
- uint64_t offset;
- enum {
- SCAN,
- SKIP,
- TRIM,
- READHOST
- } pstep;
- unsigned int host;
-
- if (NULL == (hostfile = getenv ("MP_SAVEHOSTFILE")))
- {
- GNUNET_break (0);
- return 0;
- }
- if (GNUNET_SYSERR == GNUNET_DISK_file_size (hostfile, &size, GNUNET_YES,
- GNUNET_YES))
- {
- GNUNET_break (0);
- return 0;
- }
- if (0 == size)
- {
- GNUNET_break (0);
- return 0;
- }
- buf = GNUNET_malloc (size + 1);
- rsize = GNUNET_DISK_fn_read (hostfile, buf, (size_t) size);
- if ( (GNUNET_SYSERR == rsize) || ((ssize_t) size != rsize) )
- {
- GNUNET_free (buf);
- GNUNET_break (0);
- return 0;
- }
- size++;
- offset = 0;
- pstep = SCAN;
- hostname = NULL;
- while (offset < size)
- {
- switch (pstep)
- {
- case SCAN:
- if ('!' == buf[offset])
- pstep = SKIP;
- else
- pstep = TRIM;
- break;
- case SKIP:
- if ('\n' == buf[offset])
- pstep = SCAN;
- break;
- case TRIM:
- if ('!' == buf[offset])
- {
- pstep = SKIP;
- break;
- }
- if ( (' ' == buf[offset])
- || ('\t' == buf[offset])
- || ('\r' == buf[offset]) )
- pstep = TRIM;
- else
- {
- pstep = READHOST;
- hostname = &buf[offset];
- }
- break;
- case READHOST:
- if (isspace (buf[offset]))
- {
- buf[offset] = '\0';
- for (host = 0; host < nhosts; host++)
- if (0 == strcmp (hostnames[host], hostname))
- break;
- if (host == nhosts)
- {
- LOG_DEBUG ("Adding host: %s\n", hostname);
- hostname = GNUNET_strdup (hostname);
- GNUNET_array_append (hostnames, nhosts, hostname);
- }
- else
- LOG_DEBUG ("Not adding host %s as it is already included\n",
hostname);
- hostname = NULL;
- pstep = SCAN;
- }
- break;
- }
- offset++;
- }
- GNUNET_free_non_null (buf);
- return nhosts;
-}
-
-
-/**
* Main function that will be run by the scheduler.
*
* @param cls closure
@@ -247,7 +53,7 @@
unsigned long code;
enum GNUNET_OS_ProcessStatusType proc_status;
int rank;
- int msg_size;
+ unsigned int host;
if (MPI_SUCCESS != MPI_Comm_rank (MPI_COMM_WORLD, &rank))
{
@@ -291,13 +97,17 @@
GNUNET_break (0);
return;
}
- if (0 == get_loadleveler_hosts())
+ if (0 == (nhosts = GNUNET_TESTBED_hosts_load_from_loadleveler (config,
&hosts)))
{
GNUNET_break (0);
ret = GNUNET_SYSERR;
return;
}
- resolve_task_id = GNUNET_SCHEDULER_add_now (&resolve_task, NULL);
+ for (host = 0; host < nhosts; host++)
+ GNUNET_TESTBED_host_destroy (hosts[host]);
+ GNUNET_free (hosts);
+ hosts = NULL;
+ ret = GNUNET_OK;
}
@@ -330,12 +140,6 @@
_("Spawns cmd after starting my the MPI run-time"),
options, &run, NULL);
(void) MPI_Finalize ();
- for (host = 0; host < nhosts; host++)
- GNUNET_free (hostnames[host]);
- for (host = 0; host < nhostaddrs; host++)
- GNUNET_free (hostaddrs[host]);
- GNUNET_free_non_null (hostnames);
- GNUNET_free_non_null (hostaddrs);
if ((GNUNET_OK == rres) && (GNUNET_OK == ret))
return 0;
printf ("Something went wrong\n");
Modified: gnunet/src/testbed/testbed_api_hosts.c
===================================================================
--- gnunet/src/testbed/testbed_api_hosts.c 2013-02-27 14:12:33 UTC (rev
26214)
+++ gnunet/src/testbed/testbed_api_hosts.c 2013-02-27 14:22:24 UTC (rev
26215)
@@ -63,6 +63,12 @@
} while (0)
/**
+ * Log an error message at log-level 'level' that indicates a failure of the
+ * command 'cmd' with the message given by gai_strerror(rc).
+ */
+#define LOG_GAI(level, cmd, rc) do { LOG(level, _("`%s' failed at %s:%d with
error: %s\n"), cmd, __FILE__, __LINE__, gai_strerror(rc)); } while(0)
+
+/**
* Number of extra elements we create space for when we grow host list
*/
#define HOST_LIST_GROW_STEP 10
@@ -525,6 +531,200 @@
/**
+ * Resolves a hostname using getaddrinfo
+ *
+ * @param host the hostname
+ * @return the string representing the IPv4 address of the given host; NULL
upon error
+ */
+const char *
+simple_resolve (const char *host)
+{
+ struct addrinfo *res;
+ const struct sockaddr_in *in_addr;
+ char *hostip;
+ struct addrinfo hint;
+ unsigned int rc;
+
+ hint.ai_family = AF_INET; /* IPv4 */
+ hint.ai_socktype = 0;
+ hint.ai_protocol = 0;
+ hint.ai_addrlen = 0;
+ hint.ai_addr = NULL;
+ hint.ai_canonname = NULL;
+ hint.ai_next = NULL;
+ hint.ai_flags = AI_NUMERICSERV;
+ res = NULL;
+ LOG_DEBUG ("Resolving [%s]\n", host);
+ if (0 != (rc = getaddrinfo (host, "22", &hint, &res)))
+ {
+ LOG_GAI (GNUNET_ERROR_TYPE_ERROR, "getaddrinfo", rc);
+ return NULL;
+ }
+ GNUNET_assert (NULL != res);
+ GNUNET_assert (NULL != res->ai_addr);
+ GNUNET_assert (sizeof (struct sockaddr_in) == res->ai_addrlen);
+ in_addr = (const struct sockaddr_in *) res->ai_addr;
+ hostip = inet_ntoa (in_addr->sin_addr);
+ GNUNET_assert (NULL != hostip);
+ LOG_DEBUG ("Resolved [%s] to [%s]\n", host, hostip);
+ return hostip;
+}
+
+
+/**
+ * Loads the set of host allocated by the LoadLeveler Job Scheduler. This
+ * function is only available when compiled with support for LoadLeveler and is
+ * used for running on the SuperMUC
+ *
+ * @param cfg the configuration to use as a template while starting a
controller
+ * on any of the loaded hosts. Operation queue sizes specific to a
host
+ * are also read from this configuration handle
+ * @param hosts set to the hosts found in the file; caller must free this if
+ * number of hosts returned is greater than 0
+ * @return number of hosts returned in 'hosts', 0 on error
+ */
+unsigned int
+GNUNET_TESTBED_hosts_load_from_loadleveler (const struct
+ GNUNET_CONFIGURATION_Handle *cfg,
+ struct GNUNET_TESTBED_Host
***hosts)
+{
+ const char *hostfile;
+ char *buf;
+ char *hostname;
+ char **hostnames;
+ char **hostaddrs;
+ char *hostip;
+ struct GNUNET_TESTBED_Host **host_list;
+ ssize_t rsize;
+ uint64_t size;
+ uint64_t offset;
+ enum {
+ SCAN,
+ SKIP,
+ TRIM,
+ READHOST
+ } pstep;
+ unsigned int host;
+ unsigned int nhosts;
+ unsigned int nhostaddrs;
+
+ if (NULL == (hostfile = getenv ("MP_SAVEHOSTFILE")))
+ {
+ GNUNET_break (0);
+ return 0;
+ }
+ if (GNUNET_SYSERR == GNUNET_DISK_file_size (hostfile, &size, GNUNET_YES,
+ GNUNET_YES))
+ {
+ GNUNET_break (0);
+ return 0;
+ }
+ if (0 == size)
+ {
+ GNUNET_break (0);
+ return 0;
+ }
+ buf = GNUNET_malloc (size + 1);
+ rsize = GNUNET_DISK_fn_read (hostfile, buf, (size_t) size);
+ if ( (GNUNET_SYSERR == rsize) || ((ssize_t) size != rsize) )
+ {
+ GNUNET_free (buf);
+ GNUNET_break (0);
+ return 0;
+ }
+ size++;
+ offset = 0;
+ pstep = SCAN;
+ hostname = NULL;
+ hostnames = NULL;
+ hostaddrs = NULL;
+ nhosts = 0;
+ nhostaddrs = 0;
+ while (offset < size)
+ {
+ switch (pstep)
+ {
+ case SCAN:
+ if ('!' == buf[offset])
+ pstep = SKIP;
+ else
+ pstep = TRIM;
+ break;
+ case SKIP:
+ if ('\n' == buf[offset])
+ pstep = SCAN;
+ break;
+ case TRIM:
+ if ('!' == buf[offset])
+ {
+ pstep = SKIP;
+ break;
+ }
+ if ( (' ' == buf[offset])
+ || ('\t' == buf[offset])
+ || ('\r' == buf[offset]) )
+ pstep = TRIM;
+ else
+ {
+ pstep = READHOST;
+ hostname = &buf[offset];
+ }
+ break;
+ case READHOST:
+ if (isspace (buf[offset]))
+ {
+ buf[offset] = '\0';
+ for (host = 0; host < nhosts; host++)
+ if (0 == strcmp (hostnames[host], hostname))
+ break;
+ if (host == nhosts)
+ {
+ LOG_DEBUG ("Adding host [%s]\n", hostname);
+ hostname = GNUNET_strdup (hostname);
+ GNUNET_array_append (hostnames, nhosts, hostname);
+ }
+ else
+ LOG_DEBUG ("Not adding host [%s] as it is already included\n",
hostname);
+ hostname = NULL;
+ pstep = SCAN;
+ }
+ break;
+ }
+ offset++;
+ }
+ GNUNET_free_non_null (buf);
+ if (NULL == hostnames)
+ return 0;
+ for (host = 0; host < nhosts; host++)
+ {
+ hostip = simple_resolve (hostnames[host]);
+ if (NULL == hostip)
+ {
+ nhosts = 0;
+ goto cleanup;
+ }
+ GNUNET_array_append (hostaddrs, nhostaddrs, GNUNET_strdup (hostip));
+ }
+ GNUNET_assert (nhostaddrs == nhosts);
+ if (NULL == hosts)
+ goto cleanup;
+ host_list = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Host *) *
nhostaddrs);
+ for (host = 0; host < nhosts; host++)
+ host_list[host] = GNUNET_TESTBED_host_create (hostaddrs[host], NULL, cfg,
0);
+ *hosts = host_list;
+
+ cleanup:
+ for (host = 0; host < nhosts; host++)
+ GNUNET_free (hostnames[host]);
+ GNUNET_free(hostnames);
+ for (host = 0; (NULL != hostaddrs) && (host < nhostaddrs); host++)
+ GNUNET_free (hostaddrs[host]);
+ GNUNET_free (hostaddrs);
+ return nhosts;
+}
+
+
+/**
* Destroy a host handle. Must only be called once everything
* running on that host has been stopped.
*
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r26215 - in gnunet/src: include testbed,
gnunet <=