From nobody Sat Feb 7 10:44:37 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=1607709977; cv=none; d=zohomail.com; s=zohoarc; b=Gxfma2YoOzuWB4JHTqpRlVoCX3dkzxvA+RWZQSZbwqXhxEAFTnk0d/N9ovXznjL2zRZUThRvhxSzBkV5yKtWbVj7aE+/VDXFUvIp7ZsMvKrZ+EGYRP6wta03iFxLj/P1uWau+TLk8OJ4tdUTRcOR/RQdhP1BP53UazX2fA6VJa0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1607709977; 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=HSFFe2lL6Kc3CUz2hr9oZs3mDPCrjL3EGfNqiQ4YZMI=; b=fkkZTRUjVRar2c0LcbFqGqPr5WPziOiPRbYUQEP2AlAvax59O1zQSaMdeqRhMQSq3fXI5UcTjrXhnw1/eW0YQwewUUCj3K9dfa686HjnIu6SQ2Hu06XCOULKEO4DP0DZs26wP1iUlGP14T1hdGbF1hw6KaaRCNpC8d/aOdV9szw= 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 1607709977199903.0373465278573; Fri, 11 Dec 2020 10:06:17 -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-332-IMV0hxdHMh-XU6qge6vAXg-1; Fri, 11 Dec 2020 13:06:10 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0F70CC73B1; Fri, 11 Dec 2020 18:05:57 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E04F45D9E8; Fri, 11 Dec 2020 18:05:56 +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 AB8911809CA9; Fri, 11 Dec 2020 18:05:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0BBI5kqF027605 for ; Fri, 11 Dec 2020 13:05:46 -0500 Received: by smtp.corp.redhat.com (Postfix) id 735372166B2A; Fri, 11 Dec 2020 18:05:46 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6DDC02166B29 for ; Fri, 11 Dec 2020 18:05:46 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) (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 53BFD800B3B for ; Fri, 11 Dec 2020 18:05:46 +0000 (UTC) Received: from mail-qt1-f177.google.com (mail-qt1-f177.google.com [209.85.160.177]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-159-JGQmk99TMCyYKqkgBsN-SQ-1; Fri, 11 Dec 2020 13:05:43 -0500 Received: by mail-qt1-f177.google.com with SMTP id z3so7072301qtw.9 for ; Fri, 11 Dec 2020 10:05:43 -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.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Dec 2020 10:05:42 -0800 (PST) X-MC-Unique: IMV0hxdHMh-XU6qge6vAXg-1 X-MC-Unique: JGQmk99TMCyYKqkgBsN-SQ-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=HSFFe2lL6Kc3CUz2hr9oZs3mDPCrjL3EGfNqiQ4YZMI=; b=JIT0Rzr7/p1A1IgCeCgATql08FVCec2PUel8kpYn3vXdTObRHFbpKdktQKG6ZmMeQ1 pM4tuTJazC3aZq9J/Na2mkj59g9dwMWjXTn1wsCs2+5H3oe4ll0idWg+4WHmWDVh8rYU Xv3nGeA8eOg5Ccr9PO1Zf7rxfh971LibtW6lKElOtXfDINAnyKvo/Yu72XpsGs21zEhU ZUEwxMoH/7so8xXLVtVzQ+C7bQXTew0FFfdALiI/jmFFqCE6E+mV1XSsEOELuHrMNStJ tG/tOhpSjNsBmWrNdr/wWb+cuX12p15zl7LkJBBEwcGYZfeFD3WPaaZKdquTyeAcF51+ Z7bg== X-Gm-Message-State: AOAM533IVqejiah6BBq/DgM3weo50yd2DGTkqsAuhqatzC5PD23QIBw/ IhEECqJXDgrubWoHmfbC2gOSEojD8/vL6g== X-Google-Smtp-Source: ABdhPJwOe/gO3CDpd25Vlv3lD541RpQ46KlfYofYV5OiK2Ge7foAptI70IpVKObHUP8ZZBCaMxXXKQ== X-Received: by 2002:ac8:490a:: with SMTP id e10mr16928270qtq.15.1607709943030; Fri, 11 Dec 2020 10:05:43 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH 08/12] domain_conf: move all DeviceDefValidateInternal() helpers to domain_validate Date: Fri, 11 Dec 2020 15:05:12 -0300 Message-Id: <20201211180516.1952683-9-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.6 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.79 on 10.5.11.14 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" Moving all remaining static helpers of virDomainDeviceDefValidateInternal() will allow the next patch to move the function itself, and virDomainDeviceDefValidate(), to domain_validate.c. Signed-off-by: Daniel Henrique Barboza --- src/conf/domain_conf.c | 150 ------------------------------------- src/conf/domain_validate.c | 150 +++++++++++++++++++++++++++++++++++++ src/conf/domain_validate.h | 6 ++ 3 files changed, 156 insertions(+), 150 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index a541e7bca6..ebe895948f 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -6022,156 +6022,6 @@ virDomainDefHasUSB(const virDomainDef *def) } =20 =20 -static int -virDomainHostdevDefValidate(const virDomainHostdevDef *hostdev) -{ - if (hostdev->mode =3D=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) { - switch ((virDomainHostdevSubsysType) hostdev->source.subsys.type) { - case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: - if (hostdev->info->type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NO= NE && - hostdev->info->type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_UN= ASSIGNED && - hostdev->info->type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PC= I) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("PCI host devices must use 'pci' or " - "'unassigned' address type")); - return -1; - } - break; - case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: - if (hostdev->info->type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NO= NE && - hostdev->info->type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DR= IVE) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("SCSI host device must use 'drive' " - "address type")); - return -1; - } - break; - case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST: - if (hostdev->info->type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NO= NE && - hostdev->info->type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PC= I && - hostdev->info->type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CC= W) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("SCSI_host host device must use 'pci' " - "or 'ccw' address type")); - return -1; - } - break; - case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: - if (hostdev->info->type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NO= NE && - hostdev->info->type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_US= B) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("USB host device must use 'usb' address t= ype")); - return -1; - } - break; - case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: - case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST: - break; - } - } - return 0; -} - - -static int -virDomainMemoryDefValidate(const virDomainMemoryDef *mem, - const virDomainDef *def) -{ - if (mem->model =3D=3D VIR_DOMAIN_MEMORY_MODEL_NVDIMM) { - if (!mem->nvdimmPath) { - virReportError(VIR_ERR_XML_DETAIL, "%s", - _("path is required for model 'nvdimm'")); - return -1; - } - - if (mem->discard =3D=3D VIR_TRISTATE_BOOL_YES) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("discard is not supported for nvdimms")); - return -1; - } - - if (ARCH_IS_PPC64(def->os.arch) && mem->labelsize =3D=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("label size is required for NVDIMM device")); - return -1; - } - } - - return 0; -} - - -static int -virDomainVsockDefValidate(const virDomainVsockDef *vsock) -{ - if (vsock->guest_cid > 0 && vsock->guest_cid <=3D 2) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("guest CIDs must be >=3D 3")); - return -1; - } - - return 0; -} - -static int -virDomainInputDefValidate(const virDomainInputDef *input) -{ - switch ((virDomainInputType) input->type) { - case VIR_DOMAIN_INPUT_TYPE_MOUSE: - case VIR_DOMAIN_INPUT_TYPE_TABLET: - case VIR_DOMAIN_INPUT_TYPE_KBD: - if (input->source.evdev) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("setting source evdev path only supporte= d for " - "passthrough input devices")); - return -1; - } - break; - - case VIR_DOMAIN_INPUT_TYPE_PASSTHROUGH: - if (input->bus !=3D VIR_DOMAIN_INPUT_BUS_VIRTIO) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("only bus 'virtio' is supported for 'pass= through' " - "input devices")); - return -1; - } - break; - - case VIR_DOMAIN_INPUT_TYPE_LAST: - default: - virReportEnumRangeError(virDomainInputType, input->type); - return -1; - } - - return 0; -} - - -static int -virDomainShmemDefValidate(const virDomainShmemDef *shmem) -{ - if (strchr(shmem->name, '/')) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("shmem name cannot include '/' character")); - return -1; - } - - if (STREQ(shmem->name, ".")) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("shmem name cannot be equal to '.'")); - return -1; - } - - if (STREQ(shmem->name, "..")) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("shmem name cannot be equal to '..'")); - return -1; - } - - return 0; -} - - static int virDomainDeviceDefValidateInternal(const virDomainDeviceDef *dev, const virDomainDef *def) diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c index 6ca4ebb0ea..ec955daf66 100644 --- a/src/conf/domain_validate.c +++ b/src/conf/domain_validate.c @@ -1321,3 +1321,153 @@ virDomainNetDefValidate(const virDomainNetDef *net) =20 return 0; } + + +int +virDomainHostdevDefValidate(const virDomainHostdevDef *hostdev) +{ + if (hostdev->mode =3D=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) { + switch ((virDomainHostdevSubsysType) hostdev->source.subsys.type) { + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: + if (hostdev->info->type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NO= NE && + hostdev->info->type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_UN= ASSIGNED && + hostdev->info->type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PC= I) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("PCI host devices must use 'pci' or " + "'unassigned' address type")); + return -1; + } + break; + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: + if (hostdev->info->type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NO= NE && + hostdev->info->type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DR= IVE) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("SCSI host device must use 'drive' " + "address type")); + return -1; + } + break; + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST: + if (hostdev->info->type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NO= NE && + hostdev->info->type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PC= I && + hostdev->info->type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CC= W) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("SCSI_host host device must use 'pci' " + "or 'ccw' address type")); + return -1; + } + break; + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: + if (hostdev->info->type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NO= NE && + hostdev->info->type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_US= B) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("USB host device must use 'usb' address t= ype")); + return -1; + } + break; + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST: + break; + } + } + return 0; +} + + +int +virDomainMemoryDefValidate(const virDomainMemoryDef *mem, + const virDomainDef *def) +{ + if (mem->model =3D=3D VIR_DOMAIN_MEMORY_MODEL_NVDIMM) { + if (!mem->nvdimmPath) { + virReportError(VIR_ERR_XML_DETAIL, "%s", + _("path is required for model 'nvdimm'")); + return -1; + } + + if (mem->discard =3D=3D VIR_TRISTATE_BOOL_YES) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("discard is not supported for nvdimms")); + return -1; + } + + if (ARCH_IS_PPC64(def->os.arch) && mem->labelsize =3D=3D 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("label size is required for NVDIMM device")); + return -1; + } + } + + return 0; +} + + +int +virDomainVsockDefValidate(const virDomainVsockDef *vsock) +{ + if (vsock->guest_cid > 0 && vsock->guest_cid <=3D 2) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("guest CIDs must be >=3D 3")); + return -1; + } + + return 0; +} + +int +virDomainInputDefValidate(const virDomainInputDef *input) +{ + switch ((virDomainInputType) input->type) { + case VIR_DOMAIN_INPUT_TYPE_MOUSE: + case VIR_DOMAIN_INPUT_TYPE_TABLET: + case VIR_DOMAIN_INPUT_TYPE_KBD: + if (input->source.evdev) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("setting source evdev path only supporte= d for " + "passthrough input devices")); + return -1; + } + break; + + case VIR_DOMAIN_INPUT_TYPE_PASSTHROUGH: + if (input->bus !=3D VIR_DOMAIN_INPUT_BUS_VIRTIO) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("only bus 'virtio' is supported for 'pass= through' " + "input devices")); + return -1; + } + break; + + case VIR_DOMAIN_INPUT_TYPE_LAST: + default: + virReportEnumRangeError(virDomainInputType, input->type); + return -1; + } + + return 0; +} + + +int +virDomainShmemDefValidate(const virDomainShmemDef *shmem) +{ + if (strchr(shmem->name, '/')) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("shmem name cannot include '/' character")); + return -1; + } + + if (STREQ(shmem->name, ".")) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("shmem name cannot be equal to '.'")); + return -1; + } + + if (STREQ(shmem->name, "..")) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("shmem name cannot be equal to '..'")); + return -1; + } + + return 0; +} diff --git a/src/conf/domain_validate.h b/src/conf/domain_validate.h index d38d2f4e06..e04ecab065 100644 --- a/src/conf/domain_validate.h +++ b/src/conf/domain_validate.h @@ -51,3 +51,9 @@ int virDomainDefValidate(virDomainDefPtr def, void *parseOpaque); int virDomainActualNetDefValidate(const virDomainNetDef *net); int virDomainNetDefValidate(const virDomainNetDef *net); +int virDomainHostdevDefValidate(const virDomainHostdevDef *hostdev); +int virDomainMemoryDefValidate(const virDomainMemoryDef *mem, + const virDomainDef *def); +int virDomainVsockDefValidate(const virDomainVsockDef *vsock); +int virDomainInputDefValidate(const virDomainInputDef *input); +int virDomainShmemDefValidate(const virDomainShmemDef *shmem); --=20 2.26.2