From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id CB09B93F6 for ; Tue, 2 Feb 2016 16:10:11 +0100 (CET) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga102.fm.intel.com with ESMTP; 02 Feb 2016 07:10:10 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.22,385,1449561600"; d="scan'208";a="41051456" Received: from irsmsx110.ger.corp.intel.com ([163.33.3.25]) by fmsmga004.fm.intel.com with ESMTP; 02 Feb 2016 07:10:09 -0800 Received: from irsmsx108.ger.corp.intel.com ([169.254.11.102]) by irsmsx110.ger.corp.intel.com ([169.254.15.31]) with mapi id 14.03.0248.002; Tue, 2 Feb 2016 15:10:09 +0000 From: "Dumitrescu, Cristian" To: Rich Lane , "dev@dpdk.org" Thread-Topic: [PATCH v2] cfgfile: support looking up sections by index Thread-Index: AQHRUnPHToa+YzHvK0eoDrruck7n3p8Y7JcQ Date: Tue, 2 Feb 2016 15:10:08 +0000 Message-ID: <3EB4FA525960D640B5BDFFD6A3D891264794DACE@IRSMSX108.ger.corp.intel.com> References: <1453003104-19107-1-git-send-email-rlane@bigswitch.com> <1453178510-113435-1-git-send-email-rlane@bigswitch.com> In-Reply-To: <1453178510-113435-1-git-send-email-rlane@bigswitch.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiMWI5MmEzNWEtMzA3Ni00M2Y5LWIxMjktMWE1NzlkNTYxNzM2IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX1BVQkxJQyJ9XX1dfSwiU3ViamVjdExhYmVscyI6W10sIlRNQ1ZlcnNpb24iOiIxNS40LjEwLjE5IiwiVHJ1c3RlZExhYmVsSGFzaCI6IktaRWNJWFRTRktyVGoxa1FuT2c5NFlsZVI5bFZlek9HTlNRd3ZScFNtNU09In0= x-ctpclassification: CTP_PUBLIC x-originating-ip: [163.33.239.181] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH v2] cfgfile: support looking up sections by index X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 02 Feb 2016 15:10:12 -0000 > -----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 ; Panu Matilainen > > Subject: [PATCH v2] cfgfile: support looking up sections by index >=20 > This is useful when sections have duplicate names. Hi Rich, You are right, I can see this is needed to allow multiple sections with ide= ntical name in the same configuration file. When sections with the same nam= e are not allowed, then this is not needed, as the current API is sufficien= t. 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 differenti= ating between sections with the same name can only done based on the positi= on of the section in the configuration file, which is an error prone option= . Some examples:=20 1. While maintaining a large config file, keeping a specific section at a f= ixed position quickly becomes a pain, and shifting the position of the sect= ion up or down can completely change the application behavior; 2. Using basic pre-processors (like CPP or M4) or scripts, the master confi= guration file can include other configuration files, with the inclusion of = each decided at run-time based on application command line parameters, so t= he position of certain sections is actually not known until run-time. Can you provide some examples when having multiple sections with the same n= ame is a key requirement? A straight forward workaround to having multiple sections with the same nam= e is to add a number to the name of each such section. Using the current AP= I, all the sections with the same prefix name can be read gracefully. As an= example, the ip_pipeline application allows multiple sections with the sam= e 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 >=20 > Signed-off-by: Rich Lane > --- > v1->v2: > - Added new symbol to version script. >=20 > 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(+) >=20 > diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cf= gfile.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; > } >=20 > +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 >=3D cfg->num_sections) > + return -1; > + > + sect =3D cfg->sections[index]; > + for (i =3D 0; i < max_entries && i < sect->num_entries; i++) > + entries[i] =3D *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_cf= gfile.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); >=20 > +/** 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 sectio= n > +* 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 otherwis= e > +*/ > +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 { >=20 > local: *; > }; > + > +DPDK_2.3 { > + global: > + > + rte_cfgfile_section_entries_by_index; > +} DPDK_2.0; > -- > 1.9.1