From nobody Sat Feb 7 10:50:42 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1607709962; cv=none; d=zohomail.com; s=zohoarc; b=Nzdnd3J/f7y8OdvwPXhww95HCDpsPKK4GDF4j2k5azqL/hpH4q35PIRIYc1EIbR+Y3KLlB6yLm0ZbglSjxJUcxCAtACps+ewNO160DWhC03pLnX/NFy4F/5B34oQVUc4J+wjFhvJhnPuWft2lZdMEGwj+3uHTT0LvcMjANlS4OA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1607709962; h=Content-Type:Content-Transfer-Encoding:Cc: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=OhbbjvGLQfCECzKUjXgyex8++xpgEnWnhYBAPH4mEGw=; b=De8SZQkunvWbCVc8D+epzP3b7xJUM+9U7K/8VMLJrPjq5eKihLobvrPZTZN8a/44p0xld58YU6nWNEMXVQn7wp/00Q5JdpufdU1htJELoC0mC5fjMM8teRRZoR/RfP/vAdPFn6Ea3Gm9RA7CxS0qWPHlqJpShEb4azP1AC329Qg= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1607709962766929.6926817559398; Fri, 11 Dec 2020 10:06:02 -0800 (PST) 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-476-If3m2M1SPCybOIweiuxFsg-1; Fri, 11 Dec 2020 13:05:58 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 64677800D53; Fri, 11 Dec 2020 18:05:51 +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 3D4151992D; Fri, 11 Dec 2020 18:05:51 +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 0A9054EEF6; Fri, 11 Dec 2020 18:05:51 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0BBI5gd5027576 for ; Fri, 11 Dec 2020 13:05:42 -0500 Received: by smtp.corp.redhat.com (Postfix) id 9BE4F2026D3B; Fri, 11 Dec 2020 18:05:42 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9565C2026D11 for ; Fri, 11 Dec 2020 18:05:39 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C3D931875041 for ; Fri, 11 Dec 2020 18:05:39 +0000 (UTC) Received: from mail-qk1-f194.google.com (mail-qk1-f194.google.com [209.85.222.194]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-53-o6zVxeQLMoiSqFmMAm3ILQ-1; Fri, 11 Dec 2020 13:05:37 -0500 Received: by mail-qk1-f194.google.com with SMTP id w79so9285925qkb.5 for ; Fri, 11 Dec 2020 10:05:37 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c6:9e32:a7fb:6602:e8c2:3c0f]) by smtp.gmail.com with ESMTPSA id y6sm7585703qkj.60.2020.12.11.10.05.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Dec 2020 10:05:35 -0800 (PST) X-MC-Unique: If3m2M1SPCybOIweiuxFsg-1 X-MC-Unique: o6zVxeQLMoiSqFmMAm3ILQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OhbbjvGLQfCECzKUjXgyex8++xpgEnWnhYBAPH4mEGw=; b=mEd4aGhmWM9qbiv98B3p0LyXJTnbvhk0WE5ICdnL0swqMvknhKqnoXG97Ey+5bviee mCZd8geBrxlgX5ELpHi+H4A5JEOD8hsRP3Zs/dP7OPeC3DcAESzwmwjHE2IEmrBET2Lh 4ZxDvN56byOuw7QO0hVOLyqA2YQNwp8FHIyA18Wb0a1EY0MsvCAfT9yTeihlf2f3TJas 1lWIoxVnW+P4f1iyimNKbY+Mo1jBp1LNAVRZYZNm/TK6yh7BU+C6iGtNz88P8weKHVBS gK0/7ea7NT1gd/kHlHJD7GKnPy630CZbBp5Ow4OiAFg5XKijoAOHam0nYD6smSx0m1/F mHfQ== X-Gm-Message-State: AOAM531lGtFGeIJdz40OVEj9KKLleqTVaCO2m77Hb78XSSmcCamtVew+ EIbky37uoVM4xqqZPwIEXKpsGC9T06SjCA== X-Google-Smtp-Source: ABdhPJxpUGDeDVOJcmw/v/GH9V/CwbJYK3GlK1QzxunYJy7m0jf8trNkkOao31Jz1jg0/ZvfsuXABQ== X-Received: by 2002:a37:478f:: with SMTP id u137mr17321531qka.16.1607709936388; Fri, 11 Dec 2020 10:05:36 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH 05/12] domain_conf.c: move virDomainDeviceDefValidate() to domain_validate.c Date: Fri, 11 Dec 2020 15:05:09 -0300 Message-Id: <20201211180516.1952683-6-danielhb413@gmail.com> In-Reply-To: <20201211180516.1952683-1-danielhb413@gmail.com> References: <20201211180516.1952683-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza 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.23 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 Content-Type: text/plain; charset="utf-8" Move virDomainDeviceDefValidate() and all its helper functions to domain_validate.c. Signed-off-by: Daniel Henrique Barboza --- src/conf/domain_conf.c | 137 +------------------------------------ src/conf/domain_conf.h | 16 +++-- src/conf/domain_validate.c | 129 ++++++++++++++++++++++++++++++++++ src/conf/domain_validate.h | 4 ++ src/libvirt_private.syms | 2 +- src/qemu/qemu_process.c | 1 + 6 files changed, 147 insertions(+), 142 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 1cd7733652..bf9d00094c 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -5643,13 +5643,6 @@ virDomainDeviceDefPostParseOne(virDomainDeviceDefPtr= dev, } =20 =20 -struct virDomainDefPostParseDeviceIteratorData { - virDomainXMLOptionPtr xmlopt; - void *parseOpaque; - unsigned int parseFlags; -}; - - static int virDomainDefPostParseDeviceIterator(virDomainDefPtr def, virDomainDeviceDefPtr dev, @@ -6398,7 +6391,7 @@ virDomainDeviceDefValidateInternal(const virDomainDev= iceDef *dev, } =20 =20 -static int +int virDomainDeviceDefValidate(const virDomainDeviceDef *dev, const virDomainDef *def, unsigned int parseFlags, @@ -6420,19 +6413,6 @@ virDomainDeviceDefValidate(const virDomainDeviceDef = *dev, } =20 =20 -static int -virDomainDefValidateDeviceIterator(virDomainDefPtr def, - virDomainDeviceDefPtr dev, - virDomainDeviceInfoPtr info G_GNUC_UNUS= ED, - void *opaque) -{ - struct virDomainDefPostParseDeviceIteratorData *data =3D opaque; - return virDomainDeviceDefValidate(dev, def, - data->parseFlags, data->xmlopt, - data->parseOpaque); -} - - bool virDomainDefLifecycleActionAllowed(virDomainLifecycle type, virDomainLifecycleAction action) @@ -6465,121 +6445,6 @@ virDomainDefLifecycleActionAllowed(virDomainLifecyc= le type, } =20 =20 -static int -virDomainDefValidateInternal(const virDomainDef *def, - virDomainXMLOptionPtr xmlopt) -{ - if (virDomainDefDuplicateDiskInfoValidate(def) < 0) - return -1; - - if (virDomainDefDuplicateDriveAddressesValidate(def) < 0) - return -1; - - if (virDomainDefGetVcpusTopology(def, NULL) < 0) - return -1; - - if (virDomainDefValidateAliases(def, NULL) < 0) - return -1; - - if (def->iommu && - def->iommu->intremap =3D=3D VIR_TRISTATE_SWITCH_ON && - def->features[VIR_DOMAIN_FEATURE_IOAPIC] !=3D VIR_DOMAIN_IOAPIC_QE= MU) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("IOMMU interrupt remapping requires split I/O API= C " - "(ioapic driver=3D'qemu')")); - return -1; - } - - if (def->iommu && - def->iommu->eim =3D=3D VIR_TRISTATE_SWITCH_ON && - def->iommu->intremap !=3D VIR_TRISTATE_SWITCH_ON) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("IOMMU eim requires interrupt remapping to be ena= bled")); - return -1; - } - - if (virDomainDefLifecycleActionValidate(def) < 0) - return -1; - - if (virDomainDefMemtuneValidate(def) < 0) - return -1; - - if (virDomainDefOSValidate(def, xmlopt) < 0) - return -1; - - if (virDomainDefCputuneValidate(def) < 0) - return -1; - - if (virDomainDefBootValidate(def) < 0) - return -1; - - if (virDomainDefVideoValidate(def) < 0) - return -1; - - if (virDomainDefTunablesValidate(def) < 0) - return -1; - - if (virDomainDefIdMapValidate(def) < 0) - return -1; - - if (virDomainNumaDefValidate(def->numa) < 0) - return -1; - - return 0; -} - - -/** - * virDomainDefValidate: - * @def: domain definition - * @caps: driver capabilities object - * @parseFlags: virDomainDefParseFlags - * @xmlopt: XML parser option object - * @parseOpaque: hypervisor driver specific data for this validation run - * - * This validation function is designed to take checks of globally invalid - * configurations that the parser needs to accept so that VMs don't vanish= upon - * daemon restart. Such definition can be rejected upon startup or define,= where - * this function shall be called. - * - * Returns 0 if domain definition is valid, -1 on error and reports an - * appropriate message. - */ -int -virDomainDefValidate(virDomainDefPtr def, - unsigned int parseFlags, - virDomainXMLOptionPtr xmlopt, - void *parseOpaque) -{ - struct virDomainDefPostParseDeviceIteratorData data =3D { - .xmlopt =3D xmlopt, - .parseFlags =3D parseFlags, - .parseOpaque =3D parseOpaque, - }; - - /* validate configuration only in certain places */ - if (parseFlags & VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE) - return 0; - - /* call the domain config callback */ - if (xmlopt->config.domainValidateCallback && - xmlopt->config.domainValidateCallback(def, xmlopt->config.priv, pa= rseOpaque) < 0) - return -1; - - /* iterate the devices */ - if (virDomainDeviceInfoIterateFlags(def, - virDomainDefValidateDeviceIterator, - (DOMAIN_DEVICE_ITERATE_ALL_CONSOLE= S | - DOMAIN_DEVICE_ITERATE_MISSING_INF= O), - &data) < 0) - return -1; - - if (virDomainDefValidateInternal(def, xmlopt) < 0) - return -1; - - return 0; -} - int virDomainObjCheckActive(virDomainObjPtr dom) { diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 5f8ec16b7d..1c1533ed2f 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3006,6 +3006,12 @@ struct _virDomainXMLOption { virDomainMomentPostParseCallback momentPostParse; }; =20 +struct virDomainDefPostParseDeviceIteratorData { + virDomainXMLOptionPtr xmlopt; + void *parseOpaque; + unsigned int parseFlags; +}; + bool virDomainSCSIDriveAddressIsUsed(const virDomainDef *def, const virDomainDeviceDriveAddress *addr); @@ -3018,11 +3024,6 @@ bool virDomainDefHasUSB(const virDomainDef *def); =20 bool virDomainDeviceAliasIsUserAlias(const char *aliasStr); =20 -int virDomainDefValidate(virDomainDefPtr def, - unsigned int parseFlags, - virDomainXMLOptionPtr xmlopt, - void *parseOpaque); - int virDomainActualNetDefValidate(const virDomainNetDef *net); =20 @@ -3124,6 +3125,11 @@ void virDomainRedirdevDefFree(virDomainRedirdevDefPt= r def); void virDomainRedirFilterDefFree(virDomainRedirFilterDefPtr def); void virDomainShmemDefFree(virDomainShmemDefPtr def); void virDomainDeviceDefFree(virDomainDeviceDefPtr def); +int virDomainDeviceDefValidate(const virDomainDeviceDef *dev, + const virDomainDef *def, + unsigned int parseFlags, + virDomainXMLOptionPtr xmlopt, + void *parseOpaque); G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainDeviceDef, virDomainDeviceDefFree); virDomainDeviceDefPtr virDomainDeviceDefCopy(virDomainDeviceDefPtr src, const virDomainDef *def, diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c index 02cd761ee2..47aa3e4375 100644 --- a/src/conf/domain_validate.c +++ b/src/conf/domain_validate.c @@ -1040,3 +1040,132 @@ virDomainDefCputuneValidate(const virDomainDef *def) } #undef CPUTUNE_VALIDATE_PERIOD #undef CPUTUNE_VALIDATE_QUOTA + + +static int +virDomainDefValidateInternal(const virDomainDef *def, + virDomainXMLOptionPtr xmlopt) +{ + if (virDomainDefDuplicateDiskInfoValidate(def) < 0) + return -1; + + if (virDomainDefDuplicateDriveAddressesValidate(def) < 0) + return -1; + + if (virDomainDefGetVcpusTopology(def, NULL) < 0) + return -1; + + if (virDomainDefValidateAliases(def, NULL) < 0) + return -1; + + if (def->iommu && + def->iommu->intremap =3D=3D VIR_TRISTATE_SWITCH_ON && + def->features[VIR_DOMAIN_FEATURE_IOAPIC] !=3D VIR_DOMAIN_IOAPIC_QE= MU) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("IOMMU interrupt remapping requires split I/O API= C " + "(ioapic driver=3D'qemu')")); + return -1; + } + + if (def->iommu && + def->iommu->eim =3D=3D VIR_TRISTATE_SWITCH_ON && + def->iommu->intremap !=3D VIR_TRISTATE_SWITCH_ON) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("IOMMU eim requires interrupt remapping to be ena= bled")); + return -1; + } + + if (virDomainDefLifecycleActionValidate(def) < 0) + return -1; + + if (virDomainDefMemtuneValidate(def) < 0) + return -1; + + if (virDomainDefOSValidate(def, xmlopt) < 0) + return -1; + + if (virDomainDefCputuneValidate(def) < 0) + return -1; + + if (virDomainDefBootValidate(def) < 0) + return -1; + + if (virDomainDefVideoValidate(def) < 0) + return -1; + + if (virDomainDefTunablesValidate(def) < 0) + return -1; + + if (virDomainDefIdMapValidate(def) < 0) + return -1; + + if (virDomainNumaDefValidate(def->numa) < 0) + return -1; + + return 0; +} + + +static int +virDomainDefValidateDeviceIterator(virDomainDefPtr def, + virDomainDeviceDefPtr dev, + virDomainDeviceInfoPtr info G_GNUC_UNUS= ED, + void *opaque) +{ + struct virDomainDefPostParseDeviceIteratorData *data =3D opaque; + return virDomainDeviceDefValidate(dev, def, + data->parseFlags, data->xmlopt, + data->parseOpaque); +} + + +/** + * virDomainDefValidate: + * @def: domain definition + * @caps: driver capabilities object + * @parseFlags: virDomainDefParseFlags + * @xmlopt: XML parser option object + * @parseOpaque: hypervisor driver specific data for this validation run + * + * This validation function is designed to take checks of globally invalid + * configurations that the parser needs to accept so that VMs don't vanish= upon + * daemon restart. Such definition can be rejected upon startup or define,= where + * this function shall be called. + * + * Returns 0 if domain definition is valid, -1 on error and reports an + * appropriate message. + */ +int +virDomainDefValidate(virDomainDefPtr def, + unsigned int parseFlags, + virDomainXMLOptionPtr xmlopt, + void *parseOpaque) +{ + struct virDomainDefPostParseDeviceIteratorData data =3D { + .xmlopt =3D xmlopt, + .parseFlags =3D parseFlags, + .parseOpaque =3D parseOpaque, + }; + + /* validate configuration only in certain places */ + if (parseFlags & VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE) + return 0; + + /* call the domain config callback */ + if (xmlopt->config.domainValidateCallback && + xmlopt->config.domainValidateCallback(def, xmlopt->config.priv, pa= rseOpaque) < 0) + return -1; + + /* iterate the devices */ + if (virDomainDeviceInfoIterateFlags(def, + virDomainDefValidateDeviceIterator, + (DOMAIN_DEVICE_ITERATE_ALL_CONSOLE= S | + DOMAIN_DEVICE_ITERATE_MISSING_INF= O), + &data) < 0) + return -1; + + if (virDomainDefValidateInternal(def, xmlopt) < 0) + return -1; + + return 0; +} diff --git a/src/conf/domain_validate.h b/src/conf/domain_validate.h index 4247dfd758..309ae5f950 100644 --- a/src/conf/domain_validate.h +++ b/src/conf/domain_validate.h @@ -58,3 +58,7 @@ int virDomainDefMemtuneValidate(const virDomainDef *def); int virDomainDefOSValidate(const virDomainDef *def, virDomainXMLOptionPtr xmlopt); int virDomainDefCputuneValidate(const virDomainDef *def); +int virDomainDefValidate(virDomainDefPtr def, + unsigned int parseFlags, + virDomainXMLOptionPtr xmlopt, + void *parseOpaque); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index c3056232db..3cbc336bad 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -342,7 +342,6 @@ virDomainDefSave; virDomainDefSetMemoryTotal; virDomainDefSetVcpus; virDomainDefSetVcpusMax; -virDomainDefValidate; virDomainDefVcpuOrderClear; virDomainDeleteConfig; virDomainDeviceAliasIsUserAlias; @@ -744,6 +743,7 @@ virDomainConfVMNWFilterTeardown; =20 =20 # conf/domain_validate.h +virDomainDefValidate; virDomainDeviceValidateAliasForHotplug; =20 =20 diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 3b64caa619..bb78967ca3 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -74,6 +74,7 @@ #include "virhostcpu.h" #include "domain_audit.h" #include "domain_nwfilter.h" +#include "domain_validate.h" #include "locking/domain_lock.h" #include "viruuid.h" #include "virprocess.h" --=20 2.26.2