From nobody Mon Feb 9 13:37:59 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=1618587570; cv=none; d=zohomail.com; s=zohoarc; b=myjlG2CdTV6o7t+GqXD8558H3+IvEpYgq17sicsMj2Dry+blK5eKWPSJrhSxDubMnRAQRDleNBT7DJ/QnnvAZEKU3c7gyNa5OOikSblkOlIihpeidpEP0x2lAVSqGSiu5azcZFTCznf3adxf8YGpWkGgddcjPitOl9PSM+9LAO4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618587570; 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=16Gm0ODHiAQ+IauuHm/ilbdVjxCBkAoyUnRmF3sj4wQ=; b=a0bHmXsiSk6AsT60s5tkBjmac2wuWZcTuniX5NPWYNokogno8Ge4pLCE83NW0TheO5ZZNP86V7mnf9uAyQReTcn9OpF4MjWlnWmb01PDWBldHW5EV9YOGYiK9KSm0cgvpYGjuc2UCbRSJiHcrohJowrYTP3jmCdJCuvFTvWnmfA= 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 1618587570012986.9509281575891; Fri, 16 Apr 2021 08:39:30 -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-228-ss69e6I4NmKe45LT-OtrXQ-1; Fri, 16 Apr 2021 11:39:26 -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 A979784BA43; Fri, 16 Apr 2021 15:39:21 +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 865C85D9C6; Fri, 16 Apr 2021 15:39:21 +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 4BD0E44A63; Fri, 16 Apr 2021 15:39:21 +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 13GFYttU009264 for ; Fri, 16 Apr 2021 11:34:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9474B5C3DF; Fri, 16 Apr 2021 15:34:55 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id E68BE5C6BD for ; Fri, 16 Apr 2021 15:34:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618587568; 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=16Gm0ODHiAQ+IauuHm/ilbdVjxCBkAoyUnRmF3sj4wQ=; b=dZ6KAAotb7xZ02frjw0DMQbi6Dr2r0m1LNBxd3Ynp5LHj0ynZNdUq5bfgQHTsGV675zOqn ERrKiFtX1SNAikYDMMzAqCRO26W/2tdpXA72OURZxPJHYCOSYLNBpiuwJaecFuiKP0RwKy j8DhbWoqFtFj8cYY8dv3nqAXlYcoQY8= X-MC-Unique: ss69e6I4NmKe45LT-OtrXQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 06/25] conf: domain: Split out source validation part from virDomainDiskDefParseValidate Date: Fri, 16 Apr 2021 17:34:24 +0200 Message-Id: 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" Separate the validation of the source so that it can be reused once we split up the XML parser too. Signed-off-by: Peter Krempa --- src/conf/domain_conf.c | 82 +++++++++++++++++++++++------------------- 1 file changed, 46 insertions(+), 36 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index f59d17930b..0eec4c9356 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -9045,29 +9045,55 @@ virDomainDiskDefGeometryParse(virDomainDiskDef *def, static int -virDomainDiskSourceDefParseAuthValidate(const virStorageSource *src) +virDomainDiskDefParseValidateSourceChainOne(const virStorageSource *src) { - virStorageAuthDef *authdef =3D src->auth; - int actUsage; + if (src->type =3D=3D VIR_STORAGE_TYPE_NETWORK && src->auth) { + virStorageAuthDef *authdef =3D src->auth; + int actUsage; - if (src->type !=3D VIR_STORAGE_TYPE_NETWORK || !authdef) - return 0; + if ((actUsage =3D virSecretUsageTypeFromString(authdef->secrettype= )) < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown secret type '%s'"), + NULLSTR(authdef->secrettype)); + return -1; + } - 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->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; @@ -9078,7 +9104,8 @@ static int virDomainDiskDefParseValidate(const virDomainDiskDef *def) { - virStorageSource *next; + 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) { @@ -9150,23 +9177,6 @@ virDomainDiskDefParseValidate(const virDomainDiskDef= *def) } } - for (next =3D def->src; next; next =3D next->backingStore) { - if (virDomainDiskSourceDefParseAuthValidate(next) < 0) - return -1; - - if (next->encryption) { - virStorageEncryption *encryption =3D next->encryption; - - if (encryption->format =3D=3D VIR_STORAGE_ENCRYPTION_FORMAT_LU= KS && - encryption->encinfo.cipher_name) { - - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("supplying for domain disk defin= ition " - "is unnecessary")); - return -1; - } - } - } return 0; } --=20 2.30.2