commit 19d4e467707e187f6736f24a35f5a51275d869ce Author: Michal Prívozník Date: Thu Jan 28 14:13:32 2021 +0100 conf: Improve virDomainVirtioOptionsCheckABIStability() The virDomainVirtioOptionsCheckABIStability() function is called from various ABI stability check functions. Every caller checks if both old and new definitions have virtio options set and only after that they call the function. This is suboptimal because: a) this check can be done in the function itself (making all callers shorter), b) is inherently wrong, because it doesn't catch case where one definition has virtio options set and the other doesn't. Do proper checks at the beginning of the function and simplify its calls. Signed-off-by: Michal Privoznik Reviewed-by: Ján Tomko Index: libvirt-7.0.0/src/conf/domain_conf.c =================================================================== --- libvirt-7.0.0.orig/src/conf/domain_conf.c +++ libvirt-7.0.0/src/conf/domain_conf.c @@ -21491,6 +21491,15 @@ static bool virDomainVirtioOptionsCheckABIStability(virDomainVirtioOptionsPtr src, virDomainVirtioOptionsPtr dst) { + if (!src && !dst) + return true; + + if (!src || !dst) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Target device virtio options don't match the source")); + return false; + } + if (src->iommu != dst->iommu) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Target device iommu option '%s' does not " @@ -21575,8 +21584,7 @@ virDomainDiskDefCheckABIStability(virDom return false; } - if (src->virtio && dst->virtio && - !virDomainVirtioOptionsCheckABIStability(src->virtio, dst->virtio)) + if (!virDomainVirtioOptionsCheckABIStability(src->virtio, dst->virtio)) return false; if (!virDomainDeviceInfoCheckABIStability(&src->info, &dst->info)) @@ -21635,8 +21643,7 @@ virDomainControllerDefCheckABIStability( } } - if (src->virtio && dst->virtio && - !virDomainVirtioOptionsCheckABIStability(src->virtio, dst->virtio)) + if (!virDomainVirtioOptionsCheckABIStability(src->virtio, dst->virtio)) return false; if (!virDomainDeviceInfoCheckABIStability(&src->info, &dst->info)) @@ -21669,8 +21676,7 @@ virDomainFsDefCheckABIStability(virDomai return false; } - if (src->virtio && dst->virtio && - !virDomainVirtioOptionsCheckABIStability(src->virtio, dst->virtio)) + if (!virDomainVirtioOptionsCheckABIStability(src->virtio, dst->virtio)) return false; if (!virDomainDeviceInfoCheckABIStability(&src->info, &dst->info)) @@ -21718,8 +21724,7 @@ virDomainNetDefCheckABIStability(virDoma return false; } - if (src->virtio && dst->virtio && - !virDomainVirtioOptionsCheckABIStability(src->virtio, dst->virtio)) + if (!virDomainVirtioOptionsCheckABIStability(src->virtio, dst->virtio)) return false; if (!virDomainDeviceInfoCheckABIStability(&src->info, &dst->info)) @@ -21757,8 +21762,7 @@ virDomainInputDefCheckABIStability(virDo return false; } - if (src->virtio && dst->virtio && - !virDomainVirtioOptionsCheckABIStability(src->virtio, dst->virtio)) + if (!virDomainVirtioOptionsCheckABIStability(src->virtio, dst->virtio)) return false; if (!virDomainDeviceInfoCheckABIStability(&src->info, &dst->info)) @@ -21857,8 +21861,7 @@ virDomainVideoDefCheckABIStability(virDo } } - if (src->virtio && dst->virtio && - !virDomainVirtioOptionsCheckABIStability(src->virtio, dst->virtio)) + if (!virDomainVirtioOptionsCheckABIStability(src->virtio, dst->virtio)) return false; if (!virDomainDeviceInfoCheckABIStability(&src->info, &dst->info)) @@ -22071,8 +22074,7 @@ virDomainMemballoonDefCheckABIStability( return false; } - if (src->virtio && dst->virtio && - !virDomainVirtioOptionsCheckABIStability(src->virtio, dst->virtio)) + if (!virDomainVirtioOptionsCheckABIStability(src->virtio, dst->virtio)) return false; if (!virDomainDeviceInfoCheckABIStability(&src->info, &dst->info)) @@ -22094,8 +22096,7 @@ virDomainRNGDefCheckABIStability(virDoma return false; } - if (src->virtio && dst->virtio && - !virDomainVirtioOptionsCheckABIStability(src->virtio, dst->virtio)) + if (!virDomainVirtioOptionsCheckABIStability(src->virtio, dst->virtio)) return false; if (!virDomainDeviceInfoCheckABIStability(&src->info, &dst->info))