From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id B61A945AEA; Wed, 9 Oct 2024 06:49:57 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1307640DCB; Wed, 9 Oct 2024 06:49:42 +0200 (CEST) Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by mails.dpdk.org (Postfix) with ESMTP id C174240A70 for ; Wed, 9 Oct 2024 06:49:35 +0200 (CEST) Received: from mail.maildlp.com (unknown [172.19.88.234]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4XNgLG6SQlz1HKJp; Wed, 9 Oct 2024 12:45:26 +0800 (CST) Received: from dggpeml500024.china.huawei.com (unknown [7.185.36.10]) by mail.maildlp.com (Postfix) with ESMTPS id 5E377140134; Wed, 9 Oct 2024 12:49:32 +0800 (CST) Received: from localhost.localdomain (10.50.165.33) by dggpeml500024.china.huawei.com (7.185.36.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Wed, 9 Oct 2024 12:49:32 +0800 From: Chengwen Feng To: , CC: , Subject: [PATCH v6 1/4] kvargs: add one new process API Date: Wed, 9 Oct 2024 04:50:27 +0000 Message-ID: <20241009045030.26874-2-fengchengwen@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20241009045030.26874-1-fengchengwen@huawei.com> References: <20230314124813.39521-1-fengchengwen@huawei.com> <20241009045030.26874-1-fengchengwen@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.50.165.33] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpeml500024.china.huawei.com (7.185.36.10) X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The rte_kvargs_process() was used to handle key=value (e.g. socket_id=0), it also supports to handle only-key (e.g. socket_id). But many drivers's callback can only handle key=value, it will segment fault if handles only-key. so the patchset [1] was introduced. Because the patchset [1] modified too much drivers, therefore: 1) A new API rte_kvargs_process_opt() was introduced, it inherits the function of rte_kvargs_process() which could handle both key=value and only-key cases. 2) Constraint the rte_kvargs_process() can only handle key=value cases, it will return -1 when handle only-key case (that is the matched key's value is NULL). This patch also make sure the rte_kvargs_process_opt() and rte_kvargs_process() API both return -1 when the kvlist parameter is NULL. [1] https://patches.dpdk.org/project/dpdk/patch/20230320092110.37295-1-fengchengwen@huawei.com/ Signed-off-by: Chengwen Feng --- doc/guides/rel_notes/release_24_11.rst | 13 ++++++++ lib/kvargs/rte_kvargs.c | 43 ++++++++++++++++++++------ lib/kvargs/rte_kvargs.h | 39 +++++++++++++++++++++-- lib/kvargs/version.map | 7 +++++ 4 files changed, 90 insertions(+), 12 deletions(-) diff --git a/doc/guides/rel_notes/release_24_11.rst b/doc/guides/rel_notes/release_24_11.rst index e0a9aa55a1..873f0639dc 100644 --- a/doc/guides/rel_notes/release_24_11.rst +++ b/doc/guides/rel_notes/release_24_11.rst @@ -96,6 +96,19 @@ API Changes Also, make sure to start the actual text at the margin. ======================================================= +* **Updated kvargs process API.** + + * Introduced rte_kvargs_process_opt() API, which inherits the function + of rte_kvargs_process() and could handle both key=value and only-key + cases. + + * Constraint rte_kvargs_process() API can only handle key=value cases, + it will return -1 when handle only-key case (that is the matched key's + value is NULL). + + * Make sure rte_kvargs_process_opt() and rte_kvargs_process() API both + return -1 when the kvlist parameter is NULL. + ABI Changes ----------- diff --git a/lib/kvargs/rte_kvargs.c b/lib/kvargs/rte_kvargs.c index c77bb82feb..b02f22f5a2 100644 --- a/lib/kvargs/rte_kvargs.c +++ b/lib/kvargs/rte_kvargs.c @@ -167,31 +167,56 @@ rte_kvargs_count(const struct rte_kvargs *kvlist, const char *key_match) return ret; } -/* - * For each matching key, call the given handler function. - */ -int -rte_kvargs_process(const struct rte_kvargs *kvlist, - const char *key_match, - arg_handler_t handler, - void *opaque_arg) +static int +kvargs_process_common(const struct rte_kvargs *kvlist, + const char *key_match, + arg_handler_t handler, + void *opaque_arg, + bool support_only_key) { const struct rte_kvargs_pair *pair; unsigned i; if (kvlist == NULL) - return 0; + return -1; for (i = 0; i < kvlist->count; i++) { pair = &kvlist->pairs[i]; if (key_match == NULL || strcmp(pair->key, key_match) == 0) { + if (!support_only_key && pair->value == NULL) + return -1; if ((*handler)(pair->key, pair->value, opaque_arg) < 0) return -1; } } + return 0; } +/* + * For each matching key in key=value, call the given handler function. + */ +int +rte_kvargs_process(const struct rte_kvargs *kvlist, + const char *key_match, + arg_handler_t handler, + void *opaque_arg) +{ + return kvargs_process_common(kvlist, key_match, handler, opaque_arg, false); +} + +/* + * For each matching key in key=value or only-key, call the given handler function. + */ +int +rte_kvargs_process_opt(const struct rte_kvargs *kvlist, + const char *key_match, + arg_handler_t handler, + void *opaque_arg) +{ + return kvargs_process_common(kvlist, key_match, handler, opaque_arg, true); +} + /* free the rte_kvargs structure */ void rte_kvargs_free(struct rte_kvargs *kvlist) diff --git a/lib/kvargs/rte_kvargs.h b/lib/kvargs/rte_kvargs.h index b0d1301c61..b37cd4902f 100644 --- a/lib/kvargs/rte_kvargs.h +++ b/lib/kvargs/rte_kvargs.h @@ -6,6 +6,8 @@ #ifndef _RTE_KVARGS_H_ #define _RTE_KVARGS_H_ +#include + /** * @file * RTE Argument parsing @@ -166,14 +168,17 @@ const char *rte_kvargs_get_with_value(const struct rte_kvargs *kvlist, const char *key, const char *value); /** - * Call a handler function for each key/value matching the key + * Call a handler function for each key=value matching the key * - * For each key/value association that matches the given key, calls the + * For each key=value association that matches the given key, calls the * handler function with the for a given arg_name passing the value on the * dictionary for that key and a given extra argument. * + * @note Compared to @see rte_kvargs_process_opt, this API will return -1 + * when handle only-key case (that is the matched key's value is NULL). + * * @param kvlist - * The rte_kvargs structure. No error if NULL. + * The rte_kvargs structure. * @param key_match * The key on which the handler should be called, or NULL to process handler * on all associations @@ -189,6 +194,34 @@ const char *rte_kvargs_get_with_value(const struct rte_kvargs *kvlist, int rte_kvargs_process(const struct rte_kvargs *kvlist, const char *key_match, arg_handler_t handler, void *opaque_arg); +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Call a handler function for each key=value or only-key matching the key + * + * For each key=value or only-key association that matches the given key, calls + * the handler function with the for a given arg_name passing the value on the + * dictionary for that key and a given extra argument. + * + * @param kvlist + * The rte_kvargs structure. + * @param key_match + * The key on which the handler should be called, or NULL to process handler + * on all associations + * @param handler + * The function to call for each matching key + * @param opaque_arg + * A pointer passed unchanged to the handler + * + * @return + * - 0 on success + * - Negative on error + */ +__rte_experimental +int rte_kvargs_process_opt(const struct rte_kvargs *kvlist, + const char *key_match, arg_handler_t handler, void *opaque_arg); + /** * Count the number of associations matching the given key * diff --git a/lib/kvargs/version.map b/lib/kvargs/version.map index b50f1a97a1..178f476236 100644 --- a/lib/kvargs/version.map +++ b/lib/kvargs/version.map @@ -11,3 +11,10 @@ DPDK_25 { local: *; }; + +EXPERIMENTAL { + global: + + # added in 24.11 + rte_kvargs_process_opt; +}; -- 2.17.1