1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-20 07:59:00 +00:00

vbox: Rename vboxDumpIDEHDDs to vboxDumpDisks

Because it deals with other disk types as well not just IDE. Also this
function now returns -1 on error
This commit is contained in:
Dawid Zamirski 2017-11-07 13:49:21 -05:00 committed by John Ferlan
parent 8339d273bb
commit c27f79a895

View File

@ -3254,13 +3254,11 @@ vboxDumpStorageControllers(virDomainDefPtr def, IMachine *machine)
} }
static void static int
vboxDumpIDEHDDs(virDomainDefPtr def, vboxDriverPtr data, IMachine *machine) vboxDumpDisks(virDomainDefPtr def, vboxDriverPtr data, IMachine *machine)
{ {
/* dump IDE hdds if present */
vboxArray mediumAttachments = VBOX_ARRAY_INITIALIZER; vboxArray mediumAttachments = VBOX_ARRAY_INITIALIZER;
bool error = false; int ret = -1, diskCount = 0;
int diskCount = 0;
size_t i; size_t i;
PRUint32 maxPortPerInst[StorageBus_Floppy + 1] = {}; PRUint32 maxPortPerInst[StorageBus_Floppy + 1] = {};
PRUint32 maxSlotPerPort[StorageBus_Floppy + 1] = {}; PRUint32 maxSlotPerPort[StorageBus_Floppy + 1] = {};
@ -3284,24 +3282,22 @@ vboxDumpIDEHDDs(virDomainDefPtr def, vboxDriverPtr data, IMachine *machine)
} }
/* Allocate mem, if fails return error */ /* Allocate mem, if fails return error */
if (VIR_ALLOC_N(def->disks, def->ndisks) >= 0) { if (VIR_ALLOC_N(def->disks, def->ndisks) < 0)
for (i = 0; i < def->ndisks; i++) { goto cleanup;
virDomainDiskDefPtr disk = virDomainDiskDefNew(NULL);
if (!disk) { for (i = 0; i < def->ndisks; i++) {
error = true; virDomainDiskDefPtr disk = virDomainDiskDefNew(NULL);
break; if (!disk)
} goto cleanup;
def->disks[i] = disk;
} def->disks[i] = disk;
} else {
error = true;
} }
if (!error) if (!vboxGetMaxPortSlotValues(data->vboxObj, maxPortPerInst, maxSlotPerPort))
error = !vboxGetMaxPortSlotValues(data->vboxObj, maxPortPerInst, maxSlotPerPort); goto cleanup;
/* get the attachment details here */ /* get the attachment details here */
for (i = 0; i < mediumAttachments.count && diskCount < def->ndisks && !error; i++) { for (i = 0; i < mediumAttachments.count && diskCount < def->ndisks; i++) {
IMediumAttachment *imediumattach = mediumAttachments.items[i]; IMediumAttachment *imediumattach = mediumAttachments.items[i];
IStorageController *storageController = NULL; IStorageController *storageController = NULL;
PRUnichar *storageControllerName = NULL; PRUnichar *storageControllerName = NULL;
@ -3347,8 +3343,8 @@ vboxDumpIDEHDDs(virDomainDefPtr def, vboxDriverPtr data, IMachine *machine)
if (!virDomainDiskGetSource(def->disks[diskCount])) { if (!virDomainDiskGetSource(def->disks[diskCount])) {
VBOX_RELEASE(medium); VBOX_RELEASE(medium);
VBOX_RELEASE(storageController); VBOX_RELEASE(storageController);
error = true;
break; goto cleanup;
} }
gVBoxAPI.UIStorageController.GetBus(storageController, &storageBus); gVBoxAPI.UIStorageController.GetBus(storageController, &storageBus);
@ -3385,8 +3381,8 @@ vboxDumpIDEHDDs(virDomainDefPtr def, vboxDriverPtr data, IMachine *machine)
deviceInst, devicePort, deviceSlot); deviceInst, devicePort, deviceSlot);
VBOX_RELEASE(medium); VBOX_RELEASE(medium);
VBOX_RELEASE(storageController); VBOX_RELEASE(storageController);
error = true;
break; goto cleanup;
} }
gVBoxAPI.UIMedium.GetReadOnly(medium, &readOnly); gVBoxAPI.UIMedium.GetReadOnly(medium, &readOnly);
@ -3401,15 +3397,12 @@ vboxDumpIDEHDDs(virDomainDefPtr def, vboxDriverPtr data, IMachine *machine)
diskCount++; diskCount++;
} }
ret = 0;
cleanup:
gVBoxAPI.UArray.vboxArrayRelease(&mediumAttachments); gVBoxAPI.UArray.vboxArrayRelease(&mediumAttachments);
/* cleanup on error */ return ret;
if (error) {
for (i = 0; i < def->ndisks; i++)
VIR_FREE(def->disks[i]);
VIR_FREE(def->disks);
def->ndisks = 0;
}
} }
static int static int
@ -4103,8 +4096,8 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags)
goto cleanup; goto cleanup;
if (vboxDumpStorageControllers(def, machine) < 0) if (vboxDumpStorageControllers(def, machine) < 0)
goto cleanup; goto cleanup;
if (vboxDumpDisks(def, data, machine) < 0)
vboxDumpIDEHDDs(def, data, machine); goto cleanup;
vboxDumpSharedFolders(def, data, machine); vboxDumpSharedFolders(def, data, machine);
vboxDumpNetwork(def, data, machine, networkAdapterCount); vboxDumpNetwork(def, data, machine, networkAdapterCount);