From patchwork Tue Jan 24 17:48:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 92376 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp1789485obz; Tue, 24 Jan 2017 08:51:38 -0800 (PST) X-Received: by 10.55.11.13 with SMTP id 13mr32729025qkl.201.1485276698179; Tue, 24 Jan 2017 08:51:38 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id b132si13534520qka.270.2017.01.24.08.51.37; Tue, 24 Jan 2017 08:51:38 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id CC97461063; Tue, 24 Jan 2017 16:51:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 2BD1762D83; Tue, 24 Jan 2017 16:49:11 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 8273B6085F; Tue, 24 Jan 2017 16:48:58 +0000 (UTC) Received: from mail-lf0-f43.google.com (mail-lf0-f43.google.com [209.85.215.43]) by lists.linaro.org (Postfix) with ESMTPS id DF684607F9 for ; Tue, 24 Jan 2017 16:48:53 +0000 (UTC) Received: by mail-lf0-f43.google.com with SMTP id x1so27766131lff.0 for ; Tue, 24 Jan 2017 08:48:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=qxtX4n7Ath3aNeULDBA2ITIWeQYyTL/2752bItmFR8U=; b=q8KxoBY6A3BWp5R8FXLvmA/A4pLV8N45SKh0H/sCJQcVRdaZnY4CWNVc5bKnyUT9Pj 0HVHmBnagv7lkAJo6U8HmkA828Zg5rljlfi4BhiBvIJXaRuKmfMe2EVCljCkZXGw+qzc wMqEEZc4MJKwoRXOWFkB7NpBQ67+qKyG+g7DKeEZt6q6P96Wg0WqwNMv7o0xpw8+303D o4hnjU6xHFli0AZu0oK8Bndd0Ru2X4NB0wJK22qFc/1accSs6nySXqRxE4wGsHdEviiL rRGwanJMZ1BTpbsM5ZnB7rYEIcLTXNGsy9IPUx39y/E/wWL4AfNcffX0G71jA0GGo3DQ d+JQ== X-Gm-Message-State: AIkVDXIghODiGZgihH2uTL0D08aY98VGSudAUJ4Erlq/fMGp3iq0afAywwNiB4DHPEU39Q+8aZI= X-Received: by 10.25.163.130 with SMTP id m124mr6544771lfe.19.1485276532584; Tue, 24 Jan 2017 08:48:52 -0800 (PST) Received: from erachmi-ericsson.ki.sw.ericsson.se (c-83-233-76-66.cust.bredband2.com. [83.233.76.66]) by smtp.gmail.com with ESMTPSA id y10sm7605276lja.22.2017.01.24.08.48.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 24 Jan 2017 08:48:52 -0800 (PST) From: Christophe Milard To: mike.holmes@linaro.org, yi.he@linaro.org, maxim.uvarov@linaro.com, lng-odp@lists.linaro.org Date: Tue, 24 Jan 2017 18:48:04 +0100 Message-Id: <1485280086-3958-4-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1485280086-3958-1-git-send-email-christophe.milard@linaro.org> References: <1485280086-3958-1-git-send-email-christophe.milard@linaro.org> Subject: [lng-odp] [API-NEXT PATCHv11 3/5] linux-gen: init: adding configuration file parsing X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" The parsing of the odp.conf configuration file is added. The file is searched first in filename specified in the environment variable $ODP_SYSCONFIG_FILE (where the special string "none" prevent any file loading) The file is then searched in the user home directory (~) and then is the $prefix/etc directory. This requires libconfig (sudo apt-get install libconfig-dev) Signed-off-by: Christophe Milard --- .travis.yml | 2 +- DEPENDENCIES | 8 +-- platform/linux-generic/Makefile.am | 1 + platform/linux-generic/include/odp_internal.h | 2 + platform/linux-generic/m4/configure.m4 | 11 ++++ platform/linux-generic/odp_init.c | 80 +++++++++++++++++++++++++++ 6 files changed, 99 insertions(+), 5 deletions(-) -- 2.7.4 diff --git a/.travis.yml b/.travis.yml index 03e61b1..a6f770c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,7 +19,7 @@ sudo: required before_install: - sudo apt-get -qq update - - sudo apt-get install automake autoconf libtool libssl-dev graphviz mscgen doxygen + - sudo apt-get install automake autoconf libtool libssl-dev graphviz mscgen doxygen libconfig-dev - sudo apt-get install libpcap-dev linux-headers-`uname -r` - gem install asciidoctor diff --git a/DEPENDENCIES b/DEPENDENCIES index f1f0edd..f285783 100644 --- a/DEPENDENCIES +++ b/DEPENDENCIES @@ -18,18 +18,18 @@ Prerequisites for building the OpenDataPlane (ODP) API 3. Required libraries - Libraries currently required to link: openssl + Libraries currently required to link: openssl, libconfig -3.1 OpenSSL native compile +3.1 OpenSSL and libconf native compile For native compilation, simply load the necessary libraries using the appropriate tool set. On Debian/Ubuntu systems: - $ sudo apt-get install libssl-dev + $ sudo apt-get install libssl-dev libconfig-dev On CentOS/RedHat/Fedora systems: - $ sudo yum install openssl-devel + $ sudo yum install openssl-devel libconfig-devel 3.2 OpenSSL cross compilation diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am index 2d97414..579fc3c 100644 --- a/platform/linux-generic/Makefile.am +++ b/platform/linux-generic/Makefile.am @@ -8,6 +8,7 @@ AM_CFLAGS += -I$(srcdir)/include AM_CFLAGS += -I$(top_srcdir)/include AM_CFLAGS += -I$(top_builddir)/include AM_CFLAGS += -Iinclude +AM_CFLAGS += -DSYSCONFDIR=\"@sysconfdir@\" include_HEADERS = \ $(top_srcdir)/include/odp.h \ diff --git a/platform/linux-generic/include/odp_internal.h b/platform/linux-generic/include/odp_internal.h index b313b1f..9d1fc58 100644 --- a/platform/linux-generic/include/odp_internal.h +++ b/platform/linux-generic/include/odp_internal.h @@ -22,6 +22,7 @@ extern "C" { #include #include #include +#include extern __thread int __odp_errno; @@ -50,6 +51,7 @@ struct odp_global_data_s { odp_cpumask_t control_cpus; odp_cpumask_t worker_cpus; int num_cpus_installed; + config_t configuration; }; enum init_stage { diff --git a/platform/linux-generic/m4/configure.m4 b/platform/linux-generic/m4/configure.m4 index d3e5528..5fab0cc 100644 --- a/platform/linux-generic/m4/configure.m4 +++ b/platform/linux-generic/m4/configure.m4 @@ -28,6 +28,17 @@ AC_LINK_IFELSE( echo "Use newer version. For gcc > 4.7.0" exit -1) +# Check for libconfig (required) +AC_CHECK_HEADERS([libconfig.h], HEADER_LIBCONFIG="yes") +PKG_CHECK_MODULES([PKGCONFIG], [libconfig >= 1.3.2], LIBRARY_LIBCONFIG="yes") +if test "x$LIBRARY_LIBCONFIG" != "x" && test "x$HEADER_LIBCONFIG" != "x" ; then + CFLAGS="$CFLAGS $PKGCONFIG_CFLAGS" + LIBS="$LIBS $PKGCONFIG_LIBS" + AM_CPPFLAGS="$AM_CPPFLAGS `pkg-config --cflags-only-I libconfig`" +else + AC_MSG_FAILURE([libconfig not found (required)]) +fi + m4_include([platform/linux-generic/m4/odp_pthread.m4]) m4_include([platform/linux-generic/m4/odp_openssl.m4]) m4_include([platform/linux-generic/m4/odp_pcap.m4]) diff --git a/platform/linux-generic/odp_init.c b/platform/linux-generic/odp_init.c index 06c6143..0e9167c 100644 --- a/platform/linux-generic/odp_init.c +++ b/platform/linux-generic/odp_init.c @@ -10,6 +10,8 @@ #include #include #include +#include +#include #include #include #include @@ -21,6 +23,15 @@ #define _ODP_FILES_FMT "odp-%d-" #define _ODP_TMPDIR "/tmp" +/* the name of the ODP configuration file: */ +#define CONFIGURATION_FILE_ENV_NONE "none" +#define CONFIGURATION_FILE "odp.conf" +#define CONFIGURATION_FILE_USR ("." CONFIGURATION_FILE) +#define CONFIGURATION_FILE_SYS (SYSCONFDIR "/" CONFIGURATION_FILE) + +/* the ODP configuration file name can also be oveerwritten by env. variable: */ +#define ODP_SYSCONFIG_FILE_ENV "ODP_SYSCONFIG_FILE" + struct odp_global_data_s odp_global_data; /* remove all files staring with "odp-" from a directory "dir" */ @@ -65,6 +76,72 @@ static int cleanup_files(const char *dirpath, int odp_pid) return 0; } +/* read the odp configuration file + * + * the configuration file is read from: + * 1) Wherever env variable ODP_SYSCONFIG_FILE says (or "none") + * 2) ./odp.conf + * 3) the @sysconfig@/odp.conf + * (checked in reverse order overwritting each-other) + * So the environment variable setting supperseeds any other file. + * If the environment variable exists and set to the string "none" + * the configuration file reading is inibited (used to prevent + * test which do not need a file to read the user or system files) + */ +static int read_configfile(void) +{ + config_t *cf; + const char *config_filename; + char user_config_filename[PATH_MAX]; + char *env_config_filename; + + /* initialize and read the configuration file if any: */ + cf = &odp_global_data.configuration; + config_init(cf); + config_filename = NULL; + /* check if the system config file can be reached :*/ + if (access(CONFIGURATION_FILE_SYS, R_OK) != -1) + config_filename = CONFIGURATION_FILE_SYS; + /* check if the user config file can be reached (overwrite if so) :*/ + strncpy(user_config_filename, getenv("HOME"), PATH_MAX); + if (user_config_filename[0]) { + strncat(user_config_filename, "/", PATH_MAX); + strncat(user_config_filename, CONFIGURATION_FILE_USR, PATH_MAX); + if ((access(user_config_filename, R_OK) != -1)) + config_filename = user_config_filename; + } + /* check if other config file is specified via env (overwrite if so):*/ + env_config_filename = getenv(ODP_SYSCONFIG_FILE_ENV); + if (env_config_filename) { + /* none means "read no file": */ + if (!strcmp(env_config_filename, CONFIGURATION_FILE_ENV_NONE)) + return 0; + if (access(env_config_filename, R_OK) != -1) { + config_filename = env_config_filename; + } else { + ODP_ERR("Cannot read ODP configurattion file %s " + "(set by env variable " + ODP_SYSCONFIG_FILE_ENV ")\n", + env_config_filename); + config_filename = NULL; + return -1; + } + } + if (config_filename) { + ODP_DBG("Reading configuration file: %s\n", config_filename); + if (!config_read_file(cf, config_filename)) { + ODP_ERR("%s:%d - %s\n", + config_error_file(cf), + config_error_line(cf), + config_error_text(cf)); + config_destroy(cf); + return(-1); + } + } + + return 0; +} + int odp_init_global(odp_instance_t *instance, const odp_init_t *params, const odp_platform_init_t *platform_params ODP_UNUSED) @@ -87,6 +164,9 @@ int odp_init_global(odp_instance_t *instance, cleanup_files(_ODP_TMPDIR, odp_global_data.main_pid); + if (read_configfile()) + goto init_failed; + if (odp_cpumask_init_global(params)) { ODP_ERR("ODP cpumask init failed.\n"); goto init_failed;