Skip to content

Commit

Permalink
Merge pull request #892 from grondo/hwloc-byrank-hostname
Browse files Browse the repository at this point in the history
resource-hwloc: put HostName in by_rank directory
  • Loading branch information
chu11 committed Nov 3, 2016
2 parents a06cf00 + b096018 commit e8f8968
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/modules/resource-hwloc/resource.c
Expand Up @@ -266,6 +266,17 @@ static int walk_topology (flux_t *h,
return ret; return ret;
} }


static int put_hostname (flux_t *h, const char *base, const char *hostname)
{
int rc;
char *key;
if (asprintf (&key, "%s.HostName", base) < 0)
return (-1);
rc = kvs_put_string (h, key, hostname);
free (key);
return (rc);
}

static int load_info_to_kvs (flux_t *h, ctx_t *ctx) static int load_info_to_kvs (flux_t *h, ctx_t *ctx)
{ {
char *base_path = NULL; char *base_path = NULL;
Expand Down Expand Up @@ -296,6 +307,10 @@ static int load_info_to_kvs (flux_t *h, ctx_t *ctx)
const char *hostname = hwloc_obj_get_info_by_name (machine, "HostName"); const char *hostname = hwloc_obj_get_info_by_name (machine, "HostName");
char *kvs_hostname = escape_kvs_key (hostname); char *kvs_hostname = escape_kvs_key (hostname);
char *host_path = xasprintf ("resource.hwloc.by_host.%s", kvs_hostname); char *host_path = xasprintf ("resource.hwloc.by_host.%s", kvs_hostname);

if (put_hostname (h, base_path, hostname) < 0)
flux_log_error (h, "failed to record hostname for this rank");

free (kvs_hostname); free (kvs_hostname);
(void) kvs_unlink (h, host_path); (void) kvs_unlink (h, host_path);
if (ctx->walk_topology && if (ctx->walk_topology &&
Expand Down
6 changes: 6 additions & 0 deletions t/t2005-hwloc-basic.t
Expand Up @@ -116,4 +116,10 @@ test_expect_success 'hwloc: reload fails on invalid rank' '
grep "No route to host" stderr grep "No route to host" stderr
' '


test_expect_success 'hwloc: HostName is populated in by_rank' '
HW_HOST=$(flux kvs get resource.hwloc.by_rank.0.HostName) &&
REAL_HOST=$(hostname) &&
test x"$HW_HOST" = x"$REAL_HOST"
'

test_done test_done

0 comments on commit e8f8968

Please sign in to comment.