From: Konrad Rzeszutek Wilk Subject: Re: [OPW PATCH V3] tools: xl: refactor code to parse network device options Date: Tue, 21 Oct 2014 12:27:41 -0400 Message-ID: <20141021162741.GA2555@andromeda.dapyr.net> References: <1413901175-12026-1-git-send-email-alecsandrasandulescu@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XgcIE-0006mY-8Y for xen-devel@lists.xenproject.org; Tue, 21 Oct 2014 16:28:18 +0000 Content-Disposition: inline In-Reply-To: <1413901175-12026-1-git-send-email-alecsandrasandulescu@gmail.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Alexandra Sandulescu Cc: xen-devel@lists.xenproject.org, Alexandra Sandulescu , wei.liu2@citrix.com, ian.campbell@citrix.com List-Id: xen-devel@lists.xenproject.org On Tue, Oct 21, 2014 at 05:19:35PM +0300, Alexandra Sandulescu wrote: > From: Alexandra Sandulescu > > This patch removes duplicate code in /tools/libxl/xl_cmdimpl.c by > adding parse_nic_config function. This function parses configuration > data and adds the information into libxl_device_nic struct. It is > called in both main_networkattach and parse_config_data functions > to replace duplicate code. > > Signed-off-by: Alexandra Sandulescu > --- > tools/libxl/xl_cmdimpl.c | 188 ++++++++++++++++++----------------------------- > 1 file changed, 71 insertions(+), 117 deletions(-) > > diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c > index ea43761..31a0dcb 100644 > --- a/tools/libxl/xl_cmdimpl.c > +++ b/tools/libxl/xl_cmdimpl.c > @@ -903,6 +903,74 @@ static void replace_string(char **str, const char *val) > *str = xstrdup(val); > } > > +/* for now used only by main_networkattach, but can be reused elsewhere */ > +static int match_option_size(const char *prefix, size_t len, > + char *arg, char **argopt) > +{ > + int rc = strncmp(prefix, arg, len); > + if (!rc) *argopt = arg+len; > + return !rc; > +} > +#define MATCH_OPTION(prefix, arg, oparg) \ > + match_option_size((prefix "="), sizeof((prefix)), (arg), &(oparg)) > + > +/* Parses network data and adds info into nic > + * Returns 1 if the input token does not match one of the keys > + * or parsed values are not correct. Successful parse returns 0 */ > +static int parse_nic_config(libxl_device_nic *nic, XLU_Config **config, char *token) > +{ > + char *endptr, *oparg; > + int i; > + unsigned int val; > + > + if (MATCH_OPTION("type", token, oparg)) { > + if (!strcmp("vif", oparg)) { > + nic->nictype = LIBXL_NIC_TYPE_VIF; > + } else if (!strcmp("ioemu", oparg)) { > + nic->nictype = LIBXL_NIC_TYPE_VIF_IOEMU; > + } else { > + fprintf(stderr, "Invalid parameter `type'.\n"); > + return 1; > + } > + } else if (MATCH_OPTION("mac", token, oparg)) { > + for (i = 0; i < 6; i++){ Your '{' needs a space beforehand.