Patch Detail
Show a patch.
GET /api/patches/22754/?format=api
{ "id": 22754, "url": "https://patchwork.libcamera.org/api/patches/22754/?format=api", "web_url": "https://patchwork.libcamera.org/patch/22754/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20250206161607.50738-9-mzamazal@redhat.com>", "date": "2025-02-06T16:15:59", "name": "[v7,08/15] config: Look up IPA configurables in configuration file", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "d8326c165b82d3a71b2e4b1a38937e0ecabbea05", "submitter": { "id": 177, "url": "https://patchwork.libcamera.org/api/people/177/?format=api", "name": "Milan Zamazal", "email": "mzamazal@redhat.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/22754/mbox/", "series": [ { "id": 4993, "url": "https://patchwork.libcamera.org/api/series/4993/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4993", "date": "2025-02-06T16:15:51", "name": "Add global configuration file", "version": 7, "mbox": "https://patchwork.libcamera.org/series/4993/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/22754/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/22754/checks/", "tags": {}, "headers": { "Return-Path": "<libcamera-devel-bounces@lists.libcamera.org>", "X-Original-To": "parsemail@patchwork.libcamera.org", "Delivered-To": "parsemail@patchwork.libcamera.org", "Received": [ "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 433E4C32EF\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 6 Feb 2025 16:16:45 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id BE1786860E;\n\tThu, 6 Feb 2025 17:16:44 +0100 (CET)", "from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.129.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9BFBD68601\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 6 Feb 2025 17:16:42 +0100 (CET)", "from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com\n\t(ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63])\n\tby relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,\n\tcipher=TLS_AES_256_GCM_SHA384) id us-mta-425-NEz7gveyOEaBlSTGhT5R-g-1;\n\tThu, 06 Feb 2025 11:16:36 -0500", "from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com\n\t(mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com\n\t[10.30.177.111])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\tkey-exchange X25519 server-signature RSA-PSS (2048 bits)\n\tserver-digest SHA256) (No client certificate requested)\n\tby mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix)\n\twith ESMTPS id 4D66E1956096; Thu, 6 Feb 2025 16:16:35 +0000 (UTC)", "from mzamazal-thinkpadp1gen3.tpbc.com (unknown [10.43.17.31])\n\tby mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix)\n\twith ESMTP id 563E618004A7; Thu, 6 Feb 2025 16:16:33 +0000 (UTC)" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=redhat.com header.i=@redhat.com\n\theader.b=\"PIDg7Y/5\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1738858601;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\tto:to:cc:cc:mime-version:mime-version:content-type:content-type:\n\tcontent-transfer-encoding:content-transfer-encoding:\n\tin-reply-to:in-reply-to:references:references;\n\tbh=HLq0XOhO0puHpAd8G8A/XwMIn0QSqNPIq3PlZmKTpwk=;\n\tb=PIDg7Y/5lztAL+aAvOuSzhOnTGBdk5Hce8yUYZrNZgeLibHTU8I/mqfzVucW0K0SwnEhh6\n\tBrw1HSsmvkXsynOAIC7m89a0YQuyOUFaHyCu3fO7rayWWpkRkUTPQfnPK1poR1ufeRtPnm\n\ti3KMnl3zS5ioaG0Fa7yxmjhpgxTWsMs=", "X-MC-Unique": "NEz7gveyOEaBlSTGhT5R-g-1", "X-Mimecast-MFC-AGG-ID": "NEz7gveyOEaBlSTGhT5R-g", "From": "Milan Zamazal <mzamazal@redhat.com>", "To": "libcamera-devel@lists.libcamera.org", "Cc": "Milan Zamazal <mzamazal@redhat.com>, Kieran Bingham\n\t<kieran.bingham@ideasonboard.com>, Naushir Patuck\n\t<naush@raspberrypi.com>, =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?=\n\t<pobrn@protonmail.com>, Laurent Pinchart\n\t<laurent.pinchart@ideasonboard.com>", "Subject": "[PATCH v7 08/15] config: Look up IPA configurables in configuration\n\tfile", "Date": "Thu, 6 Feb 2025 17:15:59 +0100", "Message-ID": "<20250206161607.50738-9-mzamazal@redhat.com>", "In-Reply-To": "<20250206161607.50738-1-mzamazal@redhat.com>", "References": "<20250206161607.50738-1-mzamazal@redhat.com>", "MIME-Version": "1.0", "X-Scanned-By": "MIMEDefang 3.4.1 on 10.30.177.111", "X-Mimecast-Spam-Score": "0", "X-Mimecast-MFC-PROC-ID": "dz7e3aTEciIiSTZraoSm7kY_uVClF66eDSQUs8iSxAA_1738858595", "X-Mimecast-Originator": "redhat.com", "Content-Transfer-Encoding": "8bit", "content-type": "text/plain; charset=\"US-ASCII\"; x-default=true", "X-BeenThere": "libcamera-devel@lists.libcamera.org", "X-Mailman-Version": "2.1.29", "Precedence": "list", "List-Id": "<libcamera-devel.lists.libcamera.org>", "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>", "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>", "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>", "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>", "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "This patch adds configuration options for environment variables used in\nthe IPA proxy. Two utility functions configuration retrieval functions\nare added, to retrieve lists of values.\n\nThe configuration snippet:\n\n configuration:\n ipa:\n config_paths:\n - config path 1\n - config path 2\n - ...\n module_paths:\n - module path 1\n - module path 2\n - ...\n proxy_paths:\n - proxy path 1\n - proxy path 2\n - ...\n force_isolation: BOOL\n ipas:\n IPA_NAME:\n tuning_file: TUNING FILE\n\nSigned-off-by: Milan Zamazal <mzamazal@redhat.com>\n---\n .../libcamera/internal/global_configuration.h | 4 ++\n src/libcamera/base/global_configuration.cpp | 51 +++++++++++++++\n src/libcamera/ipa_manager.cpp | 32 +++++----\n src/libcamera/ipa_proxy.cpp | 65 ++++++++++---------\n 4 files changed, 109 insertions(+), 43 deletions(-)", "diff": "diff --git a/include/libcamera/internal/global_configuration.h b/include/libcamera/internal/global_configuration.h\nindex a6e21a2d..ffa6454c 100644\n--- a/include/libcamera/internal/global_configuration.h\n+++ b/include/libcamera/internal/global_configuration.h\n@@ -48,8 +48,12 @@ std::optional<T> option(const std::string &confPath)\n \treturn c->get<T>();\n }\n \n+std::vector<std::string> listOption(const std::string &confPath);\n std::optional<std::string> envOption(const char *const envVariable,\n \t\t\t\t const std::string &confPath);\n+std::vector<std::string> envListOption(\n+\tconst char *const envVariable,\n+\tconst std::string &confPath);\n \n } /* namespace GlobalConfiguration */\n \ndiff --git a/src/libcamera/base/global_configuration.cpp b/src/libcamera/base/global_configuration.cpp\nindex 3dc31c48..e69951b4 100644\n--- a/src/libcamera/base/global_configuration.cpp\n+++ b/src/libcamera/base/global_configuration.cpp\n@@ -9,11 +9,14 @@\n \n #include <filesystem>\n #include <memory>\n+#include <optional>\n #include <string>\n #include <sys/types.h>\n+#include <vector>\n \n #include <libcamera/base/file.h>\n #include <libcamera/base/log.h>\n+#include <libcamera/base/utils.h>\n \n #include \"libcamera/internal/yaml_parser.h\"\n \n@@ -152,6 +155,24 @@ void initialize()\n * in the configuration file and matches type \\a T, no value otherwise\n */\n \n+/**\n+ * \\brief Return values of the configuration option identified by \\a confPath\n+ * \\tparam T The type of the retrieved configuration value\n+ * \\param[in] confPath Sequence of the YAML section names (excluding\n+ * `configuration') leading to the requested list option, separated by dots\n+ * \\return A vector of strings (empty one if the option is not found)\n+ */\n+std::vector<std::string> listOption(const std::string &confPath)\n+{\n+\tconst YamlObject *c = &configuration();\n+\tfor (auto part : utils::split(confPath, \".\")) {\n+\t\tc = &(*c)[part];\n+\t\tif (!*c)\n+\t\t\treturn {};\n+\t}\n+\treturn c->getList<std::string>().value_or(std::vector<std::string>());\n+}\n+\n /**\n * \\brief Return value of the configuration option from a file or environment\n * \\param[in] envVariable Environment variable to get the value from\n@@ -179,6 +200,36 @@ std::optional<std::string> envOption(\n \treturn option<std::string>(confPath);\n }\n \n+/**\n+ * \\brief Return values of the configuration option from a file or environment\n+ * \\param[in] envVariable Environment variable to get the value from\n+ * \\param[in] confPath The same as in GlobalConfiguration::option\n+ *\n+ * This helper looks first at the given environment variable and if it is\n+ * defined (even if it is empty) then it splits its value by semicolons and\n+ * returns the resulting list of strings. Otherwise it looks for \\a confPath the\n+ * same way as in GlobalConfiguration::option, value of which must be a list of\n+ * strings.\n+ *\n+ * \\note Support for using environment variables to configure libcamera behavior\n+ * is provided here mostly for backward compatibility reasons. Introducing new\n+ * configuration environment variables is discouraged.\n+ *\n+ * \\return A vector of strings retrieved from the given environment option or\n+ * configuration file (an empty vector is returned if nothing is found)\n+ */\n+std::vector<std::string> envListOption(\n+\tconst char *const envVariable,\n+\tconst std::string &confPath)\n+{\n+\tconst char *envValue = utils::secure_getenv(envVariable);\n+\tif (envValue) {\n+\t\tauto items = utils::split(envValue, \":\");\n+\t\treturn std::vector<std::string>(items.begin(), items.end());\n+\t}\n+\treturn listOption(confPath);\n+}\n+\n /**\n * \\brief Return configuration version\n *\ndiff --git a/src/libcamera/ipa_manager.cpp b/src/libcamera/ipa_manager.cpp\nindex 33ae74e8..21753eb6 100644\n--- a/src/libcamera/ipa_manager.cpp\n+++ b/src/libcamera/ipa_manager.cpp\n@@ -9,6 +9,7 @@\n \n #include <algorithm>\n #include <dirent.h>\n+#include <numeric>\n #include <string.h>\n #include <sys/types.h>\n \n@@ -114,18 +115,25 @@ IPAManager::IPAManager()\n \tunsigned int ipaCount = 0;\n \n \t/* User-specified paths take precedence. */\n-\tconst char *modulePaths = utils::secure_getenv(\"LIBCAMERA_IPA_MODULE_PATH\");\n-\tif (modulePaths) {\n-\t\tfor (const auto &dir : utils::split(modulePaths, \":\")) {\n-\t\t\tif (dir.empty())\n-\t\t\t\tcontinue;\n+\tconst auto modulePaths =\n+\t\tGlobalConfiguration::envListOption(\n+\t\t\t\"LIBCAMERA_IPA_MODULE_PATH\", \"ipa.module_paths\");\n+\tfor (const auto &dir : modulePaths) {\n+\t\tif (dir.empty())\n+\t\t\tcontinue;\n \n-\t\t\tipaCount += addDir(dir.c_str());\n-\t\t}\n+\t\tipaCount += addDir(dir.c_str());\n+\t}\n \n-\t\tif (!ipaCount)\n-\t\t\tLOG(IPAManager, Warning)\n-\t\t\t\t<< \"No IPA found in '\" << modulePaths << \"'\";\n+\tif (!ipaCount) {\n+\t\tstd::string paths;\n+\t\tif (!modulePaths.empty()) {\n+\t\t\tpaths = std::accumulate(std::next(modulePaths.begin()),\n+\t\t\t\t\t\tmodulePaths.end(),\n+\t\t\t\t\t\tmodulePaths[0],\n+\t\t\t\t\t\t[](std::string s1, std::string s2) { return s1 + \":\" + s2; });\n+\t\t}\n+\t\tLOG(IPAManager, Warning) << \"No IPA found in '\" << paths << \"'\";\n \t}\n \n \t/*\n@@ -289,7 +297,9 @@ bool IPAManager::isSignatureValid([[maybe_unused]] IPAModule *ipa) const\n {\n #if HAVE_IPA_PUBKEY\n \tchar *force = utils::secure_getenv(\"LIBCAMERA_IPA_FORCE_ISOLATION\");\n-\tif (force && force[0] != '\\0') {\n+\tif ((force && force[0] != '\\0') ||\n+\t (!force && GlobalConfiguration::option<bool>(\"ipa.force_isolation\")\n+\t\t\t .value_or(false))) {\n \t\tLOG(IPAManager, Debug)\n \t\t\t<< \"Isolation of IPA module \" << ipa->path()\n \t\t\t<< \" forced through environment variable\";\ndiff --git a/src/libcamera/ipa_proxy.cpp b/src/libcamera/ipa_proxy.cpp\nindex 25f772a4..10c6ff8e 100644\n--- a/src/libcamera/ipa_proxy.cpp\n+++ b/src/libcamera/ipa_proxy.cpp\n@@ -14,6 +14,7 @@\n #include <libcamera/base/log.h>\n #include <libcamera/base/utils.h>\n \n+#include \"libcamera/internal/global_configuration.h\"\n #include \"libcamera/internal/ipa_module.h\"\n \n /**\n@@ -105,37 +106,37 @@ std::string IPAProxy::configurationFile(const std::string &name,\n \tconst std::string ipaName = ipam_->info().name;\n \n \t/*\n-\t * Start with any user override through the module-specific environment\n-\t * variable. Use the name of the IPA module up to the first '/' to\n-\t * construct the variable name.\n+\t * Start with any user override through the module-specific configuration or\n+\t * environment variable. Use the name of the IPA module up to the first '/'\n+\t * to construct the configuration and variable names.\n \t */\n-\tstd::string ipaEnvName = ipaName.substr(0, ipaName.find('/'));\n+\tstd::string ipaBaseName = ipaName.substr(0, ipaName.find('/'));\n+\tstd::string ipaConfigName = \"ipa.ipas.\" + ipaBaseName + \".tuning_file\";\n+\tstd::string ipaEnvName = ipaBaseName;\n \tstd::transform(ipaEnvName.begin(), ipaEnvName.end(), ipaEnvName.begin(),\n \t\t [](unsigned char c) { return std::toupper(c); });\n \tipaEnvName = \"LIBCAMERA_\" + ipaEnvName + \"_TUNING_FILE\";\n \n-\tchar const *configFromEnv = utils::secure_getenv(ipaEnvName.c_str());\n-\tif (configFromEnv && *configFromEnv == '\\0')\n-\t\treturn { configFromEnv };\n+\tauto config = GlobalConfiguration::envOption(ipaEnvName.c_str(), ipaConfigName);\n+\tif (config)\n+\t\treturn { config.value() };\n \n \tstruct stat statbuf;\n \tint ret;\n \n \t/*\n-\t * Check the directory pointed to by the IPA config path environment\n-\t * variable next.\n+\t * Check the directory pointed to by the IPA config path next.\n \t */\n-\tconst char *confPaths = utils::secure_getenv(\"LIBCAMERA_IPA_CONFIG_PATH\");\n-\tif (confPaths) {\n-\t\tfor (const auto &dir : utils::split(confPaths, \":\")) {\n-\t\t\tif (dir.empty())\n-\t\t\t\tcontinue;\n-\n-\t\t\tstd::string confPath = dir + \"/\" + ipaName + \"/\" + name;\n-\t\t\tret = stat(confPath.c_str(), &statbuf);\n-\t\t\tif (ret == 0 && (statbuf.st_mode & S_IFMT) == S_IFREG)\n-\t\t\t\treturn confPath;\n-\t\t}\n+\tauto confPaths =\n+\t\tGlobalConfiguration::envListOption(\n+\t\t\t\"LIBCAMERA_IPA_CONFIG_PATH\", \"ipa.config_paths\");\n+\tfor (const auto &dir : confPaths) {\n+\t\tif (dir.empty())\n+\t\t\tcontinue;\n+\t\tstd::string confPath = dir + \"/\" + ipaName + \"/\" + name;\n+\t\tret = stat(confPath.c_str(), &statbuf);\n+\t\tif (ret == 0 && (statbuf.st_mode & S_IFMT) == S_IFREG)\n+\t\t\treturn confPath;\n \t}\n \n \tstd::string root = utils::libcameraSourcePath();\n@@ -199,18 +200,18 @@ std::string IPAProxy::resolvePath(const std::string &file) const\n {\n \tstd::string proxyFile = \"/\" + file;\n \n-\t/* Check env variable first. */\n-\tconst char *execPaths = utils::secure_getenv(\"LIBCAMERA_IPA_PROXY_PATH\");\n-\tif (execPaths) {\n-\t\tfor (const auto &dir : utils::split(execPaths, \":\")) {\n-\t\t\tif (dir.empty())\n-\t\t\t\tcontinue;\n-\n-\t\t\tstd::string proxyPath = dir;\n-\t\t\tproxyPath += proxyFile;\n-\t\t\tif (!access(proxyPath.c_str(), X_OK))\n-\t\t\t\treturn proxyPath;\n-\t\t}\n+\t/* Check the configuration first. */\n+\tconst auto execPaths =\n+\t\tGlobalConfiguration::envListOption(\n+\t\t\t\"LIBCAMERA_IPA_PROXY_PATH\", \"ipa.proxy_paths\");\n+\tfor (const auto &dir : execPaths) {\n+\t\tif (dir.empty())\n+\t\t\tcontinue;\n+\n+\t\tstd::string proxyPath = dir;\n+\t\tproxyPath += proxyFile;\n+\t\tif (!access(proxyPath.c_str(), X_OK))\n+\t\t\treturn proxyPath;\n \t}\n \n \t/*\n", "prefixes": [ "v7", "08/15" ] }