[dpdk-dev,3/5] cfgfile: add support for unamed global section

Message ID 1488482971-170522-4-git-send-email-allain.legacy@windriver.com (mailing list archive)
State Superseded, archived
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Allain Legacy March 2, 2017, 7:29 p.m. UTC
  The current implementation of the cfgfile library requires that all
key=value pairs be within [SECTION] definitions.  The ini file standard
allows for key=value pairs in an unnamed section.  That section is
considered the [GLOBAL] section.

This commit adds the capability of parsing key=value pairs from such an
unnamed section. The CFG_FLAG_GLOBAL_SECTION flag must be passed to the
rte_cfgfile_load() API to enable this functionality.

Signed-off-by: Allain Legacy <allain.legacy@windriver.com>
---
 lib/librte_cfgfile/rte_cfgfile.c | 16 ++++++++++++++++
 lib/librte_cfgfile/rte_cfgfile.h |  6 ++++++
 2 files changed, 22 insertions(+)
  

Comments

Cristian Dumitrescu March 3, 2017, 10:53 a.m. UTC | #1
> -----Original Message-----
> From: Allain Legacy [mailto:allain.legacy@windriver.com]
> Sent: Thursday, March 2, 2017 7:29 PM
> To: Richardson, Bruce <bruce.richardson@intel.com>; Dumitrescu, Cristian
> <cristian.dumitrescu@intel.com>
> Cc: dev@dpdk.org; Jolliffe, Ian (Wind River) <ian.jolliffe@windriver.com>
> Subject: [PATCH 3/5] cfgfile: add support for unamed global section
> 
> The current implementation of the cfgfile library requires that all
> key=value pairs be within [SECTION] definitions.  The ini file standard
> allows for key=value pairs in an unnamed section.  That section is
> considered the [GLOBAL] section.
> 
> This commit adds the capability of parsing key=value pairs from such an
> unnamed section. The CFG_FLAG_GLOBAL_SECTION flag must be passed to
> the
> rte_cfgfile_load() API to enable this functionality.
> 

What is the motivation for the having key/value pair outside of any section? What would be the drawback of having the user explicitly define a GLOBAL section to host these key/value pairs?
  
Allain Legacy March 3, 2017, 11:03 a.m. UTC | #2
> -----Original Message-----
> From: Dumitrescu, Cristian [mailto:cristian.dumitrescu@intel.com]
> 
> What is the motivation for the having key/value pair outside of any section?
> What would be the drawback of having the user explicitly define a GLOBAL
> section to host these key/value pairs?
Global parameters that are outside of sections are part of the ini informal "standard".   Our app use this format.

https://en.wikipedia.org/wiki/INI_file#Global_properties
  
Cristian Dumitrescu March 3, 2017, 11:06 a.m. UTC | #3
> -----Original Message-----
> From: Legacy, Allain [mailto:Allain.Legacy@windriver.com]
> Sent: Friday, March 3, 2017 11:04 AM
> To: Dumitrescu, Cristian <cristian.dumitrescu@intel.com>; Richardson, Bruce
> <bruce.richardson@intel.com>
> Cc: dev@dpdk.org; Jolliffe, Ian (Wind River) <ian.jolliffe@windriver.com>
> Subject: RE: [PATCH 3/5] cfgfile: add support for unamed global section
> 
> > -----Original Message-----
> > From: Dumitrescu, Cristian [mailto:cristian.dumitrescu@intel.com]
> >
> > What is the motivation for the having key/value pair outside of any
> section?
> > What would be the drawback of having the user explicitly define a GLOBAL
> > section to host these key/value pairs?
> Global parameters that are outside of sections are part of the ini informal
> "standard".   Our app use this format.
> 
> https://en.wikipedia.org/wiki/INI_file#Global_properties
> 
> 

I am not totally against it, but IMO this option is a bit confusing. Again, what's wrong with user explicitly adding the GLOBAL section if needed?
  
Allain Legacy March 3, 2017, 11:15 a.m. UTC | #4
> -----Original Message-----
> From: Dumitrescu, Cristian [mailto:cristian.dumitrescu@intel.com]
> 
> I am not totally against it, but IMO this option is a bit confusing. Again, what's
> wrong with user explicitly adding the GLOBAL section if needed?
There's nothing wrong with using a global section.   It is our preference to use this method because we need to support a legacy file format that needs to be parsed by other non-DPDK applications.  Those applications expect this format.
  
Cristian Dumitrescu March 3, 2017, 11:18 a.m. UTC | #5
> -----Original Message-----
> From: Legacy, Allain [mailto:Allain.Legacy@windriver.com]
> Sent: Friday, March 3, 2017 11:15 AM
> To: Dumitrescu, Cristian <cristian.dumitrescu@intel.com>; Richardson, Bruce
> <bruce.richardson@intel.com>
> Cc: dev@dpdk.org; Jolliffe, Ian (Wind River) <ian.jolliffe@windriver.com>
> Subject: RE: [PATCH 3/5] cfgfile: add support for unamed global section
> 
> > -----Original Message-----
> > From: Dumitrescu, Cristian [mailto:cristian.dumitrescu@intel.com]
> >
> > I am not totally against it, but IMO this option is a bit confusing. Again,
> what's
> > wrong with user explicitly adding the GLOBAL section if needed?
> There's nothing wrong with using a global section.   It is our preference to use
> this method because we need to support a legacy file format that needs to
> be parsed by other non-DPDK applications.  Those applications expect this
> format.

OK, legacy is a good enough reason for me.
  

Patch

diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cfgfile.c
index 7a9206d..2aba169 100644
--- a/lib/librte_cfgfile/rte_cfgfile.c
+++ b/lib/librte_cfgfile/rte_cfgfile.c
@@ -108,6 +108,22 @@  struct rte_cfgfile *
 
 	memset(cfg, 0, size);
 
+	if (flags & CFG_FLAG_GLOBAL_SECTION) {
+		curr_section = 0;
+		allocated_entries = CFG_ALLOC_ENTRY_BATCH;
+		cfg->sections[curr_section] = malloc(
+			sizeof(*cfg->sections[0]) +
+			sizeof(cfg->sections[0]->entries[0]) *
+			allocated_entries);
+		if (cfg->sections[curr_section] == NULL) {
+			printf("Error - no memory for global section\n");
+			goto error1;
+		}
+
+		snprintf(cfg->sections[curr_section]->name,
+				 sizeof(cfg->sections[0]->name), "GLOBAL");
+	}
+
 	while (fgets(buffer, sizeof(buffer), f) != NULL) {
 		char *pos = NULL;
 		size_t len = strnlen(buffer, sizeof(buffer));
diff --git a/lib/librte_cfgfile/rte_cfgfile.h b/lib/librte_cfgfile/rte_cfgfile.h
index b40e6a1..fce1efc 100644
--- a/lib/librte_cfgfile/rte_cfgfile.h
+++ b/lib/librte_cfgfile/rte_cfgfile.h
@@ -67,6 +67,12 @@  struct rte_cfgfile_entry {
 };
 
 /**
+ * Indicates that the file supports key value entries before the first defined
+ * section.  These entries can be accessed in the "GLOBAL" section.
+ */
+#define CFG_FLAG_GLOBAL_SECTION (1 << 0)
+
+/**
 * Open config file
 *
 * @param filename