On Thu, Aug 13, 2009 at 03:32:45PM +0200, Pritesh Kothari wrote:
Hi All,
I have made some changes to the functions vboxNetworkCreateXML(),
vboxNetworkDefineXML(), vboxNetworkUndefine() and vboxNetworkDestroy() to handle
multiple host only interfaces as multiple host only interfaces are supported
by VirtualBox 3.0 and greater.
ACk, looks fine.
commit e32b0c4d92d0c2acfb43284c636d693625fedea7
Author: Pritesh Kothari <Pritesh.Kothari(a)Sun.com>
Date: Thu Aug 13 14:24:44 2009 +0200
libvirt: Merged vboxNetworkUndefine() and vboxNetworkDestroy() and
added code to handle multiple hostonly interfaces.
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 6de277f..0180b9b 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -5191,7 +5191,7 @@ static virNetworkPtr vboxNetworkDefineXML(virConnectPtr conn, const
char *xml) {
return vboxNetworkDefineCreateXML(conn, xml, false);
}
-static int vboxNetworkUndefine(virNetworkPtr network) {
+static int vboxNetworkUndefineDestroy(virNetworkPtr network, bool removeinterface) {
vboxGlobalData *data = network->conn->privateData;
char *networkNameUtf8 = NULL;
int ret = -1;
@@ -5230,19 +5230,48 @@ static int vboxNetworkUndefine(virNetworkPtr network) {
PRUnichar *networkNameUtf16 = NULL;
IDHCPServer *dhcpServer = NULL;
+#if VBOX_API_VERSION != 2002
+ if (removeinterface) {
+ PRUnichar *iidUtf16 = NULL;
+ IProgress *progress = NULL;
+
+ networkInterface->vtbl->GetId(networkInterface,
&iidUtf16);
+
+ if (iidUtf16) {
+#if VBOX_API_VERSION == 3000
+ IHostNetworkInterface *netInt = NULL;
+ host->vtbl->RemoveHostOnlyNetworkInterface(host,
iidUtf16, &netInt, &progress);
+ if (netInt)
+ netInt->vtbl->nsisupports.Release((nsISupports *)
netInt);
+#else /* VBOX_API_VERSION > 3000 */
+ host->vtbl->RemoveHostOnlyNetworkInterface(host,
iidUtf16, &progress);
+#endif /* VBOX_API_VERSION > 3000 */
+ data->pFuncs->pfnUtf16Free(iidUtf16);
+ }
+
+ if (progress) {
+ progress->vtbl->WaitForCompletion(progress, -1);
+ progress->vtbl->nsisupports.Release((nsISupports
*)progress);
+ }
+ }
+#endif /* VBOX_API_VERSION != 2002 */
+
data->pFuncs->pfnUtf8ToUtf16(networkNameUtf8 ,
&networkNameUtf16);
data->vboxObj->vtbl->FindDHCPServerByNetworkName(data->vboxObj,
networkNameUtf16,
&dhcpServer);
if (dhcpServer) {
- data->vboxObj->vtbl->RemoveDHCPServer(data->vboxObj,
dhcpServer);
+ dhcpServer->vtbl->SetEnabled(dhcpServer, PR_FALSE);
+ dhcpServer->vtbl->Stop(dhcpServer);
+ if (removeinterface)
+
data->vboxObj->vtbl->RemoveDHCPServer(data->vboxObj, dhcpServer);
dhcpServer->vtbl->nsisupports.Release((nsISupports *)
dhcpServer);
}
data->pFuncs->pfnUtf16Free(networkNameUtf16);
- }
+ }
networkInterface->vtbl->nsisupports.Release((nsISupports *)
networkInterface);
}
@@ -5258,6 +5287,10 @@ cleanup:
return ret;
}
+static int vboxNetworkUndefine(virNetworkPtr network) {
+ return vboxNetworkUndefineDestroy(network, true);
+}
+
static int vboxNetworkCreate(virNetworkPtr network) {
vboxGlobalData *data = network->conn->privateData;
char *networkNameUtf8 = NULL;
@@ -5337,74 +5370,7 @@ cleanup:
}
static int vboxNetworkDestroy(virNetworkPtr network) {
- vboxGlobalData *data = network->conn->privateData;
- char *networkNameUtf8 = NULL;
- int ret = -1;
-
- /* Current limitation of the function for VirtualBox 2.2.* is
- * that the default hostonly network "vboxnet0" is always active
- * and thus all this functions does is stop the dhcp server,
- * but the network can still be used without the dhcp server
- * by giving the machine static IP
- */
-
- if (virAsprintf(&networkNameUtf8, "HostInterfaceNetworking-%s",
network->name) < 0) {
- virReportOOMError(network->conn);
- goto cleanup;
- }
-
- if (data->vboxObj) {
- IHost *host = NULL;
-
- data->vboxObj->vtbl->GetHost(data->vboxObj, &host);
- if (host) {
- PRUnichar *networkInterfaceNameUtf16 = NULL;
- IHostNetworkInterface *networkInterface = NULL;
-
- data->pFuncs->pfnUtf8ToUtf16(network->name,
&networkInterfaceNameUtf16);
-
- host->vtbl->FindHostNetworkInterfaceByName(host,
networkInterfaceNameUtf16, &networkInterface);
-
- if (networkInterface) {
- PRUint32 interfaceType = 0;
-
- networkInterface->vtbl->GetInterfaceType(networkInterface,
&interfaceType);
-
- if (interfaceType == HostNetworkInterfaceType_HostOnly) {
- PRUnichar *networkNameUtf16 = NULL;
- IDHCPServer *dhcpServer = NULL;
-
-
- data->pFuncs->pfnUtf8ToUtf16(networkNameUtf8 ,
&networkNameUtf16);
-
-
data->vboxObj->vtbl->FindDHCPServerByNetworkName(data->vboxObj,
- networkNameUtf16,
- &dhcpServer);
- if (dhcpServer) {
-
- dhcpServer->vtbl->SetEnabled(dhcpServer, PR_FALSE);
-
- dhcpServer->vtbl->Stop(dhcpServer);
-
- dhcpServer->vtbl->nsisupports.Release((nsISupports *)
dhcpServer);
- }
-
- data->pFuncs->pfnUtf16Free(networkNameUtf16);
- }
-
- networkInterface->vtbl->nsisupports.Release((nsISupports *)
networkInterface);
- }
-
- data->pFuncs->pfnUtf16Free(networkInterfaceNameUtf16);
- host->vtbl->nsisupports.Release((nsISupports *) host);
- }
- }
-
- ret = 0;
-
-cleanup:
- VIR_FREE(networkNameUtf8);
- return ret;
+ return vboxNetworkUndefineDestroy(network, false);
}
static char *vboxNetworkDumpXML(virNetworkPtr network, int flags ATTRIBUTE_UNUSED) {
--
Libvir-list mailing list
Libvir-list(a)redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
--
|: Red Hat, Engineering, London -o-
http://people.redhat.com/berrange/ :|
|:
http://libvirt.org -o-
http://virt-manager.org -o-
http://ovirt.org :|
|:
http://autobuild.org -o-
http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|