All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cfgfile: support looking up sections by index
@ 2016-01-17  3:58 Rich Lane
  2016-01-18 12:58 ` Panu Matilainen
  2016-01-19  4:41 ` [PATCH v2] " Rich Lane
  0 siblings, 2 replies; 15+ messages in thread
From: Rich Lane @ 2016-01-17  3:58 UTC (permalink / raw)
  To: dev

This is useful when sections have duplicate names.

Signed-off-by: Rich Lane <rlane@bigswitch.com>
---
 lib/librte_cfgfile/rte_cfgfile.c | 16 ++++++++++++++++
 lib/librte_cfgfile/rte_cfgfile.h | 23 +++++++++++++++++++++++
 2 files changed, 39 insertions(+)

diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cfgfile.c
index a677dad..0bb40a4 100644
--- a/lib/librte_cfgfile/rte_cfgfile.c
+++ b/lib/librte_cfgfile/rte_cfgfile.c
@@ -333,6 +333,22 @@ rte_cfgfile_section_entries(struct rte_cfgfile *cfg, const char *sectionname,
 	return i;
 }
 
+int
+rte_cfgfile_section_entries_by_index(struct rte_cfgfile *cfg, int index,
+		struct rte_cfgfile_entry *entries, int max_entries)
+{
+	int i;
+	const struct rte_cfgfile_section *sect;
+
+	if (index >= cfg->num_sections)
+		return -1;
+
+	sect = cfg->sections[index];
+	for (i = 0; i < max_entries && i < sect->num_entries; i++)
+		entries[i] = *sect->entries[i];
+	return i;
+}
+
 const char *
 rte_cfgfile_get_entry(struct rte_cfgfile *cfg, const char *sectionname,
 		const char *entryname)
diff --git a/lib/librte_cfgfile/rte_cfgfile.h b/lib/librte_cfgfile/rte_cfgfile.h
index d443782..8e69971 100644
--- a/lib/librte_cfgfile/rte_cfgfile.h
+++ b/lib/librte_cfgfile/rte_cfgfile.h
@@ -155,6 +155,29 @@ int rte_cfgfile_section_entries(struct rte_cfgfile *cfg,
 	struct rte_cfgfile_entry *entries,
 	int max_entries);
 
+/** Get section entries as key-value pairs
+*
+* The index of a section is the same as the index of its name in the
+* result of rte_cfgfile_sections. This API can be used when there are
+* multiple sections with the same name.
+*
+* @param cfg
+*   Config file
+* @param index
+*   Section index
+* @param entries
+*   Pre-allocated array of at least max_entries entries where the section
+*   entries are stored as key-value pair after successful invocation
+* @param max_entries
+*   Maximum number of section entries to be stored in entries array
+* @return
+*   Number of entries populated on success, negative error code otherwise
+*/
+int rte_cfgfile_section_entries_by_index(struct rte_cfgfile *cfg,
+	int index,
+	struct rte_cfgfile_entry *entries,
+	int max_entries);
+
 /** Get value of the named entry in named config file section
 *
 * @param cfg
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [PATCH] cfgfile: support looking up sections by index
  2016-01-17  3:58 [PATCH] cfgfile: support looking up sections by index Rich Lane
@ 2016-01-18 12:58 ` Panu Matilainen
  2016-01-19  4:41 ` [PATCH v2] " Rich Lane
  1 sibling, 0 replies; 15+ messages in thread
From: Panu Matilainen @ 2016-01-18 12:58 UTC (permalink / raw)
  To: Rich Lane, dev

On 01/17/2016 05:58 AM, Rich Lane wrote:
> This is useful when sections have duplicate names.
>
> Signed-off-by: Rich Lane <rlane@bigswitch.com>
> ---
>   lib/librte_cfgfile/rte_cfgfile.c | 16 ++++++++++++++++
>   lib/librte_cfgfile/rte_cfgfile.h | 23 +++++++++++++++++++++++
>   2 files changed, 39 insertions(+)
>

This is missing the corresponding entry to 
lib/librte_cfgfile/rte_cfgfile_version.map

	- Panu -

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH v2] cfgfile: support looking up sections by index
  2016-01-17  3:58 [PATCH] cfgfile: support looking up sections by index Rich Lane
  2016-01-18 12:58 ` Panu Matilainen
@ 2016-01-19  4:41 ` Rich Lane
  2016-01-21  7:42   ` Panu Matilainen
                     ` (2 more replies)
  1 sibling, 3 replies; 15+ messages in thread
From: Rich Lane @ 2016-01-19  4:41 UTC (permalink / raw)
  To: dev

This is useful when sections have duplicate names.

Signed-off-by: Rich Lane <rlane@bigswitch.com>
---
v1->v2:
- Added new symbol to version script.

 lib/librte_cfgfile/rte_cfgfile.c           | 16 ++++++++++++++++
 lib/librte_cfgfile/rte_cfgfile.h           | 23 +++++++++++++++++++++++
 lib/librte_cfgfile/rte_cfgfile_version.map |  6 ++++++
 3 files changed, 45 insertions(+)

diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cfgfile.c
index a677dad..0bb40a4 100644
--- a/lib/librte_cfgfile/rte_cfgfile.c
+++ b/lib/librte_cfgfile/rte_cfgfile.c
@@ -333,6 +333,22 @@ rte_cfgfile_section_entries(struct rte_cfgfile *cfg, const char *sectionname,
 	return i;
 }
 
+int
+rte_cfgfile_section_entries_by_index(struct rte_cfgfile *cfg, int index,
+		struct rte_cfgfile_entry *entries, int max_entries)
+{
+	int i;
+	const struct rte_cfgfile_section *sect;
+
+	if (index >= cfg->num_sections)
+		return -1;
+
+	sect = cfg->sections[index];
+	for (i = 0; i < max_entries && i < sect->num_entries; i++)
+		entries[i] = *sect->entries[i];
+	return i;
+}
+
 const char *
 rte_cfgfile_get_entry(struct rte_cfgfile *cfg, const char *sectionname,
 		const char *entryname)
diff --git a/lib/librte_cfgfile/rte_cfgfile.h b/lib/librte_cfgfile/rte_cfgfile.h
index d443782..8e69971 100644
--- a/lib/librte_cfgfile/rte_cfgfile.h
+++ b/lib/librte_cfgfile/rte_cfgfile.h
@@ -155,6 +155,29 @@ int rte_cfgfile_section_entries(struct rte_cfgfile *cfg,
 	struct rte_cfgfile_entry *entries,
 	int max_entries);
 
+/** Get section entries as key-value pairs
+*
+* The index of a section is the same as the index of its name in the
+* result of rte_cfgfile_sections. This API can be used when there are
+* multiple sections with the same name.
+*
+* @param cfg
+*   Config file
+* @param index
+*   Section index
+* @param entries
+*   Pre-allocated array of at least max_entries entries where the section
+*   entries are stored as key-value pair after successful invocation
+* @param max_entries
+*   Maximum number of section entries to be stored in entries array
+* @return
+*   Number of entries populated on success, negative error code otherwise
+*/
+int rte_cfgfile_section_entries_by_index(struct rte_cfgfile *cfg,
+	int index,
+	struct rte_cfgfile_entry *entries,
+	int max_entries);
+
 /** Get value of the named entry in named config file section
 *
 * @param cfg
diff --git a/lib/librte_cfgfile/rte_cfgfile_version.map b/lib/librte_cfgfile/rte_cfgfile_version.map
index bf6c6fd..f6a27a9 100644
--- a/lib/librte_cfgfile/rte_cfgfile_version.map
+++ b/lib/librte_cfgfile/rte_cfgfile_version.map
@@ -13,3 +13,9 @@ DPDK_2.0 {
 
 	local: *;
 };
+
+DPDK_2.3 {
+	global:
+
+	rte_cfgfile_section_entries_by_index;
+} DPDK_2.0;
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [PATCH v2] cfgfile: support looking up sections by index
  2016-01-19  4:41 ` [PATCH v2] " Rich Lane
@ 2016-01-21  7:42   ` Panu Matilainen
  2016-02-02 15:10   ` Dumitrescu, Cristian
  2016-02-10 19:12   ` [PATCH v3] " Rich Lane
  2 siblings, 0 replies; 15+ messages in thread
From: Panu Matilainen @ 2016-01-21  7:42 UTC (permalink / raw)
  To: Rich Lane, dev

On 01/19/2016 06:41 AM, Rich Lane wrote:
> This is useful when sections have duplicate names.
>
> Signed-off-by: Rich Lane <rlane@bigswitch.com>
> ---
> v1->v2:
> - Added new symbol to version script.
>
>   lib/librte_cfgfile/rte_cfgfile.c           | 16 ++++++++++++++++
>   lib/librte_cfgfile/rte_cfgfile.h           | 23 +++++++++++++++++++++++
>   lib/librte_cfgfile/rte_cfgfile_version.map |  6 ++++++
>   3 files changed, 45 insertions(+)
>
> diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cfgfile.c
> index a677dad..0bb40a4 100644
> --- a/lib/librte_cfgfile/rte_cfgfile.c
> +++ b/lib/librte_cfgfile/rte_cfgfile.c
> @@ -333,6 +333,22 @@ rte_cfgfile_section_entries(struct rte_cfgfile *cfg, const char *sectionname,
>   	return i;
>   }
>
> +int
> +rte_cfgfile_section_entries_by_index(struct rte_cfgfile *cfg, int index,
> +		struct rte_cfgfile_entry *entries, int max_entries)
> +{
> +	int i;
> +	const struct rte_cfgfile_section *sect;
> +
> +	if (index >= cfg->num_sections)
> +		return -1;
> +
> +	sect = cfg->sections[index];

Since index is a signed int, I think you should check for < 0 as well in 
the above. Sorry for not noticing/mentioning that on the first round, I 
wasn't so much reviewing the code as just skimming through for general 
API/ABI issues.

Other than that, looks ok to me.

	- Panu -

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v2] cfgfile: support looking up sections by index
  2016-01-19  4:41 ` [PATCH v2] " Rich Lane
  2016-01-21  7:42   ` Panu Matilainen
@ 2016-02-02 15:10   ` Dumitrescu, Cristian
  2016-02-10 19:13     ` Rich Lane
  2016-02-10 19:12   ` [PATCH v3] " Rich Lane
  2 siblings, 1 reply; 15+ messages in thread
From: Dumitrescu, Cristian @ 2016-02-02 15:10 UTC (permalink / raw)
  To: Rich Lane, dev



> -----Original Message-----
> From: Rich Lane [mailto:rich.lane@bigswitch.com]
> Sent: Tuesday, January 19, 2016 4:42 AM
> To: dev@dpdk.org
> Cc: Dumitrescu, Cristian <cristian.dumitrescu@intel.com>; Panu Matilainen
> <pmatilai@redhat.com>
> Subject: [PATCH v2] cfgfile: support looking up sections by index
> 
> This is useful when sections have duplicate names.

Hi Rich,

You are right, I can see this is needed to allow multiple sections with identical name in the same configuration file. When sections with the same name are not allowed, then this is not needed, as the current API is sufficient.

To me, having several sections with the same name does not look like a good idea, in fact it might look like an application design flaw, as differentiating between sections with the same name can only done based on the position of the section in the configuration file, which is an error prone option. Some examples: 
1. While maintaining a large config file, keeping a specific section at a fixed position quickly becomes a pain, and shifting the position of the section up or down can completely change the application behavior;
2. Using basic pre-processors (like CPP or M4) or scripts, the master configuration file can include other configuration files, with the inclusion of each decided at run-time based on application command line parameters, so the position of certain sections is actually not known until run-time.

Can you provide some examples when having multiple sections with the same name is a key requirement?

A straight forward workaround to having multiple sections with the same name is to add a number to the name of each such section. Using the current API, all the sections with the same prefix name can be read gracefully. As an example, the ip_pipeline application allows multiple sections with the same name prefix but a different number prefix:
PIPELINE0, PIPELINE1, ...
LINK0, LINK1, ...
MEMPOOL0, MEMPOOL1, ...
RXQ0.0, RXQ0.1, RXQ1.0, ...
TXQ0.0, TXQ0.1, TXQ1.0, ...

Is there a reason why this approach is not acceptable for your application?

Regards,
Cristian

> 
> Signed-off-by: Rich Lane <rlane@bigswitch.com>
> ---
> v1->v2:
> - Added new symbol to version script.
> 
>  lib/librte_cfgfile/rte_cfgfile.c           | 16 ++++++++++++++++
>  lib/librte_cfgfile/rte_cfgfile.h           | 23 +++++++++++++++++++++++
>  lib/librte_cfgfile/rte_cfgfile_version.map |  6 ++++++
>  3 files changed, 45 insertions(+)
> 
> diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cfgfile.c
> index a677dad..0bb40a4 100644
> --- a/lib/librte_cfgfile/rte_cfgfile.c
> +++ b/lib/librte_cfgfile/rte_cfgfile.c
> @@ -333,6 +333,22 @@ rte_cfgfile_section_entries(struct rte_cfgfile *cfg,
> const char *sectionname,
>  	return i;
>  }
> 
> +int
> +rte_cfgfile_section_entries_by_index(struct rte_cfgfile *cfg, int index,
> +		struct rte_cfgfile_entry *entries, int max_entries)
> +{
> +	int i;
> +	const struct rte_cfgfile_section *sect;
> +
> +	if (index >= cfg->num_sections)
> +		return -1;
> +
> +	sect = cfg->sections[index];
> +	for (i = 0; i < max_entries && i < sect->num_entries; i++)
> +		entries[i] = *sect->entries[i];
> +	return i;
> +}
> +
>  const char *
>  rte_cfgfile_get_entry(struct rte_cfgfile *cfg, const char *sectionname,
>  		const char *entryname)
> diff --git a/lib/librte_cfgfile/rte_cfgfile.h b/lib/librte_cfgfile/rte_cfgfile.h
> index d443782..8e69971 100644
> --- a/lib/librte_cfgfile/rte_cfgfile.h
> +++ b/lib/librte_cfgfile/rte_cfgfile.h
> @@ -155,6 +155,29 @@ int rte_cfgfile_section_entries(struct rte_cfgfile
> *cfg,
>  	struct rte_cfgfile_entry *entries,
>  	int max_entries);
> 
> +/** Get section entries as key-value pairs
> +*
> +* The index of a section is the same as the index of its name in the
> +* result of rte_cfgfile_sections. This API can be used when there are
> +* multiple sections with the same name.
> +*
> +* @param cfg
> +*   Config file
> +* @param index
> +*   Section index
> +* @param entries
> +*   Pre-allocated array of at least max_entries entries where the section
> +*   entries are stored as key-value pair after successful invocation
> +* @param max_entries
> +*   Maximum number of section entries to be stored in entries array
> +* @return
> +*   Number of entries populated on success, negative error code otherwise
> +*/
> +int rte_cfgfile_section_entries_by_index(struct rte_cfgfile *cfg,
> +	int index,
> +	struct rte_cfgfile_entry *entries,
> +	int max_entries);
> +
>  /** Get value of the named entry in named config file section
>  *
>  * @param cfg
> diff --git a/lib/librte_cfgfile/rte_cfgfile_version.map
> b/lib/librte_cfgfile/rte_cfgfile_version.map
> index bf6c6fd..f6a27a9 100644
> --- a/lib/librte_cfgfile/rte_cfgfile_version.map
> +++ b/lib/librte_cfgfile/rte_cfgfile_version.map
> @@ -13,3 +13,9 @@ DPDK_2.0 {
> 
>  	local: *;
>  };
> +
> +DPDK_2.3 {
> +	global:
> +
> +	rte_cfgfile_section_entries_by_index;
> +} DPDK_2.0;
> --
> 1.9.1

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH v3] cfgfile: support looking up sections by index
  2016-01-19  4:41 ` [PATCH v2] " Rich Lane
  2016-01-21  7:42   ` Panu Matilainen
  2016-02-02 15:10   ` Dumitrescu, Cristian
@ 2016-02-10 19:12   ` Rich Lane
  2016-02-16 20:48     ` Dumitrescu, Cristian
  2016-02-16 22:58     ` [PATCH v4] " Rich Lane
  2 siblings, 2 replies; 15+ messages in thread
From: Rich Lane @ 2016-02-10 19:12 UTC (permalink / raw)
  To: dev

This is useful when sections have duplicate names.

Signed-off-by: Rich Lane <rlane@bigswitch.com>
---
v2->v3
- Added check for index < 0.
v1->v2:
- Added new symbol to version script.

 lib/librte_cfgfile/rte_cfgfile.c           | 16 ++++++++++++++++
 lib/librte_cfgfile/rte_cfgfile.h           | 23 +++++++++++++++++++++++
 lib/librte_cfgfile/rte_cfgfile_version.map |  6 ++++++
 3 files changed, 45 insertions(+)

diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cfgfile.c
index a677dad..eba0713 100644
--- a/lib/librte_cfgfile/rte_cfgfile.c
+++ b/lib/librte_cfgfile/rte_cfgfile.c
@@ -333,6 +333,22 @@ rte_cfgfile_section_entries(struct rte_cfgfile *cfg, const char *sectionname,
 	return i;
 }
 
+int
+rte_cfgfile_section_entries_by_index(struct rte_cfgfile *cfg, int index,
+		struct rte_cfgfile_entry *entries, int max_entries)
+{
+	int i;
+	const struct rte_cfgfile_section *sect;
+
+	if (index < 0 || index >= cfg->num_sections)
+		return -1;
+
+	sect = cfg->sections[index];
+	for (i = 0; i < max_entries && i < sect->num_entries; i++)
+		entries[i] = *sect->entries[i];
+	return i;
+}
+
 const char *
 rte_cfgfile_get_entry(struct rte_cfgfile *cfg, const char *sectionname,
 		const char *entryname)
diff --git a/lib/librte_cfgfile/rte_cfgfile.h b/lib/librte_cfgfile/rte_cfgfile.h
index d443782..8e69971 100644
--- a/lib/librte_cfgfile/rte_cfgfile.h
+++ b/lib/librte_cfgfile/rte_cfgfile.h
@@ -155,6 +155,29 @@ int rte_cfgfile_section_entries(struct rte_cfgfile *cfg,
 	struct rte_cfgfile_entry *entries,
 	int max_entries);
 
+/** Get section entries as key-value pairs
+*
+* The index of a section is the same as the index of its name in the
+* result of rte_cfgfile_sections. This API can be used when there are
+* multiple sections with the same name.
+*
+* @param cfg
+*   Config file
+* @param index
+*   Section index
+* @param entries
+*   Pre-allocated array of at least max_entries entries where the section
+*   entries are stored as key-value pair after successful invocation
+* @param max_entries
+*   Maximum number of section entries to be stored in entries array
+* @return
+*   Number of entries populated on success, negative error code otherwise
+*/
+int rte_cfgfile_section_entries_by_index(struct rte_cfgfile *cfg,
+	int index,
+	struct rte_cfgfile_entry *entries,
+	int max_entries);
+
 /** Get value of the named entry in named config file section
 *
 * @param cfg
diff --git a/lib/librte_cfgfile/rte_cfgfile_version.map b/lib/librte_cfgfile/rte_cfgfile_version.map
index bf6c6fd..f6a27a9 100644
--- a/lib/librte_cfgfile/rte_cfgfile_version.map
+++ b/lib/librte_cfgfile/rte_cfgfile_version.map
@@ -13,3 +13,9 @@ DPDK_2.0 {
 
 	local: *;
 };
+
+DPDK_2.3 {
+	global:
+
+	rte_cfgfile_section_entries_by_index;
+} DPDK_2.0;
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [PATCH v2] cfgfile: support looking up sections by index
  2016-02-02 15:10   ` Dumitrescu, Cristian
@ 2016-02-10 19:13     ` Rich Lane
  0 siblings, 0 replies; 15+ messages in thread
From: Rich Lane @ 2016-02-10 19:13 UTC (permalink / raw)
  To: Dumitrescu, Cristian; +Cc: dev

On Tue, Feb 2, 2016 at 7:10 AM, Dumitrescu, Cristian <
cristian.dumitrescu@intel.com> wrote:

>
>
> > -----Original Message-----
> > From: Rich Lane [mailto:rich.lane@bigswitch.com]
> > Sent: Tuesday, January 19, 2016 4:42 AM
> > To: dev@dpdk.org
> > Cc: Dumitrescu, Cristian <cristian.dumitrescu@intel.com>; Panu
> Matilainen
> > <pmatilai@redhat.com>
> > Subject: [PATCH v2] cfgfile: support looking up sections by index
> >
> > This is useful when sections have duplicate names.
>
> Hi Rich,
>
> You are right, I can see this is needed to allow multiple sections with
> identical name in the same configuration file. When sections with the same
> name are not allowed, then this is not needed, as the current API is
> sufficient.
>
> To me, having several sections with the same name does not look like a
> good idea, in fact it might look like an application design flaw, as
> differentiating between sections with the same name can only done based on
> the position of the section in the configuration file, which is an error
> prone option. Some examples:
> 1. While maintaining a large config file, keeping a specific section at a
> fixed position quickly becomes a pain, and shifting the position of the
> section up or down can completely change the application behavior;
> 2. Using basic pre-processors (like CPP or M4) or scripts, the master
> configuration file can include other configuration files, with the
> inclusion of each decided at run-time based on application command line
> parameters, so the position of certain sections is actually not known until
> run-time.
>
> Can you provide some examples when having multiple sections with the same
> name is a key requirement?
>

My application uses a config file to assign RX/TX queues to cores. Ports
and cores have names (e.g. "core.fwd0"), but there's no reason to name
queues. The order of the queue sections is unimportant.


> A straight forward workaround to having multiple sections with the same
> name is to add a number to the name of each such section. Using the current
> API, all the sections with the same prefix name can be read gracefully. As
> an example, the ip_pipeline application allows multiple sections with the
> same name prefix but a different number prefix:
> PIPELINE0, PIPELINE1, ...
> LINK0, LINK1, ...
> MEMPOOL0, MEMPOOL1, ...
> RXQ0.0, RXQ0.1, RXQ1.0, ...
> TXQ0.0, TXQ0.1, TXQ1.0, ...
>
> Is there a reason why this approach is not acceptable for your application?
>

It is less usable. The person writing the config file must generate those
suffixes which are irrelevant to what they're trying to express. The sole
effect is to add another source of errors.

Additionally, this API allows reading a config file in linear instead of
quadratic time (wrt number of sections). While my config files aren't long
enough to make this a requirement it certainly seems desirable.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v3] cfgfile: support looking up sections by index
  2016-02-10 19:12   ` [PATCH v3] " Rich Lane
@ 2016-02-16 20:48     ` Dumitrescu, Cristian
  2016-02-16 22:58     ` [PATCH v4] " Rich Lane
  1 sibling, 0 replies; 15+ messages in thread
From: Dumitrescu, Cristian @ 2016-02-16 20:48 UTC (permalink / raw)
  To: Rich Lane, dev



> -----Original Message-----
> From: Rich Lane [mailto:rich.lane@bigswitch.com]
> Sent: Wednesday, February 10, 2016 7:12 PM
> To: dev@dpdk.org
> Cc: Dumitrescu, Cristian <cristian.dumitrescu@intel.com>; Panu Matilainen
> <pmatilai@redhat.com>
> Subject: [PATCH v3] cfgfile: support looking up sections by index
> 
> This is useful when sections have duplicate names.
> 
> Signed-off-by: Rich Lane <rlane@bigswitch.com>
> ---
> v2->v3
> - Added check for index < 0.
> v1->v2:
> - Added new symbol to version script.
> 
>  lib/librte_cfgfile/rte_cfgfile.c           | 16 ++++++++++++++++
>  lib/librte_cfgfile/rte_cfgfile.h           | 23 +++++++++++++++++++++++
>  lib/librte_cfgfile/rte_cfgfile_version.map |  6 ++++++
>  3 files changed, 45 insertions(+)
> 
> diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cfgfile.c
> index a677dad..eba0713 100644
> --- a/lib/librte_cfgfile/rte_cfgfile.c
> +++ b/lib/librte_cfgfile/rte_cfgfile.c
> @@ -333,6 +333,22 @@ rte_cfgfile_section_entries(struct rte_cfgfile *cfg,
> const char *sectionname,
>  	return i;
>  }
> 
> +int
> +rte_cfgfile_section_entries_by_index(struct rte_cfgfile *cfg, int index,
> +		struct rte_cfgfile_entry *entries, int max_entries)
> +{
> +	int i;
> +	const struct rte_cfgfile_section *sect;
> +
> +	if (index < 0 || index >= cfg->num_sections)
> +		return -1;
> +
> +	sect = cfg->sections[index];
> +	for (i = 0; i < max_entries && i < sect->num_entries; i++)
> +		entries[i] = *sect->entries[i];
> +	return i;
> +}
> +
>  const char *
>  rte_cfgfile_get_entry(struct rte_cfgfile *cfg, const char *sectionname,
>  		const char *entryname)
> diff --git a/lib/librte_cfgfile/rte_cfgfile.h b/lib/librte_cfgfile/rte_cfgfile.h
> index d443782..8e69971 100644
> --- a/lib/librte_cfgfile/rte_cfgfile.h
> +++ b/lib/librte_cfgfile/rte_cfgfile.h
> @@ -155,6 +155,29 @@ int rte_cfgfile_section_entries(struct rte_cfgfile
> *cfg,
>  	struct rte_cfgfile_entry *entries,
>  	int max_entries);
> 
> +/** Get section entries as key-value pairs
> +*
> +* The index of a section is the same as the index of its name in the
> +* result of rte_cfgfile_sections. This API can be used when there are
> +* multiple sections with the same name.
> +*
> +* @param cfg
> +*   Config file
> +* @param index
> +*   Section index
> +* @param entries
> +*   Pre-allocated array of at least max_entries entries where the section
> +*   entries are stored as key-value pair after successful invocation
> +* @param max_entries
> +*   Maximum number of section entries to be stored in entries array
> +* @return
> +*   Number of entries populated on success, negative error code otherwise
> +*/
> +int rte_cfgfile_section_entries_by_index(struct rte_cfgfile *cfg,
> +	int index,

For the purpose of consistency, this function should provide back to the user the name of the section as an output parameter: char *name.
This parameter should either be NULL (when user does not care about the section name) or pre-allocated by the user with at least CFG_NAME_LEN characters.

> +	struct rte_cfgfile_entry *entries,
> +	int max_entries);
> +

Also the doxygen comment of the following existing functions should be updated to state that, in the case multiple sections with the same name exist, these functions are working with the first section with this name:
- rte_cfgfile_section_num_entries()
- rte_cfgfile_section_entries()
- rte_cfgfile_get_entry()
- rte_cfgfile_has_entry()

>  /** Get value of the named entry in named config file section
>  *
>  * @param cfg
> diff --git a/lib/librte_cfgfile/rte_cfgfile_version.map
> b/lib/librte_cfgfile/rte_cfgfile_version.map
> index bf6c6fd..f6a27a9 100644
> --- a/lib/librte_cfgfile/rte_cfgfile_version.map
> +++ b/lib/librte_cfgfile/rte_cfgfile_version.map
> @@ -13,3 +13,9 @@ DPDK_2.0 {
> 
>  	local: *;
>  };
> +
> +DPDK_2.3 {
> +	global:
> +
> +	rte_cfgfile_section_entries_by_index;
> +} DPDK_2.0;
> --
> 1.9.1

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH v4] cfgfile: support looking up sections by index
  2016-02-10 19:12   ` [PATCH v3] " Rich Lane
  2016-02-16 20:48     ` Dumitrescu, Cristian
@ 2016-02-16 22:58     ` Rich Lane
  2016-02-19 15:18       ` Dumitrescu, Cristian
  2016-02-22 20:30       ` [PATCH v5] " Rich Lane
  1 sibling, 2 replies; 15+ messages in thread
From: Rich Lane @ 2016-02-16 22:58 UTC (permalink / raw)
  To: dev

This is useful when sections have duplicate names.

Signed-off-by: Rich Lane <rlane@bigswitch.com>
---
v3->v4:
- Added section name return value.
- Updated API docs for other functions.
v2->v3
- Added check for index < 0.
v1->v2:
- Added new symbol to version script.

 lib/librte_cfgfile/rte_cfgfile.c           | 18 ++++++++++++++
 lib/librte_cfgfile/rte_cfgfile.h           | 39 ++++++++++++++++++++++++++++++
 lib/librte_cfgfile/rte_cfgfile_version.map |  6 +++++
 3 files changed, 63 insertions(+)

diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cfgfile.c
index a677dad..c086fc5 100644
--- a/lib/librte_cfgfile/rte_cfgfile.c
+++ b/lib/librte_cfgfile/rte_cfgfile.c
@@ -333,6 +333,24 @@ rte_cfgfile_section_entries(struct rte_cfgfile *cfg, const char *sectionname,
 	return i;
 }
 
+int
+rte_cfgfile_section_entries_by_index(struct rte_cfgfile *cfg, int index,
+		struct rte_cfgfile_entry *entries, int max_entries,
+		char *sectionname)
+{
+	int i;
+	const struct rte_cfgfile_section *sect;
+
+	if (index < 0 || index >= cfg->num_sections)
+		return -1;
+
+	sect = cfg->sections[index];
+	snprintf(sectionname, CFG_NAME_LEN, "%s", sect->name);
+	for (i = 0; i < max_entries && i < sect->num_entries; i++)
+		entries[i] = *sect->entries[i];
+	return i;
+}
+
 const char *
 rte_cfgfile_get_entry(struct rte_cfgfile *cfg, const char *sectionname,
 		const char *entryname)
diff --git a/lib/librte_cfgfile/rte_cfgfile.h b/lib/librte_cfgfile/rte_cfgfile.h
index d443782..67c9f6c 100644
--- a/lib/librte_cfgfile/rte_cfgfile.h
+++ b/lib/librte_cfgfile/rte_cfgfile.h
@@ -126,6 +126,9 @@ int rte_cfgfile_has_section(struct rte_cfgfile *cfg, const char *sectionname);
 /**
 * Get number of entries in given config file section
 *
+* If multiple sections have the given name this function operates on the
+* first one.
+*
 * @param cfg
 *   Config file
 * @param sectionname
@@ -138,6 +141,9 @@ int rte_cfgfile_section_num_entries(struct rte_cfgfile *cfg,
 
 /** Get section entries as key-value pairs
 *
+* If multiple sections have the given name this function operates on the
+* first one.
+*
 * @param cfg
 *   Config file
 * @param sectionname
@@ -155,8 +161,38 @@ int rte_cfgfile_section_entries(struct rte_cfgfile *cfg,
 	struct rte_cfgfile_entry *entries,
 	int max_entries);
 
+/** Get section entries as key-value pairs
+*
+* The index of a section is the same as the index of its name in the
+* result of rte_cfgfile_sections. This API can be used when there are
+* multiple sections with the same name.
+*
+* @param cfg
+*   Config file
+* @param index
+*   Section index
+* @param entries
+*   Pre-allocated array of at least max_entries entries where the section
+*   entries are stored as key-value pair after successful invocation
+* @param max_entries
+*   Maximum number of section entries to be stored in entries array
+* @param sectionname
+*   Pre-allocated string of at least CFG_NAME_LEN characters where the
+*   section name is stored after successful invocation.
+* @return
+*   Number of entries populated on success, negative error code otherwise
+*/
+int rte_cfgfile_section_entries_by_index(struct rte_cfgfile *cfg,
+	int index,
+	struct rte_cfgfile_entry *entries,
+	int max_entries,
+	char *sectionname);
+
 /** Get value of the named entry in named config file section
 *
+* If multiple sections have the given name this function operates on the
+* first one.
+*
 * @param cfg
 *   Config file
 * @param sectionname
@@ -172,6 +208,9 @@ const char *rte_cfgfile_get_entry(struct rte_cfgfile *cfg,
 
 /** Check if given entry exists in named config file section
 *
+* If multiple sections have the given name this function operates on the
+* first one.
+*
 * @param cfg
 *   Config file
 * @param sectionname
diff --git a/lib/librte_cfgfile/rte_cfgfile_version.map b/lib/librte_cfgfile/rte_cfgfile_version.map
index bf6c6fd..f6a27a9 100644
--- a/lib/librte_cfgfile/rte_cfgfile_version.map
+++ b/lib/librte_cfgfile/rte_cfgfile_version.map
@@ -13,3 +13,9 @@ DPDK_2.0 {
 
 	local: *;
 };
+
+DPDK_2.3 {
+	global:
+
+	rte_cfgfile_section_entries_by_index;
+} DPDK_2.0;
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [PATCH v4] cfgfile: support looking up sections by index
  2016-02-16 22:58     ` [PATCH v4] " Rich Lane
@ 2016-02-19 15:18       ` Dumitrescu, Cristian
  2016-02-22 20:30       ` [PATCH v5] " Rich Lane
  1 sibling, 0 replies; 15+ messages in thread
From: Dumitrescu, Cristian @ 2016-02-19 15:18 UTC (permalink / raw)
  To: Rich Lane, dev



> -----Original Message-----
> From: Rich Lane [mailto:rich.lane@bigswitch.com]
> Sent: Tuesday, February 16, 2016 10:59 PM
> To: dev@dpdk.org
> Cc: Dumitrescu, Cristian <cristian.dumitrescu@intel.com>; Panu Matilainen
> <pmatilai@redhat.com>
> Subject: [PATCH v4] cfgfile: support looking up sections by index
> 
> This is useful when sections have duplicate names.
> 
> Signed-off-by: Rich Lane <rlane@bigswitch.com>
> ---
> v3->v4:
> - Added section name return value.
> - Updated API docs for other functions.
> v2->v3
> - Added check for index < 0.
> v1->v2:
> - Added new symbol to version script.
> 
>  lib/librte_cfgfile/rte_cfgfile.c           | 18 ++++++++++++++
>  lib/librte_cfgfile/rte_cfgfile.h           | 39
> ++++++++++++++++++++++++++++++
>  lib/librte_cfgfile/rte_cfgfile_version.map |  6 +++++
>  3 files changed, 63 insertions(+)
> 
> diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cfgfile.c
> index a677dad..c086fc5 100644
> --- a/lib/librte_cfgfile/rte_cfgfile.c
> +++ b/lib/librte_cfgfile/rte_cfgfile.c
> @@ -333,6 +333,24 @@ rte_cfgfile_section_entries(struct rte_cfgfile *cfg,
> const char *sectionname,
>  	return i;
>  }
> 
> +int
> +rte_cfgfile_section_entries_by_index(struct rte_cfgfile *cfg, int index,
> +		struct rte_cfgfile_entry *entries, int max_entries,
> +		char *sectionname)

To be inline with the other API functions, can we please place the sectionname parameter after cfg and index and before entries and max_entries (be the 3rd parameter). Thanks!

> +{
> +	int i;
> +	const struct rte_cfgfile_section *sect;
> +
> +	if (index < 0 || index >= cfg->num_sections)
> +		return -1;
> +
> +	sect = cfg->sections[index];
> +	snprintf(sectionname, CFG_NAME_LEN, "%s", sect->name);
> +	for (i = 0; i < max_entries && i < sect->num_entries; i++)
> +		entries[i] = *sect->entries[i];
> +	return i;
> +}
> +
>  const char *
>  rte_cfgfile_get_entry(struct rte_cfgfile *cfg, const char *sectionname,
>  		const char *entryname)
> diff --git a/lib/librte_cfgfile/rte_cfgfile.h b/lib/librte_cfgfile/rte_cfgfile.h
> index d443782..67c9f6c 100644
> --- a/lib/librte_cfgfile/rte_cfgfile.h
> +++ b/lib/librte_cfgfile/rte_cfgfile.h
> @@ -126,6 +126,9 @@ int rte_cfgfile_has_section(struct rte_cfgfile *cfg,
> const char *sectionname);
>  /**
>  * Get number of entries in given config file section
>  *
> +* If multiple sections have the given name this function operates on the
> +* first one.
> +*
>  * @param cfg
>  *   Config file
>  * @param sectionname
> @@ -138,6 +141,9 @@ int rte_cfgfile_section_num_entries(struct rte_cfgfile
> *cfg,
> 
>  /** Get section entries as key-value pairs
>  *
> +* If multiple sections have the given name this function operates on the
> +* first one.
> +*
>  * @param cfg
>  *   Config file
>  * @param sectionname
> @@ -155,8 +161,38 @@ int rte_cfgfile_section_entries(struct rte_cfgfile
> *cfg,
>  	struct rte_cfgfile_entry *entries,
>  	int max_entries);
> 
> +/** Get section entries as key-value pairs
> +*
> +* The index of a section is the same as the index of its name in the
> +* result of rte_cfgfile_sections. This API can be used when there are
> +* multiple sections with the same name.
> +*
> +* @param cfg
> +*   Config file
> +* @param index
> +*   Section index
> +* @param entries
> +*   Pre-allocated array of at least max_entries entries where the section
> +*   entries are stored as key-value pair after successful invocation
> +* @param max_entries
> +*   Maximum number of section entries to be stored in entries array
> +* @param sectionname
> +*   Pre-allocated string of at least CFG_NAME_LEN characters where the
> +*   section name is stored after successful invocation.
> +* @return
> +*   Number of entries populated on success, negative error code otherwise
> +*/
> +int rte_cfgfile_section_entries_by_index(struct rte_cfgfile *cfg,
> +	int index,
> +	struct rte_cfgfile_entry *entries,
> +	int max_entries,
> +	char *sectionname);
> +
>  /** Get value of the named entry in named config file section
>  *
> +* If multiple sections have the given name this function operates on the
> +* first one.
> +*
>  * @param cfg
>  *   Config file
>  * @param sectionname
> @@ -172,6 +208,9 @@ const char *rte_cfgfile_get_entry(struct rte_cfgfile
> *cfg,
> 
>  /** Check if given entry exists in named config file section
>  *
> +* If multiple sections have the given name this function operates on the
> +* first one.
> +*
>  * @param cfg
>  *   Config file
>  * @param sectionname
> diff --git a/lib/librte_cfgfile/rte_cfgfile_version.map
> b/lib/librte_cfgfile/rte_cfgfile_version.map
> index bf6c6fd..f6a27a9 100644
> --- a/lib/librte_cfgfile/rte_cfgfile_version.map
> +++ b/lib/librte_cfgfile/rte_cfgfile_version.map
> @@ -13,3 +13,9 @@ DPDK_2.0 {
> 
>  	local: *;
>  };
> +
> +DPDK_2.3 {
> +	global:
> +
> +	rte_cfgfile_section_entries_by_index;
> +} DPDK_2.0;
> --
> 1.9.1

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH v5] cfgfile: support looking up sections by index
  2016-02-16 22:58     ` [PATCH v4] " Rich Lane
  2016-02-19 15:18       ` Dumitrescu, Cristian
@ 2016-02-22 20:30       ` Rich Lane
  2016-02-23  0:12         ` Dumitrescu, Cristian
  2016-02-25 20:43         ` [PATCH v6] " Rich Lane
  1 sibling, 2 replies; 15+ messages in thread
From: Rich Lane @ 2016-02-22 20:30 UTC (permalink / raw)
  To: dev

This is useful when sections have duplicate names.

Signed-off-by: Rich Lane <rlane@bigswitch.com>
---
v4->v5:
- Reordered sectionname argument.
v3->v4:
- Added section name return value.
- Updated API docs for other functions.
v2->v3
- Added check for index < 0.
v1->v2:
- Added new symbol to version script.

 lib/librte_cfgfile/rte_cfgfile.c           | 18 ++++++++++++++
 lib/librte_cfgfile/rte_cfgfile.h           | 39 ++++++++++++++++++++++++++++++
 lib/librte_cfgfile/rte_cfgfile_version.map |  6 +++++
 3 files changed, 63 insertions(+)

diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cfgfile.c
index 1cd523f..75625a2 100644
--- a/lib/librte_cfgfile/rte_cfgfile.c
+++ b/lib/librte_cfgfile/rte_cfgfile.c
@@ -333,6 +333,24 @@ rte_cfgfile_section_entries(struct rte_cfgfile *cfg, const char *sectionname,
 	return i;
 }
 
+int
+rte_cfgfile_section_entries_by_index(struct rte_cfgfile *cfg, int index,
+		char *sectionname,
+		struct rte_cfgfile_entry *entries, int max_entries)
+{
+	int i;
+	const struct rte_cfgfile_section *sect;
+
+	if (index < 0 || index >= cfg->num_sections)
+		return -1;
+
+	sect = cfg->sections[index];
+	snprintf(sectionname, CFG_NAME_LEN, "%s", sect->name);
+	for (i = 0; i < max_entries && i < sect->num_entries; i++)
+		entries[i] = *sect->entries[i];
+	return i;
+}
+
 const char *
 rte_cfgfile_get_entry(struct rte_cfgfile *cfg, const char *sectionname,
 		const char *entryname)
diff --git a/lib/librte_cfgfile/rte_cfgfile.h b/lib/librte_cfgfile/rte_cfgfile.h
index d443782..689fd66 100644
--- a/lib/librte_cfgfile/rte_cfgfile.h
+++ b/lib/librte_cfgfile/rte_cfgfile.h
@@ -126,6 +126,9 @@ int rte_cfgfile_has_section(struct rte_cfgfile *cfg, const char *sectionname);
 /**
 * Get number of entries in given config file section
 *
+* If multiple sections have the given name this function operates on the
+* first one.
+*
 * @param cfg
 *   Config file
 * @param sectionname
@@ -138,6 +141,9 @@ int rte_cfgfile_section_num_entries(struct rte_cfgfile *cfg,
 
 /** Get section entries as key-value pairs
 *
+* If multiple sections have the given name this function operates on the
+* first one.
+*
 * @param cfg
 *   Config file
 * @param sectionname
@@ -155,8 +161,38 @@ int rte_cfgfile_section_entries(struct rte_cfgfile *cfg,
 	struct rte_cfgfile_entry *entries,
 	int max_entries);
 
+/** Get section entries as key-value pairs
+*
+* The index of a section is the same as the index of its name in the
+* result of rte_cfgfile_sections. This API can be used when there are
+* multiple sections with the same name.
+*
+* @param cfg
+*   Config file
+* @param index
+*   Section index
+* @param entries
+*   Pre-allocated array of at least max_entries entries where the section
+*   entries are stored as key-value pair after successful invocation
+* @param max_entries
+*   Maximum number of section entries to be stored in entries array
+* @param sectionname
+*   Pre-allocated string of at least CFG_NAME_LEN characters where the
+*   section name is stored after successful invocation.
+* @return
+*   Number of entries populated on success, negative error code otherwise
+*/
+int rte_cfgfile_section_entries_by_index(struct rte_cfgfile *cfg,
+	int index,
+	char *sectionname,
+	struct rte_cfgfile_entry *entries,
+	int max_entries);
+
 /** Get value of the named entry in named config file section
 *
+* If multiple sections have the given name this function operates on the
+* first one.
+*
 * @param cfg
 *   Config file
 * @param sectionname
@@ -172,6 +208,9 @@ const char *rte_cfgfile_get_entry(struct rte_cfgfile *cfg,
 
 /** Check if given entry exists in named config file section
 *
+* If multiple sections have the given name this function operates on the
+* first one.
+*
 * @param cfg
 *   Config file
 * @param sectionname
diff --git a/lib/librte_cfgfile/rte_cfgfile_version.map b/lib/librte_cfgfile/rte_cfgfile_version.map
index bf6c6fd..f6a27a9 100644
--- a/lib/librte_cfgfile/rte_cfgfile_version.map
+++ b/lib/librte_cfgfile/rte_cfgfile_version.map
@@ -13,3 +13,9 @@ DPDK_2.0 {
 
 	local: *;
 };
+
+DPDK_2.3 {
+	global:
+
+	rte_cfgfile_section_entries_by_index;
+} DPDK_2.0;
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [PATCH v5] cfgfile: support looking up sections by index
  2016-02-22 20:30       ` [PATCH v5] " Rich Lane
@ 2016-02-23  0:12         ` Dumitrescu, Cristian
  2016-02-25 20:43         ` [PATCH v6] " Rich Lane
  1 sibling, 0 replies; 15+ messages in thread
From: Dumitrescu, Cristian @ 2016-02-23  0:12 UTC (permalink / raw)
  To: Rich Lane, dev



> -----Original Message-----
> From: Rich Lane [mailto:rich.lane@bigswitch.com]
> Sent: Monday, February 22, 2016 8:31 PM
> To: dev@dpdk.org
> Cc: Dumitrescu, Cristian <cristian.dumitrescu@intel.com>; Panu Matilainen
> <pmatilai@redhat.com>
> Subject: [PATCH v5] cfgfile: support looking up sections by index
> 
> This is useful when sections have duplicate names.
> 
> Signed-off-by: Rich Lane <rlane@bigswitch.com>
> ---
> v4->v5:
> - Reordered sectionname argument.
> v3->v4:
> - Added section name return value.
> - Updated API docs for other functions.
> v2->v3
> - Added check for index < 0.
> v1->v2:
> - Added new symbol to version script.
> 
>  lib/librte_cfgfile/rte_cfgfile.c           | 18 ++++++++++++++
>  lib/librte_cfgfile/rte_cfgfile.h           | 39
> ++++++++++++++++++++++++++++++
>  lib/librte_cfgfile/rte_cfgfile_version.map |  6 +++++
>  3 files changed, 63 insertions(+)
> 
> diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cfgfile.c
> index 1cd523f..75625a2 100644
> --- a/lib/librte_cfgfile/rte_cfgfile.c
> +++ b/lib/librte_cfgfile/rte_cfgfile.c
> @@ -333,6 +333,24 @@ rte_cfgfile_section_entries(struct rte_cfgfile *cfg,
> const char *sectionname,
>  	return i;
>  }
> 
> +int
> +rte_cfgfile_section_entries_by_index(struct rte_cfgfile *cfg, int index,
> +		char *sectionname,
> +		struct rte_cfgfile_entry *entries, int max_entries)
> +{
> +	int i;
> +	const struct rte_cfgfile_section *sect;
> +
> +	if (index < 0 || index >= cfg->num_sections)
> +		return -1;
> +
> +	sect = cfg->sections[index];
> +	snprintf(sectionname, CFG_NAME_LEN, "%s", sect->name);
> +	for (i = 0; i < max_entries && i < sect->num_entries; i++)
> +		entries[i] = *sect->entries[i];
> +	return i;
> +}
> +
>  const char *
>  rte_cfgfile_get_entry(struct rte_cfgfile *cfg, const char *sectionname,
>  		const char *entryname)
> diff --git a/lib/librte_cfgfile/rte_cfgfile.h b/lib/librte_cfgfile/rte_cfgfile.h
> index d443782..689fd66 100644
> --- a/lib/librte_cfgfile/rte_cfgfile.h
> +++ b/lib/librte_cfgfile/rte_cfgfile.h
> @@ -126,6 +126,9 @@ int rte_cfgfile_has_section(struct rte_cfgfile *cfg,
> const char *sectionname);
>  /**
>  * Get number of entries in given config file section
>  *
> +* If multiple sections have the given name this function operates on the
> +* first one.
> +*
>  * @param cfg
>  *   Config file
>  * @param sectionname
> @@ -138,6 +141,9 @@ int rte_cfgfile_section_num_entries(struct rte_cfgfile
> *cfg,
> 
>  /** Get section entries as key-value pairs
>  *
> +* If multiple sections have the given name this function operates on the
> +* first one.
> +*
>  * @param cfg
>  *   Config file
>  * @param sectionname
> @@ -155,8 +161,38 @@ int rte_cfgfile_section_entries(struct rte_cfgfile
> *cfg,
>  	struct rte_cfgfile_entry *entries,
>  	int max_entries);
> 
> +/** Get section entries as key-value pairs
> +*
> +* The index of a section is the same as the index of its name in the
> +* result of rte_cfgfile_sections. This API can be used when there are
> +* multiple sections with the same name.
> +*
> +* @param cfg
> +*   Config file
> +* @param index
> +*   Section index
> +* @param entries
> +*   Pre-allocated array of at least max_entries entries where the section
> +*   entries are stored as key-value pair after successful invocation
> +* @param max_entries
> +*   Maximum number of section entries to be stored in entries array

The description for sectionname should also be moved after the description of index parameter to match the argument order. We're nearly there :)

> +* @param sectionname
> +*   Pre-allocated string of at least CFG_NAME_LEN characters where the
> +*   section name is stored after successful invocation.
> +* @return
> +*   Number of entries populated on success, negative error code otherwise
> +*/
> +int rte_cfgfile_section_entries_by_index(struct rte_cfgfile *cfg,
> +	int index,
> +	char *sectionname,
> +	struct rte_cfgfile_entry *entries,
> +	int max_entries);
> +
>  /** Get value of the named entry in named config file section
>  *
> +* If multiple sections have the given name this function operates on the
> +* first one.
> +*
>  * @param cfg
>  *   Config file
>  * @param sectionname
> @@ -172,6 +208,9 @@ const char *rte_cfgfile_get_entry(struct rte_cfgfile
> *cfg,
> 
>  /** Check if given entry exists in named config file section
>  *
> +* If multiple sections have the given name this function operates on the
> +* first one.
> +*
>  * @param cfg
>  *   Config file
>  * @param sectionname
> diff --git a/lib/librte_cfgfile/rte_cfgfile_version.map
> b/lib/librte_cfgfile/rte_cfgfile_version.map
> index bf6c6fd..f6a27a9 100644
> --- a/lib/librte_cfgfile/rte_cfgfile_version.map
> +++ b/lib/librte_cfgfile/rte_cfgfile_version.map
> @@ -13,3 +13,9 @@ DPDK_2.0 {
> 
>  	local: *;
>  };
> +
> +DPDK_2.3 {
> +	global:
> +
> +	rte_cfgfile_section_entries_by_index;
> +} DPDK_2.0;
> --
> 1.9.1

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH v6] cfgfile: support looking up sections by index
  2016-02-22 20:30       ` [PATCH v5] " Rich Lane
  2016-02-23  0:12         ` Dumitrescu, Cristian
@ 2016-02-25 20:43         ` Rich Lane
  2016-02-25 20:49           ` Dumitrescu, Cristian
  1 sibling, 1 reply; 15+ messages in thread
From: Rich Lane @ 2016-02-25 20:43 UTC (permalink / raw)
  To: dev

This is useful when sections have duplicate names.

Signed-off-by: Rich Lane <rlane@bigswitch.com>
---
v5->v6:
- Reordered sectionname argument in comment.
v4->v5:
- Reordered sectionname argument.
v3->v4:
- Added section name return value.
- Updated API docs for other functions.
v2->v3
- Added check for index < 0.
v1->v2:
- Added new symbol to version script.

 lib/librte_cfgfile/rte_cfgfile.c           | 18 ++++++++++++++
 lib/librte_cfgfile/rte_cfgfile.h           | 39 ++++++++++++++++++++++++++++++
 lib/librte_cfgfile/rte_cfgfile_version.map |  6 +++++
 3 files changed, 63 insertions(+)

diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cfgfile.c
index 1cd523f..75625a2 100644
--- a/lib/librte_cfgfile/rte_cfgfile.c
+++ b/lib/librte_cfgfile/rte_cfgfile.c
@@ -333,6 +333,24 @@ rte_cfgfile_section_entries(struct rte_cfgfile *cfg, const char *sectionname,
 	return i;
 }
 
+int
+rte_cfgfile_section_entries_by_index(struct rte_cfgfile *cfg, int index,
+		char *sectionname,
+		struct rte_cfgfile_entry *entries, int max_entries)
+{
+	int i;
+	const struct rte_cfgfile_section *sect;
+
+	if (index < 0 || index >= cfg->num_sections)
+		return -1;
+
+	sect = cfg->sections[index];
+	snprintf(sectionname, CFG_NAME_LEN, "%s", sect->name);
+	for (i = 0; i < max_entries && i < sect->num_entries; i++)
+		entries[i] = *sect->entries[i];
+	return i;
+}
+
 const char *
 rte_cfgfile_get_entry(struct rte_cfgfile *cfg, const char *sectionname,
 		const char *entryname)
diff --git a/lib/librte_cfgfile/rte_cfgfile.h b/lib/librte_cfgfile/rte_cfgfile.h
index d443782..834f828 100644
--- a/lib/librte_cfgfile/rte_cfgfile.h
+++ b/lib/librte_cfgfile/rte_cfgfile.h
@@ -126,6 +126,9 @@ int rte_cfgfile_has_section(struct rte_cfgfile *cfg, const char *sectionname);
 /**
 * Get number of entries in given config file section
 *
+* If multiple sections have the given name this function operates on the
+* first one.
+*
 * @param cfg
 *   Config file
 * @param sectionname
@@ -138,6 +141,9 @@ int rte_cfgfile_section_num_entries(struct rte_cfgfile *cfg,
 
 /** Get section entries as key-value pairs
 *
+* If multiple sections have the given name this function operates on the
+* first one.
+*
 * @param cfg
 *   Config file
 * @param sectionname
@@ -155,8 +161,38 @@ int rte_cfgfile_section_entries(struct rte_cfgfile *cfg,
 	struct rte_cfgfile_entry *entries,
 	int max_entries);
 
+/** Get section entries as key-value pairs
+*
+* The index of a section is the same as the index of its name in the
+* result of rte_cfgfile_sections. This API can be used when there are
+* multiple sections with the same name.
+*
+* @param cfg
+*   Config file
+* @param index
+*   Section index
+* @param sectionname
+*   Pre-allocated string of at least CFG_NAME_LEN characters where the
+*   section name is stored after successful invocation.
+* @param entries
+*   Pre-allocated array of at least max_entries entries where the section
+*   entries are stored as key-value pair after successful invocation
+* @param max_entries
+*   Maximum number of section entries to be stored in entries array
+* @return
+*   Number of entries populated on success, negative error code otherwise
+*/
+int rte_cfgfile_section_entries_by_index(struct rte_cfgfile *cfg,
+	int index,
+	char *sectionname,
+	struct rte_cfgfile_entry *entries,
+	int max_entries);
+
 /** Get value of the named entry in named config file section
 *
+* If multiple sections have the given name this function operates on the
+* first one.
+*
 * @param cfg
 *   Config file
 * @param sectionname
@@ -172,6 +208,9 @@ const char *rte_cfgfile_get_entry(struct rte_cfgfile *cfg,
 
 /** Check if given entry exists in named config file section
 *
+* If multiple sections have the given name this function operates on the
+* first one.
+*
 * @param cfg
 *   Config file
 * @param sectionname
diff --git a/lib/librte_cfgfile/rte_cfgfile_version.map b/lib/librte_cfgfile/rte_cfgfile_version.map
index bf6c6fd..f6a27a9 100644
--- a/lib/librte_cfgfile/rte_cfgfile_version.map
+++ b/lib/librte_cfgfile/rte_cfgfile_version.map
@@ -13,3 +13,9 @@ DPDK_2.0 {
 
 	local: *;
 };
+
+DPDK_2.3 {
+	global:
+
+	rte_cfgfile_section_entries_by_index;
+} DPDK_2.0;
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [PATCH v6] cfgfile: support looking up sections by index
  2016-02-25 20:43         ` [PATCH v6] " Rich Lane
@ 2016-02-25 20:49           ` Dumitrescu, Cristian
  2016-02-29 10:29             ` Thomas Monjalon
  0 siblings, 1 reply; 15+ messages in thread
From: Dumitrescu, Cristian @ 2016-02-25 20:49 UTC (permalink / raw)
  To: Rich Lane, dev



> -----Original Message-----
> From: Rich Lane [mailto:rich.lane@bigswitch.com]
> Sent: Thursday, February 25, 2016 8:43 PM
> To: dev@dpdk.org
> Cc: Dumitrescu, Cristian <cristian.dumitrescu@intel.com>; Panu Matilainen
> <pmatilai@redhat.com>
> Subject: [PATCH v6] cfgfile: support looking up sections by index
> 
> This is useful when sections have duplicate names.
> 
> Signed-off-by: Rich Lane <rlane@bigswitch.com>
> ---
> v5->v6:
> - Reordered sectionname argument in comment.

Acked-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>

Thanks, Rich!

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v6] cfgfile: support looking up sections by index
  2016-02-25 20:49           ` Dumitrescu, Cristian
@ 2016-02-29 10:29             ` Thomas Monjalon
  0 siblings, 0 replies; 15+ messages in thread
From: Thomas Monjalon @ 2016-02-29 10:29 UTC (permalink / raw)
  To: Rich Lane; +Cc: dev

> > This is useful when sections have duplicate names.
> > 
> > Signed-off-by: Rich Lane <rlane@bigswitch.com>
> > ---
> > v5->v6:
> > - Reordered sectionname argument in comment.
> 
> Acked-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
> 
> Thanks, Rich!

Applied, thanks

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2016-02-29 10:30 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-17  3:58 [PATCH] cfgfile: support looking up sections by index Rich Lane
2016-01-18 12:58 ` Panu Matilainen
2016-01-19  4:41 ` [PATCH v2] " Rich Lane
2016-01-21  7:42   ` Panu Matilainen
2016-02-02 15:10   ` Dumitrescu, Cristian
2016-02-10 19:13     ` Rich Lane
2016-02-10 19:12   ` [PATCH v3] " Rich Lane
2016-02-16 20:48     ` Dumitrescu, Cristian
2016-02-16 22:58     ` [PATCH v4] " Rich Lane
2016-02-19 15:18       ` Dumitrescu, Cristian
2016-02-22 20:30       ` [PATCH v5] " Rich Lane
2016-02-23  0:12         ` Dumitrescu, Cristian
2016-02-25 20:43         ` [PATCH v6] " Rich Lane
2016-02-25 20:49           ` Dumitrescu, Cristian
2016-02-29 10:29             ` Thomas Monjalon

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.