vbox: add support for 4.3 APIs

Makefile.am, vbox_V4_3.c and vbox_driver.c do regular
modifitions to support a new version of APIs.

vbox_tmpl.c basically fixes incompatibilities since 4.2.

The affected incompatibilities of 4.3 are:
* IMachine::Delete() has been renamed to IMachine::deleteConfig()
* IMedium::CreateBaseStorage() now accepts multiple variant values
* IDisplay::GetScreenResolution() now returns the display position
  in the guest
* IMachine now has multiple IUSBControllers and IUSBDeviceFilters
  handles USB device filters instead of (obsolete) IUSBController

This patch is tested on Mac OS X 10.8.5 and Fedora 19.

Signed-off-by: Ryota Ozaki <ozaki.ryota@gmail.com>
This commit is contained in:
Ryota Ozaki 2013-11-21 23:41:07 +09:00 committed by Laine Stump
parent f6a5fba2dc
commit c677ee8529
4 changed files with 95 additions and 3 deletions

View File

@ -650,7 +650,8 @@ VBOX_DRIVER_SOURCES = \
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/vbox_V4_1.c vbox/vbox_CAPI_v4_1.h \
vbox/vbox_V4_2.c vbox/vbox_CAPI_v4_2.h vbox/vbox_V4_2.c vbox/vbox_CAPI_v4_2.h \
vbox/vbox_V4_3.c vbox/vbox_CAPI_v4_3.h
VBOX_DRIVER_EXTRA_DIST = \ VBOX_DRIVER_EXTRA_DIST = \
vbox/vbox_tmpl.c vbox/README \ vbox/vbox_tmpl.c vbox/README \

13
src/vbox/vbox_V4_3.c Normal file
View File

@ -0,0 +1,13 @@
/** @file vbox_V4_3.c
* C file to include support for multiple versions of VirtualBox
* at runtime.
*/
#include <config.h>
/** The API Version */
#define VBOX_API_VERSION 4003
/** Version specific prefix. */
#define NAME(name) vbox43##name
#include "vbox_tmpl.c"

View File

@ -64,6 +64,9 @@ extern virStorageDriver vbox41StorageDriver;
extern virDriver vbox42Driver; extern virDriver vbox42Driver;
extern virNetworkDriver vbox42NetworkDriver; extern virNetworkDriver vbox42NetworkDriver;
extern virStorageDriver vbox42StorageDriver; extern virStorageDriver vbox42StorageDriver;
extern virDriver vbox43Driver;
extern virNetworkDriver vbox43NetworkDriver;
extern virStorageDriver vbox43StorageDriver;
static virDriver vboxDriverDummy; static virDriver vboxDriverDummy;
@ -132,6 +135,11 @@ int vboxRegister(void) {
driver = &vbox42Driver; driver = &vbox42Driver;
networkDriver = &vbox42NetworkDriver; networkDriver = &vbox42NetworkDriver;
storageDriver = &vbox42StorageDriver; storageDriver = &vbox42StorageDriver;
} else if (uVersion >= 4002051 && uVersion < 4003051) {
VIR_DEBUG("VirtualBox API version: 4.3");
driver = &vbox43Driver;
networkDriver = &vbox43NetworkDriver;
storageDriver = &vbox43StorageDriver;
} else { } else {
VIR_DEBUG("Unsupported VirtualBox API version: %u", uVersion); VIR_DEBUG("Unsupported VirtualBox API version: %u", uVersion);
} }

View File

@ -74,6 +74,8 @@
# include "vbox_CAPI_v4_1.h" # include "vbox_CAPI_v4_1.h"
#elif VBOX_API_VERSION == 4002 #elif VBOX_API_VERSION == 4002
# include "vbox_CAPI_v4_2.h" # include "vbox_CAPI_v4_2.h"
#elif VBOX_API_VERSION == 4003
# include "vbox_CAPI_v4_3.h"
#else #else
# error "Unsupport VBOX_API_VERSION" # error "Unsupport VBOX_API_VERSION"
#endif #endif
@ -2208,13 +2210,19 @@ vboxDomainGetMaxVcpus(virDomainPtr dom)
static void vboxHostDeviceGetXMLDesc(vboxGlobalData *data, virDomainDefPtr def, IMachine *machine) static void vboxHostDeviceGetXMLDesc(vboxGlobalData *data, virDomainDefPtr def, IMachine *machine)
{ {
#if VBOX_API_VERSION < 4003
IUSBController *USBController = NULL; IUSBController *USBController = NULL;
PRBool enabled = PR_FALSE; PRBool enabled = PR_FALSE;
#else
IUSBDeviceFilters *USBDeviceFilters = NULL;
#endif
vboxArray deviceFilters = VBOX_ARRAY_INITIALIZER; vboxArray deviceFilters = VBOX_ARRAY_INITIALIZER;
size_t i; size_t i;
PRUint32 USBFilterCount = 0; PRUint32 USBFilterCount = 0;
def->nhostdevs = 0; def->nhostdevs = 0;
#if VBOX_API_VERSION < 4003
machine->vtbl->GetUSBController(machine, &USBController); machine->vtbl->GetUSBController(machine, &USBController);
if (!USBController) if (!USBController)
@ -2227,6 +2235,16 @@ static void vboxHostDeviceGetXMLDesc(vboxGlobalData *data, virDomainDefPtr def,
vboxArrayGet(&deviceFilters, USBController, vboxArrayGet(&deviceFilters, USBController,
USBController->vtbl->GetDeviceFilters); USBController->vtbl->GetDeviceFilters);
#else
machine->vtbl->GetUSBDeviceFilters(machine, &USBDeviceFilters);
if (!USBDeviceFilters)
return;
vboxArrayGet(&deviceFilters, USBDeviceFilters,
USBDeviceFilters->vtbl->GetDeviceFilters);
#endif
if (deviceFilters.count <= 0) if (deviceFilters.count <= 0)
goto release_filters; goto release_filters;
@ -2298,8 +2316,12 @@ static void vboxHostDeviceGetXMLDesc(vboxGlobalData *data, virDomainDefPtr def,
release_filters: release_filters:
vboxArrayRelease(&deviceFilters); vboxArrayRelease(&deviceFilters);
#if VBOX_API_VERSION < 4003
release_controller: release_controller:
VBOX_RELEASE(USBController); VBOX_RELEASE(USBController);
#else
VBOX_RELEASE(USBDeviceFilters);
#endif
} }
static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) { static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) {
@ -4850,7 +4872,11 @@ vboxAttachDisplay(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine)
static void static void
vboxAttachUSB(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine) vboxAttachUSB(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine)
{ {
#if VBOX_API_VERSION < 4003
IUSBController *USBController = NULL; IUSBController *USBController = NULL;
#else
IUSBDeviceFilters *USBDeviceFilters = NULL;
#endif
size_t i = 0; size_t i = 0;
bool isUSB = false; bool isUSB = false;
@ -4884,6 +4910,7 @@ vboxAttachUSB(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine)
if (!isUSB) if (!isUSB)
return; return;
#if VBOX_API_VERSION < 4003
/* First Start the USB Controller and then loop /* First Start the USB Controller and then loop
* to attach USB Devices to it * to attach USB Devices to it
*/ */
@ -4893,10 +4920,16 @@ vboxAttachUSB(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine)
return; return;
USBController->vtbl->SetEnabled(USBController, 1); USBController->vtbl->SetEnabled(USBController, 1);
#if VBOX_API_VERSION < 4002 # if VBOX_API_VERSION < 4002
USBController->vtbl->SetEnabledEhci(USBController, 1); USBController->vtbl->SetEnabledEhci(USBController, 1);
#else # else
USBController->vtbl->SetEnabledEHCI(USBController, 1); USBController->vtbl->SetEnabledEHCI(USBController, 1);
# endif
#else
machine->vtbl->GetUSBDeviceFilters(machine, &USBDeviceFilters);
if (!USBDeviceFilters)
return;
#endif #endif
for (i = 0; i < def->nhostdevs; i++) { for (i = 0; i < def->nhostdevs; i++) {
@ -4921,9 +4954,15 @@ vboxAttachUSB(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine)
if (virAsprintf(&filtername, "filter%04zu", i) >= 0) { if (virAsprintf(&filtername, "filter%04zu", i) >= 0) {
VBOX_UTF8_TO_UTF16(filtername, &filternameUtf16); VBOX_UTF8_TO_UTF16(filtername, &filternameUtf16);
VIR_FREE(filtername); VIR_FREE(filtername);
#if VBOX_API_VERSION < 4003
USBController->vtbl->CreateDeviceFilter(USBController, USBController->vtbl->CreateDeviceFilter(USBController,
filternameUtf16, filternameUtf16,
&filter); &filter);
#else
USBDeviceFilters->vtbl->CreateDeviceFilter(USBDeviceFilters,
filternameUtf16,
&filter);
#endif
} }
VBOX_UTF16_FREE(filternameUtf16); VBOX_UTF16_FREE(filternameUtf16);
@ -4950,12 +4989,23 @@ vboxAttachUSB(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine)
VBOX_UTF16_FREE(productIdUtf16); VBOX_UTF16_FREE(productIdUtf16);
} }
filter->vtbl->SetActive(filter, 1); filter->vtbl->SetActive(filter, 1);
#if VBOX_API_VERSION < 4003
USBController->vtbl->InsertDeviceFilter(USBController, USBController->vtbl->InsertDeviceFilter(USBController,
i, i,
filter); filter);
#else
USBDeviceFilters->vtbl->InsertDeviceFilter(USBDeviceFilters,
i,
filter);
#endif
VBOX_RELEASE(filter); VBOX_RELEASE(filter);
} }
#if VBOX_API_VERSION < 4003
VBOX_RELEASE(USBController); VBOX_RELEASE(USBController);
#else
VBOX_RELEASE(USBDeviceFilters);
#endif
} }
static void static void
@ -5321,12 +5371,20 @@ vboxDomainUndefineFlags(virDomainPtr dom, unsigned int flags)
SAFEARRAY **media, SAFEARRAY **media,
IProgress **progress); IProgress **progress);
# if VBOX_API_VERSION < 4003
((IMachine_Delete)machine->vtbl->Delete)(machine, &safeArray, &progress); ((IMachine_Delete)machine->vtbl->Delete)(machine, &safeArray, &progress);
# else
((IMachine_Delete)machine->vtbl->DeleteConfig)(machine, &safeArray, &progress);
# endif
# else # else
/* XPCOM doesn't like NULL as an array, even when the array size is 0. /* XPCOM doesn't like NULL as an array, even when the array size is 0.
* Instead pass it a dummy array to avoid passing NULL. */ * Instead pass it a dummy array to avoid passing NULL. */
IMedium *array[] = { NULL }; IMedium *array[] = { NULL };
# if VBOX_API_VERSION < 4003
machine->vtbl->Delete(machine, 0, array, &progress); machine->vtbl->Delete(machine, 0, array, &progress);
# else
machine->vtbl->DeleteConfig(machine, 0, array, &progress);
# endif
# endif # endif
if (progress != NULL) { if (progress != NULL) {
progress->vtbl->WaitForCompletion(progress, -1); progress->vtbl->WaitForCompletion(progress, -1);
@ -8613,7 +8671,11 @@ static virStorageVolPtr vboxStorageVolCreateXML(virStoragePoolPtr pool,
if (def->capacity == def->allocation) if (def->capacity == def->allocation)
variant = HardDiskVariant_Fixed; variant = HardDiskVariant_Fixed;
#if VBOX_API_VERSION < 4003
rc = hardDisk->vtbl->CreateBaseStorage(hardDisk, logicalSize, variant, &progress); rc = hardDisk->vtbl->CreateBaseStorage(hardDisk, logicalSize, variant, &progress);
#else
rc = hardDisk->vtbl->CreateBaseStorage(hardDisk, logicalSize, 1, &variant, &progress);
#endif
if (NS_SUCCEEDED(rc) && progress) { if (NS_SUCCEEDED(rc) && progress) {
#if VBOX_API_VERSION == 2002 #if VBOX_API_VERSION == 2002
nsresult resultCode; nsresult resultCode;
@ -9140,10 +9202,18 @@ vboxDomainScreenshot(virDomainPtr dom,
PRUint32 width, height, bitsPerPixel; PRUint32 width, height, bitsPerPixel;
PRUint32 screenDataSize; PRUint32 screenDataSize;
PRUint8 *screenData; PRUint8 *screenData;
# if VBOX_API_VERSION >= 4003
PRInt32 xOrigin, yOrigin;
# endif
rc = display->vtbl->GetScreenResolution(display, screen, rc = display->vtbl->GetScreenResolution(display, screen,
&width, &height, &width, &height,
# if VBOX_API_VERSION < 4003
&bitsPerPixel); &bitsPerPixel);
# else
&bitsPerPixel,
&xOrigin, &yOrigin);
# endif
if (NS_FAILED(rc) || !width || !height) { if (NS_FAILED(rc) || !width || !height) {
virReportError(VIR_ERR_OPERATION_FAILED, "%s", virReportError(VIR_ERR_OPERATION_FAILED, "%s",