From nobody Mon Feb 9 12:27:30 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1618587575; cv=none; d=zohomail.com; s=zohoarc; b=cLxn2pUdeRDUguCZZGJUBQDE1zOAQTLK4mqQ4cVQYhA77FOgDABq+kAnOgC5R82lDxx4WcBBH87XbfefQswUlYnz8lkGrW/fbytbQQBwCNFS18JlXn5SHfZV58+5KOUSgkJfDVUGwnQtuMRaF+6UvcvahFY4XDw5Pb/a1KL6lMI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618587575; 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=ChKVSVfwBPl/AZec1sgGF4JuPx20pAqz0/FAip3H/2g=; b=cNn95hsR4/nIzssXQdQV63pNmp7PPVtk06SfCrl2EqzEVL/bc0Eed8P6YShwezocidGJxUneI0p+fJ9tpp+Gn3PpV429IHJ+VNBTDjrtFNoAho4z8GMSQ8rzA73yJEB963XdCLrjPP0DeankA+SOVANRidNAwGgxhrNbTU0mNls= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1618587575445950.8350989595733; Fri, 16 Apr 2021 08:39:35 -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-372-cppbq7YQO2ejpy_KwPLK_Q-1; Fri, 16 Apr 2021 11:39:29 -0400 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 6936C1008065; Fri, 16 Apr 2021 15:39:24 +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 494975DAA5; Fri, 16 Apr 2021 15:39:24 +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 0FDDE44A66; Fri, 16 Apr 2021 15:39:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 13GFYxvh009305 for ; Fri, 16 Apr 2021 11:34:59 -0400 Received: by smtp.corp.redhat.com (Postfix) id ECF1B5C3DF; Fri, 16 Apr 2021 15:34:59 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id 47C025C6BD for ; Fri, 16 Apr 2021 15:34:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618587574; 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=ChKVSVfwBPl/AZec1sgGF4JuPx20pAqz0/FAip3H/2g=; b=eHBsJuQKxVyt08a9njZt6033Axn6vxk0pVzzweZdnGgQaPYdSuW4jGqjLUfD9rwqrnEEKe WXuZuqVvTJ+ZG2D2EQCYz/M5pHiicNPIb5lZpzDXl2JDLP0CaI28/qpm8l32/7ijmDrmFk UYdherZIvUtb+1wvhwa9FpJ/fxK8zO0= X-MC-Unique: cppbq7YQO2ejpy_KwPLK_Q-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 10/25] conf: Move code from virDomainDiskDefParseValidate to virDomainDiskDefValidate Date: Fri, 16 Apr 2021 17:34:28 +0200 Message-Id: <57013829eb90e3ea50fbd8850d7e9f6f52774129.1618587222.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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.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 X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Unify the two distinct disk definition validators. Signed-off-by: Peter Krempa --- src/conf/domain_conf.c | 143 +------------------------------------ src/conf/domain_validate.c | 125 ++++++++++++++++++++++++++++++++ src/conf/domain_validate.h | 2 + 3 files changed, 128 insertions(+), 142 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 3f32e046f3..c8c0476a42 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -9044,144 +9044,6 @@ virDomainDiskDefGeometryParse(virDomainDiskDef *def, } -static int -virDomainDiskDefParseValidateSourceChainOne(const virStorageSource *src) -{ - if (src->type =3D=3D VIR_STORAGE_TYPE_NETWORK && src->auth) { - virStorageAuthDef *authdef =3D src->auth; - int actUsage; - - if ((actUsage =3D virSecretUsageTypeFromString(authdef->secrettype= )) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown secret type '%s'"), - NULLSTR(authdef->secrettype)); - return -1; - } - - if ((src->protocol =3D=3D VIR_STORAGE_NET_PROTOCOL_ISCSI && - actUsage !=3D VIR_SECRET_USAGE_TYPE_ISCSI) || - (src->protocol =3D=3D VIR_STORAGE_NET_PROTOCOL_RBD && - actUsage !=3D VIR_SECRET_USAGE_TYPE_CEPH)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("invalid secret type '%s'"), - virSecretUsageTypeToString(actUsage)); - return -1; - } - } - - if (src->encryption) { - virStorageEncryption *encryption =3D src->encryption; - - if (encryption->format =3D=3D VIR_STORAGE_ENCRYPTION_FORMAT_LUKS && - encryption->encinfo.cipher_name) { - - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("supplying for domain disk definitio= n " - "is unnecessary")); - return -1; - } - } - - return 0; -} - - -static int -virDomainDiskDefParseValidateSource(const virStorageSource *src) -{ - const virStorageSource *next; - - for (next =3D src; next; next =3D next->backingStore) { - if (virDomainDiskDefParseValidateSourceChainOne(next) < 0) - return -1; - } - - return 0; -} - - -static int -virDomainDiskDefParseValidate(const virDomainDiskDef *def) - -{ - if (virDomainDiskDefParseValidateSource(def->src) < 0) - return -1; - - if (def->bus !=3D VIR_DOMAIN_DISK_BUS_VIRTIO) { - if (def->event_idx !=3D VIR_TRISTATE_SWITCH_ABSENT) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("disk event_idx mode supported only for virti= o bus")); - return -1; - } - - if (def->ioeventfd !=3D VIR_TRISTATE_SWITCH_ABSENT) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("disk ioeventfd mode supported only for virti= o bus")); - return -1; - } - } - - if (def->device !=3D VIR_DOMAIN_DISK_DEVICE_LUN) { - if (def->rawio !=3D VIR_TRISTATE_BOOL_ABSENT) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("rawio can be used only with device=3D'lun'")= ); - return -1; - } - - if (def->sgio !=3D VIR_DOMAIN_DEVICE_SGIO_DEFAULT) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("sgio can be used only with device=3D'lun'")); - return -1; - } - } - - if (def->device =3D=3D VIR_DOMAIN_DISK_DEVICE_FLOPPY && - def->bus !=3D VIR_DOMAIN_DISK_BUS_FDC) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Invalid bus type '%s' for floppy disk"), - virDomainDiskBusTypeToString(def->bus)); - return -1; - } - - if (def->device !=3D VIR_DOMAIN_DISK_DEVICE_FLOPPY && - def->bus =3D=3D VIR_DOMAIN_DISK_BUS_FDC) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Invalid bus type '%s' for disk"), - virDomainDiskBusTypeToString(def->bus)); - return -1; - } - - if (def->removable !=3D VIR_TRISTATE_SWITCH_ABSENT && - def->bus !=3D VIR_DOMAIN_DISK_BUS_USB) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("removable is only valid for usb disks")); - return -1; - } - - if (def->startupPolicy !=3D VIR_DOMAIN_STARTUP_POLICY_DEFAULT) { - if (def->src->type =3D=3D VIR_STORAGE_TYPE_NETWORK) { - virReportError(VIR_ERR_XML_ERROR, - _("Setting disk %s is not allowed for " - "disk of network type"), - virDomainStartupPolicyTypeToString(def->startup= Policy)); - return -1; - } - - if (def->device !=3D VIR_DOMAIN_DISK_DEVICE_CDROM && - def->device !=3D VIR_DOMAIN_DISK_DEVICE_FLOPPY && - def->startupPolicy =3D=3D VIR_DOMAIN_STARTUP_POLICY_REQUISITE)= { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("Setting disk 'requisite' is allowed only for= " - "cdrom or floppy")); - return -1; - } - } - - - return 0; -} - - static int virDomainDiskDefDriverParseXML(virDomainDiskDef *def, xmlNodePtr cur, @@ -9730,9 +9592,6 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt, virDomainDiskDefParsePrivateData(ctxt, def, xmlopt) < 0) return NULL; - if (virDomainDiskDefParseValidate(def) < 0) - return NULL; - return g_steal_pointer(&def); } @@ -16497,7 +16356,7 @@ virDomainDiskDefParseSource(const char *xmlStr, return NULL; } - if (virDomainDiskDefParseValidateSource(src) < 0) + if (virDomainDiskDefValidateSource(src) < 0) return NULL; return g_steal_pointer(&src); diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c index 4d253599af..97fa218252 100644 --- a/src/conf/domain_validate.c +++ b/src/conf/domain_validate.c @@ -430,6 +430,62 @@ virDomainDiskVhostUserValidate(const virDomainDiskDef = *disk) } +static int +virDomainDiskDefValidateSourceChainOne(const virStorageSource *src) +{ + if (src->type =3D=3D VIR_STORAGE_TYPE_NETWORK && src->auth) { + virStorageAuthDef *authdef =3D src->auth; + int actUsage; + + if ((actUsage =3D virSecretUsageTypeFromString(authdef->secrettype= )) < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown secret type '%s'"), + NULLSTR(authdef->secrettype)); + return -1; + } + + if ((src->protocol =3D=3D VIR_STORAGE_NET_PROTOCOL_ISCSI && + actUsage !=3D VIR_SECRET_USAGE_TYPE_ISCSI) || + (src->protocol =3D=3D VIR_STORAGE_NET_PROTOCOL_RBD && + actUsage !=3D VIR_SECRET_USAGE_TYPE_CEPH)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("invalid secret type '%s'"), + virSecretUsageTypeToString(actUsage)); + return -1; + } + } + + if (src->encryption) { + virStorageEncryption *encryption =3D src->encryption; + + if (encryption->format =3D=3D VIR_STORAGE_ENCRYPTION_FORMAT_LUKS && + encryption->encinfo.cipher_name) { + + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("supplying for domain disk definitio= n " + "is unnecessary")); + return -1; + } + } + + return 0; +} + + +int +virDomainDiskDefValidateSource(const virStorageSource *src) +{ + const virStorageSource *next; + + for (next =3D src; next; next =3D next->backingStore) { + if (virDomainDiskDefValidateSourceChainOne(next) < 0) + return -1; + } + + return 0; +} + + #define VENDOR_LEN 8 #define PRODUCT_LEN 16 @@ -439,6 +495,9 @@ virDomainDiskDefValidate(const virDomainDef *def, { virStorageSource *next; + if (virDomainDiskDefValidateSource(disk->src) < 0) + return -1; + /* Validate LUN configuration */ if (disk->device =3D=3D VIR_DOMAIN_DISK_DEVICE_LUN) { /* volumes haven't been translated at this point, so accept them */ @@ -457,6 +516,18 @@ virDomainDiskDefValidate(const virDomainDef *def, _(" allowed only for lun devices= ")); return -1; } + + if (disk->rawio !=3D VIR_TRISTATE_BOOL_ABSENT) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("rawio can be used only with device=3D'lun'")= ); + return -1; + } + + if (disk->sgio !=3D VIR_DOMAIN_DEVICE_SGIO_DEFAULT) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("sgio can be used only with device=3D'lun'")); + return -1; + } } /* Reject disks with a bus type that is not compatible with the @@ -490,6 +561,18 @@ virDomainDiskDefValidate(const virDomainDef *def, return -1; } + if (disk->event_idx !=3D VIR_TRISTATE_SWITCH_ABSENT) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("disk event_idx mode supported only for virti= o bus")); + return -1; + } + + if (disk->ioeventfd !=3D VIR_TRISTATE_SWITCH_ABSENT) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("disk ioeventfd mode supported only for virti= o bus")); + return -1; + } + if (virDomainCheckVirtioOptionsAreAbsent(disk->virtio) < 0) return -1; } @@ -538,6 +621,48 @@ virDomainDiskDefValidate(const virDomainDef *def, return -1; } + if (disk->device =3D=3D VIR_DOMAIN_DISK_DEVICE_FLOPPY && + disk->bus !=3D VIR_DOMAIN_DISK_BUS_FDC) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Invalid bus type '%s' for floppy disk"), + virDomainDiskBusTypeToString(disk->bus)); + return -1; + } + + if (disk->device !=3D VIR_DOMAIN_DISK_DEVICE_FLOPPY && + disk->bus =3D=3D VIR_DOMAIN_DISK_BUS_FDC) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Invalid bus type '%s' for disk"), + virDomainDiskBusTypeToString(disk->bus)); + return -1; + } + + if (disk->removable !=3D VIR_TRISTATE_SWITCH_ABSENT && + disk->bus !=3D VIR_DOMAIN_DISK_BUS_USB) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("removable is only valid for usb disks")); + return -1; + } + + if (disk->startupPolicy !=3D VIR_DOMAIN_STARTUP_POLICY_DEFAULT) { + if (disk->src->type =3D=3D VIR_STORAGE_TYPE_NETWORK) { + virReportError(VIR_ERR_XML_ERROR, + _("Setting disk %s is not allowed for " + "disk of network type"), + virDomainStartupPolicyTypeToString(disk->startu= pPolicy)); + return -1; + } + + if (disk->device !=3D VIR_DOMAIN_DISK_DEVICE_CDROM && + disk->device !=3D VIR_DOMAIN_DISK_DEVICE_FLOPPY && + disk->startupPolicy =3D=3D VIR_DOMAIN_STARTUP_POLICY_REQUISITE= ) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("Setting disk 'requisite' is allowed only for= " + "cdrom or floppy")); + return -1; + } + } + return 0; } diff --git a/src/conf/domain_validate.h b/src/conf/domain_validate.h index 5f31616c85..38a1abcc8f 100644 --- a/src/conf/domain_validate.h +++ b/src/conf/domain_validate.h @@ -38,3 +38,5 @@ int virDomainDeviceDefValidate(const virDomainDeviceDef *= dev, unsigned int parseFlags, virDomainXMLOption *xmlopt, void *parseOpaque); + +int virDomainDiskDefValidateSource(const virStorageSource *src); --=20 2.30.2