[libvirt] [ PATCH ] fix multiple veth problem for OpenVZ

Daniel Veillard veillard at redhat.com
Fri Feb 19 15:53:00 UTC 2010


On Wed, Jan 06, 2010 at 10:36:06PM +0900, Yuji NISHIDA wrote:
> Dear all
> 
> This is to fix multiple veth problem.
> NETIF setting was overwritten after first CT because any CT could not be found by character name.
> 

  I found that old patch that we apparently forgot.

> ---
>  src/openvz/openvz_conf.c   |   38 ++++++++++++++++++++++++++++++++++++++
>  src/openvz/openvz_conf.h   |    1 +
>  src/openvz/openvz_driver.c |    2 +-
>  3 files changed, 40 insertions(+), 1 deletions(-)
> 
> diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c
> index 43bbaf2..9fb9f7e 100644
> --- a/src/openvz/openvz_conf.c
> +++ b/src/openvz/openvz_conf.c
> @@ -948,3 +948,41 @@ static int openvzAssignUUIDs(void)
>      VIR_FREE(conf_dir);
>      return 0;
>  }
> +
> +
> +/*
> + * Return CTID from name
> + *
> + */
> +
> +int openvzGetVEID(char *name) {

  name is actually a "const char *"

> +    char cmd[64];
> +    int veid;
> +    FILE *fp;
> +
> +    strcpy( cmd, VZLIST );
> +    strcat( cmd, " " );
> +    strcat( cmd, name );
> +    strcat( cmd, " -ovpsid -H" );

  and to avoid an horrible out of buffer write if name or VZLIST path is
  too long I fixed this to use virAsprintf() to allocate and format the
  command.

> +    if ((fp = popen(cmd, "r")) == NULL) {
> +        openvzError(NULL, VIR_ERR_INTERNAL_ERROR, "%s", _("popen failed"));
> +        return -1;
> +    }
> +
> +    if (fscanf(fp, "%d\n", &veid ) != 1) {
> +        if (feof(fp))
> +            return -1;
> +
> +        openvzError(NULL, VIR_ERR_INTERNAL_ERROR,
> +                    "%s", _("Failed to parse vzlist output"));
> +        goto cleanup;
> +    }
> +
> +    return veid;
> +
> + cleanup:
> +    fclose(fp);
> +    return -1;
> +}
> diff --git a/src/openvz/openvz_conf.h b/src/openvz/openvz_conf.h
> index 00e18b4..518c267 100644
> --- a/src/openvz/openvz_conf.h
> +++ b/src/openvz/openvz_conf.h
> @@ -66,5 +66,6 @@ void openvzFreeDriver(struct openvz_driver *driver);
>  int strtoI(const char *str);
>  int openvzSetDefinedUUID(int vpsid, unsigned char *uuid);
>  unsigned int openvzGetNodeCPUs(void);
> +int openvzGetVEID(char *name);

  made the parameter const 

>  #endif /* OPENVZ_CONF_H */
> diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c
> index 196fd8c..879b5d0 100644
> --- a/src/openvz/openvz_driver.c
> +++ b/src/openvz/openvz_driver.c
> @@ -667,7 +667,7 @@ openvzDomainSetNetwork(virConnectPtr conn, const char *vpsid,
>      if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE) {
>          virBuffer buf = VIR_BUFFER_INITIALIZER;
>          char *dev_name_ve;
> -        int veid = strtoI(vpsid);
> +        int veid = openvzGetVEID(vpsid);
>  
>          //--netif_add ifname[,mac,host_ifname,host_mac]
>          ADD_ARG_LIT("--netif_add") ;

  That said the patch looks reasonable once those are fixed, so I pushed
  this, please double check,

    thanks !

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel at veillard.com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/




More information about the libvir-list mailing list