Deal with the incompatible changes in the VirtualBox 4.1 API.
INetworkAdapter has its different AttachTo* method replaced by
a settable attachmentType property.
The maximum number of network adapters is now requestable per
chipset type.
The OpenMedium method got a bool parameter to request opening
a medium under a new IID.
---
This patch is compile-tested only and was created by fixing compile
errors and looking at the changelog between VirtualBox 4.0 and 4.1.
As I currently don't have VirtualBox 4.1 installed and don't have
time to upgrade my system and test this, it would be nice if someone
with VirtualBox 4.1 at hand could runtime test this patch.
The new vbox_CAPI_v4_1.h header file hase been edited out of this patch.
The full patch is attached packed.
src/Makefile.am | 3 +-
src/vbox/vbox_CAPI_v4_1.h | 7882 +++++++++++++++++++++++++++++++++++++++++++++
src/vbox/vbox_V4_1.c | 13 +
src/vbox/vbox_driver.c | 8 +
src/vbox/vbox_tmpl.c | 88 +-
5 files changed, 7983 insertions(+), 11 deletions(-)
create mode 100644 src/vbox/vbox_CAPI_v4_1.h
create mode 100644 src/vbox/vbox_V4_1.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 2555f81..7f4b43c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -339,7 +339,8 @@ VBOX_DRIVER_SOURCES = \
vbox/vbox_V3_0.c vbox/vbox_CAPI_v3_0.h \
vbox/vbox_V3_1.c vbox/vbox_CAPI_v3_1.h \
vbox/vbox_V3_2.c vbox/vbox_CAPI_v3_2.h \
- vbox/vbox_V4_0.c vbox/vbox_CAPI_v4_0.h
+ vbox/vbox_V4_0.c vbox/vbox_CAPI_v4_0.h \
+ vbox/vbox_V4_1.c vbox/vbox_CAPI_v4_1.h
VBOX_DRIVER_EXTRA_DIST = \
vbox/vbox_tmpl.c vbox/README \
diff --git a/src/vbox/vbox_V4_1.c b/src/vbox/vbox_V4_1.c
new file mode 100644
index 0000000..00fab09
--- /dev/null
+++ b/src/vbox/vbox_V4_1.c
@@ -0,0 +1,13 @@
+/** @file vbox_V4_0.c
+ * C file to include support for multiple versions of VirtualBox
+ * at runtime.
+ */
+
+#include <config.h>
+
+/** The API Version */
+#define VBOX_API_VERSION 4001
+/** Version specific prefix. */
+#define NAME(name) vbox41##name
+
+#include "vbox_tmpl.c"
diff --git a/src/vbox/vbox_driver.c b/src/vbox/vbox_driver.c
index 430ab40..3d208e8 100644
--- a/src/vbox/vbox_driver.c
+++ b/src/vbox/vbox_driver.c
@@ -60,6 +60,9 @@ extern virStorageDriver vbox32StorageDriver;
extern virDriver vbox40Driver;
extern virNetworkDriver vbox40NetworkDriver;
extern virStorageDriver vbox40StorageDriver;
+extern virDriver vbox41Driver;
+extern virNetworkDriver vbox41NetworkDriver;
+extern virStorageDriver vbox41StorageDriver;
static virDriver vboxDriverDummy;
@@ -122,6 +125,11 @@ int vboxRegister(void) {
driver = &vbox40Driver;
networkDriver = &vbox40NetworkDriver;
storageDriver = &vbox40StorageDriver;
+ } else if (uVersion >= 4000051 && uVersion < 4001051) {
+ VIR_DEBUG("VirtualBox API version: 4.1");
+ driver = &vbox41Driver;
+ networkDriver = &vbox41NetworkDriver;
+ storageDriver = &vbox41StorageDriver;
} else {
VIR_DEBUG("Unsupport VirtualBox API version");
}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index bc19b63..a956684 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -68,6 +68,8 @@
# include "vbox_CAPI_v3_2.h"
#elif VBOX_API_VERSION == 4000
# include "vbox_CAPI_v4_0.h"
+#elif VBOX_API_VERSION == 4001
+# include "vbox_CAPI_v4_1.h"
#else
# error "Unsupport VBOX_API_VERSION"
#endif
@@ -2207,6 +2209,9 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int
flags) {
#endif /* VBOX_API_VERSION >= 4000 */
IAudioAdapter *audioAdapter = NULL;
IUSBController *USBController = NULL;
+#if VBOX_API_VERSION >= 4001
+ PRUint32 chipsetType = ChipsetType_Null;
+#endif /* VBOX_API_VERSION >= 4001 */
ISystemProperties *systemProperties = NULL;
@@ -2218,11 +2223,19 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int
flags) {
machine->vtbl->GetMemorySize(machine, &memorySize);
def->mem.cur_balloon = memorySize * 1024;
+#if VBOX_API_VERSION >= 4001
+ machine->vtbl->GetChipsetType(machine, &chipsetType);
+#endif /* VBOX_API_VERSION >= 4001 */
+
data->vboxObj->vtbl->GetSystemProperties(data->vboxObj,
&systemProperties);
if (systemProperties) {
systemProperties->vtbl->GetMaxGuestRAM(systemProperties,
&maxMemorySize);
systemProperties->vtbl->GetMaxBootPosition(systemProperties,
&maxBootPosition);
+#if VBOX_API_VERSION < 4001
systemProperties->vtbl->GetNetworkAdapterCount(systemProperties,
&netAdpCnt);
+#else /* VBOX_API_VERSION >= 4000 */
+ systemProperties->vtbl->GetMaxNetworkAdapters(systemProperties,
chipsetType, &netAdpCnt);
+#endif /* VBOX_API_VERSION >= 4000 */
systemProperties->vtbl->GetSerialPortCount(systemProperties,
&serialPortCount);
systemProperties->vtbl->GetParallelPortCount(systemProperties,
¶llelPortCount);
VBOX_RELEASE(systemProperties);
@@ -2826,7 +2839,11 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int
flags) {
def->nets[netAdpIncCnt]->type =
VIR_DOMAIN_NET_TYPE_BRIDGE;
+#if VBOX_API_VERSION < 4001
adapter->vtbl->GetHostInterface(adapter,
&hostIntUtf16);
+#else /* VBOX_API_VERSION >= 4001 */
+ adapter->vtbl->GetBridgedInterface(adapter,
&hostIntUtf16);
+#endif /* VBOX_API_VERSION >= 4001 */
VBOX_UTF16_TO_UTF8(hostIntUtf16, &hostInt);
def->nets[netAdpIncCnt]->data.bridge.brname =
strdup(hostInt);
@@ -2854,7 +2871,11 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int
flags) {
def->nets[netAdpIncCnt]->type =
VIR_DOMAIN_NET_TYPE_NETWORK;
+#if VBOX_API_VERSION < 4001
adapter->vtbl->GetHostInterface(adapter,
&hostIntUtf16);
+#else /* VBOX_API_VERSION >= 4001 */
+ adapter->vtbl->GetHostOnlyInterface(adapter,
&hostIntUtf16);
+#endif /* VBOX_API_VERSION >= 4001 */
VBOX_UTF16_TO_UTF8(hostIntUtf16, &hostInt);
def->nets[netAdpIncCnt]->data.network.name =
strdup(hostInt);
@@ -4072,12 +4093,18 @@ vboxAttachDrives(virDomainDefPtr def, vboxGlobalData *data,
IMachine *machine)
} else {
rc = 0;
}
-# else /* VBOX_API_VERSION >= 4000 */
+# elif VBOX_API_VERSION == 4000
rc = data->vboxObj->vtbl->OpenMedium(data->vboxObj,
mediumFileUtf16,
deviceType, accessMode,
&medium);
-# endif /* VBOX_API_VERSION >= 4000 */
+# elif VBOX_API_VERSION >= 4001
+ rc = data->vboxObj->vtbl->OpenMedium(data->vboxObj,
+ mediumFileUtf16,
+ deviceType, accessMode,
+ false,
+ &medium);
+# endif /* VBOX_API_VERSION >= 4001 */
VBOX_UTF16_FREE(mediumEmpty);
}
@@ -4206,13 +4233,25 @@ static void
vboxAttachNetwork(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine)
{
ISystemProperties *systemProperties = NULL;
+#if VBOX_API_VERSION >= 4001
+ PRUint32 chipsetType = ChipsetType_Null;
+#endif /* VBOX_API_VERSION >= 4001 */
PRUint32 networkAdapterCount = 0;
int i = 0;
+#if VBOX_API_VERSION >= 4001
+ machine->vtbl->GetChipsetType(machine, &chipsetType);
+#endif /* VBOX_API_VERSION >= 4001 */
+
data->vboxObj->vtbl->GetSystemProperties(data->vboxObj,
&systemProperties);
if (systemProperties) {
+#if VBOX_API_VERSION < 4001
systemProperties->vtbl->GetNetworkAdapterCount(systemProperties,
&networkAdapterCount);
+#else /* VBOX_API_VERSION >= 4000 */
+ systemProperties->vtbl->GetMaxNetworkAdapters(systemProperties,
chipsetType,
+ &networkAdapterCount);
+#endif /* VBOX_API_VERSION >= 4000 */
VBOX_RELEASE(systemProperties);
systemProperties = NULL;
}
@@ -4285,19 +4324,31 @@ vboxAttachNetwork(virDomainDefPtr def, vboxGlobalData *data,
IMachine *machine)
PRUnichar *hostInterface = NULL;
/* Bridged Network */
+#if VBOX_API_VERSION < 4001
adapter->vtbl->AttachToBridgedInterface(adapter);
+#else /* VBOX_API_VERSION >= 4001 */
+ adapter->vtbl->SetAttachmentType(adapter,
NetworkAttachmentType_Bridged);
+#endif /* VBOX_API_VERSION >= 4001 */
if (def->nets[i]->data.bridge.brname) {
VBOX_UTF8_TO_UTF16(def->nets[i]->data.bridge.brname,
&hostInterface);
+#if VBOX_API_VERSION < 4001
adapter->vtbl->SetHostInterface(adapter, hostInterface);
+#else /* VBOX_API_VERSION >= 4001 */
+ adapter->vtbl->SetBridgedInterface(adapter, hostInterface);
+#endif /* VBOX_API_VERSION >= 4001 */
VBOX_UTF16_FREE(hostInterface);
}
} else if (def->nets[i]->type == VIR_DOMAIN_NET_TYPE_INTERNAL) {
PRUnichar *internalNetwork = NULL;
/* Internal Network */
+#if VBOX_API_VERSION < 4001
adapter->vtbl->AttachToInternalNetwork(adapter);
+#else /* VBOX_API_VERSION >= 4001 */
+ adapter->vtbl->SetAttachmentType(adapter,
NetworkAttachmentType_Internal);
+#endif /* VBOX_API_VERSION >= 4001 */
if (def->nets[i]->data.internal.name) {
VBOX_UTF8_TO_UTF16(def->nets[i]->data.internal.name,
@@ -4311,22 +4362,38 @@ vboxAttachNetwork(virDomainDefPtr def, vboxGlobalData *data,
IMachine *machine)
* on *nix and mac, on windows you can create and configure
* as many as you want)
*/
+#if VBOX_API_VERSION < 4001
adapter->vtbl->AttachToHostOnlyInterface(adapter);
+#else /* VBOX_API_VERSION >= 4001 */
+ adapter->vtbl->SetAttachmentType(adapter,
NetworkAttachmentType_HostOnly);
+#endif /* VBOX_API_VERSION >= 4001 */
if (def->nets[i]->data.network.name) {
VBOX_UTF8_TO_UTF16(def->nets[i]->data.network.name,
&hostInterface);
+#if VBOX_API_VERSION < 4001
adapter->vtbl->SetHostInterface(adapter, hostInterface);
+#else /* VBOX_API_VERSION >= 4001 */
+ adapter->vtbl->SetHostOnlyInterface(adapter, hostInterface);
+#endif /* VBOX_API_VERSION >= 4001 */
VBOX_UTF16_FREE(hostInterface);
}
} else if (def->nets[i]->type == VIR_DOMAIN_NET_TYPE_USER) {
/* NAT */
+#if VBOX_API_VERSION < 4001
adapter->vtbl->AttachToNAT(adapter);
+#else /* VBOX_API_VERSION >= 4001 */
+ adapter->vtbl->SetAttachmentType(adapter,
NetworkAttachmentType_NAT);
+#endif /* VBOX_API_VERSION >= 4001 */
} else {
/* else always default to NAT if we don't understand
* what option is been passed to us
*/
+#if VBOX_API_VERSION < 4001
adapter->vtbl->AttachToNAT(adapter);
+#else /* VBOX_API_VERSION >= 4001 */
+ adapter->vtbl->SetAttachmentType(adapter,
NetworkAttachmentType_NAT);
+#endif /* VBOX_API_VERSION >= 4001 */
}
VBOX_UTF8_TO_UTF16(macaddrvbox, &MACAddress);
@@ -6534,9 +6601,10 @@ cleanup:
return ret;
}
-#if VBOX_API_VERSION == 2002 || VBOX_API_VERSION == 4000
+#if VBOX_API_VERSION <= 2002 || VBOX_API_VERSION >= 4000
/* No Callback support for VirtualBox 2.2.* series */
-#else /* !(VBOX_API_VERSION == 2002) && !(VBOX_API_VERSION == 4000) */
+ /* No Callback support for VirtualBox 4.* series */
+#else /* !(VBOX_API_VERSION == 2002 || VBOX_API_VERSION >= 4000) */
/* Functions needed for Callbacks */
static nsresult PR_COM_METHOD
@@ -7098,7 +7166,7 @@ static int vboxDomainEventDeregisterAny(virConnectPtr conn,
return ret;
}
-#endif /* !(VBOX_API_VERSION == 2002) && !(VBOX_API_VERSION == 4000) */
+#endif /* !(VBOX_API_VERSION == 2002 || VBOX_API_VERSION >= 4000) */
/**
* The Network Functions here on
@@ -8774,7 +8842,7 @@ static char *vboxStorageVolGetPath(virStorageVolPtr vol) {
return ret;
}
-#if VBOX_API_VERSION == 4000
+#if VBOX_API_VERSION >= 4000
static char *
vboxDomainScreenshot(virDomainPtr dom,
virStreamPtr st,
@@ -8898,7 +8966,7 @@ endjob:
vboxIIDUnalloc(&iid);
return ret;
}
-#endif /* VBOX_API_VERSION == 4000 */
+#endif /* VBOX_API_VERSION >= 4000 */
/**
* Function Tables
@@ -8950,10 +9018,10 @@ virDriver NAME(Driver) = {
.domainUpdateDeviceFlags = vboxDomainUpdateDeviceFlags, /* 0.8.0 */
.nodeGetCellsFreeMemory = nodeGetCellsFreeMemory, /* 0.6.5 */
.nodeGetFreeMemory = nodeGetFreeMemory, /* 0.6.5 */
-#if VBOX_API_VERSION == 4000
+#if VBOX_API_VERSION >= 4000
.domainScreenshot = vboxDomainScreenshot, /* 0.9.2 */
#endif
-#if VBOX_API_VERSION != 2002 && VBOX_API_VERSION != 4000
+#if VBOX_API_VERSION > 2002 && VBOX_API_VERSION < 4000
.domainEventRegister = vboxDomainEventRegister, /* 0.7.0 */
.domainEventDeregister = vboxDomainEventDeregister, /* 0.7.0 */
#endif
@@ -8962,7 +9030,7 @@ virDriver NAME(Driver) = {
.domainIsActive = vboxDomainIsActive, /* 0.7.3 */
.domainIsPersistent = vboxDomainIsPersistent, /* 0.7.3 */
.domainIsUpdated = vboxDomainIsUpdated, /* 0.8.6 */
-#if VBOX_API_VERSION != 2002 && VBOX_API_VERSION != 4000
+#if VBOX_API_VERSION > 2002 && VBOX_API_VERSION < 4000
.domainEventRegisterAny = vboxDomainEventRegisterAny, /* 0.8.0 */
.domainEventDeregisterAny = vboxDomainEventDeregisterAny, /* 0.8.0 */
#endif
--
1.7.4.1