提交 73ce5050 编写于 作者: M Matthias Bolte

vbox: Add support for VirtualBox 4.1

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.
上级 96f28f7f
...@@ -339,7 +339,8 @@ VBOX_DRIVER_SOURCES = \ ...@@ -339,7 +339,8 @@ VBOX_DRIVER_SOURCES = \
vbox/vbox_V3_0.c vbox/vbox_CAPI_v3_0.h \ 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_1.c vbox/vbox_CAPI_v3_1.h \
vbox/vbox_V3_2.c vbox/vbox_CAPI_v3_2.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_DRIVER_EXTRA_DIST = \
vbox/vbox_tmpl.c vbox/README \ vbox/vbox_tmpl.c vbox/README \
......
此差异已折叠。
/** @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"
...@@ -60,6 +60,9 @@ extern virStorageDriver vbox32StorageDriver; ...@@ -60,6 +60,9 @@ extern virStorageDriver vbox32StorageDriver;
extern virDriver vbox40Driver; extern virDriver vbox40Driver;
extern virNetworkDriver vbox40NetworkDriver; extern virNetworkDriver vbox40NetworkDriver;
extern virStorageDriver vbox40StorageDriver; extern virStorageDriver vbox40StorageDriver;
extern virDriver vbox41Driver;
extern virNetworkDriver vbox41NetworkDriver;
extern virStorageDriver vbox41StorageDriver;
static virDriver vboxDriverDummy; static virDriver vboxDriverDummy;
...@@ -122,10 +125,14 @@ int vboxRegister(void) { ...@@ -122,10 +125,14 @@ int vboxRegister(void) {
driver = &vbox40Driver; driver = &vbox40Driver;
networkDriver = &vbox40NetworkDriver; networkDriver = &vbox40NetworkDriver;
storageDriver = &vbox40StorageDriver; storageDriver = &vbox40StorageDriver;
} else if (uVersion >= 4000051 && uVersion < 4001051) {
VIR_DEBUG("VirtualBox API version: 4.1");
driver = &vbox41Driver;
networkDriver = &vbox41NetworkDriver;
storageDriver = &vbox41StorageDriver;
} else { } else {
VIR_DEBUG("Unsupport VirtualBox API version"); VIR_DEBUG("Unsupported VirtualBox API version: %u", uVersion);
} }
} else { } else {
VIR_DEBUG("VBoxCGlueInit failed, using dummy driver"); VIR_DEBUG("VBoxCGlueInit failed, using dummy driver");
} }
......
...@@ -68,6 +68,8 @@ ...@@ -68,6 +68,8 @@
# include "vbox_CAPI_v3_2.h" # include "vbox_CAPI_v3_2.h"
#elif VBOX_API_VERSION == 4000 #elif VBOX_API_VERSION == 4000
# include "vbox_CAPI_v4_0.h" # include "vbox_CAPI_v4_0.h"
#elif VBOX_API_VERSION == 4001
# include "vbox_CAPI_v4_1.h"
#else #else
# error "Unsupport VBOX_API_VERSION" # error "Unsupport VBOX_API_VERSION"
#endif #endif
...@@ -2207,6 +2209,9 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) { ...@@ -2207,6 +2209,9 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) {
#endif /* VBOX_API_VERSION >= 4000 */ #endif /* VBOX_API_VERSION >= 4000 */
IAudioAdapter *audioAdapter = NULL; IAudioAdapter *audioAdapter = NULL;
IUSBController *USBController = NULL; IUSBController *USBController = NULL;
#if VBOX_API_VERSION >= 4001
PRUint32 chipsetType = ChipsetType_Null;
#endif /* VBOX_API_VERSION >= 4001 */
ISystemProperties *systemProperties = NULL; ISystemProperties *systemProperties = NULL;
...@@ -2218,11 +2223,19 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) { ...@@ -2218,11 +2223,19 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) {
machine->vtbl->GetMemorySize(machine, &memorySize); machine->vtbl->GetMemorySize(machine, &memorySize);
def->mem.cur_balloon = memorySize * 1024; 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); data->vboxObj->vtbl->GetSystemProperties(data->vboxObj, &systemProperties);
if (systemProperties) { if (systemProperties) {
systemProperties->vtbl->GetMaxGuestRAM(systemProperties, &maxMemorySize); systemProperties->vtbl->GetMaxGuestRAM(systemProperties, &maxMemorySize);
systemProperties->vtbl->GetMaxBootPosition(systemProperties, &maxBootPosition); systemProperties->vtbl->GetMaxBootPosition(systemProperties, &maxBootPosition);
#if VBOX_API_VERSION < 4001
systemProperties->vtbl->GetNetworkAdapterCount(systemProperties, &netAdpCnt); 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->GetSerialPortCount(systemProperties, &serialPortCount);
systemProperties->vtbl->GetParallelPortCount(systemProperties, &parallelPortCount); systemProperties->vtbl->GetParallelPortCount(systemProperties, &parallelPortCount);
VBOX_RELEASE(systemProperties); VBOX_RELEASE(systemProperties);
...@@ -2888,7 +2901,11 @@ sharedFoldersCleanup: ...@@ -2888,7 +2901,11 @@ sharedFoldersCleanup:
def->nets[netAdpIncCnt]->type = VIR_DOMAIN_NET_TYPE_BRIDGE; def->nets[netAdpIncCnt]->type = VIR_DOMAIN_NET_TYPE_BRIDGE;
#if VBOX_API_VERSION < 4001
adapter->vtbl->GetHostInterface(adapter, &hostIntUtf16); 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); VBOX_UTF16_TO_UTF8(hostIntUtf16, &hostInt);
def->nets[netAdpIncCnt]->data.bridge.brname = strdup(hostInt); def->nets[netAdpIncCnt]->data.bridge.brname = strdup(hostInt);
...@@ -2916,7 +2933,11 @@ sharedFoldersCleanup: ...@@ -2916,7 +2933,11 @@ sharedFoldersCleanup:
def->nets[netAdpIncCnt]->type = VIR_DOMAIN_NET_TYPE_NETWORK; def->nets[netAdpIncCnt]->type = VIR_DOMAIN_NET_TYPE_NETWORK;
#if VBOX_API_VERSION < 4001
adapter->vtbl->GetHostInterface(adapter, &hostIntUtf16); 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); VBOX_UTF16_TO_UTF8(hostIntUtf16, &hostInt);
def->nets[netAdpIncCnt]->data.network.name = strdup(hostInt); def->nets[netAdpIncCnt]->data.network.name = strdup(hostInt);
...@@ -4134,12 +4155,18 @@ vboxAttachDrives(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine) ...@@ -4134,12 +4155,18 @@ vboxAttachDrives(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine)
} else { } else {
rc = 0; rc = 0;
} }
# else /* VBOX_API_VERSION >= 4000 */ # elif VBOX_API_VERSION == 4000
rc = data->vboxObj->vtbl->OpenMedium(data->vboxObj, rc = data->vboxObj->vtbl->OpenMedium(data->vboxObj,
mediumFileUtf16, mediumFileUtf16,
deviceType, accessMode, deviceType, accessMode,
&medium); &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); VBOX_UTF16_FREE(mediumEmpty);
} }
...@@ -4268,13 +4295,25 @@ static void ...@@ -4268,13 +4295,25 @@ static void
vboxAttachNetwork(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine) vboxAttachNetwork(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine)
{ {
ISystemProperties *systemProperties = NULL; ISystemProperties *systemProperties = NULL;
#if VBOX_API_VERSION >= 4001
PRUint32 chipsetType = ChipsetType_Null;
#endif /* VBOX_API_VERSION >= 4001 */
PRUint32 networkAdapterCount = 0; PRUint32 networkAdapterCount = 0;
int i = 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); data->vboxObj->vtbl->GetSystemProperties(data->vboxObj, &systemProperties);
if (systemProperties) { if (systemProperties) {
#if VBOX_API_VERSION < 4001
systemProperties->vtbl->GetNetworkAdapterCount(systemProperties, systemProperties->vtbl->GetNetworkAdapterCount(systemProperties,
&networkAdapterCount); &networkAdapterCount);
#else /* VBOX_API_VERSION >= 4000 */
systemProperties->vtbl->GetMaxNetworkAdapters(systemProperties, chipsetType,
&networkAdapterCount);
#endif /* VBOX_API_VERSION >= 4000 */
VBOX_RELEASE(systemProperties); VBOX_RELEASE(systemProperties);
systemProperties = NULL; systemProperties = NULL;
} }
...@@ -4347,19 +4386,31 @@ vboxAttachNetwork(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine) ...@@ -4347,19 +4386,31 @@ vboxAttachNetwork(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine)
PRUnichar *hostInterface = NULL; PRUnichar *hostInterface = NULL;
/* Bridged Network */ /* Bridged Network */
#if VBOX_API_VERSION < 4001
adapter->vtbl->AttachToBridgedInterface(adapter); 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) { if (def->nets[i]->data.bridge.brname) {
VBOX_UTF8_TO_UTF16(def->nets[i]->data.bridge.brname, VBOX_UTF8_TO_UTF16(def->nets[i]->data.bridge.brname,
&hostInterface); &hostInterface);
#if VBOX_API_VERSION < 4001
adapter->vtbl->SetHostInterface(adapter, hostInterface); adapter->vtbl->SetHostInterface(adapter, hostInterface);
#else /* VBOX_API_VERSION >= 4001 */
adapter->vtbl->SetBridgedInterface(adapter, hostInterface);
#endif /* VBOX_API_VERSION >= 4001 */
VBOX_UTF16_FREE(hostInterface); VBOX_UTF16_FREE(hostInterface);
} }
} else if (def->nets[i]->type == VIR_DOMAIN_NET_TYPE_INTERNAL) { } else if (def->nets[i]->type == VIR_DOMAIN_NET_TYPE_INTERNAL) {
PRUnichar *internalNetwork = NULL; PRUnichar *internalNetwork = NULL;
/* Internal Network */ /* Internal Network */
#if VBOX_API_VERSION < 4001
adapter->vtbl->AttachToInternalNetwork(adapter); 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) { if (def->nets[i]->data.internal.name) {
VBOX_UTF8_TO_UTF16(def->nets[i]->data.internal.name, VBOX_UTF8_TO_UTF16(def->nets[i]->data.internal.name,
...@@ -4373,22 +4424,38 @@ vboxAttachNetwork(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine) ...@@ -4373,22 +4424,38 @@ vboxAttachNetwork(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine)
* on *nix and mac, on windows you can create and configure * on *nix and mac, on windows you can create and configure
* as many as you want) * as many as you want)
*/ */
#if VBOX_API_VERSION < 4001
adapter->vtbl->AttachToHostOnlyInterface(adapter); 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) { if (def->nets[i]->data.network.name) {
VBOX_UTF8_TO_UTF16(def->nets[i]->data.network.name, VBOX_UTF8_TO_UTF16(def->nets[i]->data.network.name,
&hostInterface); &hostInterface);
#if VBOX_API_VERSION < 4001
adapter->vtbl->SetHostInterface(adapter, hostInterface); adapter->vtbl->SetHostInterface(adapter, hostInterface);
#else /* VBOX_API_VERSION >= 4001 */
adapter->vtbl->SetHostOnlyInterface(adapter, hostInterface);
#endif /* VBOX_API_VERSION >= 4001 */
VBOX_UTF16_FREE(hostInterface); VBOX_UTF16_FREE(hostInterface);
} }
} else if (def->nets[i]->type == VIR_DOMAIN_NET_TYPE_USER) { } else if (def->nets[i]->type == VIR_DOMAIN_NET_TYPE_USER) {
/* NAT */ /* NAT */
#if VBOX_API_VERSION < 4001
adapter->vtbl->AttachToNAT(adapter); adapter->vtbl->AttachToNAT(adapter);
#else /* VBOX_API_VERSION >= 4001 */
adapter->vtbl->SetAttachmentType(adapter, NetworkAttachmentType_NAT);
#endif /* VBOX_API_VERSION >= 4001 */
} else { } else {
/* else always default to NAT if we don't understand /* else always default to NAT if we don't understand
* what option is been passed to us * what option is been passed to us
*/ */
#if VBOX_API_VERSION < 4001
adapter->vtbl->AttachToNAT(adapter); 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); VBOX_UTF8_TO_UTF16(macaddrvbox, &MACAddress);
...@@ -6674,9 +6741,10 @@ cleanup: ...@@ -6674,9 +6741,10 @@ cleanup:
return ret; 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 */ /* 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 */ /* Functions needed for Callbacks */
static nsresult PR_COM_METHOD static nsresult PR_COM_METHOD
...@@ -7238,7 +7306,7 @@ static int vboxDomainEventDeregisterAny(virConnectPtr conn, ...@@ -7238,7 +7306,7 @@ static int vboxDomainEventDeregisterAny(virConnectPtr conn,
return ret; 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 * The Network Functions here on
...@@ -8914,7 +8982,7 @@ static char *vboxStorageVolGetPath(virStorageVolPtr vol) { ...@@ -8914,7 +8982,7 @@ static char *vboxStorageVolGetPath(virStorageVolPtr vol) {
return ret; return ret;
} }
#if VBOX_API_VERSION == 4000 #if VBOX_API_VERSION >= 4000
static char * static char *
vboxDomainScreenshot(virDomainPtr dom, vboxDomainScreenshot(virDomainPtr dom,
virStreamPtr st, virStreamPtr st,
...@@ -9038,7 +9106,7 @@ endjob: ...@@ -9038,7 +9106,7 @@ endjob:
vboxIIDUnalloc(&iid); vboxIIDUnalloc(&iid);
return ret; return ret;
} }
#endif /* VBOX_API_VERSION == 4000 */ #endif /* VBOX_API_VERSION >= 4000 */
/** /**
* Function Tables * Function Tables
...@@ -9090,10 +9158,10 @@ virDriver NAME(Driver) = { ...@@ -9090,10 +9158,10 @@ virDriver NAME(Driver) = {
.domainUpdateDeviceFlags = vboxDomainUpdateDeviceFlags, /* 0.8.0 */ .domainUpdateDeviceFlags = vboxDomainUpdateDeviceFlags, /* 0.8.0 */
.nodeGetCellsFreeMemory = nodeGetCellsFreeMemory, /* 0.6.5 */ .nodeGetCellsFreeMemory = nodeGetCellsFreeMemory, /* 0.6.5 */
.nodeGetFreeMemory = nodeGetFreeMemory, /* 0.6.5 */ .nodeGetFreeMemory = nodeGetFreeMemory, /* 0.6.5 */
#if VBOX_API_VERSION == 4000 #if VBOX_API_VERSION >= 4000
.domainScreenshot = vboxDomainScreenshot, /* 0.9.2 */ .domainScreenshot = vboxDomainScreenshot, /* 0.9.2 */
#endif #endif
#if VBOX_API_VERSION != 2002 && VBOX_API_VERSION != 4000 #if VBOX_API_VERSION > 2002 && VBOX_API_VERSION < 4000
.domainEventRegister = vboxDomainEventRegister, /* 0.7.0 */ .domainEventRegister = vboxDomainEventRegister, /* 0.7.0 */
.domainEventDeregister = vboxDomainEventDeregister, /* 0.7.0 */ .domainEventDeregister = vboxDomainEventDeregister, /* 0.7.0 */
#endif #endif
...@@ -9102,7 +9170,7 @@ virDriver NAME(Driver) = { ...@@ -9102,7 +9170,7 @@ virDriver NAME(Driver) = {
.domainIsActive = vboxDomainIsActive, /* 0.7.3 */ .domainIsActive = vboxDomainIsActive, /* 0.7.3 */
.domainIsPersistent = vboxDomainIsPersistent, /* 0.7.3 */ .domainIsPersistent = vboxDomainIsPersistent, /* 0.7.3 */
.domainIsUpdated = vboxDomainIsUpdated, /* 0.8.6 */ .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 */ .domainEventRegisterAny = vboxDomainEventRegisterAny, /* 0.8.0 */
.domainEventDeregisterAny = vboxDomainEventDeregisterAny, /* 0.8.0 */ .domainEventDeregisterAny = vboxDomainEventDeregisterAny, /* 0.8.0 */
#endif #endif
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册