From nobody Mon Feb 9 03:48:24 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1633622717; cv=none; d=zohomail.com; s=zohoarc; b=hXZE45aqJ6C3Nk+whTKjMYIli3+CdYgEefU2Ix0Hznk71WqBStRM4uYQnr5EwZXxHujq9bNblPNBZaHB5+ypbH2uxxpbMCufF0wpBAB5eyDkFgTckLFeSKTb++ImGQe24Lcfo1bVX1+FF4/91gCENoGP2N3nmCAhIv1X36ElkY8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1633622717; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=7eBlkHlnJovzAGtvcEg3lVcBrZTM4DOitxfChxcDyA0=; b=NyIBLuprCZflIkk/WMfNwbdtqxAlq8epXLFGchiDNEMwdDkhzeR0f7we8xDPGtrqTbK94FkhQnJjnGTA6o8qpTH2XsUxtlZPCHs+AI/7Wx+jFEjyna9j3+3s39iYGGlbWXnndxq3oFi+jzdCsNxZVXWMhs30lB2gT0Yp5J09kg8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1633622717129314.6485893544193; Thu, 7 Oct 2021 09:05:17 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-575-5z7meGT0No-oaJmZqkSS2w-1; Thu, 07 Oct 2021 12:05:14 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id ECE5111B3062; Thu, 7 Oct 2021 15:47:39 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8281810D5F63; Thu, 7 Oct 2021 15:47:09 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 262FE4EA2F; Thu, 7 Oct 2021 15:47:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 197FJgPv024019 for ; Thu, 7 Oct 2021 11:19:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0DD2B5F4EE; Thu, 7 Oct 2021 15:19:42 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.5]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6E0085F4EA for ; Thu, 7 Oct 2021 15:19:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633622716; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=7eBlkHlnJovzAGtvcEg3lVcBrZTM4DOitxfChxcDyA0=; b=af+FxJeebMHU8HTJ2Ios7gqbnOq1ueBPkS5oFV3pPn3M9N0GhIop2wmOssdcmdunjnaDF6 SiwICZHeEMPZH2E2zAeJzaDg2vJttlqOV5Bu39zo2NzEp34ulOd8dirkpO+p5byLhS7L/n xai8xWs+5+SHsm0dF1Wlo+UFTQ/y4TE= X-MC-Unique: 5z7meGT0No-oaJmZqkSS2w-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 050/103] qemuValidateDomainDeviceDef: Optimize virDomainDeviceInfo validation Date: Thu, 7 Oct 2021 17:17:38 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1633622718961100001 Content-Type: text/plain; charset="utf-8" Commit ffda44030a2 added validation of the 'acpiIndex' field in virDomainDeviceInfo by calling 'virDomainDeviceInfoIterate' from 'qemuValidateDomainDef'. This is overly complicated we have 'qemuValidateDomainDeviceDef' which is already called for every single device so we can avoid the extra loop. Restructure the code by calling 'qemuValidateDomainDeviceInfo' directly from 'qemuValidateDomainDeviceDef' and avoid unnecessary calls to 'virDomainDeviceGetInfo' by calling 'qemuValidateDomainDeviceDefAddress' from 'qemuValidateDomainDeviceInfo' Signed-off-by: Peter Krempa --- src/qemu/qemu_validate.c | 79 ++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 44 deletions(-) diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index e120f3385f..3f76adb586 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -997,33 +997,6 @@ qemuValidateDomainDefPanic(const virDomainDef *def, } -static int -qemuValidateDomainDeviceInfo(virDomainDef *def G_GNUC_UNUSED, - virDomainDeviceDef *dev G_GNUC_UNUSED, - virDomainDeviceInfo *info, - void *opaque) -{ - virQEMUCaps *qemuCaps =3D opaque; - - if (info->acpiIndex) { - if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_ACPI_INDEX)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("ACPI index is not supported with this QEMU")= ); - return -1; - } - - if (info->type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE && - info->type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("ACPI index is only supported for PCI devices= ")); - return -1; - } - } - - return 0; -} - - int qemuValidateLifecycleAction(virDomainLifecycleAction onPoweroff, virDomainLifecycleAction onReboot, @@ -1252,15 +1225,6 @@ qemuValidateDomainDef(const virDomainDef *def, return -1; } - /* Explicitly discarding 'const' from 'def' is ok because - * we know our callback qemuValidateDomainDeviceInfo will - * not modify it - */ - if (virDomainDeviceInfoIterate((virDomainDef *)def, - qemuValidateDomainDeviceInfo, - qemuCaps) < 0) - return -1; - return 0; } @@ -1298,15 +1262,10 @@ qemuValidateDomainDeviceDefZPCIAddress(virDomainDev= iceInfo *info, static int -qemuValidateDomainDeviceDefAddress(const virDomainDeviceDef *dev, +qemuValidateDomainDeviceDefAddress(virDomainDeviceInfo *info, const virDomainDef *def, virQEMUCaps *qemuCaps) { - virDomainDeviceInfo *info; - - if (!(info =3D virDomainDeviceGetInfo(dev))) - return 0; - switch ((virDomainDeviceAddressType) info->type) { case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI: if (qemuValidateDomainDeviceDefZPCIAddress(info, qemuCaps) < 0) @@ -1375,6 +1334,38 @@ qemuValidateDomainDeviceDefAddress(const virDomainDe= viceDef *dev, } +static int +qemuValidateDomainDeviceInfo(const virDomainDeviceDef *dev, + const virDomainDef *def, + virQEMUCaps *qemuCaps) +{ + virDomainDeviceInfo *info; + + if (!(info =3D virDomainDeviceGetInfo(dev))) + return 0; + + if (qemuValidateDomainDeviceDefAddress(info, def, qemuCaps) < 0) + return -1; + + if (info->acpiIndex) { + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_ACPI_INDEX)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("ACPI index is not supported with this QEMU")= ); + return -1; + } + + if (info->type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE && + info->type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("ACPI index is only supported for PCI devices= ")); + return -1; + } + } + + return 0; +} + + static bool qemuValidateNetSupportsCoalesce(virDomainNetType type) { @@ -5020,8 +5011,8 @@ qemuValidateDomainDeviceDef(const virDomainDeviceDef = *dev, qemuCaps =3D qemuCapsLocal; } - if ((ret =3D qemuValidateDomainDeviceDefAddress(dev, def, qemuCaps)) <= 0) - return ret; + if (qemuValidateDomainDeviceInfo(dev, def, qemuCaps) < 0) + return -1; switch ((virDomainDeviceType)dev->type) { case VIR_DOMAIN_DEVICE_NET: --=20 2.31.1