Re: [PATH lxc_support_ethernet] fix bug:lxc don't support network type of ethernet

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

 




On 12/07/2015 08:58 PM, mark zhong wrote:
>  for exmple,the xml is:
>  <domain type = 'lxc'>
>     ...
>       <devices>
>            <interface type ="ethernet">
> 	       <mac address="02:36:1d:18:2a:e4"/>
> 		<ip address='192.168.112.105' family='ipv4' prefix='24'/>
> 		<target  dev="tap361d182e-14"/>
>            </interface>
>       <devices>
>   </domian>
> 
>   when i start lxc with that xml file,system will report error and start lxc failed
> 

Showing the error is helpful sometimes...

>   Now i create the veth pair and set mac address in lxc if the network type is ethernet
> 
> Signed-off-by: mark zhong <zhongguocheng1@xxxxxxx>
> ---
>  src/lxc/lxc_process.c | 36 ++++++++++++++++++++++++++++++++++++
>  src/lxc/lxc_process.h |  3 +++
>  2 files changed, 39 insertions(+)
> 

Not quite my area of expertise, but since it's been sitting a couple of
weeks - I figure could take a look and make some non-expert comments...

First a bit of investigation shows the following patch and response:

http://www.redhat.com/archives/libvir-list/2012-September/msg01588.html
http://www.redhat.com/archives/libvir-list/2012-September/msg01840.html

Second I was curious why "ETHERNET" was left in the switch in
virLXCProcessSetupInterfaces with just the break... I see commit id
'22cff52a2' seems to have added that (although it looks strange in the
git diff).

Whether the XML provided in that commit message actually worked - I'm
not clear.  Whether it's supposed to have actually been added - I'm
starting to doubt.

Third the added function was static to lxc_process.c so not technically
necessary to add the prototype in lxc_process.h; however, I do note that
the other cases in the switch can be called from lxc_driver for hotplug
capability...

Finally, when running this patch through make syntax-check it fails due
to TABS being used for that switch case statement.

John

> diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c
> index 57e3880..913fe36 100644
> --- a/src/lxc/lxc_process.c
> +++ b/src/lxc/lxc_process.c
> @@ -359,6 +359,39 @@ char *virLXCProcessSetupInterfaceDirect(virConnectPtr conn,
>      return ret;
>  }
>  
> +char *virLXCProcessSetupInterfaceEthernet(virDomainDefPtr vm,
> +                                          virDomainNetDefPtr net)
> +{
> +    char *ret = NULL;
> +    char *parentVeth;
> +    char *containerVeth = NULL;
> +
> +    VIR_DEBUG("calling vethCreate()");
> +    parentVeth = net->ifname;
> +    if (virNetDevVethCreate(&parentVeth, &containerVeth) < 0)
> +        goto cleanup;
> +    VIR_DEBUG("parentVeth: %s, containerVeth: %s", parentVeth, containerVeth);
> +
> +    if (net->ifname == NULL)
> +        net->ifname = parentVeth;
> +
> +    if (virNetDevSetMAC(containerVeth, &net->mac) < 0)
> +        goto cleanup;
> +
> +    if (virNetDevSetOnline(parentVeth, true) < 0)
> +        goto cleanup;
> +
> +    if (net->filter &&
> +        virDomainConfNWFilterInstantiate(vm->uuid, net) < 0)
> +        goto cleanup;
> +
> +    ret = containerVeth;
> +
> + cleanup:
> +    return ret;
> +}
> +
> +
>  static const char *nsInfoLocal[VIR_LXC_DOMAIN_NAMESPACE_LAST] = {
>      [VIR_LXC_DOMAIN_NAMESPACE_SHARENET] = "net",
>      [VIR_LXC_DOMAIN_NAMESPACE_SHAREIPC] = "ipc",
> @@ -559,6 +592,9 @@ static int virLXCProcessSetupInterfaces(virConnectPtr conn,
>              break;
>  
>          case VIR_DOMAIN_NET_TYPE_ETHERNET:
> +	    if (!(veth = virLXCProcessSetupInterfaceEthernet(def,
> +                                                            net)))
> +		goto cleanup;
>              break;
>  
>          case VIR_DOMAIN_NET_TYPE_USER:
> diff --git a/src/lxc/lxc_process.h b/src/lxc/lxc_process.h
> index b6c8083..3b4ade3 100644
> --- a/src/lxc/lxc_process.h
> +++ b/src/lxc/lxc_process.h
> @@ -53,5 +53,8 @@ char *virLXCProcessSetupInterfaceBridged(virDomainDefPtr vm,
>  char *virLXCProcessSetupInterfaceDirect(virConnectPtr conn,
>                                          virDomainDefPtr def,
>                                          virDomainNetDefPtr net);
> +char *virLXCProcessSetupInterfaceEthernet(virDomainDefPtr vm,
> +                                          virDomainNetDefPtr net);
> +
>  
>  #endif /* __LXC_PROCESS_H__ */
> 

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]