]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/spdk/dpdk/lib/librte_cfgfile/rte_cfgfile.c
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / spdk / dpdk / lib / librte_cfgfile / rte_cfgfile.c
index f8e7627a5169749e857ba6fc32586b44d70d66f2..9049fd9c2319113fc2107ec933530e0f63120aea 100644 (file)
@@ -9,6 +9,7 @@
 #include <errno.h>
 #include <rte_string_fns.h>
 #include <rte_common.h>
+#include <rte_log.h>
 
 #include "rte_cfgfile.h"
 
@@ -26,6 +27,12 @@ struct rte_cfgfile {
        struct rte_cfgfile_section *sections;
 };
 
+static int cfgfile_logtype;
+
+#define CFG_LOG(level, fmt, args...)                                   \
+       rte_log(RTE_LOG_ ## level, cfgfile_logtype, "%s(): " fmt "\n",  \
+               __func__, ## args)
+
 /** when we resize a file structure, how many extra entries
  * for new sections do we add in */
 #define CFG_ALLOC_SECTION_BATCH 8
@@ -128,7 +135,7 @@ rte_cfgfile_check_params(const struct rte_cfgfile_parameters *params)
        unsigned int i;
 
        if (!params) {
-               printf("Error - missing cfgfile parameters\n");
+               CFG_LOG(ERR, "missing cfgfile parameters\n");
                return -EINVAL;
        }
 
@@ -141,7 +148,7 @@ rte_cfgfile_check_params(const struct rte_cfgfile_parameters *params)
        }
 
        if (valid_comment == 0) {
-               printf("Error - invalid comment characters %c\n",
+               CFG_LOG(ERR, "invalid comment characters %c\n",
                       params->comment_character);
                return -ENOTSUP;
        }
@@ -160,9 +167,9 @@ struct rte_cfgfile *
 rte_cfgfile_load_with_params(const char *filename, int flags,
                             const struct rte_cfgfile_parameters *params)
 {
-       char buffer[CFG_NAME_LEN + CFG_VALUE_LEN + 4] = {0};
+       char buffer[CFG_NAME_LEN + CFG_VALUE_LEN + 4];
        int lineno = 0;
-       struct rte_cfgfile *cfg = NULL;
+       struct rte_cfgfile *cfg;
 
        if (rte_cfgfile_check_params(params))
                return NULL;
@@ -174,11 +181,11 @@ rte_cfgfile_load_with_params(const char *filename, int flags,
        cfg = rte_cfgfile_create(flags);
 
        while (fgets(buffer, sizeof(buffer), f) != NULL) {
-               char *pos = NULL;
+               char *pos;
                size_t len = strnlen(buffer, sizeof(buffer));
                lineno++;
                if ((len >= sizeof(buffer) - 1) && (buffer[len-1] != '\n')) {
-                       printf("Error line %d - no \\n found on string. "
+                       CFG_LOG(ERR, " line %d - no \\n found on string. "
                                        "Check if line too long\n", lineno);
                        goto error1;
                }
@@ -198,8 +205,9 @@ rte_cfgfile_load_with_params(const char *filename, int flags,
                        /* section heading line */
                        char *end = memchr(buffer, ']', len);
                        if (end == NULL) {
-                               printf("Error line %d - no terminating ']'"
-                                       "character found\n", lineno);
+                               CFG_LOG(ERR,
+                                       "line %d - no terminating ']' character found\n",
+                                       lineno);
                                goto error1;
                        }
                        *end = '\0';
@@ -213,8 +221,9 @@ rte_cfgfile_load_with_params(const char *filename, int flags,
                        split[0] = buffer;
                        split[1] = memchr(buffer, '=', len);
                        if (split[1] == NULL) {
-                               printf("Error line %d - no '='"
-                                       "character found\n", lineno);
+                               CFG_LOG(ERR,
+                                       "line %d - no '=' character found\n",
+                                       lineno);
                                goto error1;
                        }
                        *split[1] = '\0';
@@ -236,8 +245,9 @@ rte_cfgfile_load_with_params(const char *filename, int flags,
 
                        if (!(flags & CFG_FLAG_EMPTY_VALUES) &&
                                        (*split[1] == '\0')) {
-                               printf("Error at line %d - cannot use empty "
-                                                       "values\n", lineno);
+                               CFG_LOG(ERR,
+                                       "line %d - cannot use empty values\n",
+                                       lineno);
                                goto error1;
                        }
 
@@ -260,7 +270,7 @@ struct rte_cfgfile *
 rte_cfgfile_create(int flags)
 {
        int i;
-       struct rte_cfgfile *cfg = NULL;
+       struct rte_cfgfile *cfg;
 
        cfg = malloc(sizeof(*cfg));
 
@@ -271,17 +281,16 @@ rte_cfgfile_create(int flags)
        cfg->num_sections = 0;
 
        /* allocate first batch of sections and entries */
-       cfg->sections = malloc(sizeof(struct rte_cfgfile_section) *
-                       CFG_ALLOC_SECTION_BATCH);
-
+       cfg->sections = calloc(CFG_ALLOC_SECTION_BATCH,
+                              sizeof(struct rte_cfgfile_section));
        if (cfg->sections == NULL)
                goto error1;
 
        cfg->allocated_sections = CFG_ALLOC_SECTION_BATCH;
 
        for (i = 0; i < CFG_ALLOC_SECTION_BATCH; i++) {
-               cfg->sections[i].entries = malloc(sizeof(
-                       struct rte_cfgfile_entry) * CFG_ALLOC_ENTRY_BATCH);
+               cfg->sections[i].entries = calloc(CFG_ALLOC_ENTRY_BATCH,
+                                         sizeof(struct rte_cfgfile_entry));
 
                if (cfg->sections[i].entries == NULL)
                        goto error1;
@@ -397,7 +406,8 @@ int rte_cfgfile_set_entry(struct rte_cfgfile *cfg, const char *sectionname,
                                sizeof(curr_section->entries[i].value));
                        return 0;
                }
-       printf("Error - entry name doesn't exist\n");
+
+       CFG_LOG(ERR, "entry name doesn't exist\n");
        return -EINVAL;
 }
 
@@ -552,3 +562,10 @@ rte_cfgfile_has_entry(struct rte_cfgfile *cfg, const char *sectionname,
 {
        return rte_cfgfile_get_entry(cfg, sectionname, entryname) != NULL;
 }
+
+RTE_INIT(cfgfile_init)
+{
+       cfgfile_logtype = rte_log_register("lib.cfgfile");
+       if (cfgfile_logtype >= 0)
+               rte_log_set_level(cfgfile_logtype, RTE_LOG_INFO);
+}