qemuDomainDiskLookupByNodename: Simplify node name lookup

Use dummy variable to fill 'src' so that access to it doesn't need to be
conditionalized and use temporary variable for 'disk' rather than
dereferencing the array multiple times.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2020-12-07 12:24:31 +01:00
parent b9dcaede65
commit c3bb2b2d5d

View File

@ -9910,24 +9910,18 @@ qemuDomainDiskLookupByNodename(virDomainDefPtr def,
size_t i;
virStorageSourcePtr tmp = NULL;
if (src)
*src = NULL;
if (!src)
src = &tmp;
for (i = 0; i < def->ndisks; i++) {
if ((tmp = virStorageSourceFindByNodeName(def->disks[i]->src, nodename))) {
if (src)
*src = tmp;
virDomainDiskDefPtr domdisk = def->disks[i];
return def->disks[i];
}
if ((*src = virStorageSourceFindByNodeName(domdisk->src, nodename)))
return domdisk;
if (def->disks[i]->mirror &&
(tmp = virStorageSourceFindByNodeName(def->disks[i]->mirror, nodename))) {
if (src)
*src = tmp;
return def->disks[i];
}
if (domdisk->mirror &&
(*src = virStorageSourceFindByNodeName(domdisk->mirror, nodename)))
return domdisk;
}
return NULL;