qemu: domain: Clarify temp variable scope in qemuDomainDetermineDiskChain

The function at first validates the top image of the chain, then
traverses the chain as declared in the XML (if any) and then procedes to
detect the rest of the chain from images. All of the steps have their
own temporary iterator.

Clarify the use scope of the steps by introducing a new temp variable
holding the top level source and adding comments.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
Peter Krempa 2019-01-16 15:17:24 +01:00
parent adb15b5add
commit 73163a0e86

View File

@ -8998,48 +8998,50 @@ qemuDomainDetermineDiskChain(virQEMUDriverPtr driver,
bool report_broken) bool report_broken)
{ {
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
virStorageSourcePtr src = disk->src; virStorageSourcePtr disksrc = disk->src; /* disk source */
virStorageSourcePtr n; virStorageSourcePtr src; /* iterator for the backing chain declared in XML */
virStorageSourcePtr n; /* iterator for the backing chain detected from disk */
qemuDomainObjPrivatePtr priv = vm->privateData; qemuDomainObjPrivatePtr priv = vm->privateData;
int ret = -1; int ret = -1;
uid_t uid; uid_t uid;
gid_t gid; gid_t gid;
if (virStorageSourceIsEmpty(src)) { if (virStorageSourceIsEmpty(disksrc)) {
ret = 0; ret = 0;
goto cleanup; goto cleanup;
} }
/* There is no need to check the backing chain for disks without backing /* There is no need to check the backing chain for disks without backing
* support */ * support */
if (virStorageSourceIsLocalStorage(src) && if (virStorageSourceIsLocalStorage(disksrc) &&
src->format > VIR_STORAGE_FILE_NONE && disksrc->format > VIR_STORAGE_FILE_NONE &&
src->format < VIR_STORAGE_FILE_BACKING) { disksrc->format < VIR_STORAGE_FILE_BACKING) {
if (!virFileExists(src->path)) { if (!virFileExists(disksrc->path)) {
if (report_broken) if (report_broken)
virStorageFileReportBrokenChain(errno, src, disk->src); virStorageFileReportBrokenChain(errno, disksrc, disksrc);
goto cleanup; goto cleanup;
} }
/* terminate the chain for such images as the code below would do */ /* terminate the chain for such images as the code below would do */
if (!src->backingStore && if (!disksrc->backingStore &&
VIR_ALLOC(src->backingStore) < 0) VIR_ALLOC(disksrc->backingStore) < 0)
goto cleanup; goto cleanup;
/* host cdrom requires special treatment in qemu, so we need to check /* host cdrom requires special treatment in qemu, so we need to check
* whether a block device is a cdrom */ * whether a block device is a cdrom */
if (disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM && if (disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM &&
src->format == VIR_STORAGE_FILE_RAW && disksrc->format == VIR_STORAGE_FILE_RAW &&
virStorageSourceIsBlockLocal(src) && virStorageSourceIsBlockLocal(disksrc) &&
virFileIsCDROM(src->path) == 1) virFileIsCDROM(disksrc->path) == 1)
src->hostcdrom = true; disksrc->hostcdrom = true;
ret = 0; ret = 0;
goto cleanup; goto cleanup;
} }
src = disksrc;
/* skip to the end of the chain if there is any */ /* skip to the end of the chain if there is any */
while (virStorageSourceHasBacking(src)) { while (virStorageSourceHasBacking(src)) {
if (report_broken) { if (report_broken) {
@ -9049,11 +9051,11 @@ qemuDomainDetermineDiskChain(virQEMUDriverPtr driver,
goto cleanup; goto cleanup;
if (rv > 0) { if (rv > 0) {
if (qemuDomainStorageFileInit(driver, vm, src, disk->src) < 0) if (qemuDomainStorageFileInit(driver, vm, src, disksrc) < 0)
goto cleanup; goto cleanup;
if (virStorageFileAccess(src, F_OK) < 0) { if (virStorageFileAccess(src, F_OK) < 0) {
virStorageFileReportBrokenChain(errno, src, disk->src); virStorageFileReportBrokenChain(errno, src, disksrc);
virStorageFileDeinit(src); virStorageFileDeinit(src);
goto cleanup; goto cleanup;
} }
@ -9071,7 +9073,7 @@ qemuDomainDetermineDiskChain(virQEMUDriverPtr driver,
goto cleanup; goto cleanup;
} }
qemuDomainGetImageIds(cfg, vm, src, disk->src, &uid, &gid); qemuDomainGetImageIds(cfg, vm, src, disksrc, &uid, &gid);
if (virStorageFileGetMetadata(src, uid, gid, report_broken) < 0) if (virStorageFileGetMetadata(src, uid, gid, report_broken) < 0)
goto cleanup; goto cleanup;