[libvirt] [PATCH 3/7] parallels: better bridge network interface support
In order to support 'bridge' network adapters in parallels driver we need to plug our veth devices into corresponding linux bridges. We are going to do this by reusing our abstraction of Virtual Networks in terms of PCS. On a domain creation, we create a new Virtual Network naming it with the same name as a source bridge for each network interface. Having done this, we plug PCS veth interfaces created with names of target dev into specified bridges using our standard PCS procedures Signed-off-by: Maxim Nestratov --- src/parallels/parallels_sdk.c | 99 +++- 1 files changed, 86 insertions(+), 13 deletions(-) diff --git a/src/parallels/parallels_sdk.c b/src/parallels/parallels_sdk.c index d3fb5d4..58c52a8 100644 --- a/src/parallels/parallels_sdk.c +++ b/src/parallels/parallels_sdk.c @@ -691,9 +691,6 @@ prlsdkGetNetInfo(PRL_HANDLE netAdapter, virDomainNetDefPtr net, bool isCt) /* use device name, shown by prlctl as target device * for identifying network adapter in virDomainDefineXML */ -pret = PrlVmDev_GetIndex(netAdapter, &netAdapterIndex); -prlsdkCheckRetGoto(pret, cleanup); - pret = PrlVmDevNet_GetHostInterfaceName(netAdapter, NULL, &buflen); prlsdkCheckRetGoto(pret, cleanup); @@ -703,6 +700,9 @@ prlsdkGetNetInfo(PRL_HANDLE netAdapter, virDomainNetDefPtr net, bool isCt) pret = PrlVmDevNet_GetHostInterfaceName(netAdapter, net->ifname, &buflen); prlsdkCheckRetGoto(pret, cleanup); +pret = PrlVmDev_GetIndex(netAdapter, &netAdapterIndex); +prlsdkCheckRetGoto(pret, cleanup); + if (isCt && netAdapterIndex == (PRL_UINT32) -1) { /* venet devices don't have mac address and * always up */ @@ -740,6 +740,16 @@ prlsdkGetNetInfo(PRL_HANDLE netAdapter, virDomainNetDefPtr net, bool isCt) net->data.network.name, &buflen); prlsdkCheckRetGoto(pret, cleanup); + +/* + * We use VIR_DOMAIN_NET_TYPE_NETWORK for all network adapters + * except those whose Virtual Network Id differ from Parallels + * predefined ones such as PARALLELS_DOMAIN_BRIDGED_NETWORK_NAME + * and PARALLELS_DONAIN_ROUTED_NETWORK_NAME + */ +if (!STREQ(net->data.network.name, PARALLELS_DOMAIN_BRIDGED_NETWORK_NAME)) +net->type = VIR_DOMAIN_NET_TYPE_BRIDGE; + } pret = PrlVmDev_IsConnected(netAdapter, &isConnected); @@ -2630,10 +2640,12 @@ static const char * prlsdkFormatMac(virMacAddrPtr mac, char *macstr) return macstr; } -static int prlsdkAddNet(PRL_HANDLE sdkdom, virDomainNetDefPtr net) +static int prlsdkAddNet(PRL_HANDLE sdkdom, parallelsConnPtr privconn, virDomainNetDefPtr net) { PRL_RESULT pret; PRL_HANDLE sdknet = PRL_INVALID_HANDLE; +PRL_HANDLE vnet = PRL_INVALID_HANDLE; +PRL_HANDLE job = PRL_INVALID_HANDLE; int ret = -1; char macstr[PRL_MAC_STRING_BUFNAME]; @@ -2658,10 +2670,39 @@ static int prlsdkAddNet(PRL_HANDLE sdkdom, virDomainNetDefPtr net) pret = PrlVmDevNet_SetMacAddress(sdknet, macstr); prlsdkCheckRetGoto(pret, cleanup); -pret = PrlVmDev_SetEmulatedType(sdknet, PNA_ROUTED); -if (STREQ(net->data.network.name, PARALLELS_DOMAIN_ROUTED_NETWORK_NAME)) { +if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK) { +if (STREQ(net->data.network.name, PARALLELS_DOMAIN_ROUTED_NETWORK_NAME)) { +pret = PrlVmDev_SetEmulatedType(sdknet, PNA_ROUTED); +prlsdkCheckRetGoto(pret, cleanup); +} else if (STREQ(net->data.network.name, PARALLELS_DOMAIN_BRIDGED_NETWORK_NAME)) { +pret = PrlVmDev_SetEmulatedType(sdknet, PNA_BRIDGED_ETHERNET); +prlsdkCheckRetGoto(pret, cleanup); + +pret = PrlVmDevNet_SetVirtualNetworkId(sdknet, net->data.network.name); +prlsdkCheckRetGoto(pret, cleanup); +} +} else if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE) { +/* + * For this type of adapter we create a new + * Virtual Network assuming that bridge with given name exists + * Failing creating this means domain creation failure + */ +pret = PrlVirtNet_Create(&vnet); prlsdkCheckRetGoto(pret, cleanup); -} else { + +pret = PrlVirtNet_SetNetworkId(vnet, net->data.network.name); +prlsdkCheckRetGoto(pret, cleanup); + +pret = PrlVirtNet_SetNetworkType(vnet, PVN_BRIDGED_ETHERNET); +prlsdkCheckRetGoto(pret, cleanup); + +job = PrlSrv_AddVirtualNetwork(privconn->server, vnet, 0); +if (PRL_FAILED(pret = waitJob(job, privconn->jobTimeout))) +goto cleanup; + +pret = PrlVmDev_SetEmulatedType(sdknet, PNA_BRIDGED_ETHERNET); +prlsdkCheckRetGoto(pret, cleanup); + pret = PrlVmDevNet_SetVirtualNetworkId(sdknet, net->data.network.name); prlsdkCheckRetGoto(pret, cleanup); } @@ -2674,10 +2715,34 @
Re: [libvirt] [PATCH 3/7] parallels: better bridge network interface support
On 13.03.2015 16:52, Maxim Nestratov wrote: > In order to support 'bridge' network adapters in parallels > driver we need to plug our veth devices into corresponding > linux bridges. > We are going to do this by reusing our abstraction of > Virtual Networks in terms of PCS. On a domain creation, we > create a new Virtual Network naming it with the same name > as a source bridge for each network interface. > Having done this, we plug PCS veth interfaces created with names of > target dev into specified bridges using our standard PCS procedures > > Signed-off-by: Maxim Nestratov > --- > src/parallels/parallels_sdk.c | 99 +++- > 1 files changed, 86 insertions(+), 13 deletions(-) ACK Michal -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH 3/7] parallels: better bridge network interface support
In order to support 'bridge' network adapters in parallels driver we need to plug our veth devices into corresponding linux bridges. We are going to do this by reusing our abstraction of Virtual Networks in terms of PCS. On a domain creation, we create a new Virtual Network naming it with the same name as a source bridge for each network interface. Having done this, we plug PCS veth interfaces created with names of target dev into specified bridges using our standard PCS procedures Signed-off-by: Maxim Nestratov --- src/parallels/parallels_sdk.c | 99 +++- 1 files changed, 86 insertions(+), 13 deletions(-) diff --git a/src/parallels/parallels_sdk.c b/src/parallels/parallels_sdk.c index 76cbb02..f581fbb 100644 --- a/src/parallels/parallels_sdk.c +++ b/src/parallels/parallels_sdk.c @@ -691,9 +691,6 @@ prlsdkGetNetInfo(PRL_HANDLE netAdapter, virDomainNetDefPtr net, bool isCt) /* use device name, shown by prlctl as target device * for identifying network adapter in virDomainDefineXML */ -pret = PrlVmDev_GetIndex(netAdapter, &netAdapterIndex); -prlsdkCheckRetGoto(pret, cleanup); - pret = PrlVmDevNet_GetHostInterfaceName(netAdapter, NULL, &buflen); prlsdkCheckRetGoto(pret, cleanup); @@ -703,6 +700,9 @@ prlsdkGetNetInfo(PRL_HANDLE netAdapter, virDomainNetDefPtr net, bool isCt) pret = PrlVmDevNet_GetHostInterfaceName(netAdapter, net->ifname, &buflen); prlsdkCheckRetGoto(pret, cleanup); +pret = PrlVmDev_GetIndex(netAdapter, &netAdapterIndex); +prlsdkCheckRetGoto(pret, cleanup); + if (isCt && netAdapterIndex == (PRL_UINT32) -1) { /* venet devices don't have mac address and * always up */ @@ -740,6 +740,16 @@ prlsdkGetNetInfo(PRL_HANDLE netAdapter, virDomainNetDefPtr net, bool isCt) net->data.network.name, &buflen); prlsdkCheckRetGoto(pret, cleanup); + +/* + * We use VIR_DOMAIN_NET_TYPE_NETWORK for all network adapters + * except those whose Virtual Network Id differ from Parallels + * predefined ones such as PARALLELS_DOMAIN_BRIDGED_NETWORK_NAME + * and PARALLELS_DONAIN_ROUTED_NETWORK_NAME + */ +if (!STREQ(net->data.network.name, PARALLELS_DOMAIN_BRIDGED_NETWORK_NAME)) +net->type = VIR_DOMAIN_NET_TYPE_BRIDGE; + } pret = PrlVmDev_IsConnected(netAdapter, &isConnected); @@ -2625,10 +2635,12 @@ static const char * prlsdkFormatMac(virMacAddrPtr mac, char *macstr) return macstr; } -static int prlsdkAddNet(PRL_HANDLE sdkdom, virDomainNetDefPtr net) +static int prlsdkAddNet(PRL_HANDLE sdkdom, parallelsConnPtr privconn, virDomainNetDefPtr net) { PRL_RESULT pret; PRL_HANDLE sdknet = PRL_INVALID_HANDLE; +PRL_HANDLE vnet = PRL_INVALID_HANDLE; +PRL_HANDLE job = PRL_INVALID_HANDLE; int ret = -1; char macstr[PRL_MAC_STRING_BUFNAME]; @@ -2653,10 +2665,39 @@ static int prlsdkAddNet(PRL_HANDLE sdkdom, virDomainNetDefPtr net) pret = PrlVmDevNet_SetMacAddress(sdknet, macstr); prlsdkCheckRetGoto(pret, cleanup); -pret = PrlVmDev_SetEmulatedType(sdknet, PNA_ROUTED); -if (STREQ(net->data.network.name, PARALLELS_DOMAIN_ROUTED_NETWORK_NAME)) { +if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK) { +if (STREQ(net->data.network.name, PARALLELS_DOMAIN_ROUTED_NETWORK_NAME)) { +pret = PrlVmDev_SetEmulatedType(sdknet, PNA_ROUTED); +prlsdkCheckRetGoto(pret, cleanup); +} else if (STREQ(net->data.network.name, PARALLELS_DOMAIN_BRIDGED_NETWORK_NAME)) { +pret = PrlVmDev_SetEmulatedType(sdknet, PNA_BRIDGED_ETHERNET); +prlsdkCheckRetGoto(pret, cleanup); + +pret = PrlVmDevNet_SetVirtualNetworkId(sdknet, net->data.network.name); +prlsdkCheckRetGoto(pret, cleanup); +} +} else if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE) { +/* + * For this type of adapter we create a new + * Virtual Network assuming that bridge with given name exists + * Failing creating this means domain creation failure + */ +pret = PrlVirtNet_Create(&vnet); prlsdkCheckRetGoto(pret, cleanup); -} else { + +pret = PrlVirtNet_SetNetworkId(vnet, net->data.network.name); +prlsdkCheckRetGoto(pret, cleanup); + +pret = PrlVirtNet_SetNetworkType(vnet, PVN_BRIDGED_ETHERNET); +prlsdkCheckRetGoto(pret, cleanup); + +job = PrlSrv_AddVirtualNetwork(privconn->server, vnet, 0); +if (PRL_FAILED(pret = waitJob(job, privconn->jobTimeout))) +goto cleanup; + +pret = PrlVmDev_SetEmulatedType(sdknet, PNA_BRIDGED_ETHERNET); +prlsdkCheckRetGoto(pret, cleanup); + pret = PrlVmDevNet_SetVirtualNetworkId(sdknet, net->data.network.name); prlsdkCheckRetGoto(pret, cleanup); } @@ -2669,10 +2710,
[libvirt] [PATCH 3/7] parallels: better bridge network interface support
In order to support 'bridge' network adapters in parallels driver we need to plug our veth devices into corresponding linux bridges. We are going to do this by reusing our abstraction of Virtual Networks in terms of PCS. On a domain creation, we create a new Virtual Network naming it with the same name as a source bridge for each network interface. Having done this, we plug PCS veth interfaces created with names of target dev into specified bridges using our standard PCS procedures Signed-off-by: Maxim Nestratov --- src/parallels/parallels_sdk.c | 101 +++-- 1 files changed, 87 insertions(+), 14 deletions(-) diff --git a/src/parallels/parallels_sdk.c b/src/parallels/parallels_sdk.c index c31439f..71a64a1 100644 --- a/src/parallels/parallels_sdk.c +++ b/src/parallels/parallels_sdk.c @@ -692,9 +692,6 @@ prlsdkGetNetInfo(PRL_HANDLE netAdapter, virDomainNetDefPtr net, bool isCt) /* use device name, shown by prlctl as target device * for identifying network adapter in virDomainDefineXML */ -pret = PrlVmDev_GetIndex(netAdapter, &netAdapterIndex); -prlsdkCheckRetGoto(pret, cleanup); - pret = PrlVmDevNet_GetHostInterfaceName(netAdapter, NULL, &buflen); prlsdkCheckRetGoto(pret, cleanup); @@ -704,6 +701,9 @@ prlsdkGetNetInfo(PRL_HANDLE netAdapter, virDomainNetDefPtr net, bool isCt) pret = PrlVmDevNet_GetHostInterfaceName(netAdapter, net->ifname, &buflen); prlsdkCheckRetGoto(pret, cleanup); +pret = PrlVmDev_GetIndex(netAdapter, &netAdapterIndex); +prlsdkCheckRetGoto(pret, cleanup); + if (isCt && netAdapterIndex == (PRL_UINT32) -1) { /* venet devices don't have mac address and * always up */ @@ -741,6 +741,16 @@ prlsdkGetNetInfo(PRL_HANDLE netAdapter, virDomainNetDefPtr net, bool isCt) net->data.network.name, &buflen); prlsdkCheckRetGoto(pret, cleanup); + +/* + * We use VIR_DOMAIN_NET_TYPE_NETWORK for all network adapters + * except those whose Virtual Network Id differ from Parallels + * predefined ones such as PARALLELS_DOMAIN_BRIDGED_NETWORK_NAME + * and PARALLELS_DONAIN_ROUTED_NETWORK_NAME + */ +if (!STREQ(net->data.network.name, PARALLELS_DOMAIN_BRIDGED_NETWORK_NAME)) +net->type = VIR_DOMAIN_NET_TYPE_BRIDGE; + } pret = PrlVmDev_IsConnected(netAdapter, &isConnected); @@ -2616,10 +2626,12 @@ static const char * prlsdkFormatMac(virMacAddrPtr mac, char *macstr) return macstr; } -static int prlsdkAddNet(PRL_HANDLE sdkdom, virDomainNetDefPtr net) +static int prlsdkAddNet(PRL_HANDLE sdkdom, parallelsConnPtr privconn, virDomainNetDefPtr net) { PRL_RESULT pret; PRL_HANDLE sdknet = PRL_INVALID_HANDLE; +PRL_HANDLE vnet = PRL_INVALID_HANDLE; +PRL_HANDLE job = PRL_INVALID_HANDLE; int ret = -1; char macstr[PRL_MAC_STRING_BUFNAME]; @@ -2644,10 +2656,39 @@ static int prlsdkAddNet(PRL_HANDLE sdkdom, virDomainNetDefPtr net) pret = PrlVmDevNet_SetMacAddress(sdknet, macstr); prlsdkCheckRetGoto(pret, cleanup); -pret = PrlVmDev_SetEmulatedType(sdknet, PNA_ROUTED); -if (STREQ(net->data.network.name, PARALLELS_DOMAIN_ROUTED_NETWORK_NAME)) { +if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK) { +if (STREQ(net->data.network.name, PARALLELS_DOMAIN_ROUTED_NETWORK_NAME)) { +pret = PrlVmDev_SetEmulatedType(sdknet, PNA_ROUTED); +prlsdkCheckRetGoto(pret, cleanup); +} else if (STREQ(net->data.network.name, PARALLELS_DOMAIN_BRIDGED_NETWORK_NAME)) { +pret = PrlVmDev_SetEmulatedType(sdknet, PNA_BRIDGED_ETHERNET); +prlsdkCheckRetGoto(pret, cleanup); + +pret = PrlVmDevNet_SetVirtualNetworkId(sdknet, net->data.network.name); +prlsdkCheckRetGoto(pret, cleanup); +} +} else if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE) { +/* + * For this type of adapter we create a new + * Virtual Network assuming that bridge with given name exists + * Failing creating this means domain creation failure + */ +pret = PrlVirtNet_Create(&vnet); prlsdkCheckRetGoto(pret, cleanup); -} else { + +pret = PrlVirtNet_SetNetworkId(vnet, net->data.network.name); +prlsdkCheckRetGoto(pret, cleanup); + +pret = PrlVirtNet_SetNetworkType(vnet, PVN_BRIDGED_ETHERNET); +prlsdkCheckRetGoto(pret, cleanup); + +job = PrlSrv_AddVirtualNetwork(privconn->server, vnet, 0); +if (PRL_FAILED(pret = waitJob(job, privconn->jobTimeout))) +goto cleanup; + +pret = PrlVmDev_SetEmulatedType(sdknet, PNA_BRIDGED_ETHERNET); +prlsdkCheckRetGoto(pret, cleanup); + pret = PrlVmDevNet_SetVirtualNetworkId(sdknet, net->data.network.name); prlsdkCheckRetGoto(pret, cleanup); } @@ -2660,10 +2701