#include "collectd.h"
-#include "common.h"
-#include "utils_dpdk.h"
+#include "utils/common/common.h"
+#include "utils/dpdk/dpdk.h"
#include <rte_config.h>
#include <rte_ethdev.h>
};
typedef struct dpdk_stats_ctx_s dpdk_stats_ctx_t;
+typedef enum {
+ DPDK_STAT_STATE_OKAY = 0,
+ DPDK_STAT_STATE_CFG_ERR,
+} dpdk_stat_cfg_status;
+
#define DPDK_STATS_CTX_GET(a) ((dpdk_stats_ctx_t *)dpdk_helper_priv_get(a))
dpdk_helper_ctx_t *g_hc = NULL;
static char g_shm_name[DATA_MAX_NAME_LEN] = DPDK_STATS_NAME;
+static dpdk_stat_cfg_status g_state = DPDK_STAT_STATE_OKAY;
+
static int dpdk_stats_reinit_helper();
static void dpdk_stats_default_config(void) {
dpdk_stats_ctx_t *ec = DPDK_STATS_CTX_GET(g_hc);
int ret = dpdk_helper_init(g_shm_name, sizeof(dpdk_stats_ctx_t), &g_hc);
if (ret != 0) {
- char errbuf[ERR_BUF_SIZE];
ERROR("%s: failed to initialize %s helper(error: %s)", DPDK_STATS_PLUGIN,
- g_shm_name, sstrerror(errno, errbuf, sizeof(errbuf)));
+ g_shm_name, STRERRNO);
return ret;
}
DPDK_STATS_TRACE();
int ret = dpdk_stats_preinit();
- if (ret)
- return ret;
+ if (ret) {
+ g_state = DPDK_STAT_STATE_CFG_ERR;
+ return 0;
+ }
dpdk_stats_ctx_t *ctx = DPDK_STATS_CTX_GET(g_hc);
for (int i = 0; i < ci->children_num; i++) {
oconfig_item_t *child = ci->children + i;
- if ((strcasecmp("EnabledPortMask", child->key) == 0) &&
- (child->values[0].type == OCONFIG_TYPE_NUMBER)) {
- ctx->config.enabled_port_mask = child->values[0].value.number;
- DEBUG("%s: Enabled Port Mask 0x%X", DPDK_STATS_PLUGIN,
- ctx->config.enabled_port_mask);
- } else if (strcasecmp("SharedMemObj", child->key) == 0) {
- cf_util_get_string_buffer(child, g_shm_name, sizeof(g_shm_name));
- DEBUG("%s: Shared memory object %s", DPDK_STATS_PLUGIN, g_shm_name);
- dpdk_stats_reinit_helper();
- } else if (strcasecmp("EAL", child->key) == 0) {
+ if (strcasecmp("EnabledPortMask", child->key) == 0)
+ ret = cf_util_get_int(child, (int *)&ctx->config.enabled_port_mask);
+ else if (strcasecmp("SharedMemObj", child->key) == 0) {
+ ret = cf_util_get_string_buffer(child, g_shm_name, sizeof(g_shm_name));
+ if (ret == 0)
+ ret = dpdk_stats_reinit_helper();
+ } else if (strcasecmp("EAL", child->key) == 0)
ret = dpdk_helper_eal_config_parse(g_hc, child);
- if (ret)
- return ret;
+ else if (strcasecmp("PortName", child->key) != 0) {
+ ERROR(DPDK_STATS_PLUGIN ": unrecognized configuration option %s",
+ child->key);
+ ret = -1;
+ }
+
+ if (ret != 0) {
+ g_state = DPDK_STAT_STATE_CFG_ERR;
+ return 0;
}
}
+ DEBUG(DPDK_STATS_PLUGIN ": Enabled Port Mask 0x%X",
+ ctx->config.enabled_port_mask);
+ DEBUG(DPDK_STATS_PLUGIN ": Shared memory object %s", g_shm_name);
+
int port_num = 0;
/* parse port names after EnabledPortMask was parsed */
while (!(ctx->config.enabled_port_mask & (1 << port_num)))
port_num++;
- cf_util_get_string_buffer(child, ctx->config.port_name[port_num],
- sizeof(ctx->config.port_name[port_num]));
- DEBUG("%s: Port %d Name: %s", DPDK_STATS_PLUGIN, port_num,
+ if (cf_util_get_string_buffer(child, ctx->config.port_name[port_num],
+ sizeof(ctx->config.port_name[port_num]))) {
+ g_state = DPDK_STAT_STATE_CFG_ERR;
+ return 0;
+ }
+
+ DEBUG(DPDK_STATS_PLUGIN ": Port %d Name: %s", port_num,
ctx->config.port_name[port_num]);
port_num++;
}
}
- return ret;
+ return 0;
}
static int dpdk_helper_stats_get(dpdk_helper_ctx_t *phc) {
vl.values = &(value_t){.derive = value};
vl.values_len = 1;
vl.time = port_read_time;
- sstrncpy(vl.host, hostname_g, sizeof(vl.host));
sstrncpy(vl.plugin, DPDK_STATS_PLUGIN, sizeof(vl.plugin));
sstrncpy(vl.plugin_instance, plugin_instance, sizeof(vl.plugin_instance));
dpdk_stats_resolve_cnt_type(vl.type, sizeof(vl.type), cnt_name);
char dev_name[64];
if (ctx->config.port_name[i][0] != 0) {
- ssnprintf(dev_name, sizeof(dev_name), "%s", ctx->config.port_name[i]);
+ snprintf(dev_name, sizeof(dev_name), "%s", ctx->config.port_name[i]);
} else {
- ssnprintf(dev_name, sizeof(dev_name), "port.%d", i);
+ snprintf(dev_name, sizeof(dev_name), "port.%d", i);
}
DEBUG(" === Dispatch stats for port %d (name=%s; stats_count=%d)", i,
size_t data_size = sizeof(dpdk_stats_ctx_t) +
(ctx->stats_count * DPDK_STATS_CTX_GET_XSTAT_SIZE);
- DEBUG("%s:%d helper reinit (new_size=%zu)", __FUNCTION__, __LINE__,
+ DEBUG("%s:%d helper reinit (new_size=%" PRIsz ")", __FUNCTION__, __LINE__,
data_size);
dpdk_stats_ctx_t tmp_ctx;
int ret;
ret = dpdk_helper_init(g_shm_name, data_size, &g_hc);
if (ret != 0) {
- char errbuf[ERR_BUF_SIZE];
ERROR("%s: failed to initialize %s helper(error: %s)", DPDK_STATS_PLUGIN,
- g_shm_name, sstrerror(errno, errbuf, sizeof(errbuf)));
+ g_shm_name, STRERRNO);
return ret;
}
return 0;
}
-static int dpdk_stats_init(void) {
+static int dpdk_stats_shutdown(void) {
DPDK_STATS_TRACE();
- int ret = 0;
- ret = dpdk_stats_preinit();
- if (ret != 0) {
- return ret;
- }
+ dpdk_helper_shutdown(g_hc);
+ g_hc = NULL;
return 0;
}
-static int dpdk_stats_shutdown(void) {
+static int dpdk_stats_init(void) {
DPDK_STATS_TRACE();
-
int ret = 0;
- ret = dpdk_helper_shutdown(g_hc);
- g_hc = NULL;
+ if (g_state != DPDK_STAT_STATE_OKAY) {
+ dpdk_stats_shutdown();
+ return -1;
+ }
+
+ ret = dpdk_stats_preinit();
if (ret != 0) {
- ERROR("%s: failed to cleanup %s helper", DPDK_STATS_PLUGIN, g_shm_name);
return ret;
}
- return ret;
+ return 0;
}
void module_register(void) {