Skip to content

Commit a0703b1

Browse files
committed
Provide better FQDN support
We strip FQDNs by default because of the inherent problem of interacting with users, who generally don't like typing all that extra stuff. However, that creates a problem when being provided FQDN input during things like nspace registration. So add an MCA param to control the strip operation instead of only switching it on/off via info directing during init. Add logic to the nspace registration process to perform the strip and add aliases (for the case where the host failed to provide them). Signed-off-by: Ralph Castain <rhc@pmix.org> (cherry picked from commit c36cae0)
1 parent 59bd6f7 commit a0703b1

File tree

9 files changed

+60
-18
lines changed

9 files changed

+60
-18
lines changed

src/include/pmix_globals.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,7 @@ typedef struct {
766766
gid_t realgid; // real gid
767767
gid_t gid; // my effective gid
768768
char *hostname; // my hostname
769+
char **aliases; // aliases for my hostname
769770
uint32_t appnum; // my appnum
770771
pid_t pid; // my local pid
771772
uint32_t nodeid; // my nodeid, if given

src/mca/gds/hash/gds_hash.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "src/mca/pmdl/pmdl.h"
4141
#include "src/mca/preg/preg.h"
4242
#include "src/mca/ptl/base/base.h"
43+
#include "src/runtime/pmix_rte.h"
4344
#include "src/server/pmix_server_ops.h"
4445
#include "src/util/pmix_argv.h"
4546
#include "src/util/pmix_error.h"
@@ -380,6 +381,7 @@ static pmix_status_t hash_cache_job_info(struct pmix_namespace_t *ns,
380381
if (NULL == nd) {
381382
nd = PMIX_NEW(pmix_nodeinfo_t);
382383
nd->hostname = strdup(pmix_globals.hostname);
384+
pmix_set_aliases(&nd->aliases, nd->hostname);
383385
pmix_list_append(&trk->nodeinfo, &nd->super);
384386
}
385387
/* ensure the value isn't already on the node info */

src/mca/gds/hash/gds_utils.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Copyright (c) 2018-2020 Mellanox Technologies, Inc.
77
* All rights reserved.
88
* Copyright (c) 2023 Triad National Security, LLC. All rights reserved.
9-
* Copyright (c) 2021-2022 Nanook Consulting. All rights reserved.
9+
* Copyright (c) 2021-2025 Nanook Consulting All rights reserved.
1010
* $COPYRIGHT$
1111
*
1212
* Additional copyrights may follow
@@ -40,11 +40,13 @@
4040
#include "src/mca/pmdl/pmdl.h"
4141
#include "src/mca/preg/preg.h"
4242
#include "src/mca/ptl/base/base.h"
43+
#include "src/runtime/pmix_rte.h"
4344
#include "src/server/pmix_server_ops.h"
4445
#include "src/util/pmix_argv.h"
4546
#include "src/util/pmix_error.h"
4647
#include "src/util/pmix_hash.h"
4748
#include "src/util/pmix_name_fns.h"
49+
#include "src/util/pmix_net.h"
4850
#include "src/util/pmix_output.h"
4951
#include "src/util/pmix_environ.h"
5052

@@ -104,7 +106,8 @@ bool pmix_gds_hash_check_node(pmix_nodeinfo_t *n1, pmix_nodeinfo_t *n2)
104106
{
105107
int i, j;
106108

107-
if (UINT32_MAX != n1->nodeid && UINT32_MAX != n2->nodeid && n1->nodeid == n2->nodeid) {
109+
if (UINT32_MAX != n1->nodeid && UINT32_MAX != n2->nodeid &&
110+
n1->nodeid == n2->nodeid) {
108111
return true;
109112
}
110113

@@ -334,6 +337,7 @@ pmix_status_t pmix_gds_hash_store_map(pmix_job_t *trk, char **nodes, char **ppn,
334337
if (NULL == nd) {
335338
nd = PMIX_NEW(pmix_nodeinfo_t);
336339
nd->hostname = strdup(nodes[n]);
340+
pmix_set_aliases(&nd->aliases, nd->hostname);
337341
nd->nodeid = n;
338342
pmix_list_append(&trk->nodeinfo, &nd->super);
339343
}
@@ -430,7 +434,7 @@ pmix_status_t pmix_gds_hash_store_map(pmix_job_t *trk, char **nodes, char **ppn,
430434
kp2->key = strdup(PMIX_HOSTNAME);
431435
kp2->value = (pmix_value_t *) malloc(sizeof(pmix_value_t));
432436
kp2->value->type = PMIX_STRING;
433-
kp2->value->data.string = strdup(nodes[n]);
437+
kp2->value->data.string = strdup(nd->hostname);
434438
rank = strtol(procs[m], NULL, 10);
435439
pmix_output_verbose(2, pmix_gds_base_framework.framework_output,
436440
"[%s:%d] gds:hash:store_map for [%s:%u]: key %s",

src/mca/gds/hash/process_arrays.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,13 @@
4141
#include "src/mca/pmdl/pmdl.h"
4242
#include "src/mca/preg/preg.h"
4343
#include "src/mca/ptl/base/base.h"
44+
#include "src/runtime/pmix_rte.h"
4445
#include "src/server/pmix_server_ops.h"
4546
#include "src/util/pmix_argv.h"
4647
#include "src/util/pmix_error.h"
4748
#include "src/util/pmix_hash.h"
4849
#include "src/util/pmix_name_fns.h"
50+
#include "src/util/pmix_net.h"
4951
#include "src/util/pmix_output.h"
5052
#include "src/util/pmix_environ.h"
5153

@@ -145,6 +147,10 @@ pmix_status_t pmix_gds_hash_process_node_array(pmix_value_t *val, pmix_list_t *t
145147
return PMIX_ERR_BAD_PARAM;
146148
}
147149

150+
if (NULL != nd->hostname) {
151+
pmix_set_aliases(&nd->aliases, nd->hostname);
152+
}
153+
148154
/* see if we already have this node on the
149155
* provided list */
150156
update = false;

src/runtime/pmix_finalize.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* Copyright (c) 2016-2019 Research Organization for Information Science
1717
* and Technology (RIST). All rights reserved.
1818
* Copyright (c) 2021-2023 Triad National Security, LLC. All rights reserved.
19-
* Copyright (c) 2021-2024 Nanook Consulting All rights reserved.
19+
* Copyright (c) 2021-2025 Nanook Consulting All rights reserved.
2020
* $COPYRIGHT$
2121
*
2222
* Additional copyrights may follow
@@ -144,6 +144,10 @@ void pmix_rte_finalize(void)
144144
free(pmix_globals.hostname);
145145
pmix_globals.hostname = NULL;
146146
}
147+
if (NULL != pmix_globals.aliases) {
148+
PMIx_Argv_free(pmix_globals.aliases);
149+
pmix_globals.aliases = NULL;
150+
}
147151
PMIX_LIST_DESTRUCT(&pmix_globals.nspaces);
148152
PMIX_LIST_DESTRUCT(&pmix_client_globals.groups);
149153
PMIX_DESTRUCT(&pmix_globals.keyindex);

src/runtime/pmix_init.c

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
#endif
3737

3838
#include "src/include/pmix_globals.h"
39+
#include "src/include/pmix_dictionary.h"
40+
#include "src/include/pmix_types.h"
41+
3942
#include "src/mca/base/pmix_base.h"
4043
#include "src/mca/base/pmix_mca_base_var.h"
4144
#include "src/mca/bfrops/base/base.h"
@@ -49,6 +52,9 @@
4952
#include "src/mca/psec/base/base.h"
5053
#include "src/mca/psquash/base/base.h"
5154
#include "src/mca/ptl/base/base.h"
55+
56+
#include "src/util/pmix_error.h"
57+
#include "src/util/pmix_keyval_parse.h"
5258
#include "src/util/pmix_name_fns.h"
5359
#include "src/util/pmix_net.h"
5460
#include "src/util/pmix_output.h"
@@ -58,10 +64,6 @@
5864
#include "src/client/pmix_client_ops.h"
5965
#include "src/common/pmix_attributes.h"
6066
#include "src/event/pmix_event.h"
61-
#include "src/include/pmix_dictionary.h"
62-
#include "src/include/pmix_types.h"
63-
#include "src/util/pmix_error.h"
64-
#include "src/util/pmix_keyval_parse.h"
6567

6668
#include "src/runtime/pmix_progress_threads.h"
6769
#include "src/runtime/pmix_rte.h"
@@ -87,6 +89,7 @@ PMIX_EXPORT pmix_globals_t pmix_globals = {
8789
.realgid = 0,
8890
.gid = 0,
8991
.hostname = NULL,
92+
.aliases = NULL,
9093
.appnum = 0,
9194
.pid = 0,
9295
.nodeid = UINT32_MAX,
@@ -226,7 +229,6 @@ int pmix_rte_init(uint32_t type, pmix_info_t info[], size_t ninfo, pmix_ptl_cbfu
226229
char hostname[PMIX_MAXHOSTNAMELEN] = {0};
227230
pmix_info_t *iptr;
228231
size_t minfo;
229-
bool keepfqdn = false;
230232
pmix_iof_flags_t flags;
231233

232234
#if PMIX_NO_LIB_DESTRUCTOR
@@ -283,7 +285,7 @@ int pmix_rte_init(uint32_t type, pmix_info_t info[], size_t ninfo, pmix_ptl_cbfu
283285
} else if (PMIX_CHECK_KEY(&info[n], PMIX_EXTERNAL_AUX_EVENT_BASE)) {
284286
pmix_globals.evauxbase = (pmix_event_base_t*)info[n].value.data.ptr;
285287
} else if (PMIX_CHECK_KEY(&info[n], PMIX_HOSTNAME_KEEP_FQDN)) {
286-
keepfqdn = PMIX_INFO_TRUE(&info[n]);
288+
pmix_keep_fqdn_hostnames = PMIX_INFO_TRUE(&info[n]);
287289
} else if (PMIX_CHECK_KEY(&info[n], PMIX_BIND_PROGRESS_THREAD)) {
288290
if (NULL != pmix_progress_thread_cpus) {
289291
free(pmix_progress_thread_cpus);
@@ -435,12 +437,9 @@ int pmix_rte_init(uint32_t type, pmix_info_t info[], size_t ninfo, pmix_ptl_cbfu
435437
/* if we weren't previously given a hostname, then
436438
* use the OS one */
437439
gethostname(hostname, PMIX_MAXHOSTNAMELEN - 1);
438-
/* strip the FQDN unless told to keep it */
439-
if (!keepfqdn && !pmix_net_isaddr(hostname) && NULL != (evar = strchr(hostname, '.'))) {
440-
*evar = '\0';
441-
}
442440
pmix_globals.hostname = strdup(hostname);
443441
}
442+
pmix_set_aliases(&pmix_globals.aliases, pmix_globals.hostname);
444443
}
445444

446445
/* the choice of modules to use when communicating with a peer
@@ -582,3 +581,23 @@ int pmix_finalize_util(void)
582581
util_initialized = false;
583582
return PMIX_SUCCESS;
584583
}
584+
585+
void pmix_set_aliases(char ***aliases, char *hostname)
586+
{
587+
char *ptr;
588+
589+
if (!pmix_net_isaddr(hostname) &&
590+
NULL != (ptr = strchr(hostname, '.'))) {
591+
if (pmix_keep_fqdn_hostnames) {
592+
/* retain the non-fqdn name as an alias */
593+
*ptr = '\0';
594+
PMIx_Argv_append_unique_nosize(aliases, hostname);
595+
*ptr = '.';
596+
} else {
597+
/* add the fqdn name as an alias */
598+
PMIx_Argv_append_unique_nosize(aliases, hostname);
599+
/* retain the non-fqdn name as the node's name */
600+
*ptr = '\0';
601+
}
602+
}
603+
}

src/runtime/pmix_params.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ char *pmix_progress_thread_cpus = NULL;
5353
bool pmix_bind_progress_thread_reqd = false;
5454
int pmix_maxfd = 1024;
5555
int pmix_server_client_fintime;
56+
bool pmix_keep_fqdn_hostnames = false;
5657

5758
pmix_status_t pmix_register_params(void)
5859
{
@@ -287,6 +288,12 @@ pmix_status_t pmix_register_params(void)
287288
PMIX_MCA_BASE_VAR_TYPE_INT,
288289
&pmix_server_client_fintime);
289290

291+
pmix_keep_fqdn_hostnames = false;
292+
(void) pmix_mca_base_var_register("pmix", "pmix", NULL, "keep_fqdn_hostnames",
293+
"Whether or not to keep FQDN hostnames [default: no]",
294+
PMIX_MCA_BASE_VAR_TYPE_BOOL,
295+
&pmix_keep_fqdn_hostnames);
296+
290297
pmix_hwloc_register();
291298
return PMIX_SUCCESS;
292299
}

src/runtime/pmix_rte.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ PMIX_EXPORT extern char *pmix_progress_thread_cpus;
5252
PMIX_EXPORT extern bool pmix_bind_progress_thread_reqd;
5353
PMIX_EXPORT extern int pmix_maxfd;
5454
PMIX_EXPORT extern int pmix_server_client_fintime;
55+
PMIX_EXPORT extern bool pmix_keep_fqdn_hostnames;
5556

5657
/** version string of pmix */
5758
extern const char pmix_version_string[];
@@ -78,6 +79,8 @@ PMIX_EXPORT void pmix_rte_finalize(void);
7879
PMIX_EXPORT pmix_status_t pmix_register_params(void);
7980
PMIX_EXPORT pmix_status_t pmix_deregister_params(void);
8081

82+
PMIX_EXPORT void pmix_set_aliases(char ***aliases, char *hostname);
83+
8184
END_C_DECLS
8285

8386
#endif /* PMIX_RTE_H */

src/server/pmix_server_resolve.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,6 @@ void pmix_server_locally_resolve_peers(int sd, short args, void *cbdata)
177177
// second qualifier in the query has the nodename
178178
nd = cd->query->qualifiers[1].value.data.string;
179179

180-
// restrict our search to already available info
181-
PMIX_INFO_LOAD(&info[0], PMIX_OPTIONAL, NULL, PMIX_BOOL);
182-
183-
184180
PMIX_CONSTRUCT(&cb, pmix_cb_t);
185181
proc.rank = PMIX_RANK_UNDEF;
186182
cb.proc = &proc;

0 commit comments

Comments
 (0)