Skip to content

Commit

Permalink
fix bug causing cart test servers to be started with wrong ranks
Browse files Browse the repository at this point in the history
- add flag to indicate whether g_envs was inited
- assert on crt_env_get() if called when env is not inited
- move crt_env_get() in utils after crt_init()

Required-githooks: true

Signed-off-by: Alexander A Oganezov <[email protected]>
  • Loading branch information
frostedcmos committed Jun 4, 2024
1 parent 304b8bd commit 5499d54
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/cart/crt_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ crt_lib_init(void)
crt_gdata.cg_rpcid = start_rpcid;
crt_gdata.cg_num_cores = sysconf(_SC_NPROCESSORS_ONLN);
crt_gdata.cg_iv_inline_limit = 19456; /* 19KB */

/* envs not inited until crt_init() time */
memset(&g_envs, 0x0, sizeof(struct crt_envs_t));
}

/* Library deinit */
Expand Down Expand Up @@ -560,7 +563,7 @@ crt_init_opt(crt_group_id_t grpid, uint32_t flags, crt_init_options_t *opt)

crt_setup_log_fac();

D_INFO("libcart version %s initializing\n", CART_VERSION);
D_INFO("libcart (%s) v%s initializing\n", server ? "server" : "client", CART_VERSION);
crt_env_init();

if (opt)
Expand Down
12 changes: 11 additions & 1 deletion src/cart/crt_internal_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,18 +231,23 @@ struct crt_event_cb_priv {

struct crt_envs_t {
CRT_ENV_LIST;
bool inited;
};

#undef ENV
#undef ENV_STR
#undef ENV_STR_NO_PRINT

extern struct crt_envs_t g_envs;
static inline void crt_env_fini(void);

static inline void
crt_env_init(void)
{
memset(&g_envs, 0x0, sizeof(struct crt_envs_t));
/* release strings if already inited previously */
if (g_envs.inited)
crt_env_fini();

#define ENV(x) \
do { \
g_envs._rc_##x = d_getenv_uint(#x, &g_envs._##x); \
Expand All @@ -265,6 +270,8 @@ crt_env_init(void)
#undef ENV
#undef ENV_STR
#undef ENV_STR_NO_PRINT

g_envs.inited = true;
}

static inline void
Expand All @@ -279,10 +286,13 @@ crt_env_fini(void)
#undef ENV
#undef ENV_STR
#undef ENV_STR_NO_PRINT

g_envs.inited = false;
}

/* Returns value if env was present at load time */
#define crt_env_get(name, val) \
D_ASSERT(g_envs.inited); \
if (g_envs._rc_##name == 0) \
*val = g_envs._##name;

Expand Down
9 changes: 6 additions & 3 deletions src/cart/utils/crt_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -652,9 +652,6 @@ crtu_srv_start_basic(char *srv_group_name, crt_context_t *crt_ctx,
if (opts.assert_on_error)
D_ASSERTF(opts.is_initialized == true, "crtu_test_init not called.\n");

crt_env_get(CRT_L_RANK, &my_rank);
D_ASSERTF(rc == DER_SUCCESS, "Rank can not be retrieve: " DF_RC "\n", DP_RC(rc));

rc = d_log_init();
if (rc != 0)
D_GOTO(out, rc);
Expand All @@ -670,6 +667,12 @@ crtu_srv_start_basic(char *srv_group_name, crt_context_t *crt_ctx,
if (rc != 0)
D_GOTO(out, rc);

crt_env_get(CRT_L_RANK, &my_rank);
if (my_rank == CRT_NO_RANK) {
D_ERROR("CRT_L_RANK environment variable should have been set by crt_launch\n");
D_GOTO(out, rc = -DER_INVAL);
}

*grp = crt_group_lookup(NULL);
if (!(*grp)) {
D_ERROR("Group lookup failed\n");
Expand Down

0 comments on commit 5499d54

Please sign in to comment.