int eal_initialized;
size_t shm_size;
- const char *shm_name;
+ char shm_name[DATA_MAX_NAME_LEN];
sem_t sema_cmd_start;
sem_t sema_cmd_complete;
DPDK_HELPER_TRACE(phc->shm_name);
- ssnprintf(phc->eal_config.coremask, DATA_MAX_NAME_LEN, "%s", "0xf");
- ssnprintf(phc->eal_config.memory_channels, DATA_MAX_NAME_LEN, "%s", "1");
- ssnprintf(phc->eal_config.process_type, DATA_MAX_NAME_LEN, "%s", "secondary");
- ssnprintf(phc->eal_config.file_prefix, DATA_MAX_NAME_LEN, "%s",
- DPDK_DEFAULT_RTE_CONFIG);
+ snprintf(phc->eal_config.coremask, DATA_MAX_NAME_LEN, "%s", "0xf");
+ snprintf(phc->eal_config.memory_channels, DATA_MAX_NAME_LEN, "%s", "1");
+ snprintf(phc->eal_config.file_prefix, DATA_MAX_NAME_LEN, "%s",
+ DPDK_DEFAULT_RTE_CONFIG);
}
int dpdk_helper_eal_config_set(dpdk_helper_ctx_t *phc, dpdk_eal_config_t *ec) {
int status = 0;
for (int i = 0; i < ci->children_num; i++) {
oconfig_item_t *child = ci->children + i;
+
if (strcasecmp("Coremask", child->key) == 0) {
status = cf_util_get_string_buffer(child, phc->eal_config.coremask,
sizeof(phc->eal_config.coremask));
status = cf_util_get_string_buffer(child, phc->eal_config.socket_memory,
sizeof(phc->eal_config.socket_memory));
DEBUG("dpdk_common: EAL:Socket memory %s", phc->eal_config.socket_memory);
- } else if (strcasecmp("ProcessType", child->key) == 0) {
- status = cf_util_get_string_buffer(child, phc->eal_config.process_type,
- sizeof(phc->eal_config.process_type));
- DEBUG("dpdk_common: EAL:Process type %s", phc->eal_config.process_type);
- } else if ((strcasecmp("FilePrefix", child->key) == 0) &&
- (child->values[0].type == OCONFIG_TYPE_STRING)) {
- ssnprintf(phc->eal_config.file_prefix, DATA_MAX_NAME_LEN,
- "/var/run/.%s_config", child->values[0].value.string);
- DEBUG("dpdk_common: EAL:File prefix %s", phc->eal_config.file_prefix);
+ } else if (strcasecmp("FilePrefix", child->key) == 0) {
+ char prefix[DATA_MAX_NAME_LEN];
+
+ status = cf_util_get_string_buffer(child, prefix, sizeof(prefix));
+ if (status == 0) {
+ snprintf(phc->eal_config.file_prefix, DATA_MAX_NAME_LEN,
+ "/var/run/.%s_config", prefix);
+ DEBUG("dpdk_common: EAL:File prefix %s", phc->eal_config.file_prefix);
+ }
} else {
ERROR("dpdk_common: Invalid '%s' configuration option", child->key);
status = -EINVAL;
DPDK_HELPER_TRACE(name);
char errbuf[ERR_BUF_SIZE];
+ /*
+ * Call shm_unlink first, as 'name' might be no longer accessible after munmap
+ */
+ if (shm_unlink(name))
+ ERROR("shm_unlink failure %s", sstrerror(errno, errbuf, sizeof(errbuf)));
+
if (map != NULL) {
if (munmap(map, size))
ERROR("munmap failure %s", sstrerror(errno, errbuf, sizeof(errbuf)));
}
-
- if (shm_unlink(name))
- ERROR("shm_unlink failure %s", sstrerror(errno, errbuf, sizeof(errbuf)));
}
void *dpdk_helper_priv_get(dpdk_helper_ctx_t *phc) {
}
phc->shm_size = shm_size;
- phc->shm_name = name;
+ sstrncpy(phc->shm_name, name, sizeof(phc->shm_name));
dpdk_helper_config_default(phc);
return 0;
}
-int dpdk_helper_shutdown(dpdk_helper_ctx_t *phc) {
- if (phc == NULL) {
- ERROR("%s:Invalid argument(phc)", __FUNCTION__);
- return -EINVAL;
- }
+void dpdk_helper_shutdown(dpdk_helper_ctx_t *phc) {
+ if (phc == NULL)
+ return;
DPDK_HELPER_TRACE(phc->shm_name);
sem_destroy(&phc->sema_cmd_start);
sem_destroy(&phc->sema_cmd_complete);
dpdk_shm_cleanup(phc->shm_name, phc->shm_size, (void *)phc);
-
- return 0;
}
static int dpdk_helper_spawn(dpdk_helper_ctx_t *phc) {
/* EAL config must be initialized */
assert(phc->eal_config.coremask[0] != 0);
assert(phc->eal_config.memory_channels[0] != 0);
- assert(phc->eal_config.process_type[0] != 0);
assert(phc->eal_config.file_prefix[0] != 0);
argp[argc++] = "collectd-dpdk";
}
argp[argc++] = "--proc-type";
- argp[argc++] = phc->eal_config.process_type;
+ argp[argc++] = "secondary";
assert(argc <= (DPDK_EAL_ARGC * 2 + 1));