From nobody Sun Feb 8 19:59:39 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=1629816732; cv=none; d=zohomail.com; s=zohoarc; b=iLL+33Pls7w8ZysLMLcARBOUArHa4xz3605RINaMkqKJGQ3u8E0kI43PYNkar5SuBYPF1jruupceR9H0Cw4TaYHk8LtsB6XDXGbnj+URc0Po4pku6n9eKTmEOnfdv/i90DPXZZnJeyrBqULP8XDDKSP80KxzT2ztwMwHyB8RneE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1629816732; 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=4WUQJlvKvkgw5dgfjGwrl6KRqfxE7hZ5QHYVfzgiiho=; b=RngFfem0F750T9zir7DSmVS/PPBwpxjx1F/uOAWflt2yQGErvhjeIRiffG4f/9UCN0fdRb1BBMpCqH5Ttu1QTL8T0qfD4vtA204W7JIDaSSSx5I/t3JLV/XPOnFcNMFaXH+Jw+4uRVpCyUmrCBfDDLqziN8u658TXzzoMCC/S6w= 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) 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 1629816732289781.0936221841852; Tue, 24 Aug 2021 07:52:12 -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-459-TIc_QijVPSmvBGfhbm-t-Q-1; Tue, 24 Aug 2021 10:51:40 -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 16E3D185302B; Tue, 24 Aug 2021 14:51:35 +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 C93905DA60; Tue, 24 Aug 2021 14:51:34 +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 99FC65002D; Tue, 24 Aug 2021 14:51:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 17OEpWAH007241 for ; Tue, 24 Aug 2021 10:51:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id CAD9060C9D; Tue, 24 Aug 2021 14:51:32 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.43.2.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 50E2260C82 for ; Tue, 24 Aug 2021 14:51:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629816731; 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=4WUQJlvKvkgw5dgfjGwrl6KRqfxE7hZ5QHYVfzgiiho=; b=awRjJBmivWlb1Wr8tv6rwWFOZhlcIjiB8nh+0t42LsLbm1mxTZ3U5Wl3F1cqVyGH5Tfn0I tWLBB2gw1XxXXPMZaUAmm25cT/ujupJBA+p7tXUS4i8cBVLZgotJTmEPev7nNYR8gxIWjb PBiDmIZ+bFI/kJv1t81fUO8ns4iK4+w= X-MC-Unique: TIc_QijVPSmvBGfhbm-t-Q-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH 2/4] storage_conf: add validation against schema in pool define Date: Tue, 24 Aug 2021 16:51:09 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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) X-ZM-MESSAGEID: 1629816733780100001 Content-Type: text/plain; charset="utf-8" We need to validate the XML against schema if option '--validate' was passed to the virsh command. This patch also includes propagation of flags into the virStoragePoolDefParse() function. Signed-off-by: Kristina Hanicova --- src/conf/domain_conf.c | 2 +- src/conf/storage_conf.c | 13 ++++++++----- src/conf/storage_conf.h | 3 ++- src/storage/storage_driver.c | 4 ++-- src/test/test_driver.c | 4 ++-- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 0328447f87..6127513117 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -30707,7 +30707,7 @@ virDomainStorageSourceTranslateSourcePool(virStorag= eSource *src, if (!(poolxml =3D virStoragePoolGetXMLDesc(pool, 0))) return -1; =20 - if (!(pooldef =3D virStoragePoolDefParseString(poolxml))) + if (!(pooldef =3D virStoragePoolDefParseString(poolxml, 0))) return -1; =20 src->srcpool->pooltype =3D pooldef->type; diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index 040a413d0f..c78456695c 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -1004,12 +1004,14 @@ virStoragePoolDefParseNode(xmlDocPtr xml, =20 static virStoragePoolDef * virStoragePoolDefParse(const char *xmlStr, - const char *filename) + const char *filename, + unsigned int flags) { virStoragePoolDef *ret =3D NULL; g_autoptr(xmlDoc) xml =3D NULL; =20 - if ((xml =3D virXMLParse(filename, xmlStr, _("(storage_pool_definition= )"), NULL, false))) { + if ((xml =3D virXMLParse(filename, xmlStr, _("(storage_pool_definition= )"), + "storagepool.rng", flags & VIR_STORAGE_POOL_DEF= INE_VALIDATE))) { ret =3D virStoragePoolDefParseNode(xml, xmlDocGetRootElement(xml)); } =20 @@ -1018,16 +1020,17 @@ virStoragePoolDefParse(const char *xmlStr, =20 =20 virStoragePoolDef * -virStoragePoolDefParseString(const char *xmlStr) +virStoragePoolDefParseString(const char *xmlStr, + unsigned int flags) { - return virStoragePoolDefParse(xmlStr, NULL); + return virStoragePoolDefParse(xmlStr, NULL, flags); } =20 =20 virStoragePoolDef * virStoragePoolDefParseFile(const char *filename) { - return virStoragePoolDefParse(NULL, filename); + return virStoragePoolDefParse(NULL, filename, 0); } =20 =20 diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h index 76efaac531..aaecf138d6 100644 --- a/src/conf/storage_conf.h +++ b/src/conf/storage_conf.h @@ -275,7 +275,8 @@ virStoragePoolDef * virStoragePoolDefParseXML(xmlXPathContextPtr ctxt); =20 virStoragePoolDef * -virStoragePoolDefParseString(const char *xml); +virStoragePoolDefParseString(const char *xml, + unsigned int flags); =20 virStoragePoolDef * virStoragePoolDefParseFile(const char *filename); diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index 6aa10d89f6..37b84d038a 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -737,7 +737,7 @@ storagePoolCreateXML(virConnectPtr conn, VIR_EXCLUSIVE_FLAGS_RET(VIR_STORAGE_POOL_BUILD_OVERWRITE, VIR_STORAGE_POOL_BUILD_NO_OVERWRITE, NULL); =20 - if (!(newDef =3D virStoragePoolDefParseString(xml))) + if (!(newDef =3D virStoragePoolDefParseString(xml, 0))) goto cleanup; =20 if (virStoragePoolCreateXMLEnsureACL(conn, newDef) < 0) @@ -818,7 +818,7 @@ storagePoolDefineXML(virConnectPtr conn, =20 virCheckFlags(0, NULL); =20 - if (!(newDef =3D virStoragePoolDefParseString(xml))) + if (!(newDef =3D virStoragePoolDefParseString(xml, 0))) goto cleanup; =20 if (virXMLCheckIllegalChars("name", newDef->name, "\n") < 0) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index f60ea870db..33bab0f9d3 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -6645,7 +6645,7 @@ testStoragePoolCreateXML(virConnectPtr conn, virCheckFlags(0, NULL); =20 virObjectLock(privconn); - if (!(newDef =3D virStoragePoolDefParseString(xml))) + if (!(newDef =3D virStoragePoolDefParseString(xml, 0))) goto cleanup; =20 if (!(obj =3D virStoragePoolObjListAdd(privconn->pools, newDef, @@ -6708,7 +6708,7 @@ testStoragePoolDefineXML(virConnectPtr conn, virCheckFlags(0, NULL); =20 virObjectLock(privconn); - if (!(newDef =3D virStoragePoolDefParseString(xml))) + if (!(newDef =3D virStoragePoolDefParseString(xml, 0))) goto cleanup; =20 newDef->capacity =3D defaultPoolCap; --=20 2.31.1