Skip to content

Commit

Permalink
DAOS-14532 gurt: fix environment APIs hook (#13579)
Browse files Browse the repository at this point in the history
Replace call to the standard getenv() function with d_isenv_def(), d_agetenv() and d_freeenv_str().
It also renames the d_free_env_str() function intoduce in previous related PRs to d_freeenv_str().

Signed-off-by: Cedric Koch-Hofer <cedric.koch-hofer@intel.com>
  • Loading branch information
knard-intel authored and jolivier23 committed Feb 28, 2024
1 parent b4f9f8d commit 5dc0292
Show file tree
Hide file tree
Showing 41 changed files with 429 additions and 279 deletions.
3 changes: 2 additions & 1 deletion src/bio/bio_xstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,12 @@ bio_nvme_init(const char *nvme_conf, int numa_node, unsigned int mem_size,
nvme_glb.bd_bs_opts.cluster_sz = DAOS_BS_CLUSTER_SZ;
nvme_glb.bd_bs_opts.max_channel_ops = BIO_BS_MAX_CHANNEL_OPS;

env = getenv("VOS_BDEV_CLASS");
d_agetenv_str(&env, "VOS_BDEV_CLASS");
if (env && strcasecmp(env, "AIO") == 0) {
D_WARN("AIO device(s) will be used!\n");
nvme_glb.bd_bdev_class = BDEV_CLASS_AIO;
}
d_freeenv_str(&env);

if (numa_node > 0) {
bio_numa_node = (unsigned int)numa_node;
Expand Down
9 changes: 3 additions & 6 deletions src/cart/crt_hg.c
Original file line number Diff line number Diff line change
Expand Up @@ -782,8 +782,7 @@ crt_hg_free_protocol_info(struct na_protocol_info *na_protocol_info)
int
crt_hg_init(void)
{
int rc = 0;
char *env;
int rc = 0;

if (crt_initialized()) {
D_ERROR("CaRT already initialized.\n");
Expand All @@ -792,10 +791,8 @@ crt_hg_init(void)

#define EXT_FAC DD_FAC(external)

env = getenv("HG_LOG_SUBSYS");
if (!env) {
env = getenv("HG_LOG_LEVEL");
if (!env)
if (!d_isenv_def("HG_LOG_SUBSYS")) {
if (!d_isenv_def("HG_LOG_LEVEL"))
HG_Set_log_level("warning");
HG_Set_log_subsys("hg,na");
}
Expand Down
227 changes: 119 additions & 108 deletions src/cart/crt_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,44 @@ static volatile int gdata_init_flag;
struct crt_plugin_gdata crt_plugin_gdata;
static bool g_prov_settings_applied[CRT_PROV_COUNT];

/* List of the environment variables used in CaRT */
static const char *crt_env_names[] = {"D_PROVIDER",
"D_INTERFACE",
"D_DOMAIN",
"D_PORT",
"CRT_PHY_ADDR_STR",
"D_LOG_STDERR_IN_LOG",
"D_LOG_SIZE",
"D_LOG_FILE",
"D_LOG_FILE_APPEND_PID",
"D_LOG_MASK",
"DD_MASK",
"DD_STDERR",
"DD_SUBSYS",
"CRT_TIMEOUT",
"CRT_ATTACH_INFO_PATH",
"OFI_PORT",
"OFI_INTERFACE",
"OFI_DOMAIN",
"CRT_CREDIT_EP_CTX",
"CRT_CTX_SHARE_ADDR",
"CRT_CTX_NUM",
"D_FI_CONFIG",
"FI_UNIVERSE_SIZE",
"CRT_ENABLE_MEM_PIN",
"FI_OFI_RXM_USE_SRX",
"D_LOG_FLUSH",
"CRT_MRC_ENABLE",
"CRT_SECONDARY_PROVIDER",
"D_PROVIDER_AUTH_KEY",
"D_PORT_AUTO_ADJUST",
"D_POLL_TIMEOUT",
"D_LOG_FILE_APPEND_RANK",
"D_QUOTA_RPCS",
"D_POST_INIT",
"D_POST_INCR",
"DAOS_SIGNAL_REGISTER"};

static void
crt_lib_init(void) __attribute__((__constructor__));

Expand Down Expand Up @@ -62,51 +100,20 @@ crt_lib_fini(void)
static void
dump_envariables(void)
{
int i;
char *val;
char *envars[] = {"D_PROVIDER",
"D_INTERFACE",
"D_DOMAIN",
"D_PORT",
"CRT_PHY_ADDR_STR",
"D_LOG_STDERR_IN_LOG",
"D_LOG_SIZE",
"D_LOG_FILE",
"D_LOG_FILE_APPEND_PID",
"D_LOG_MASK",
"DD_MASK",
"DD_STDERR",
"DD_SUBSYS",
"CRT_TIMEOUT",
"CRT_ATTACH_INFO_PATH",
"OFI_PORT",
"OFI_INTERFACE",
"OFI_DOMAIN",
"CRT_CREDIT_EP_CTX",
"CRT_CTX_SHARE_ADDR",
"CRT_CTX_NUM",
"D_FI_CONFIG",
"FI_UNIVERSE_SIZE",
"CRT_ENABLE_MEM_PIN",
"FI_OFI_RXM_USE_SRX",
"D_LOG_FLUSH",
"CRT_MRC_ENABLE",
"CRT_SECONDARY_PROVIDER",
"D_PROVIDER_AUTH_KEY",
"D_PORT_AUTO_ADJUST",
"D_POLL_TIMEOUT",
"D_LOG_FILE_APPEND_RANK",
"D_QUOTA_RPCS",
"D_POST_INIT",
"D_POST_INCR"};
int i;

D_INFO("-- ENVARS: --\n");
for (i = 0; i < ARRAY_SIZE(envars); i++) {
val = getenv(envars[i]);
if (strcmp(envars[i], "D_PROVIDER_AUTH_KEY") == 0 && val)
D_INFO("%s = %s\n", envars[i], "********");
for (i = 0; i < ARRAY_SIZE(crt_env_names); i++) {
char *val = NULL;

d_agetenv_str(&val, crt_env_names[i]);
if (val == NULL)
continue;
if (strcmp(crt_env_names[i], "D_PROVIDER_AUTH_KEY") == 0)
D_INFO("%s = %s\n", crt_env_names[i], "********");
else
D_INFO("%s = %s\n", envars[i], val);
D_INFO("%s = %s\n", crt_env_names[i], val);
d_freeenv_str(&val);
}
}

Expand Down Expand Up @@ -598,38 +605,37 @@ crt_protocol_info_free(struct crt_protocol_info *protocol_info)
int
crt_init_opt(crt_group_id_t grpid, uint32_t flags, crt_init_options_t *opt)
{
char *provider_env;
char *interface_env;
char *domain_env;
char *auth_key_env;
char *tmp;
struct timeval now;
unsigned int seed;
const char *path;
bool server;
int rc = 0;
char *provider_str0 = NULL;
char *provider_str1 = NULL;
crt_provider_t primary_provider;
crt_provider_t secondary_provider;
crt_provider_t tmp_prov;
char *port_str, *port0, *port1;
char *iface0, *iface1, *domain0, *domain1;
char *auth_key0, *auth_key1;
int num_secondaries = 0;
bool port_auto_adjust = false;
int i;

server = flags & CRT_FLAG_BIT_SERVER;
port_str = NULL;
port0 = NULL;
port1 = NULL;
iface0 = NULL;
iface1 = NULL;
domain0 = NULL;
domain1 = NULL;
auth_key0 = NULL;
auth_key1 = NULL;
char *provider;
char *provider_env = NULL;
char *interface;
char *interface_env = NULL;
char *domain;
char *domain_env = NULL;
char *auth_key;
char *auth_key_env = NULL;
struct timeval now;
unsigned int seed;
char *path;
bool server = flags & CRT_FLAG_BIT_SERVER;
int rc = 0;
char *provider_str0 = NULL;
char *provider_str1 = NULL;
crt_provider_t primary_provider;
crt_provider_t secondary_provider;
crt_provider_t tmp_prov;
char *port;
char *port_env = NULL;
char *port0 = NULL;
char *port1 = NULL;
char *iface0 = NULL;
char *iface1 = NULL;
char *domain0 = NULL;
char *domain1 = NULL;
char *auth_key0 = NULL;
char *auth_key1 = NULL;
int num_secondaries = 0;
bool port_auto_adjust = false;
int i;

/* d_log_init is reference counted */
rc = d_log_init();
Expand Down Expand Up @@ -677,7 +683,7 @@ crt_init_opt(crt_group_id_t grpid, uint32_t flags, crt_init_options_t *opt)
crt_gdata.cg_auto_swim_disable =
(flags & CRT_FLAG_BIT_AUTO_SWIM_DISABLE) ? 1 : 0;

path = getenv("CRT_ATTACH_INFO_PATH");
d_agetenv_str(&path, "CRT_ATTACH_INFO_PATH");
if (path != NULL && strlen(path) > 0) {
rc = crt_group_config_path_set(path);
if (rc != 0)
Expand All @@ -687,76 +693,76 @@ crt_init_opt(crt_group_id_t grpid, uint32_t flags, crt_init_options_t *opt)
else
D_DEBUG(DB_ALL, "set group_config_path as %s.\n", path);
}
d_freeenv_str(&path);

if (opt && opt->cio_auth_key)
auth_key_env = opt->cio_auth_key;
else
auth_key_env = getenv("D_PROVIDER_AUTH_KEY");
auth_key = opt->cio_auth_key;
else {
d_agetenv_str(&auth_key_env, "D_PROVIDER_AUTH_KEY");
auth_key = auth_key_env;
}

if (opt && opt->cio_provider)
provider_env = opt->cio_provider;
provider = opt->cio_provider;
else {
provider_env = getenv(CRT_PHY_ADDR_ENV);

tmp = getenv("D_PROVIDER");
if (tmp)
provider_env = tmp;
d_agetenv_str(&provider_env, "D_PROVIDER");
if (provider_env == NULL)
d_agetenv_str(&provider_env, CRT_PHY_ADDR_ENV);
provider = provider_env;
}

if (opt && opt->cio_interface)
interface_env = opt->cio_interface;
interface = opt->cio_interface;
else {
interface_env = getenv("OFI_INTERFACE");

tmp = getenv("D_INTERFACE");
if (tmp)
interface_env = tmp;
d_agetenv_str(&interface_env, "D_INTERFACE");
if (interface_env == NULL) {
d_agetenv_str(&interface_env, "OFI_INTERFACE");
}
interface = interface_env;
}

if (opt && opt->cio_domain)
domain_env = opt->cio_domain;
domain = opt->cio_domain;
else {
domain_env = getenv("OFI_DOMAIN");

tmp = getenv("D_DOMAIN");
if (tmp)
domain_env = tmp;
d_agetenv_str(&domain_env, "D_DOMAIN");
if (domain_env == NULL)
d_agetenv_str(&domain_env, "OFI_DOMAIN");
domain = domain_env;
}

if (opt && opt->cio_port)
port_str = opt->cio_port;
port = opt->cio_port;
else {
port_str = getenv("OFI_PORT");

tmp = getenv("D_PORT");
if (tmp)
port_str = tmp;
d_agetenv_str(&port_env, "D_PORT");
if (port_env == NULL)
d_agetenv_str(&port_env, "OFI_PORT");
port = port_env;
}

d_getenv_bool("D_PORT_AUTO_ADJUST", &port_auto_adjust);

rc = __split_arg(provider_env, &provider_str0, &provider_str1);
rc = __split_arg(provider, &provider_str0, &provider_str1);
if (rc != 0)
D_GOTO(unlock, rc);

primary_provider = crt_str_to_provider(provider_str0);
secondary_provider = crt_str_to_provider(provider_str1);

if (primary_provider == CRT_PROV_UNKNOWN) {
D_ERROR("Requested provider %s not found\n", provider_env);
D_ERROR("Requested provider %s not found\n", provider);
D_GOTO(unlock, rc = -DER_NONEXIST);
}

rc = __split_arg(interface_env, &iface0, &iface1);
rc = __split_arg(interface, &iface0, &iface1);
if (rc != 0)
D_GOTO(unlock, rc);
rc = __split_arg(domain_env, &domain0, &domain1);
rc = __split_arg(domain, &domain0, &domain1);
if (rc != 0)
D_GOTO(unlock, rc);
rc = __split_arg(port_str, &port0, &port1);
rc = __split_arg(port, &port0, &port1);
if (rc != 0)
D_GOTO(unlock, rc);
rc = __split_arg(auth_key_env, &auth_key0, &auth_key1);
rc = __split_arg(auth_key, &auth_key0, &auth_key1);
if (rc != 0)
D_GOTO(unlock, rc);

Expand Down Expand Up @@ -896,6 +902,11 @@ crt_init_opt(crt_group_id_t grpid, uint32_t flags, crt_init_options_t *opt)
D_FREE(domain0);
D_FREE(provider_str0);
D_FREE(auth_key0);
d_freeenv_str(&port_env);
d_freeenv_str(&domain_env);
d_freeenv_str(&interface_env);
d_freeenv_str(&provider_env);
d_freeenv_str(&auth_key_env);

if (rc != 0) {
D_ERROR("failed, "DF_RC"\n", DP_RC(rc));
Expand Down
Loading

0 comments on commit 5dc0292

Please sign in to comment.