[libvirt] [PATCH RESEND 0/5] VirtualBox version 4.2 support for libvirt vbox driver

Hello, I'm re-sending this patch for reviewing. If necessary I'm willing to make some changes to those patches. I'm currently working on a better management for snapshots with virtualbox, and my work is based on Virtualbox 4.2 so that's why I'm re sending this patch. Regards, Manuel VIVES Ryan Woodsmall said originally: "This patch set adds VirtualBox 4.2 initial support for the libvirt vbox driver. I've tested enough to check capabilities, create a VM, destroy it, etc. Five patches total: - Patch 1 is the C API header file from Oracle, cleaned up for libvirt. - Patch 2 is the version specific source file for version dependency. - Patch 3 is the src/Makefile.am change to pick up the two new files. - Patch 4 is the vbox driver support for the new VirtualBox API/version. - Patch 5 is the vbox_tmpl.c template support for the new version. A few things have changed in the VirtualBox API - some small (capitalizations of things in function names like Ip to IP and Dhcp to DHCP) and some much larger (FindMedium is superceded by OpenMedium). The biggest change for the sake of this patch set is the signature of CreateMachine is quite a bit different. Using the Oracle source as a guide, to spin up a VM with a given UUID, it looks like a text flag has to be passed in a new argument to CreateMachine. This flag is built in the VirtualBox 4.2 specific ifdefs and is kind of ugly but works. Additionally, there is now (unused) VM groups support in CreateMachine and the previous 'osTypeId' arg is currently set to nsnull as in the Oracle code. The FindMedium to OpenMedium changes were more straightforward and are pretty clear. The rest of the vbox template changes are basically spelling/capitalization changes from the looks of things. This probably isn't perfect, but it works on git and patched against 0.10.2 for a few quick tests. Not currently on the list, so ping me directly if you need any other info on these, or if anything could use additional work. Thanks! " ryan woodsmall (5): vbox C API header for VirtualBox v4.2 vbox version-specific C file for VirtualBox v4.2 Makefile.am additions for VirtualBox v4.2 vbox driver support for VirtualBox v4.2 vbox template support for VirtualBox v4.2 src/Makefile.am | 3 +- src/vbox/vbox_CAPI_v4_2.h | 8855 +++++++++++++++++++++++++++++++++++++++++++++ src/vbox/vbox_V4_2.c | 13 + src/vbox/vbox_driver.c | 8 + src/vbox/vbox_tmpl.c | 90 +- 5 files changed, 8958 insertions(+), 11 deletions(-) create mode 100644 src/vbox/vbox_CAPI_v4_2.h create mode 100644 src/vbox/vbox_V4_2.c -- 1.7.10.4

From: ryan woodsmall <rwoodsmall@gmail.com> --- src/vbox/vbox_V4_2.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/vbox/vbox_V4_2.c diff --git a/src/vbox/vbox_V4_2.c b/src/vbox/vbox_V4_2.c new file mode 100644 index 0000000..8c5b61c --- /dev/null +++ b/src/vbox/vbox_V4_2.c @@ -0,0 +1,13 @@ +/** @file vbox_V4_2.c + * C file to include support for multiple versions of VirtualBox + * at runtime. + */ + +#include <config.h> + +/** The API Version */ +#define VBOX_API_VERSION 4002 +/** Version specific prefix. */ +#define NAME(name) vbox42##name + +#include "vbox_tmpl.c" -- 1.7.10.4

From: ryan woodsmall <rwoodsmall@gmail.com> --- src/Makefile.am | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Makefile.am b/src/Makefile.am index 430a356..467ec5d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -593,7 +593,8 @@ VBOX_DRIVER_SOURCES = \ 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_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_DRIVER_EXTRA_DIST = \ vbox/vbox_tmpl.c vbox/README \ -- 1.7.10.4

From: ryan woodsmall <rwoodsmall@gmail.com> --- src/vbox/vbox_driver.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/vbox/vbox_driver.c b/src/vbox/vbox_driver.c index a68f33d..9d07574 100644 --- a/src/vbox/vbox_driver.c +++ b/src/vbox/vbox_driver.c @@ -61,6 +61,9 @@ extern virStorageDriver vbox40StorageDriver; extern virDriver vbox41Driver; extern virNetworkDriver vbox41NetworkDriver; extern virStorageDriver vbox41StorageDriver; +extern virDriver vbox42Driver; +extern virNetworkDriver vbox42NetworkDriver; +extern virStorageDriver vbox42StorageDriver; static virDriver vboxDriverDummy; @@ -124,6 +127,11 @@ int vboxRegister(void) { driver = &vbox41Driver; networkDriver = &vbox41NetworkDriver; storageDriver = &vbox41StorageDriver; + } else if (uVersion >= 4001051 && uVersion < 4002051) { + VIR_DEBUG("VirtualBox API version: 4.2"); + driver = &vbox42Driver; + networkDriver = &vbox42NetworkDriver; + storageDriver = &vbox42StorageDriver; } else { VIR_DEBUG("Unsupported VirtualBox API version: %u", uVersion); } -- 1.7.10.4

From: ryan woodsmall <rwoodsmall@gmail.com> --- src/vbox/vbox_tmpl.c | 90 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 80 insertions(+), 10 deletions(-) diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index d37888c..5bef956 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -72,6 +72,8 @@ # include "vbox_CAPI_v4_0.h" #elif VBOX_API_VERSION == 4001 # include "vbox_CAPI_v4_1.h" +#elif VBOX_API_VERSION == 4002 +# include "vbox_CAPI_v4_2.h" #else # error "Unsupport VBOX_API_VERSION" #endif @@ -4178,9 +4180,12 @@ vboxAttachDrives(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine) continue; } -# if VBOX_API_VERSION >= 4000 +# if VBOX_API_VERSION >= 4000 && VBOX_API_VERSION < 4002 data->vboxObj->vtbl->FindMedium(data->vboxObj, mediumFileUtf16, deviceType, &medium); +# elif VBOX_API_VERSION >= 4002 + data->vboxObj->vtbl->OpenMedium(data->vboxObj, mediumFileUtf16, + deviceType, accessMode, PR_FALSE, &medium); # endif if (!medium) { @@ -4920,7 +4925,11 @@ vboxAttachUSB(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine) machine->vtbl->GetUSBController(machine, &USBController); if (USBController) { USBController->vtbl->SetEnabled(USBController, 1); +#if VBOX_API_VERSION < 4002 USBController->vtbl->SetEnabledEhci(USBController, 1); +#else + USBController->vtbl->SetEnabledEHCI(USBController, 1); +#endif for (i = 0; i < def->nhostdevs; i++) { if (def->hostdevs[i]->mode == @@ -5025,10 +5034,18 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) { vboxIID mchiid = VBOX_IID_INITIALIZER; virDomainDefPtr def = NULL; PRUnichar *machineNameUtf16 = NULL; -#if VBOX_API_VERSION >= 3002 +#if VBOX_API_VERSION >= 3002 && VBOX_API_VERSION < 4002 PRBool override = PR_FALSE; #endif nsresult rc; + char uuidstr[VIR_UUID_STRING_BUFLEN]; +#if VBOX_API_VERSION >= 4002 + const char *flagsUUIDPrefix = "UUID="; + const char *flagsForceOverwrite = "forceOverwrite=0"; + const char *flagsSeparator = ","; + char createFlags[strlen(flagsUUIDPrefix) + VIR_UUID_STRING_BUFLEN + strlen(flagsSeparator) + strlen(flagsForceOverwrite) + 1]; + PRUnichar *createFlagsUtf16 = NULL; +#endif if (!(def = virDomainDefParseString(xml, data->caps, data->xmlopt, 1 << VIR_DOMAIN_VIRT_VBOX, @@ -5038,6 +5055,8 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) { VBOX_UTF8_TO_UTF16(def->name, &machineNameUtf16); vboxIIDFromUUID(&iid, def->uuid); + virUUIDFormat(def->uuid, uuidstr); + #if VBOX_API_VERSION < 3002 rc = data->vboxObj->vtbl->CreateMachine(data->vboxObj, machineNameUtf16, @@ -5053,7 +5072,7 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) { iid.value, override, &machine); -#else /* VBOX_API_VERSION >= 4000 */ +#elif VBOX_API_VERSION >= 4000 && VBOX_API_VERSION < 4002 rc = data->vboxObj->vtbl->CreateMachine(data->vboxObj, NULL, machineNameUtf16, @@ -5061,7 +5080,23 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) { iid.value, override, &machine); -#endif /* VBOX_API_VERSION >= 4000 */ +#else /* VBOX_API_VERSION >= 4002 */ + snprintf(createFlags, sizeof(createFlags), "%s%s%s%s", + flagsUUIDPrefix, + uuidstr, + flagsSeparator, + flagsForceOverwrite + ); + VBOX_UTF8_TO_UTF16(createFlags, &createFlagsUtf16); + rc = data->vboxObj->vtbl->CreateMachine(data->vboxObj, + NULL, + machineNameUtf16, + 0, + nsnull, + nsnull, + createFlagsUtf16, + &machine); +#endif /* VBOX_API_VERSION >= 4002 */ VBOX_UTF16_FREE(machineNameUtf16); if (NS_FAILED(rc)) { @@ -7845,15 +7880,26 @@ static virNetworkPtr vboxNetworkDefineCreateXML(virConnectPtr conn, const char * * IP and enables the interface so even if the dhcpserver is not * started the interface is still up and running */ +#if VBOX_API_VERSION < 4002 networkInterface->vtbl->EnableStaticIpConfig(networkInterface, ipAddressUtf16, networkMaskUtf16); +#else + networkInterface->vtbl->EnableStaticIPConfig(networkInterface, + ipAddressUtf16, + networkMaskUtf16); +#endif VBOX_UTF16_FREE(ipAddressUtf16); VBOX_UTF16_FREE(networkMaskUtf16); } else { +#if VBOX_API_VERSION < 4002 networkInterface->vtbl->EnableDynamicIpConfig(networkInterface); networkInterface->vtbl->DhcpRediscover(networkInterface); +#else + networkInterface->vtbl->EnableDynamicIPConfig(networkInterface); + networkInterface->vtbl->DHCPRediscover(networkInterface); +#endif } rc = networkInterface->vtbl->GetId(networkInterface, &vboxnetiid.value); @@ -8451,9 +8497,13 @@ static virStorageVolPtr vboxStorageVolLookupByKey(virConnectPtr conn, const char vboxIIDFromUUID(&hddIID, uuid); #if VBOX_API_VERSION < 4000 rc = data->vboxObj->vtbl->GetHardDisk(data->vboxObj, hddIID.value, &hardDisk); -#else /* VBOX_API_VERSION >= 4000 */ +#elif VBOX_API_VERSION >= 4000 && VBOX_API_VERSION < 4002 rc = data->vboxObj->vtbl->FindMedium(data->vboxObj, hddIID.value, DeviceType_HardDisk, &hardDisk); +#else + rc = data->vboxObj->vtbl->OpenMedium(data->vboxObj, hddIID.value, + DeviceType_HardDisk, AccessMode_ReadWrite, + PR_FALSE, &hardDisk); #endif /* VBOX_API_VERSION >= 4000 */ if (NS_SUCCEEDED(rc)) { PRUint32 hddstate; @@ -8508,9 +8558,13 @@ static virStorageVolPtr vboxStorageVolLookupByPath(virConnectPtr conn, const cha #if VBOX_API_VERSION < 4000 rc = data->vboxObj->vtbl->FindHardDisk(data->vboxObj, hddPathUtf16, &hardDisk); -#else /* VBOX_API_VERSION >= 4000 */ +#elif VBOX_API_VERSION >= 4000 && VBOX_API_VERSION < 4002 rc = data->vboxObj->vtbl->FindMedium(data->vboxObj, hddPathUtf16, DeviceType_HardDisk, &hardDisk); +#else + rc = data->vboxObj->vtbl->OpenMedium(data->vboxObj, hddPathUtf16, + DeviceType_HardDisk, AccessMode_ReadWrite, + PR_FALSE, &hardDisk); #endif /* VBOX_API_VERSION >= 4000 */ if (NS_SUCCEEDED(rc)) { PRUint32 hddstate; @@ -8684,9 +8738,13 @@ static int vboxStorageVolDelete(virStorageVolPtr vol, vboxIIDFromUUID(&hddIID, uuid); #if VBOX_API_VERSION < 4000 rc = data->vboxObj->vtbl->GetHardDisk(data->vboxObj, hddIID.value, &hardDisk); -#else /* VBOX_API_VERSION >= 4000 */ +#elif VBOX_API_VERSION >= 4000 && VBOX_API_VERSION < 4002 rc = data->vboxObj->vtbl->FindMedium(data->vboxObj, hddIID.value, DeviceType_HardDisk, &hardDisk); +#else + rc = data->vboxObj->vtbl->OpenMedium(data->vboxObj, hddIID.value, + DeviceType_HardDisk, AccessMode_ReadWrite, + PR_FALSE, &hardDisk); #endif /* VBOX_API_VERSION >= 4000 */ if (NS_SUCCEEDED(rc)) { PRUint32 hddstate; @@ -8852,9 +8910,13 @@ static int vboxStorageVolGetInfo(virStorageVolPtr vol, virStorageVolInfoPtr info vboxIIDFromUUID(&hddIID, uuid); #if VBOX_API_VERSION < 4000 rc = data->vboxObj->vtbl->GetHardDisk(data->vboxObj, hddIID.value, &hardDisk); -#else /* VBOX_API_VERSION >= 4000 */ +#elif VBOX_API_VERSION >= 4000 && VBOX_API_VERSION < 4002 rc = data->vboxObj->vtbl->FindMedium(data->vboxObj, hddIID.value, DeviceType_HardDisk, &hardDisk); +#else + rc = data->vboxObj->vtbl->OpenMedium(data->vboxObj, hddIID.value, + DeviceType_HardDisk, AccessMode_ReadWrite, + PR_FALSE, &hardDisk); #endif /* VBOX_API_VERSION >= 4000 */ if (NS_SUCCEEDED(rc)) { PRUint32 hddstate; @@ -8922,9 +8984,13 @@ static char *vboxStorageVolGetXMLDesc(virStorageVolPtr vol, unsigned int flags) vboxIIDFromUUID(&hddIID, uuid); #if VBOX_API_VERSION < 4000 rc = data->vboxObj->vtbl->GetHardDisk(data->vboxObj, hddIID.value, &hardDisk); -#else /* VBOX_API_VERSION >= 4000 */ +#elif VBOX_API_VERSION >= 4000 && VBOX_API_VERSION < 4002 rc = data->vboxObj->vtbl->FindMedium(data->vboxObj, hddIID.value, DeviceType_HardDisk, &hardDisk); +#else + rc = data->vboxObj->vtbl->OpenMedium(data->vboxObj, hddIID.value, + DeviceType_HardDisk, AccessMode_ReadWrite, + PR_FALSE, &hardDisk); #endif /* VBOX_API_VERSION >= 4000 */ if (NS_SUCCEEDED(rc)) { PRUint32 hddstate; @@ -9027,9 +9093,13 @@ static char *vboxStorageVolGetPath(virStorageVolPtr vol) { vboxIIDFromUUID(&hddIID, uuid); #if VBOX_API_VERSION < 4000 rc = data->vboxObj->vtbl->GetHardDisk(data->vboxObj, hddIID.value, &hardDisk); -#else /* VBOX_API_VERSION >= 4000 */ +#elif VBOX_API_VERSION >= 4000 && VBOX_API_VERSION < 4002 rc = data->vboxObj->vtbl->FindMedium(data->vboxObj, hddIID.value, DeviceType_HardDisk, &hardDisk); +#else + rc = data->vboxObj->vtbl->OpenMedium(data->vboxObj, hddIID.value, + DeviceType_HardDisk, AccessMode_ReadWrite, + PR_FALSE, &hardDisk); #endif /* VBOX_API_VERSION >= 4000 */ if (NS_SUCCEEDED(rc)) { PRUint32 hddstate; -- 1.7.10.4

On Wed, May 22, 2013 at 10:00:12AM +0200, Manuel VIVES wrote:
Hello,
I'm re-sending this patch for reviewing. If necessary I'm willing to make some changes to those patches.
I'm currently working on a better management for snapshots with virtualbox, and my work is based on Virtualbox 4.2 so that's why I'm re sending this patch.
Regards, Manuel VIVES
Ryan Woodsmall said originally:
"This patch set adds VirtualBox 4.2 initial support for the libvirt vbox driver. I've tested enough to check capabilities, create a VM, destroy it, etc. Five patches total:
- Patch 1 is the C API header file from Oracle, cleaned up for libvirt. - Patch 2 is the version specific source file for version dependency. - Patch 3 is the src/Makefile.am change to pick up the two new files. - Patch 4 is the vbox driver support for the new VirtualBox API/version. - Patch 5 is the vbox_tmpl.c template support for the new version.
A few things have changed in the VirtualBox API - some small (capitalizations of things in function names like Ip to IP and Dhcp to DHCP) and some much larger (FindMedium is superceded by OpenMedium). The biggest change for the sake of this patch set is the signature of CreateMachine is quite a bit different. Using the Oracle source as a guide, to spin up a VM with a given UUID, it looks like a text flag has to be passed in a new argument to CreateMachine. This flag is built in the VirtualBox 4.2 specific ifdefs and is kind of ugly but works. Additionally, there is now (unused) VM groups support in CreateMachine and the previous 'osTypeId' arg is currently set to nsnull as in the Oracle code.
The FindMedium to OpenMedium changes were more straightforward and are pretty clear. The rest of the vbox template changes are basically spelling/capitalization changes from the looks of things.
This probably isn't perfect, but it works on git and patched against 0.10.2 for a few quick tests. Not currently on the list, so ping me directly if you need any other info on these, or if anything could use additional work. Thanks! "
ryan woodsmall (5): vbox C API header for VirtualBox v4.2 vbox version-specific C file for VirtualBox v4.2 Makefile.am additions for VirtualBox v4.2 vbox driver support for VirtualBox v4.2 vbox template support for VirtualBox v4.2
src/Makefile.am | 3 +- src/vbox/vbox_CAPI_v4_2.h | 8855 +++++++++++++++++++++++++++++++++++++++++++++ src/vbox/vbox_V4_2.c | 13 + src/vbox/vbox_driver.c | 8 + src/vbox/vbox_tmpl.c | 90 +- 5 files changed, 8958 insertions(+), 11 deletions(-) create mode 100644 src/vbox/vbox_CAPI_v4_2.h create mode 100644 src/vbox/vbox_V4_2.c
ACK to all pastches, they look like the sane minimum required to make vbox 4.2 work. Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On Mon, Jun 03, 2013 at 11:19:15AM +0100, Daniel P. Berrange wrote:
On Wed, May 22, 2013 at 10:00:12AM +0200, Manuel VIVES wrote:
Hello,
I'm re-sending this patch for reviewing. If necessary I'm willing to make some changes to those patches.
I'm currently working on a better management for snapshots with virtualbox, and my work is based on Virtualbox 4.2 so that's why I'm re sending this patch.
Regards, Manuel VIVES
Ryan Woodsmall said originally:
"This patch set adds VirtualBox 4.2 initial support for the libvirt vbox driver. I've tested enough to check capabilities, create a VM, destroy it, etc. Five patches total:
- Patch 1 is the C API header file from Oracle, cleaned up for libvirt. - Patch 2 is the version specific source file for version dependency. - Patch 3 is the src/Makefile.am change to pick up the two new files. - Patch 4 is the vbox driver support for the new VirtualBox API/version. - Patch 5 is the vbox_tmpl.c template support for the new version.
A few things have changed in the VirtualBox API - some small (capitalizations of things in function names like Ip to IP and Dhcp to DHCP) and some much larger (FindMedium is superceded by OpenMedium). The biggest change for the sake of this patch set is the signature of CreateMachine is quite a bit different. Using the Oracle source as a guide, to spin up a VM with a given UUID, it looks like a text flag has to be passed in a new argument to CreateMachine. This flag is built in the VirtualBox 4.2 specific ifdefs and is kind of ugly but works. Additionally, there is now (unused) VM groups support in CreateMachine and the previous 'osTypeId' arg is currently set to nsnull as in the Oracle code.
The FindMedium to OpenMedium changes were more straightforward and are pretty clear. The rest of the vbox template changes are basically spelling/capitalization changes from the looks of things.
This probably isn't perfect, but it works on git and patched against 0.10.2 for a few quick tests. Not currently on the list, so ping me directly if you need any other info on these, or if anything could use additional work. Thanks! "
ryan woodsmall (5): vbox C API header for VirtualBox v4.2 vbox version-specific C file for VirtualBox v4.2 Makefile.am additions for VirtualBox v4.2 vbox driver support for VirtualBox v4.2 vbox template support for VirtualBox v4.2
src/Makefile.am | 3 +- src/vbox/vbox_CAPI_v4_2.h | 8855 +++++++++++++++++++++++++++++++++++++++++++++ src/vbox/vbox_V4_2.c | 13 + src/vbox/vbox_driver.c | 8 + src/vbox/vbox_tmpl.c | 90 +- 5 files changed, 8958 insertions(+), 11 deletions(-) create mode 100644 src/vbox/vbox_CAPI_v4_2.h create mode 100644 src/vbox/vbox_V4_2.c
ACK to all pastches, they look like the sane minimum required to make vbox 4.2 work.
This is now pushed, though I had to merge all 5 patches into 1, since they would not compile individually & we require history to be fully bisectable at every patch. Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
participants (2)
-
Daniel P. Berrange
-
Manuel VIVES