vbox: Cleanup/prepare snasphot dumpxml functions

This patch prepares the vboxSnapshotGetReadOnlyDisks and
vboxSnapshotGetReadWriteDisks functions for further changes so that
the code movement does not obstruct the gist of those future changes.
This is done primarily because we'll need to know the type of vbox
storage controller as early as possible and make decisions based on
that info.
This commit is contained in:
Dawid Zamirski 2017-11-07 13:49:22 -05:00 committed by John Ferlan
parent c27f79a895
commit 60c519ee24

View File

@ -5653,8 +5653,9 @@ vboxDomainSnapshotGet(vboxDriverPtr data,
return snapshot; return snapshot;
} }
static int vboxSnapshotGetReadWriteDisks(virDomainSnapshotDefPtr def, static int
virDomainSnapshotPtr snapshot) vboxSnapshotGetReadWriteDisks(virDomainSnapshotDefPtr def,
virDomainSnapshotPtr snapshot)
{ {
virDomainPtr dom = snapshot->domain; virDomainPtr dom = snapshot->domain;
vboxDriverPtr data = dom->conn->privateData; vboxDriverPtr data = dom->conn->privateData;
@ -5755,26 +5756,72 @@ static int vboxSnapshotGetReadWriteDisks(virDomainSnapshotDefPtr def,
void *handle; void *handle;
size_t j = 0; size_t j = 0;
size_t k = 0; size_t k = 0;
if (!imediumattach) if (!imediumattach)
continue; continue;
rc = gVBoxAPI.UIMediumAttachment.GetController(imediumattach,
&storageControllerName);
if (NS_FAILED(rc)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Cannot get storage controller name"));
goto cleanup;
}
rc = gVBoxAPI.UIMachine.GetStorageControllerByName(machine,
storageControllerName,
&storageController);
VBOX_UTF16_FREE(storageControllerName);
if (NS_FAILED(rc)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Cannot get storage controller by name"));
goto cleanup;
}
rc = gVBoxAPI.UIStorageController.GetBus(storageController, &storageBus);
if (NS_FAILED(rc)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Cannot get storage controller bus"));
VBOX_RELEASE(storageController);
goto cleanup;
}
rc = gVBoxAPI.UIMediumAttachment.GetType(imediumattach, &deviceType);
if (NS_FAILED(rc)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Cannot get medium attachment type"));
VBOX_RELEASE(storageController);
goto cleanup;
}
rc = gVBoxAPI.UIMediumAttachment.GetPort(imediumattach, &devicePort);
if (NS_FAILED(rc)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Cannot get medium attachment port"));
VBOX_RELEASE(storageController);
goto cleanup;
}
rc = gVBoxAPI.UIMediumAttachment.GetDevice(imediumattach, &deviceSlot);
if (NS_FAILED(rc)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Cannot get medium attachment slot"));
VBOX_RELEASE(storageController);
goto cleanup;
}
rc = gVBoxAPI.UIMediumAttachment.GetMedium(imediumattach, &disk); rc = gVBoxAPI.UIMediumAttachment.GetMedium(imediumattach, &disk);
if (NS_FAILED(rc)) { if (NS_FAILED(rc)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("cannot get medium")); _("Cannot get medium"));
VBOX_RELEASE(storageController);
goto cleanup; goto cleanup;
} }
if (!disk)
continue; /* skip empty removable disk */
rc = gVBoxAPI.UIMediumAttachment.GetController(imediumattach, &storageControllerName); if (!disk) {
if (NS_FAILED(rc)) { VBOX_RELEASE(storageController);
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("cannot get controller"));
goto cleanup;
}
if (!storageControllerName) {
VBOX_RELEASE(disk);
continue; continue;
} }
handle = gVBoxAPI.UArray.handleMediumGetChildren(disk); handle = gVBoxAPI.UArray.handleMediumGetChildren(disk);
rc = gVBoxAPI.UArray.vboxArrayGet(&children, disk, handle); rc = gVBoxAPI.UArray.vboxArrayGet(&children, disk, handle);
if (NS_FAILED(rc)) { if (NS_FAILED(rc)) {
@ -5797,53 +5844,25 @@ static int vboxSnapshotGetReadWriteDisks(virDomainSnapshotDefPtr def,
char *diskSnapIdStr = NULL; char *diskSnapIdStr = NULL;
VBOX_UTF16_TO_UTF8(diskSnapId, &diskSnapIdStr); VBOX_UTF16_TO_UTF8(diskSnapId, &diskSnapIdStr);
if (STREQ(diskSnapIdStr, snapshotUuidStr)) { if (STREQ(diskSnapIdStr, snapshotUuidStr)) {
rc = gVBoxAPI.UIMachine.GetStorageControllerByName(machine,
storageControllerName,
&storageController);
VBOX_UTF16_FREE(storageControllerName);
if (!storageController) {
VBOX_RELEASE(child);
break;
}
rc = gVBoxAPI.UIMedium.GetLocation(child, &childLocUtf16); rc = gVBoxAPI.UIMedium.GetLocation(child, &childLocUtf16);
if (NS_FAILED(rc)) { if (NS_FAILED(rc)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("cannot get disk location")); _("cannot get disk location"));
VBOX_RELEASE(storageController);
VBOX_RELEASE(disk);
VBOX_RELEASE(child);
goto cleanup; goto cleanup;
} }
VBOX_UTF16_TO_UTF8(childLocUtf16, &childLocUtf8); VBOX_UTF16_TO_UTF8(childLocUtf16, &childLocUtf8);
VBOX_UTF16_FREE(childLocUtf16); VBOX_UTF16_FREE(childLocUtf16);
if (VIR_STRDUP(def->disks[diskCount].src->path, childLocUtf8) < 0) { if (VIR_STRDUP(def->disks[diskCount].src->path, childLocUtf8) < 0) {
VBOX_RELEASE(child);
VBOX_RELEASE(storageController); VBOX_RELEASE(storageController);
VBOX_RELEASE(disk);
VBOX_RELEASE(child);
goto cleanup; goto cleanup;
} }
VBOX_UTF8_FREE(childLocUtf8); VBOX_UTF8_FREE(childLocUtf8);
rc = gVBoxAPI.UIStorageController.GetBus(storageController, &storageBus);
if (NS_FAILED(rc)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("cannot get storage controller bus"));
goto cleanup;
}
rc = gVBoxAPI.UIMediumAttachment.GetType(imediumattach, &deviceType);
if (NS_FAILED(rc)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("cannot get medium attachment type"));
goto cleanup;
}
rc = gVBoxAPI.UIMediumAttachment.GetPort(imediumattach, &devicePort);
if (NS_FAILED(rc)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("cannot get medium attachment type"));
goto cleanup;
}
rc = gVBoxAPI.UIMediumAttachment.GetDevice(imediumattach, &deviceSlot);
if (NS_FAILED(rc)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("cannot get medium attachment device"));
goto cleanup;
}
def->disks[diskCount].src->type = VIR_STORAGE_TYPE_FILE; def->disks[diskCount].src->type = VIR_STORAGE_TYPE_FILE;
def->disks[diskCount].name = vboxGenerateMediumName(storageBus, def->disks[diskCount].name = vboxGenerateMediumName(storageBus,
deviceInst, deviceInst,
@ -5862,6 +5881,7 @@ static int vboxSnapshotGetReadWriteDisks(virDomainSnapshotDefPtr def,
gVBoxAPI.UArray.vboxArrayRelease(&mediumAttachments); gVBoxAPI.UArray.vboxArrayRelease(&mediumAttachments);
ret = 0; ret = 0;
cleanup: cleanup:
if (ret < 0) { if (ret < 0) {
for (i = 0; i < def->ndisks; i++) for (i = 0; i < def->ndisks; i++)
@ -5873,9 +5893,9 @@ static int vboxSnapshotGetReadWriteDisks(virDomainSnapshotDefPtr def,
return ret; return ret;
} }
static static int
int vboxSnapshotGetReadOnlyDisks(virDomainSnapshotPtr snapshot, vboxSnapshotGetReadOnlyDisks(virDomainSnapshotPtr snapshot,
virDomainSnapshotDefPtr def) virDomainSnapshotDefPtr def)
{ {
virDomainPtr dom = snapshot->domain; virDomainPtr dom = snapshot->domain;
vboxDriverPtr data = dom->conn->privateData; vboxDriverPtr data = dom->conn->privateData;
@ -5970,18 +5990,10 @@ int vboxSnapshotGetReadOnlyDisks(virDomainSnapshotPtr snapshot,
IMediumAttachment *imediumattach = mediumAttachments.items[i]; IMediumAttachment *imediumattach = mediumAttachments.items[i];
if (!imediumattach) if (!imediumattach)
continue; continue;
rc = gVBoxAPI.UIMediumAttachment.GetMedium(imediumattach, &disk);
if (NS_FAILED(rc)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("cannot get medium"));
goto cleanup;
}
if (!disk)
continue;
rc = gVBoxAPI.UIMediumAttachment.GetController(imediumattach, &storageControllerName); rc = gVBoxAPI.UIMediumAttachment.GetController(imediumattach, &storageControllerName);
if (NS_FAILED(rc)) { if (NS_FAILED(rc)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("cannot get storage controller name")); _("Cannot get storage controller name"));
goto cleanup; goto cleanup;
} }
if (!storageControllerName) if (!storageControllerName)
@ -5989,18 +6001,50 @@ int vboxSnapshotGetReadOnlyDisks(virDomainSnapshotPtr snapshot,
rc = gVBoxAPI.UIMachine.GetStorageControllerByName(machine, rc = gVBoxAPI.UIMachine.GetStorageControllerByName(machine,
storageControllerName, storageControllerName,
&storageController); &storageController);
VBOX_UTF16_FREE(storageControllerName);
if (NS_FAILED(rc)) { if (NS_FAILED(rc)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("cannot get storage controller")); _("Cannot get storage controller"));
goto cleanup; goto cleanup;
} }
VBOX_UTF16_FREE(storageControllerName);
if (!storageController) if (!storageController)
continue; continue;
rc = gVBoxAPI.UIStorageController.GetBus(storageController, &storageBus);
if (NS_FAILED(rc)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Cannot get storage controller bus"));
goto cleanup;
}
rc = gVBoxAPI.UIMediumAttachment.GetPort(imediumattach, &devicePort);
if (NS_FAILED(rc)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Cannot get medium attachment port"));
goto cleanup;
}
rc = gVBoxAPI.UIMediumAttachment.GetDevice(imediumattach, &deviceSlot);
if (NS_FAILED(rc)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Cannot get device slot"));
goto cleanup;
}
rc = gVBoxAPI.UIMediumAttachment.GetMedium(imediumattach, &disk);
if (NS_FAILED(rc)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Cannot get medium"));
goto cleanup;
}
/* skip empty removable disk */
if (!disk) {
VBOX_RELEASE(storageController);
continue;
}
rc = gVBoxAPI.UIMedium.GetLocation(disk, &mediumLocUtf16); rc = gVBoxAPI.UIMedium.GetLocation(disk, &mediumLocUtf16);
if (NS_FAILED(rc)) { if (NS_FAILED(rc)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("cannot get disk location")); _("Cannot get disk location"));
goto cleanup; goto cleanup;
} }
VBOX_UTF16_TO_UTF8(mediumLocUtf16, &mediumLocUtf8); VBOX_UTF16_TO_UTF8(mediumLocUtf16, &mediumLocUtf8);
@ -6009,11 +6053,10 @@ int vboxSnapshotGetReadOnlyDisks(virDomainSnapshotPtr snapshot,
goto cleanup; goto cleanup;
VBOX_UTF8_FREE(mediumLocUtf8); VBOX_UTF8_FREE(mediumLocUtf8);
rc = gVBoxAPI.UIMedium.GetReadOnly(disk, &readOnly);
rc = gVBoxAPI.UIStorageController.GetBus(storageController, &storageBus);
if (NS_FAILED(rc)) { if (NS_FAILED(rc)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("cannot get storage controller bus")); _("Cannot get read only attribute"));
goto cleanup; goto cleanup;
} }
if (storageBus == StorageBus_IDE) { if (storageBus == StorageBus_IDE) {
@ -6039,24 +6082,6 @@ int vboxSnapshotGetReadOnlyDisks(virDomainSnapshotPtr snapshot,
else if (deviceType == DeviceType_DVD) else if (deviceType == DeviceType_DVD)
def->dom->disks[diskCount]->device = VIR_DOMAIN_DISK_DEVICE_CDROM; def->dom->disks[diskCount]->device = VIR_DOMAIN_DISK_DEVICE_CDROM;
rc = gVBoxAPI.UIMediumAttachment.GetPort(imediumattach, &devicePort);
if (NS_FAILED(rc)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("cannot get medium attachment port"));
goto cleanup;
}
rc = gVBoxAPI.UIMediumAttachment.GetDevice(imediumattach, &deviceSlot);
if (NS_FAILED(rc)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("cannot get device"));
goto cleanup;
}
rc = gVBoxAPI.UIMedium.GetReadOnly(disk, &readOnly);
if (NS_FAILED(rc)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("cannot get read only attribute"));
goto cleanup;
}
if (readOnly == PR_TRUE) if (readOnly == PR_TRUE)
def->dom->disks[diskCount]->src->readonly = true; def->dom->disks[diskCount]->src->readonly = true;
def->dom->disks[diskCount]->src->type = VIR_STORAGE_TYPE_FILE; def->dom->disks[diskCount]->src->type = VIR_STORAGE_TYPE_FILE;
@ -6076,9 +6101,9 @@ int vboxSnapshotGetReadOnlyDisks(virDomainSnapshotPtr snapshot,
} }
diskCount ++; diskCount ++;
} }
/* cleanup on error */
ret = 0; ret = 0;
cleanup: cleanup:
if (ret < 0) { if (ret < 0) {
for (i = 0; i < def->dom->ndisks; i++) for (i = 0; i < def->dom->ndisks; i++)