[PATCH 1/6] add VirtualBox 5 support to file vbox/vbox_tmpl.c

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 src/vbox/vbox_tmpl.c | 290 ++++++++++++++++++++++++++++++++-------------------
 1 file changed, 183 insertions(+), 107 deletions(-)

diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 7a8205d..79ce001 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -69,6 +69,8 @@
 # include "vbox_CAPI_v4_3.h"
 #elif VBOX_API_VERSION == 4003004
 # include "vbox_CAPI_v4_3_4.h"
+#elif VBOX_API_VERSION == 5000000
+# include "vbox_CAPI_v5_0.h"
 #else
 # error "Unsupport VBOX_API_VERSION"
 #endif
@@ -228,18 +230,18 @@ static void nsIDtoChar(unsigned char *uuid, const nsID *iid)
     memcpy(uuidinterim, iid, VIR_UUID_BUFLEN);
     virUUIDFormat(uuidinterim, uuidstrsrc);
 
-    uuidstrdst[0] = uuidstrsrc[6];
-    uuidstrdst[1] = uuidstrsrc[7];
-    uuidstrdst[2] = uuidstrsrc[4];
-    uuidstrdst[3] = uuidstrsrc[5];
-    uuidstrdst[4] = uuidstrsrc[2];
-    uuidstrdst[5] = uuidstrsrc[3];
-    uuidstrdst[6] = uuidstrsrc[0];
-    uuidstrdst[7] = uuidstrsrc[1];
+    uuidstrdst[0]  = uuidstrsrc[6];
+    uuidstrdst[1]  = uuidstrsrc[7];
+    uuidstrdst[2]  = uuidstrsrc[4];
+    uuidstrdst[3]  = uuidstrsrc[5];
+    uuidstrdst[4]  = uuidstrsrc[2];
+    uuidstrdst[5]  = uuidstrsrc[3];
+    uuidstrdst[6]  = uuidstrsrc[0];
+    uuidstrdst[7]  = uuidstrsrc[1];
 
-    uuidstrdst[8] = uuidstrsrc[8];
+    uuidstrdst[8]  = uuidstrsrc[8];
 
-    uuidstrdst[9] = uuidstrsrc[11];
+    uuidstrdst[9]  = uuidstrsrc[11];
     uuidstrdst[10] = uuidstrsrc[12];
     uuidstrdst[11] = uuidstrsrc[9];
     uuidstrdst[12] = uuidstrsrc[10];
@@ -267,18 +269,18 @@ static void nsIDFromChar(nsID *iid, const unsigned char *uuid)
 
     virUUIDFormat(uuid, uuidstrsrc);
 
-    uuidstrdst[0] = uuidstrsrc[6];
-    uuidstrdst[1] = uuidstrsrc[7];
-    uuidstrdst[2] = uuidstrsrc[4];
-    uuidstrdst[3] = uuidstrsrc[5];
-    uuidstrdst[4] = uuidstrsrc[2];
-    uuidstrdst[5] = uuidstrsrc[3];
-    uuidstrdst[6] = uuidstrsrc[0];
-    uuidstrdst[7] = uuidstrsrc[1];
+    uuidstrdst[0]  = uuidstrsrc[6];
+    uuidstrdst[1]  = uuidstrsrc[7];
+    uuidstrdst[2]  = uuidstrsrc[4];
+    uuidstrdst[3]  = uuidstrsrc[5];
+    uuidstrdst[4]  = uuidstrsrc[2];
+    uuidstrdst[5]  = uuidstrsrc[3];
+    uuidstrdst[6]  = uuidstrsrc[0];
+    uuidstrdst[7]  = uuidstrsrc[1];
 
-    uuidstrdst[8] = uuidstrsrc[8];
+    uuidstrdst[8]  = uuidstrsrc[8];
 
-    uuidstrdst[9] = uuidstrsrc[11];
+    uuidstrdst[9]  = uuidstrsrc[11];
     uuidstrdst[10] = uuidstrsrc[12];
     uuidstrdst[11] = uuidstrsrc[9];
     uuidstrdst[12] = uuidstrsrc[10];
@@ -621,13 +623,12 @@ _vboxIIDFromArrayItem(vboxGlobalData *data, vboxIIDUnion *iidu,
 # if VBOX_API_VERSION < 4000000
 /* Only 3.x will use this function. */
 static bool vboxGetDeviceDetails(const char *deviceName,
-                                 PRUint32 *aMaxPortPerInst,
-                                 PRUint32 *aMaxSlotPerPort,
-                                 PRUint32 storageBus,
-                                 PRInt32 *deviceInst,
-                                 PRInt32 *devicePort,
-                                 PRInt32 *deviceSlot)
-{
+                                 PRUint32   *aMaxPortPerInst,
+                                 PRUint32   *aMaxSlotPerPort,
+                                 PRUint32    storageBus,
+                                 PRInt32    *deviceInst,
+                                 PRInt32    *devicePort,
+                                 PRInt32    *deviceSlot) {
     int total = 0;
     PRUint32 maxPortPerInst = 0;
     PRUint32 maxSlotPerPort = 0;
@@ -829,8 +830,8 @@ _vboxAttachDrivesOld(virDomainDefPtr def, vboxGlobalData *data, IMachine *machin
 
                 machine->vtbl->GetDVDDrive(machine, &dvdDrive);
                 if (dvdDrive) {
-                    IDVDImage *dvdImage = NULL;
-                    PRUnichar *dvdfileUtf16 = NULL;
+                    IDVDImage *dvdImage          = NULL;
+                    PRUnichar *dvdfileUtf16      = NULL;
                     vboxIID dvduuid = VBOX_IID_INITIALIZER;
                     vboxIID dvdemptyuuid = VBOX_IID_INITIALIZER;
 
@@ -873,10 +874,10 @@ _vboxAttachDrivesOld(virDomainDefPtr def, vboxGlobalData *data, IMachine *machin
             }
         } else if (def->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_DISK) {
             if (type == VIR_STORAGE_TYPE_FILE && src) {
-                IHardDisk *hardDisk = NULL;
+                IHardDisk *hardDisk     = NULL;
                 PRUnichar *hddfileUtf16 = NULL;
                 vboxIID hdduuid = VBOX_IID_INITIALIZER;
-                PRUnichar *hddEmpty = NULL;
+                PRUnichar *hddEmpty     = NULL;
                 /* Current Limitation: Harddisk can't be connected to
                  * Secondary Master as Secondary Master is always used
                  * for CD/DVD Drive, so don't connect the harddisk if it
@@ -930,8 +931,8 @@ _vboxAttachDrivesOld(virDomainDefPtr def, vboxGlobalData *data, IMachine *machin
                                 VIR_DEBUG("Not connecting harddisk to hdc as hdc"
                                        " is taken by CD/DVD Drive");
                             } else {
-                                PRInt32 channel = 0;
-                                PRInt32 device = 0;
+                                PRInt32 channel          = 0;
+                                PRInt32 device           = 0;
                                 PRUnichar *hddcnameUtf16 = NULL;
 
                                 char *hddcname;
@@ -941,13 +942,13 @@ _vboxAttachDrivesOld(virDomainDefPtr def, vboxGlobalData *data, IMachine *machin
 
                                 if (STREQ(def->disks[i]->dst, "hda")) {
                                     channel = 0;
-                                    device = 0;
+                                    device  = 0;
                                 } else if (STREQ(def->disks[i]->dst, "hdb")) {
                                     channel = 0;
-                                    device = 1;
+                                    device  = 1;
                                 } else if (STREQ(def->disks[i]->dst, "hdd")) {
                                     channel = 1;
-                                    device = 1;
+                                    device  = 1;
                                 }
 
                                 rc = machine->vtbl->AttachHardDisk(machine,
@@ -982,8 +983,8 @@ _vboxAttachDrivesOld(virDomainDefPtr def, vboxGlobalData *data, IMachine *machin
                 if (floppyDrive) {
                     rc = floppyDrive->vtbl->SetEnabled(floppyDrive, 1);
                     if (NS_SUCCEEDED(rc)) {
-                        IFloppyImage *floppyImage = NULL;
-                        PRUnichar *fdfileUtf16 = NULL;
+                        IFloppyImage *floppyImage   = NULL;
+                        PRUnichar *fdfileUtf16      = NULL;
                         vboxIID fduuid = VBOX_IID_INITIALIZER;
                         vboxIID fdemptyuuid = VBOX_IID_INITIALIZER;
 
@@ -1038,7 +1039,7 @@ static void
 _vboxAttachDrivesOld(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine)
 {
     size_t i;
-    nsresult rc = 0;
+    nsresult rc;
 
     PRUint32 maxPortPerInst[StorageBus_Floppy + 1] = {};
     PRUint32 maxSlotPerPort[StorageBus_Floppy + 1] = {};
@@ -1110,14 +1111,14 @@ _vboxAttachDrivesOld(virDomainDefPtr def, vboxGlobalData *data, IMachine *machin
                                              ? "True" : "False"));
 
         if (type == VIR_STORAGE_TYPE_FILE && src) {
-            IMedium *medium = NULL;
-            PRUnichar *mediumUUID = NULL;
+            IMedium   *medium          = NULL;
+            PRUnichar *mediumUUID      = NULL;
             PRUnichar *mediumFileUtf16 = NULL;
-            PRUint32 storageBus = StorageBus_Null;
-            PRUint32 deviceType = DeviceType_Null;
-            PRInt32 deviceInst = 0;
-            PRInt32 devicePort = 0;
-            PRInt32 deviceSlot = 0;
+            PRUint32   storageBus      = StorageBus_Null;
+            PRUint32   deviceType      = DeviceType_Null;
+            PRInt32    deviceInst      = 0;
+            PRInt32    devicePort      = 0;
+            PRInt32    deviceSlot      = 0;
 
             VBOX_UTF8_TO_UTF16(src, &mediumFileUtf16);
 
@@ -1311,7 +1312,9 @@ _vboxDomainSnapshotRestore(virDomainPtr dom,
                           ISnapshot *snapshot)
 {
     vboxGlobalData *data = dom->conn->privateData;
+# if VBOX_API_VERSION < 5000000
     IConsole *console = NULL;
+# endif /*VBOX_API_VERSION < 5000000*/
     IProgress *progress = NULL;
     PRUint32 state;
     nsresult rc;
@@ -1344,16 +1347,22 @@ _vboxDomainSnapshotRestore(virDomainPtr dom,
     }
 
     rc = VBOX_SESSION_OPEN(domiid.value, machine);
+# if VBOX_API_VERSION < 5000000
     if (NS_SUCCEEDED(rc))
         rc = data->vboxSession->vtbl->GetConsole(data->vboxSession, &console);
+# endif /*VBOX_API_VERSION < 5000000*/
     if (NS_FAILED(rc)) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("could not open VirtualBox session with domain %s"),
                        dom->name);
         goto cleanup;
     }
-
+# if VBOX_API_VERSION < 5000000
     rc = console->vtbl->RestoreSnapshot(console, snapshot, &progress);
+# elif VBOX_API_VERSION >= 5000000  /*VBOX_API_VERSION < 5000000*/
+    rc = machine->vtbl->RestoreSnapshot(machine, snapshot, &progress);
+# endif /*VBOX_API_VERSION >= 5000000*/
+
     if (NS_FAILED(rc) || !progress) {
         if (rc == VBOX_E_INVALID_VM_STATE) {
             virReportError(VIR_ERR_OPERATION_INVALID, "%s",
@@ -1378,7 +1387,9 @@ _vboxDomainSnapshotRestore(virDomainPtr dom,
 
  cleanup:
     VBOX_RELEASE(progress);
+# if VBOX_API_VERSION < 5000000
     VBOX_RELEASE(console);
+# endif /*VBOX_API_VERSION < 5000000*/
     VBOX_SESSION_CLOSE();
     vboxIIDUnalloc(&domiid);
     return ret;
@@ -1406,8 +1417,8 @@ vboxCallbackOnMachineStateChange(IVirtualBoxCallback *pThis ATTRIBUTE_UNUSED,
                                  PRUnichar *machineId, PRUint32 state)
 {
     virDomainPtr dom = NULL;
-    int event = 0;
-    int detail = 0;
+    int event        = 0;
+    int detail       = 0;
 
     vboxDriverLock(g_pVBoxGlobalData);
 
@@ -1415,7 +1426,7 @@ vboxCallbackOnMachineStateChange(IVirtualBoxCallback *pThis ATTRIBUTE_UNUSED,
     DEBUGPRUnichar("machineId", machineId);
 
     if (machineId) {
-        char *machineIdUtf8 = NULL;
+        char *machineIdUtf8       = NULL;
         unsigned char uuid[VIR_UUID_BUFLEN];
 
         g_pVBoxGlobalData->pFuncs->pfnUtf16ToUtf8(machineId, &machineIdUtf8);
@@ -1426,31 +1437,31 @@ vboxCallbackOnMachineStateChange(IVirtualBoxCallback *pThis ATTRIBUTE_UNUSED,
             virObjectEventPtr ev;
 
             if (state == MachineState_Starting) {
-                event = VIR_DOMAIN_EVENT_STARTED;
+                event  = VIR_DOMAIN_EVENT_STARTED;
                 detail = VIR_DOMAIN_EVENT_STARTED_BOOTED;
             } else if (state == MachineState_Restoring) {
-                event = VIR_DOMAIN_EVENT_STARTED;
+                event  = VIR_DOMAIN_EVENT_STARTED;
                 detail = VIR_DOMAIN_EVENT_STARTED_RESTORED;
             } else if (state == MachineState_Paused) {
-                event = VIR_DOMAIN_EVENT_SUSPENDED;
+                event  = VIR_DOMAIN_EVENT_SUSPENDED;
                 detail = VIR_DOMAIN_EVENT_SUSPENDED_PAUSED;
             } else if (state == MachineState_Running) {
-                event = VIR_DOMAIN_EVENT_RESUMED;
+                event  = VIR_DOMAIN_EVENT_RESUMED;
                 detail = VIR_DOMAIN_EVENT_RESUMED_UNPAUSED;
             } else if (state == MachineState_PoweredOff) {
-                event = VIR_DOMAIN_EVENT_STOPPED;
+                event  = VIR_DOMAIN_EVENT_STOPPED;
                 detail = VIR_DOMAIN_EVENT_STOPPED_SHUTDOWN;
             } else if (state == MachineState_Stopping) {
-                event = VIR_DOMAIN_EVENT_STOPPED;
+                event  = VIR_DOMAIN_EVENT_STOPPED;
                 detail = VIR_DOMAIN_EVENT_STOPPED_DESTROYED;
             } else if (state == MachineState_Aborted) {
-                event = VIR_DOMAIN_EVENT_STOPPED;
+                event  = VIR_DOMAIN_EVENT_STOPPED;
                 detail = VIR_DOMAIN_EVENT_STOPPED_CRASHED;
             } else if (state == MachineState_Saving) {
-                event = VIR_DOMAIN_EVENT_STOPPED;
+                event  = VIR_DOMAIN_EVENT_STOPPED;
                 detail = VIR_DOMAIN_EVENT_STOPPED_SAVED;
             } else {
-                event = VIR_DOMAIN_EVENT_STOPPED;
+                event  = VIR_DOMAIN_EVENT_STOPPED;
                 detail = VIR_DOMAIN_EVENT_STOPPED_SHUTDOWN;
             }
 
@@ -1525,8 +1536,8 @@ vboxCallbackOnMachineRegistered(IVirtualBoxCallback *pThis ATTRIBUTE_UNUSED,
                                 PRUnichar *machineId, PRBool registered)
 {
     virDomainPtr dom = NULL;
-    int event = 0;
-    int detail = 0;
+    int event        = 0;
+    int detail       = 0;
 
     vboxDriverLock(g_pVBoxGlobalData);
 
@@ -1534,7 +1545,7 @@ vboxCallbackOnMachineRegistered(IVirtualBoxCallback *pThis ATTRIBUTE_UNUSED,
     DEBUGPRUnichar("machineId", machineId);
 
     if (machineId) {
-        char *machineIdUtf8 = NULL;
+        char *machineIdUtf8       = NULL;
         unsigned char uuid[VIR_UUID_BUFLEN];
 
         g_pVBoxGlobalData->pFuncs->pfnUtf16ToUtf8(machineId, &machineIdUtf8);
@@ -1551,10 +1562,10 @@ vboxCallbackOnMachineRegistered(IVirtualBoxCallback *pThis ATTRIBUTE_UNUSED,
              * to show the VIR_DOMAIN_EVENT_UNDEFINED event
              */
             if (registered) {
-                event = VIR_DOMAIN_EVENT_DEFINED;
+                event  = VIR_DOMAIN_EVENT_DEFINED;
                 detail = VIR_DOMAIN_EVENT_DEFINED_ADDED;
             } else {
-                event = VIR_DOMAIN_EVENT_UNDEFINED;
+                event  = VIR_DOMAIN_EVENT_UNDEFINED;
                 detail = VIR_DOMAIN_EVENT_UNDEFINED_REMOVED;
             }
 
@@ -1750,7 +1761,7 @@ vboxConnectDomainEventRegister(virConnectPtr conn,
                                virFreeCallback freecb)
 {
     vboxGlobalData *data = conn->privateData;
-    int vboxRet = -1;
+    int vboxRet          = -1;
     nsresult rc;
     int ret = -1;
 
@@ -1854,7 +1865,7 @@ static int vboxConnectDomainEventRegisterAny(virConnectPtr conn,
                                              virFreeCallback freecb)
 {
     vboxGlobalData *data = conn->privateData;
-    int vboxRet = -1;
+    int vboxRet          = -1;
     nsresult rc;
     int ret = -1;
 
@@ -2160,26 +2171,26 @@ _dumpIDEHDDsOld(virDomainDefPtr def,
                 vboxGlobalData *data,
                 IMachine *machine)
 {
-    PRInt32 hddNum = 0;
-    IHardDisk *hardDiskPM = NULL;
-    IHardDisk *hardDiskPS = NULL;
-    IHardDisk *hardDiskSS = NULL;
-    const char *hddBus = "IDE";
-    PRUnichar *hddBusUtf16 = NULL;
+    PRInt32       hddNum                = 0;
+    IHardDisk    *hardDiskPM            = NULL;
+    IHardDisk    *hardDiskPS            = NULL;
+    IHardDisk    *hardDiskSS            = NULL;
+    const char   *hddBus                = "IDE";
+    PRUnichar    *hddBusUtf16           = NULL;
 
     /* dump IDE hdds if present */
     VBOX_UTF8_TO_UTF16(hddBus, &hddBusUtf16);
 
     def->ndisks = 0;
-    machine->vtbl->GetHardDisk(machine, hddBusUtf16, 0, 0, &hardDiskPM);
+    machine->vtbl->GetHardDisk(machine, hddBusUtf16, 0, 0,  &hardDiskPM);
     if (hardDiskPM)
         def->ndisks++;
 
-    machine->vtbl->GetHardDisk(machine, hddBusUtf16, 0, 1, &hardDiskPS);
+    machine->vtbl->GetHardDisk(machine, hddBusUtf16, 0, 1,  &hardDiskPS);
     if (hardDiskPS)
         def->ndisks++;
 
-    machine->vtbl->GetHardDisk(machine, hddBusUtf16, 1, 1, &hardDiskSS);
+    machine->vtbl->GetHardDisk(machine, hddBusUtf16, 1, 1,  &hardDiskSS);
     if (hardDiskSS)
         def->ndisks++;
 
@@ -2199,8 +2210,8 @@ _dumpIDEHDDsOld(virDomainDefPtr def,
 
     if (hardDiskPM) {
         PRUnichar *hddlocationUtf16 = NULL;
-        char *hddlocation = NULL;
-        PRUint32 hddType = HardDiskType_Normal;
+        char *hddlocation           = NULL;
+        PRUint32 hddType            = HardDiskType_Normal;
 
         hardDiskPM->vtbl->imedium.GetLocation((IMedium *)hardDiskPM, &hddlocationUtf16);
         VBOX_UTF16_TO_UTF8(hddlocationUtf16, &hddlocation);
@@ -2221,8 +2232,8 @@ _dumpIDEHDDsOld(virDomainDefPtr def,
 
     if (hardDiskPS) {
         PRUnichar *hddlocationUtf16 = NULL;
-        char *hddlocation = NULL;
-        PRUint32 hddType = HardDiskType_Normal;
+        char *hddlocation           = NULL;
+        PRUint32 hddType            = HardDiskType_Normal;
 
         hardDiskPS->vtbl->imedium.GetLocation((IMedium *)hardDiskPS, &hddlocationUtf16);
         VBOX_UTF16_TO_UTF8(hddlocationUtf16, &hddlocation);
@@ -2243,8 +2254,8 @@ _dumpIDEHDDsOld(virDomainDefPtr def,
 
     if (hardDiskSS) {
         PRUnichar *hddlocationUtf16 = NULL;
-        char *hddlocation = NULL;
-        PRUint32 hddType = HardDiskType_Normal;
+        char *hddlocation           = NULL;
+        PRUint32 hddType            = HardDiskType_Normal;
 
         hardDiskSS->vtbl->imedium.GetLocation((IMedium *)hardDiskSS, &hddlocationUtf16);
         VBOX_UTF16_TO_UTF8(hddlocationUtf16, &hddlocation);
@@ -2269,10 +2280,10 @@ _dumpDVD(virDomainDefPtr def,
          vboxGlobalData *data,
          IMachine *machine)
 {
-    IDVDDrive *dvdDrive = NULL;
-    IDVDImage *dvdImage = NULL;
+    IDVDDrive *dvdDrive      = NULL;
+    IDVDImage *dvdImage      = NULL;
     PRUnichar *locationUtf16 = NULL;
-    char *location = NULL;
+    char *location           = NULL;
 
 
     /* dump CDROM/DVD if the drive is attached and has DVD/CD in it */
@@ -2323,8 +2334,8 @@ _dumpDVD(virDomainDefPtr def,
 static int
 _attachDVD(vboxGlobalData *data, IMachine *machine, const char *src)
 {
-    IDVDDrive *dvdDrive = NULL;
-    IDVDImage *dvdImage = NULL;
+    IDVDDrive *dvdDrive     = NULL;
+    IDVDImage *dvdImage     = NULL;
     PRUnichar *dvdfileUtf16 = NULL;
     vboxIID dvduuid = VBOX_IID_INITIALIZER;
     vboxIID dvdemptyuuid = VBOX_IID_INITIALIZER;
@@ -2410,10 +2421,10 @@ _dumpFloppy(virDomainDefPtr def,
 {
     IFloppyDrive *floppyDrive = NULL;
     IFloppyImage *floppyImage = NULL;
-    PRUnichar *locationUtf16 = NULL;
-    char *location = NULL;
-    PRBool enabled = PR_FALSE;
-    PRUint32 state = DriveState_Null;
+    PRUnichar *locationUtf16  = NULL;
+    char *location            = NULL;
+    PRBool enabled            = PR_FALSE;
+    PRUint32 state            = DriveState_Null;
 
     /* dump Floppy if the drive is attached and has floppy in it */
     machine->vtbl->GetFloppyDrive(machine, &floppyDrive);
@@ -2466,8 +2477,8 @@ static int
 _attachFloppy(vboxGlobalData *data, IMachine *machine, const char *src)
 {
     IFloppyDrive *floppyDrive;
-    IFloppyImage *floppyImage = NULL;
-    PRUnichar *fdfileUtf16 = NULL;
+    IFloppyImage *floppyImage   = NULL;
+    PRUnichar *fdfileUtf16      = NULL;
     vboxIID fduuid = VBOX_IID_INITIALIZER;
     vboxIID fdemptyuuid = VBOX_IID_INITIALIZER;
     nsresult rc;
@@ -2812,7 +2823,7 @@ _virtualboxCreateMachine(vboxGlobalData *data, virDomainDefPtr def, IMachine **m
 {
     vboxIID iid = VBOX_IID_INITIALIZER;
     PRUnichar *machineNameUtf16 = NULL;
-    nsresult rc = -1;
+    nsresult rc;
 
     VBOX_UTF8_TO_UTF16(def->name, &machineNameUtf16);
     vboxIIDFromUUID(&iid, def->uuid);
@@ -2825,7 +2836,7 @@ _virtualboxCreateMachine(vboxGlobalData *data, virDomainDefPtr def, IMachine **m
                                                     iid.value,
                                                     machine);
 #elif VBOX_API_VERSION < 4000000 /* 3002000 <= VBOX_API_VERSION < 4000000 */
-        PRBool override = PR_FALSE;
+        PRBool override             = PR_FALSE;
         rc = data->vboxObj->vtbl->CreateMachine(data->vboxObj,
                                                 machineNameUtf16,
                                                 NULL,
@@ -2834,7 +2845,7 @@ _virtualboxCreateMachine(vboxGlobalData *data, virDomainDefPtr def, IMachine **m
                                                 override,
                                                 machine);
 #elif VBOX_API_VERSION >= 4000000 && VBOX_API_VERSION < 4002000
-        PRBool override = PR_FALSE;
+        PRBool override             = PR_FALSE;
         rc = data->vboxObj->vtbl->CreateMachine(data->vboxObj,
                                                 NULL,
                                                 machineNameUtf16,
@@ -2843,12 +2854,18 @@ _virtualboxCreateMachine(vboxGlobalData *data, virDomainDefPtr def, IMachine **m
                                                 override,
                                                 machine);
 #else /* VBOX_API_VERSION >= 4002000 */
-        char *createFlags = NULL;
+        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;
 
-        if (virAsprintf(&createFlags,
-                        "UUID=%s,forceOverwrite=0", uuidstr) < 0)
-            goto cleanup;
+        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,
@@ -2858,8 +2875,6 @@ _virtualboxCreateMachine(vboxGlobalData *data, virDomainDefPtr def, IMachine **m
                                                 nsnull,
                                                 createFlagsUtf16,
                                                 machine);
- cleanup:
-        VIR_FREE(createFlags);
 #endif /* VBOX_API_VERSION >= 4002000 */
     }
     VBOX_UTF16_FREE(machineNameUtf16);
@@ -2874,7 +2889,12 @@ _virtualboxCreateHardDisk(IVirtualBox *vboxObj, PRUnichar *format,
     /* In vbox 2.2 and 3.0, this function will create a IHardDisk object.
      * In vbox 3.1 and later, this function will create a IMedium object.
      */
+#if VBOX_API_VERSION < 5000000
     return vboxObj->vtbl->CreateHardDisk(vboxObj, format, location, hardDisk);
+#elif VBOX_API_VERSION >= 5000000 /*VBOX_API_VERSION >= 5000000*/
+    return vboxObj->vtbl->CreateMedium(vboxObj, format, location, AccessMode_ReadWrite, DeviceType_HardDisk, hardDisk);
+#endif /*VBOX_API_VERSION >= 5000000*/
+
 }
 
 static nsresult
@@ -3366,7 +3386,23 @@ _sessionGetMachine(ISession *session, IMachine **machine)
 static nsresult
 _consoleSaveState(IConsole *console, IProgress **progress)
 {
+#if VBOX_API_VERSION < 5000000
     return console->vtbl->SaveState(console, progress);
+#else /*VBOX_API_VERSION < 5000000*/
+    IMachine *machine;
+    nsresult rc;
+
+    rc = console->vtbl->GetMachine(console, &machine);
+
+    if (NS_SUCCEEDED(rc))
+      rc = machine->vtbl->SaveState(machine, progress);
+    else
+      virReportError(VIR_ERR_INTERNAL_ERROR,
+                     _("unable to get machine from console. (error %d)"), rc);
+
+    return rc;
+
+#endif /*VBOX_API_VERSION >= 5000000*/
 }
 
 static nsresult
@@ -3414,7 +3450,25 @@ static nsresult
 _consoleTakeSnapshot(IConsole *console, PRUnichar *name,
                      PRUnichar *description, IProgress **progress)
 {
+#if VBOX_API_VERSION < 5000000
     return console->vtbl->TakeSnapshot(console, name, description, progress);
+#else
+    IMachine *machine;
+    nsresult rc;
+    PRUnichar *id = NULL;
+    bool bpause = true; /*NO live snapshot*/
+
+    rc = console->vtbl->GetMachine(console, &machine);
+
+    if (NS_SUCCEEDED(rc))
+      rc = machine->vtbl->TakeSnapshot(machine, name, description, bpause, &id, progress);
+    else
+      virReportError(VIR_ERR_INTERNAL_ERROR,
+                     _("unable to get machine from console. (error %d)"), rc);
+
+    VBOX_RELEASE(machine);
+    return rc;
+#endif /* VBOX_API_VERSION >= 5000000 */
 }
 
 static nsresult
@@ -3422,9 +3476,24 @@ _consoleDeleteSnapshot(IConsole *console, vboxIIDUnion *iidu, IProgress **progre
 {
 #if VBOX_API_VERSION < 3001000
     return console->vtbl->DiscardSnapshot(console, IID_MEMBER(value), progress);
-#else /* VBOX_API_VERSION >= 3001000 */
+#elif VBOX_API_VERSION >= 3001000 && VBOX_API_VERSION < 5000000 /* VBOX_API_VERSION >= 3001000 */
     return console->vtbl->DeleteSnapshot(console, IID_MEMBER(value), progress);
-#endif /* VBOX_API_VERSION >= 3001000 */
+#else /* VBOX_API_VERSION >= 5000000 */
+    IMachine *machine;
+    nsresult rc;
+
+    rc = console->vtbl->GetMachine(console, &machine);
+
+    if (NS_SUCCEEDED(rc))
+      rc = machine->vtbl->DeleteSnapshot(machine, IID_MEMBER(value), progress);
+    else
+      virReportError(VIR_ERR_INTERNAL_ERROR,
+                     _("unable to get machine from console. (error %d)"), rc);
+
+    VBOX_RELEASE(machine);
+
+    return rc;
+#endif /* VBOX_API_VERSION >= 5000000 */
 }
 
 static nsresult
@@ -4342,11 +4411,18 @@ _displayGetScreenResolution(IDisplay *display ATTRIBUTE_UNUSED,
 #elif VBOX_API_VERSION < 4003000
     return display->vtbl->GetScreenResolution(display, screenId, width,
                                               height, bitsPerPixel);
-#else /* VBOX_API_VERSION >= 4003000 */
+#elif VBOX_API_VERSION < 5000000 /* VBOX_API_VERSION >= 4003000 */
     return display->vtbl->GetScreenResolution(display, screenId, width,
                                               height, bitsPerPixel,
                                               xOrigin, yOrigin);
-#endif /* VBOX_API_VERSION >= 4003000 */
+#else /*VBOX_API_VERSION >= 5000000 */
+    PRUint32 gms;
+
+    return display->vtbl->GetScreenResolution(display, screenId, width,
+                                              height, bitsPerPixel,
+                                              xOrigin, yOrigin, &gms);
+#endif /* VBOX_API_VERSION >= 5000000 */
+
 }
 
 static nsresult
@@ -4357,10 +4433,10 @@ _displayTakeScreenShotPNGToArray(IDisplay *display ATTRIBUTE_UNUSED,
                                  PRUint32 *screenDataSize ATTRIBUTE_UNUSED,
                                  PRUint8** screenData ATTRIBUTE_UNUSED)
 {
-#if VBOX_API_VERSION < 4000000
+#if VBOX_API_VERSION < 4000000 || VBOX_API_VERSION >= 5000000
     vboxUnsupported();
     return 0;
-#else /* VBOX_API_VERSION >= 4000000 */
+#else /* VBOX_API_VERSION >= 4000000 && VBOX_API_VERSION < 5000000 */
     return display->vtbl->TakeScreenShotPNGToArray(display, screenId, width,
                                                    height, screenDataSize,
                                                    screenData);
-- 
2.7.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux