[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [OPW PATCH V3] tools: xl: refactor code to parse network device options



On Tue, Oct 21, 2014 at 05:19:35PM +0300, Alexandra Sandulescu wrote:
> From: Alexandra Sandulescu <alexandra.sandulescu1@xxxxxxxx>
> 
> 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 <alecsandra.sandulescu@xxxxxxxxx>
> ---
>  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.

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.