From b19710b9b6039728620a8d557a322ef139529226 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Fri, 24 Nov 2017 12:09:53 +0100 Subject: [PATCH] qemu: domain: Refactor control flow in qemuDomainDetermineDiskChain Split out clearing of the backing chain prior to other code since it will be required later and optimize few layers of nested conditions and loops. --- src/qemu/qemu_domain.c | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index d1e391f481..5dc3d73f48 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -6369,29 +6369,26 @@ qemuDomainDetermineDiskChain(virQEMUDriverPtr driver, goto cleanup; } - if (virStorageSourceHasBacking(src)) { - if (force_probe) { - virStorageSourceBackingStoreClear(src); - } else { - /* skip to the end of the chain */ - while (virStorageSourceIsBacking(src)) { - if (report_broken && - virStorageFileSupportsAccess(src)) { - - if (qemuDomainStorageFileInit(driver, vm, src, disk->src) < 0) - goto cleanup; - - if (virStorageFileAccess(src, F_OK) < 0) { - virStorageFileReportBrokenChain(errno, src, disk->src); - virStorageFileDeinit(src); - goto cleanup; - } + if (force_probe) + virStorageSourceBackingStoreClear(src); - virStorageFileDeinit(src); - } - src = src->backingStore; + /* skip to the end of the chain if there is any */ + while (virStorageSourceHasBacking(src)) { + if (report_broken && + virStorageFileSupportsAccess(src)) { + + if (qemuDomainStorageFileInit(driver, vm, src, disk->src) < 0) + goto cleanup; + + if (virStorageFileAccess(src, F_OK) < 0) { + virStorageFileReportBrokenChain(errno, src, disk->src); + virStorageFileDeinit(src); + goto cleanup; } + + virStorageFileDeinit(src); } + src = src->backingStore; } /* We skipped to the end of the chain. Skip detection if there's the -- 2.47.2