Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/122514/?format=api
http://patches.dpdk.org/api/patches/122514/?format=api", "web_url": "http://patches.dpdk.org/project/dpdk/patch/20230125103809.1250080-2-tduszynski@marvell.com/", "project": { "id": 1, "url": "http://patches.dpdk.org/api/projects/1/?format=api", "name": "DPDK", "link_name": "dpdk", "list_id": "dev.dpdk.org", "list_email": "dev@dpdk.org", "web_url": "http://core.dpdk.org", "scm_url": "git://dpdk.org/dpdk", "webscm_url": "http://git.dpdk.org/dpdk", "list_archive_url": "https://inbox.dpdk.org/dev", "list_archive_url_format": "https://inbox.dpdk.org/dev/{}", "commit_url_format": "" }, "msgid": "<20230125103809.1250080-2-tduszynski@marvell.com>", "list_archive_url": "https://inbox.dpdk.org/dev/20230125103809.1250080-2-tduszynski@marvell.com", "date": "2023-01-25T10:38:08", "name": "[1/2] lib: add helper to read strings from sysfs files", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": true, "hash": "2377bc7e03f0fa28f4d52ff4894a623fe32d5262", "submitter": { "id": 2215, "url": "http://patches.dpdk.org/api/people/2215/?format=api", "name": "Tomasz Duszynski", "email": "tduszynski@marvell.com" }, "delegate": { "id": 1, "url": "http://patches.dpdk.org/api/users/1/?format=api", "username": "tmonjalo", "first_name": "Thomas", "last_name": "Monjalon", "email": "thomas@monjalon.net" }, "mbox": "http://patches.dpdk.org/project/dpdk/patch/20230125103809.1250080-2-tduszynski@marvell.com/mbox/", "series": [ { "id": 26650, "url": "http://patches.dpdk.org/api/series/26650/?format=api", "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=26650", "date": "2023-01-25T10:38:08", "name": "add platform bus", "version": 1, "mbox": "http://patches.dpdk.org/series/26650/mbox/" } ], "comments": "http://patches.dpdk.org/api/patches/122514/comments/", "check": "warning", "checks": "http://patches.dpdk.org/api/patches/122514/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<dev-bounces@dpdk.org>", "X-Original-To": "patchwork@inbox.dpdk.org", "Delivered-To": "patchwork@inbox.dpdk.org", "Received": [ "from mails.dpdk.org (mails.dpdk.org [217.70.189.124])\n\tby inbox.dpdk.org (Postfix) with ESMTP id CF86842483;\n\tWed, 25 Jan 2023 11:38:22 +0100 (CET)", "from mails.dpdk.org (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id 701CF42D31;\n\tWed, 25 Jan 2023 11:38:22 +0100 (CET)", "from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com\n [67.231.156.173])\n by mails.dpdk.org (Postfix) with ESMTP id BFCA140684\n for <dev@dpdk.org>; Wed, 25 Jan 2023 11:38:20 +0100 (CET)", "from pps.filterd (m0045851.ppops.net [127.0.0.1])\n by mx0b-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id\n 30P7tgF0023368; Wed, 25 Jan 2023 02:38:19 -0800", "from dc5-exch01.marvell.com ([199.233.59.181])\n by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3nb0f68ncq-1\n (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT);\n Wed, 25 Jan 2023 02:38:19 -0800", "from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH01.marvell.com\n (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.42;\n Wed, 25 Jan 2023 02:38:17 -0800", "from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com\n (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.42 via Frontend\n Transport; Wed, 25 Jan 2023 02:38:17 -0800", "from cavium-DT10.. (unknown [10.28.34.39])\n by maili.marvell.com (Postfix) with ESMTP id 9F81A3F706F;\n Wed, 25 Jan 2023 02:38:14 -0800 (PST)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com;\n h=from : to : cc :\n subject : date : message-id : in-reply-to : references : mime-version :\n content-transfer-encoding : content-type; s=pfpt0220;\n bh=nbq/oGpvCJMGRkR+1Icm51EWAR1ZUhaWXzsWPZ5MiPY=;\n b=Xpb8Kw4dKmN1ZUIy4fIxiZjquRFhBo88/ei+cB+fkASMeRpH271TIOb7UchCCufYIE4d\n YwRO+ZcYys4alGO8mO9VIwBNxc8B6ociiWtZ1009MmsMT1OjrkX8LpMn1Maq0XFHnLVG\n wVGzKYpzTuvVpKVHsg7zB74dYhC8a9UXh2meI7JHhPZwNM/nmQuO7bWDecH+q9CARKyY\n H7T+UQzre6Azs1MLersXoVlAjv78D7SWvsClxCYhHvEksFXWmNmX9OjJgv2X8toJz5xD\n HAEgXRzQynxqwPAdrCZpq66WlLrHmtxF1RzzDpkfkn6x6Y/ppLW+L1DsEAqurEvK7sNH wA==", "From": "Tomasz Duszynski <tduszynski@marvell.com>", "To": "<dev@dpdk.org>", "CC": "<thomas@monjalon.net>, <jerinj@marvell.com>, <stephen@networkplumber.org>,\n <chenbo.xia@intel.com>, Tomasz Duszynski <tduszynski@marvell.com>", "Subject": "[PATCH 1/2] lib: add helper to read strings from sysfs files", "Date": "Wed, 25 Jan 2023 11:38:08 +0100", "Message-ID": "<20230125103809.1250080-2-tduszynski@marvell.com>", "X-Mailer": "git-send-email 2.34.1", "In-Reply-To": "<20230125103809.1250080-1-tduszynski@marvell.com>", "References": "<20230125103809.1250080-1-tduszynski@marvell.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Content-Type": "text/plain", "X-Proofpoint-GUID": "cyRrnTsYXwLlEvgMPmmFtod0Yvu0wJhF", "X-Proofpoint-ORIG-GUID": "cyRrnTsYXwLlEvgMPmmFtod0Yvu0wJhF", "X-Proofpoint-Virus-Version": "vendor=baseguard\n engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.122.1\n definitions=2023-01-25_05,2023-01-25_01,2022-06-22_01", "X-BeenThere": "dev@dpdk.org", "X-Mailman-Version": "2.1.29", "Precedence": "list", "List-Id": "DPDK patches and discussions <dev.dpdk.org>", "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n <mailto:dev-request@dpdk.org?subject=unsubscribe>", "List-Archive": "<http://mails.dpdk.org/archives/dev/>", "List-Post": "<mailto:dev@dpdk.org>", "List-Help": "<mailto:dev-request@dpdk.org?subject=help>", "List-Subscribe": "<https://mails.dpdk.org/listinfo/dev>,\n <mailto:dev-request@dpdk.org?subject=subscribe>", "Errors-To": "dev-bounces@dpdk.org" }, "content": "Reading strings from sysfs files is a re-occurring pattern\nhence add helper for doing that.\n\nSigned-off-by: Tomasz Duszynski <tduszynski@marvell.com>\n---\n app/test/test_eal_fs.c | 108 ++++++++++++++++++++++++++++----\n lib/eal/common/eal_filesystem.h | 6 ++\n lib/eal/unix/eal_filesystem.c | 24 ++++---\n lib/eal/version.map | 1 +\n 4 files changed, 121 insertions(+), 18 deletions(-)", "diff": "diff --git a/app/test/test_eal_fs.c b/app/test/test_eal_fs.c\nindex b3686edcb4..6c373fc7f1 100644\n--- a/app/test/test_eal_fs.c\n+++ b/app/test/test_eal_fs.c\n@@ -20,12 +20,33 @@ test_eal_fs(void)\n \n #else\n \n+static int\n+temp_create(char *filename, size_t len)\n+{\n+\tchar file_template[] = \"/tmp/eal_test_XXXXXX\";\n+\tchar proc_path[PATH_MAX];\n+\tint fd;\n+\n+\tfd = mkstemp(file_template);\n+\tif (fd == -1) {\n+\t\tperror(\"mkstemp() failure\");\n+\t\treturn -1;\n+\t}\n+\n+\tsnprintf(proc_path, sizeof(proc_path), \"/proc/self/fd/%d\", fd);\n+\tif (readlink(proc_path, filename, len) < 0) {\n+\t\tperror(\"readlink() failure\");\n+\t\tclose(fd);\n+\t\treturn -1;\n+\t}\n+\n+\treturn fd;\n+}\n+\n static int\n test_parse_sysfs_value(void)\n {\n \tchar filename[PATH_MAX] = \"\";\n-\tchar proc_path[PATH_MAX];\n-\tchar file_template[] = \"/tmp/eal_test_XXXXXX\";\n \tint tmp_file_handle = -1;\n \tFILE *fd = NULL;\n \tunsigned valid_number;\n@@ -40,16 +61,10 @@ test_parse_sysfs_value(void)\n \n \t/* get a temporary filename to use for all tests - create temp file handle and then\n \t * use /proc to get the actual file that we can open */\n-\ttmp_file_handle = mkstemp(file_template);\n-\tif (tmp_file_handle == -1) {\n-\t\tperror(\"mkstemp() failure\");\n+\ttmp_file_handle = temp_create(filename, sizeof(filename));\n+\tif (tmp_file_handle < 0)\n \t\tgoto error;\n-\t}\n-\tsnprintf(proc_path, sizeof(proc_path), \"/proc/self/fd/%d\", tmp_file_handle);\n-\tif (readlink(proc_path, filename, sizeof(filename)) < 0) {\n-\t\tperror(\"readlink() failure\");\n-\t\tgoto error;\n-\t}\n+\n \tprintf(\"Temporary file is: %s\\n\", filename);\n \n \t/* test we get an error value if we use file before it's created */\n@@ -175,11 +190,82 @@ test_parse_sysfs_value(void)\n \treturn -1;\n }\n \n+static int\n+test_parse_sysfs_string(void)\n+{\n+\tconst char *teststr = \"the quick brown dog jumps over the lazy fox\\n\";\n+\tchar filename[PATH_MAX] = \"\";\n+\tchar buf[BUFSIZ] = { };\n+\tint tmp_file_handle;\n+\tFILE *fd = NULL;\n+\n+#ifdef RTE_EXEC_ENV_FREEBSD\n+\t/* BSD doesn't have /proc/pid/fd */\n+\treturn 0;\n+#endif\n+\tprintf(\"Testing function eal_parse_sysfs_string()\\n\");\n+\n+\t/* get a temporary filename to use for all tests - create temp file handle and then\n+\t * use /proc to get the actual file that we can open\n+\t */\n+\ttmp_file_handle = temp_create(filename, sizeof(filename));\n+\tif (tmp_file_handle < 0)\n+\t\tgoto error;\n+\n+\tprintf(\"Temporary file is: %s\\n\", filename);\n+\n+\t/* test we get an error value if we use file before it's created */\n+\tprintf(\"Test reading a missing file ...\\n\");\n+\tif (eal_parse_sysfs_string(\"/dev/not-quite-null\", buf, sizeof(buf)) == 0) {\n+\t\tprintf(\"Error with eal_parse_sysfs_string() - returned success on reading empty file\\n\");\n+\t\tgoto error;\n+\t}\n+\tprintf(\"Confirmed return error when reading empty file\\n\");\n+\n+\t/* test reading a string from file */\n+\tprintf(\"Test reading string ...\\n\");\n+\tfd = fopen(filename, \"w\");\n+\tif (fd == NULL) {\n+\t\tprintf(\"line %d, Error opening %s: %s\\n\", __LINE__, filename, strerror(errno));\n+\t\tgoto error;\n+\t}\n+\tfprintf(fd, \"%s\", teststr);\n+\tfclose(fd);\n+\tfd = NULL;\n+\tif (eal_parse_sysfs_string(filename, buf, sizeof(buf) - 1) < 0) {\n+\t\tprintf(\"eal_parse_sysfs_string() returned error - test failed\\n\");\n+\t\tgoto error;\n+\t}\n+\tif (strcmp(teststr, buf)) {\n+\t\tprintf(\"Invalid string read by eal_parse_sysfs_string() - test failed\\n\");\n+\t\tgoto error;\n+\t}\n+\t/* don't print newline */\n+\tbuf[strlen(buf) - 1] = '\\0';\n+\tprintf(\"Read '%s\\\\n' ok\\n\", buf);\n+\n+\tclose(tmp_file_handle);\n+\tunlink(filename);\n+\tprintf(\"eal_parse_sysfs_string() - OK\\n\");\n+\treturn 0;\n+\n+error:\n+\tif (fd)\n+\t\tfclose(fd);\n+\tif (tmp_file_handle > 0)\n+\t\tclose(tmp_file_handle);\n+\tif (filename[0] != '\\0')\n+\t\tunlink(filename);\n+\treturn -1;\n+}\n+\n static int\n test_eal_fs(void)\n {\n \tif (test_parse_sysfs_value() < 0)\n \t\treturn -1;\n+\tif (test_parse_sysfs_string() < 0)\n+\t\treturn -1;\n \treturn 0;\n }\n \ndiff --git a/lib/eal/common/eal_filesystem.h b/lib/eal/common/eal_filesystem.h\nindex 5d21f07c20..ac6449f529 100644\n--- a/lib/eal/common/eal_filesystem.h\n+++ b/lib/eal/common/eal_filesystem.h\n@@ -104,4 +104,10 @@ eal_get_hugefile_path(char *buffer, size_t buflen, const char *hugedir, int f_id\n * Used to read information from files on /sys */\n int eal_parse_sysfs_value(const char *filename, unsigned long *val);\n \n+/** Function to read a string from a file on the filesystem.\n+ * Used to read information for files in /sys\n+ */\n+__rte_internal\n+int eal_parse_sysfs_string(const char *filename, char *str, size_t size);\n+\n #endif /* EAL_FILESYSTEM_H */\ndiff --git a/lib/eal/unix/eal_filesystem.c b/lib/eal/unix/eal_filesystem.c\nindex afbab9368a..8ed10094be 100644\n--- a/lib/eal/unix/eal_filesystem.c\n+++ b/lib/eal/unix/eal_filesystem.c\n@@ -76,12 +76,9 @@ int eal_create_runtime_dir(void)\n \treturn 0;\n }\n \n-/* parse a sysfs (or other) file containing one integer value */\n-int eal_parse_sysfs_value(const char *filename, unsigned long *val)\n+int eal_parse_sysfs_string(const char *filename, char *str, size_t size)\n {\n \tFILE *f;\n-\tchar buf[BUFSIZ];\n-\tchar *end = NULL;\n \n \tif ((f = fopen(filename, \"r\")) == NULL) {\n \t\tRTE_LOG(ERR, EAL, \"%s(): cannot open sysfs value %s\\n\",\n@@ -89,19 +86,32 @@ int eal_parse_sysfs_value(const char *filename, unsigned long *val)\n \t\treturn -1;\n \t}\n \n-\tif (fgets(buf, sizeof(buf), f) == NULL) {\n+\tif (fgets(str, size, f) == NULL) {\n \t\tRTE_LOG(ERR, EAL, \"%s(): cannot read sysfs value %s\\n\",\n \t\t\t__func__, filename);\n \t\tfclose(f);\n \t\treturn -1;\n \t}\n+\tfclose(f);\n+\treturn 0;\n+}\n+\n+/* parse a sysfs (or other) file containing one integer value */\n+int eal_parse_sysfs_value(const char *filename, unsigned long *val)\n+{\n+\tchar buf[BUFSIZ];\n+\tchar *end = NULL;\n+\tint ret;\n+\n+\tret = eal_parse_sysfs_string(filename, buf, sizeof(buf));\n+\tif (ret < 0)\n+\t\treturn ret;\n+\n \t*val = strtoul(buf, &end, 0);\n \tif ((buf[0] == '\\0') || (end == NULL) || (*end != '\\n')) {\n \t\tRTE_LOG(ERR, EAL, \"%s(): cannot parse sysfs value %s\\n\",\n \t\t\t\t__func__, filename);\n-\t\tfclose(f);\n \t\treturn -1;\n \t}\n-\tfclose(f);\n \treturn 0;\n }\ndiff --git a/lib/eal/version.map b/lib/eal/version.map\nindex 7ad12a7dc9..9118bb6228 100644\n--- a/lib/eal/version.map\n+++ b/lib/eal/version.map\n@@ -445,6 +445,7 @@ EXPERIMENTAL {\n INTERNAL {\n \tglobal:\n \n+\teal_parse_sysfs_string; # WINDOWS_NO_EXPORT\n \trte_bus_register;\n \trte_bus_unregister;\n \trte_eal_get_baseaddr;\n", "prefixes": [ "1/2" ] }{ "id": 122514, "url": "