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; size_t i;
virStorageSourcePtr tmp = NULL; virStorageSourcePtr tmp = NULL;
if (src) if (!src)
*src = NULL; src = &tmp;
for (i = 0; i < def->ndisks; i++) { for (i = 0; i < def->ndisks; i++) {
if ((tmp = virStorageSourceFindByNodeName(def->disks[i]->src, nodename))) { virDomainDiskDefPtr domdisk = def->disks[i];
if (src)
*src = tmp;
return def->disks[i]; if ((*src = virStorageSourceFindByNodeName(domdisk->src, nodename)))
} return domdisk;
if (def->disks[i]->mirror && if (domdisk->mirror &&
(tmp = virStorageSourceFindByNodeName(def->disks[i]->mirror, nodename))) { (*src = virStorageSourceFindByNodeName(domdisk->mirror, nodename)))
if (src) return domdisk;
*src = tmp;
return def->disks[i];
}
} }
return NULL; return NULL;