From nobody Fri May 3 14:45:32 2024 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=1666276751; cv=none; d=zohomail.com; s=zohoarc; b=JE27z0SvvHWL5XdBtK9Xq+THAAfH79J973vW6f/1iLQ8WB+RCl+2I2i1rxr1d6Q0W9B46P2LfpLJO0CDJzPlSis1hfjmGYnwhpuEfjq8lbYPeFbjWpgRxBfnlBACvRLfX+iKrC0FLeXhzvHsCW60/ZVg0G/s3rdziqyJgt4Crtw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666276751; 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=xMsyIIv/nOC629dID40k3DCr4GkgBmdE/YLqS/SjFqU=; b=EiiRSPGjjzPj69DrL11BVsbvLHH3q2D6K3Wcxe10gXnGxWo2exshPH1WcLY0KIiwbEbu1wpXYgosvdJxbWwaWbD68QLAqg1JwkkycMKNsGGDnAm0kQXUid6Cf3iU2ygPSg8vMpbXPdUB6T4q+VbJMi73KEPpsBFCebqaZTqnCh0= 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 1666276751680725.2635791331131; Thu, 20 Oct 2022 07:39:11 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-647-DUDs58VJOyWXn0FB3Z6gWg-1; Thu, 20 Oct 2022 10:38:32 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8962F18E0951; Thu, 20 Oct 2022 14:38:27 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7CAB24B3FC6; Thu, 20 Oct 2022 14:38:22 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id CDC1D1946A44; Thu, 20 Oct 2022 14:38:07 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id ABADB19465B9 for ; Thu, 20 Oct 2022 14:38:06 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 7AA5A1759F; Thu, 20 Oct 2022 14:37:58 +0000 (UTC) Received: from speedmetal.lan (ovpn-208-27.brq.redhat.com [10.40.208.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id B97781759E for ; Thu, 20 Oct 2022 14:37:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666276749; 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=xMsyIIv/nOC629dID40k3DCr4GkgBmdE/YLqS/SjFqU=; b=GfS0j1zWt62N9JOZ6AS5tmkidTIffcTRyMLpNKypOdHLD8Sev+qRMGAz+Fr2aSJuZvVaDJ shcBZb//Z6khk8jpscdh3TNBPmIlt6LX6eLTKrAz+eF8gWWMQPEd463W2CpHjiEGRGNyEE Bh7oQORaqrUSHS4Ioy2Oyi43zSBrITc= X-MC-Unique: DUDs58VJOyWXn0FB3Z6gWg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 1/6] conf: node_device: Add 'validate' argument to virNodeDeviceDefParse Date: Thu, 20 Oct 2022 16:37:50 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 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: 1666276751864100001 Content-Type: text/plain; charset="utf-8" Allow callers to request XML validation against the schema. All callers for now pass 'false'. Signed-off-by: Peter Krempa Reviewed-by: Jonathon Jongsma --- src/conf/node_device_conf.c | 5 +++-- src/conf/node_device_conf.h | 3 ++- src/hypervisor/domain_driver.c | 6 +++--- src/node_device/node_device_driver.c | 4 ++-- src/test/test_driver.c | 4 ++-- tests/nodedevmdevctltest.c | 4 ++-- tests/nodedevxml2xmltest.c | 3 ++- 7 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index bdfbbab434..f5283a77b3 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -2479,14 +2479,15 @@ virNodeDeviceDefParse(const char *str, int create, const char *virt_type, virNodeDeviceDefParserCallbacks *parserCallbacks, - void *opaque) + void *opaque, + bool validate) { g_autoptr(xmlDoc) xml =3D NULL; g_autoptr(xmlXPathContext) ctxt =3D NULL; g_autoptr(virNodeDeviceDef) def =3D NULL; if (!(xml =3D virXMLParse(filename, str, _("(node_device_definition)"), - "device", &ctxt, NULL, false))) + "device", &ctxt, "nodedev.rng", validate))) return NULL; if (!(def =3D virNodeDeviceDefParseXML(ctxt, create, virt_type))) diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h index a556358632..2b2c8f797e 100644 --- a/src/conf/node_device_conf.h +++ b/src/conf/node_device_conf.h @@ -382,7 +382,8 @@ virNodeDeviceDefParse(const char *str, int create, const char *virt_type, virNodeDeviceDefParserCallbacks *parserCallbacks, - void *opaque); + void *opaque, + bool validate); virNodeDeviceDef * virNodeDeviceDefParseXML(xmlXPathContextPtr ctxt, diff --git a/src/hypervisor/domain_driver.c b/src/hypervisor/domain_driver.c index c154f00eea..d020b94921 100644 --- a/src/hypervisor/domain_driver.c +++ b/src/hypervisor/domain_driver.c @@ -395,7 +395,7 @@ virDomainDriverNodeDeviceReset(virNodeDevicePtr dev, if (!xml) return -1; - def =3D virNodeDeviceDefParse(xml, NULL, EXISTING_DEVICE, NULL, NULL, = NULL); + def =3D virNodeDeviceDefParse(xml, NULL, EXISTING_DEVICE, NULL, NULL, = NULL, false); if (!def) return -1; @@ -440,7 +440,7 @@ virDomainDriverNodeDeviceReAttach(virNodeDevicePtr dev, if (!xml) return -1; - def =3D virNodeDeviceDefParse(xml, NULL, EXISTING_DEVICE, NULL, NULL, = NULL); + def =3D virNodeDeviceDefParse(xml, NULL, EXISTING_DEVICE, NULL, NULL, = NULL, false); if (!def) return -1; @@ -488,7 +488,7 @@ virDomainDriverNodeDeviceDetachFlags(virNodeDevicePtr d= ev, if (!xml) return -1; - def =3D virNodeDeviceDefParse(xml, NULL, EXISTING_DEVICE, NULL, NULL, = NULL); + def =3D virNodeDeviceDefParse(xml, NULL, EXISTING_DEVICE, NULL, NULL, = NULL, false); if (!def) return -1; diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index 8e93b0dd6f..d067234ab3 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -885,7 +885,7 @@ nodeDeviceCreateXML(virConnectPtr conn, virt_type =3D virConnectGetType(conn); if (!(def =3D virNodeDeviceDefParse(xmlDesc, NULL, CREATE_DEVICE, virt= _type, - &driver->parserCallbacks, NULL))) + &driver->parserCallbacks, NULL, fals= e))) return NULL; if (virNodeDeviceCreateXMLEnsureACL(conn, def) < 0) @@ -1406,7 +1406,7 @@ nodeDeviceDefineXML(virConnect *conn, virt_type =3D virConnectGetType(conn); if (!(def =3D virNodeDeviceDefParse(xmlDesc, NULL, CREATE_DEVICE, virt= _type, - &driver->parserCallbacks, NULL))) + &driver->parserCallbacks, NULL, fals= e))) return NULL; if (virNodeDeviceDefineXMLEnsureACL(conn, def) < 0) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 67c70de11d..9b397e66b1 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -7629,7 +7629,7 @@ testNodeDeviceMockCreateVport(testDriver *driver, if (!xml) goto cleanup; - if (!(def =3D virNodeDeviceDefParse(xml, NULL, EXISTING_DEVICE, NULL, = NULL, NULL))) + if (!(def =3D virNodeDeviceDefParse(xml, NULL, EXISTING_DEVICE, NULL, = NULL, NULL, false))) goto cleanup; VIR_FREE(def->name); @@ -7691,7 +7691,7 @@ testNodeDeviceCreateXML(virConnectPtr conn, virCheckFlags(0, NULL); - if (!(def =3D virNodeDeviceDefParse(xmlDesc, NULL, CREATE_DEVICE, NULL= , NULL, NULL))) + if (!(def =3D virNodeDeviceDefParse(xmlDesc, NULL, CREATE_DEVICE, NULL= , NULL, NULL, false))) goto cleanup; /* We run this simply for validation - it essentially validates that diff --git a/tests/nodedevmdevctltest.c b/tests/nodedevmdevctltest.c index 02e85d4779..4dc524b5a5 100644 --- a/tests/nodedevmdevctltest.c +++ b/tests/nodedevmdevctltest.c @@ -71,7 +71,7 @@ testMdevctlCmd(virMdevctlCommand cmd_type, } if (!(def =3D virNodeDeviceDefParse(NULL, mdevxml, create, VIRT_TYPE, - &parser_callbacks, NULL))) + &parser_callbacks, NULL, false))) return -1; /* this function will set a stdin buffer containing the json configura= tion @@ -143,7 +143,7 @@ testMdevctlAutostart(const void *data G_GNUC_UNUSED) g_autoptr(virCommandDryRunToken) dryRunToken =3D virCommandDryRunToken= New(); if (!(def =3D virNodeDeviceDefParse(NULL, mdevxml, CREATE_DEVICE, VIRT= _TYPE, - &parser_callbacks, NULL))) + &parser_callbacks, NULL, false))) return -1; virCommandSetDryRun(dryRunToken, &buf, true, true, NULL, NULL); diff --git a/tests/nodedevxml2xmltest.c b/tests/nodedevxml2xmltest.c index d1c0652e7d..068ec68769 100644 --- a/tests/nodedevxml2xmltest.c +++ b/tests/nodedevxml2xmltest.c @@ -23,7 +23,8 @@ testCompareXMLToXMLFiles(const char *xml, const char *out= file) if (virTestLoadFile(xml, &xmlData) < 0) goto fail; - if (!(dev =3D virNodeDeviceDefParse(xmlData, NULL, EXISTING_DEVICE, NU= LL, NULL, NULL))) + if (!(dev =3D virNodeDeviceDefParse(xmlData, NULL, EXISTING_DEVICE, NU= LL, + NULL, NULL, false))) goto fail; /* Calculate some things that are not read in */ --=20 2.37.3 From nobody Fri May 3 14:45:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1666276717; cv=none; d=zohomail.com; s=zohoarc; b=W7Pgn6oZ8EngJmUsAr3Zu6psjJnowWVbNaOvOJQlnCLStHbRjrdRO630bY9kBPcQ2BhbHouQ3llqfxReC298P99eOkQcr1DTFJlbc2O5QNqbmqY9uDhsDHhQLsMNsMyG0/tAyQnuLOKCbbgOEsqIAjh8ZMw53hYwyscJg6KEcuQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666276717; 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=wOEioPUaV9a1oUqdNhAjqP48bUeE5lgW02xzImuFT68=; b=c7PJW4ieXl6nGVSd96M9q61Pmjcj7reyOiAavyhIml6tRQACjAU5rLtm9RDCir4LJ/vdd8EbBgkvMTYsN3g1q5H9GGFMCYecXH5adJ4xVJ290MYzKSybjtf/Jg06Is+a8NdgfXAJpKgjEron9UuBmzb+fWxA/etQqavwm4fcMzY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 1666276717166667.370368159002; Thu, 20 Oct 2022 07:38:37 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-643-Ms_kELcFNMKAGwtVeuYMuw-1; Thu, 20 Oct 2022 10:38:31 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 322493C0F250; Thu, 20 Oct 2022 14:38:27 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id D11F4215CDA7; Thu, 20 Oct 2022 14:38:19 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id BF2B019465BA; Thu, 20 Oct 2022 14:38:07 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id ABB4319465BA for ; Thu, 20 Oct 2022 14:38:06 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 7477918EB4; Thu, 20 Oct 2022 14:37:59 +0000 (UTC) Received: from speedmetal.lan (ovpn-208-27.brq.redhat.com [10.40.208.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id DE4B91759E for ; Thu, 20 Oct 2022 14:37:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666276716; 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=wOEioPUaV9a1oUqdNhAjqP48bUeE5lgW02xzImuFT68=; b=ZH7nZOzfN2b2M833htu1IpF07xhjeqNyA1Vu2YuV76Cw538cOSKGeQpR6c8hL0yeW2nHsG YwofdGsie2Mkjoq9llZ6lcO9RLG20VygNVj0j53XnyyGYH0dNwanlaqCEVQlTc26p26FRj Vr18uZCk9xBR/yfJh2Q8vtel94MJRHo= X-MC-Unique: Ms_kELcFNMKAGwtVeuYMuw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 2/6] nodedev: Add VIR_NODE_DEVICE_(CREATE|DEFINE)_XML_VALIDATE flags Date: Thu, 20 Oct 2022 16:37:51 +0200 Message-Id: <46adcd8558046f515f10e6b7cdd175c07f2435ce.1666276542.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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: 1666276717730100004 Content-Type: text/plain; charset="utf-8" The node device APIs which get XML from the user don't yet support XML validation flags. Introduce virNodeDeviceCreateXMLFlags and virNodeDeviceDefineXMLFlags with the appropriate flags and add virsh support for the new flags. Signed-off-by: Peter Krempa Reviewed-by: Jonathon Jongsma --- docs/manpages/virsh.rst | 10 ++++++++-- include/libvirt/libvirt-nodedev.h | 19 +++++++++++++++++++ src/libvirt-nodedev.c | 4 ++-- tools/virsh-nodedev.c | 20 ++++++++++++++++++-- 4 files changed, 47 insertions(+), 6 deletions(-) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index 61fcb2e9ca..532d4e779c 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -5203,7 +5203,7 @@ nodedev-create :: - nodedev-create FILE + nodedev-create FILE [--validate] Create a device on the host node that can then be assigned to virtual machines. Normally, libvirt is able to automatically determine which @@ -5211,6 +5211,9 @@ host nodes are available for use, but this allows reg= istration of host hardware that libvirt did not automatically detect. *file* contains xml for a top-level description of a node device. +If *--validate* is specified, validates the format of the XML document aga= inst +an internal RNG schema. + nodedev-destroy --------------- @@ -5234,11 +5237,14 @@ nodedev-define :: - nodedev-define FILE + nodedev-define FILE [--validate] Define an inactive persistent device or modify an existing persistent one = from the XML *FILE*. +If *--validate* is specified, validates the format of the XML document aga= inst +an internal RNG schema. + nodedev-undefine ---------------- diff --git a/include/libvirt/libvirt-nodedev.h b/include/libvirt/libvirt-no= dedev.h index 4fccd3f614..428b0d722f 100644 --- a/include/libvirt/libvirt-nodedev.h +++ b/include/libvirt/libvirt-nodedev.h @@ -130,12 +130,31 @@ int virNodeDeviceDetachFlags(virN= odeDevicePtr dev, int virNodeDeviceReAttach (virNodeDevicePtr dev); int virNodeDeviceReset (virNodeDevicePtr dev); +/** + * virNodeDeviceCreateXMLFlags: + * + * Since: 8.10.0 + */ +typedef enum { + VIR_NODE_DEVICE_CREATE_XML_VALIDATE =3D 1 << 0, /* Validate the XML do= cument against schema (Since: 8.10.0) */ +} virNodeDeviceCreateXMLFlags; + virNodeDevicePtr virNodeDeviceCreateXML (virConnectPtr conn, const char *xmlDesc, unsigned int flags); int virNodeDeviceDestroy (virNodeDevicePtr dev); + +/** + * virNodeDeviceDefineXMLFlags: + * + * Since: 8.10.0 + */ +typedef enum { + VIR_NODE_DEVICE_DEFINE_XML_VALIDATE =3D 1 << 0, /* Validate the XML do= cument against schema (Since: 8.10.0) */ +} virNodeDeviceDefineXMLFlags; + virNodeDevicePtr virNodeDeviceDefineXML(virConnectPtr conn, const char *xmlDesc, unsigned int flags); diff --git a/src/libvirt-nodedev.c b/src/libvirt-nodedev.c index d5a24ea2ef..1b7dee113e 100644 --- a/src/libvirt-nodedev.c +++ b/src/libvirt-nodedev.c @@ -694,7 +694,7 @@ virNodeDeviceReset(virNodeDevicePtr dev) * virNodeDeviceCreateXML: * @conn: pointer to the hypervisor connection * @xmlDesc: string containing an XML description of the device to be crea= ted - * @flags: extra flags; not used yet, so callers should always pass 0 + * @flags: bitwise-OR of supported virNodeDeviceCreateXMLFlags * * Create a new device on the VM host machine, for example, virtual * HBAs created using vport_create. @@ -778,7 +778,7 @@ virNodeDeviceDestroy(virNodeDevicePtr dev) * virNodeDeviceDefineXML: * @conn: pointer to the hypervisor connection * @xmlDesc: string containing an XML description of the device to be defi= ned - * @flags: extra flags; not used yet, so callers should always pass 0 + * @flags: bitwise-OR of supported virNodeDeviceDefineXMLFlags * * Define a new device on the VM host machine, for example, a mediated dev= ice * diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index 2adcad9c10..5dbec65367 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -50,6 +50,10 @@ static const vshCmdInfo info_node_device_create[] =3D { static const vshCmdOptDef opts_node_device_create[] =3D { VIRSH_COMMON_OPT_FILE(N_("file containing an XML description " "of the device")), + {.name =3D "validate", + .type =3D VSH_OT_BOOL, + .help =3D N_("validate the XML against the schema") + }, {.name =3D NULL} }; @@ -60,6 +64,7 @@ cmdNodeDeviceCreate(vshControl *ctl, const vshCmd *cmd) const char *from =3D NULL; g_autofree char *buffer =3D NULL; virshControl *priv =3D ctl->privData; + unsigned int flags =3D 0; if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) return false; @@ -67,7 +72,10 @@ cmdNodeDeviceCreate(vshControl *ctl, const vshCmd *cmd) if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) return false; - if (!(dev =3D virNodeDeviceCreateXML(priv->conn, buffer, 0))) { + if (vshCommandOptBool(cmd, "validate")) + flags |=3D VIR_NODE_DEVICE_CREATE_XML_VALIDATE; + + if (!(dev =3D virNodeDeviceCreateXML(priv->conn, buffer, flags))) { vshError(ctl, _("Failed to create node device from %s"), from); return false; } @@ -1058,6 +1066,10 @@ static const vshCmdInfo info_node_device_define[] = =3D { static const vshCmdOptDef opts_node_device_define[] =3D { VIRSH_COMMON_OPT_FILE(N_("file containing an XML description " "of the device")), + {.name =3D "validate", + .type =3D VSH_OT_BOOL, + .help =3D N_("validate the XML against the schema") + }, {.name =3D NULL} }; @@ -1068,6 +1080,7 @@ cmdNodeDeviceDefine(vshControl *ctl, const vshCmd *cm= d G_GNUC_UNUSED) const char *from =3D NULL; g_autofree char *buffer =3D NULL; virshControl *priv =3D ctl->privData; + unsigned int flags =3D 0; if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) return false; @@ -1075,7 +1088,10 @@ cmdNodeDeviceDefine(vshControl *ctl, const vshCmd *c= md G_GNUC_UNUSED) if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) return false; - if (!(dev =3D virNodeDeviceDefineXML(priv->conn, buffer, 0))) { + if (vshCommandOptBool(cmd, "validate")) + flags |=3D VIR_NODE_DEVICE_DEFINE_XML_VALIDATE; + + if (!(dev =3D virNodeDeviceDefineXML(priv->conn, buffer, flags))) { vshError(ctl, _("Failed to define node device from '%s'"), from); return false; } --=20 2.37.3 From nobody Fri May 3 14:45:32 2024 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=1666276715; cv=none; d=zohomail.com; s=zohoarc; b=RM+QLSWP70OBswpb8heQPGrBz5VshHxFcQ3J110NUfdRn3GxHPHO/IHOYSqmOpkCDzn3Kg7kHcYeDJeLSu7a8CdzSJCX57n4wQP+ADdjaVA1hgmOEBdnoFFrWPl6GuCBshli9eUWzLaKKCKVrZ+HI046v0w61CE3713eoXMLYLY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666276715; 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=2qi8HX3khxbI+vCGCKnPEsPZWb4x+6/npF/T65PNXKE=; b=EiEsipkZxDRzLrVldzjqq+ay1eTnn0cxo2bC+oC+IVl4NjCYcVUrp/qUx5a2yJ8s1GBhXrzB2AifIEAJ8dSOERpAFGk7RZiMud/hbmK57RwV4hFSXrc12lLkoQVZySWEd9PgE7oHQPsLcWKnEzKV0BFdY579kPRSq4useSmjwXQ= 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 166627671527159.88899437442103; Thu, 20 Oct 2022 07:38:35 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-574-pW9VZkf2NWKZVXHOUvqDqw-1; Thu, 20 Oct 2022 10:38:31 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E25F0380391E; Thu, 20 Oct 2022 14:38:27 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id B0FF21401CDA; Thu, 20 Oct 2022 14:38:27 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 3C02D1946A66; Thu, 20 Oct 2022 14:38:08 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 18EDE19465BA for ; Thu, 20 Oct 2022 14:38:07 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 7101735429; Thu, 20 Oct 2022 14:38:00 +0000 (UTC) Received: from speedmetal.lan (ovpn-208-27.brq.redhat.com [10.40.208.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id D039E1759E for ; Thu, 20 Oct 2022 14:37:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666276714; 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=2qi8HX3khxbI+vCGCKnPEsPZWb4x+6/npF/T65PNXKE=; b=VfoPav/A5gQ103tYoUUogDf9KC+mRc02TeCdlJRlXg9kz2T0X2OXwiy8wsl4XKMWC9+Mal r7oq9qm2Wkm+6jK7s1X3U3qEqextLfrvn6FayIk3yClyG5CH64GyM1uUOQMNUBxbuI/CLF /l++8srsZZWZwKH6G/YnMHqI94TE7kY= X-MC-Unique: pW9VZkf2NWKZVXHOUvqDqw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 3/6] nodedev|test: Implement support for validating node device XMLs Date: Thu, 20 Oct 2022 16:37:52 +0200 Message-Id: <922822dee7dbef2e06f6e01d0a5572ad2f5b4d53.1666276542.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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: 1666276715785100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa Reviewed-by: Jonathon Jongsma --- src/node_device/node_device_driver.c | 10 ++++++---- src/test/test_driver.c | 6 ++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index d067234ab3..0fdfe1db96 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -876,8 +876,9 @@ nodeDeviceCreateXML(virConnectPtr conn, g_autofree char *wwpn =3D NULL; virNodeDevicePtr device =3D NULL; const char *virt_type =3D NULL; + bool validate =3D flags & VIR_NODE_DEVICE_CREATE_XML_VALIDATE; - virCheckFlags(0, NULL); + virCheckFlags(VIR_NODE_DEVICE_CREATE_XML_VALIDATE, NULL); if (nodeDeviceInitWait() < 0) return NULL; @@ -885,7 +886,7 @@ nodeDeviceCreateXML(virConnectPtr conn, virt_type =3D virConnectGetType(conn); if (!(def =3D virNodeDeviceDefParse(xmlDesc, NULL, CREATE_DEVICE, virt= _type, - &driver->parserCallbacks, NULL, fals= e))) + &driver->parserCallbacks, NULL, vali= date))) return NULL; if (virNodeDeviceCreateXMLEnsureACL(conn, def) < 0) @@ -1397,8 +1398,9 @@ nodeDeviceDefineXML(virConnect *conn, const char *virt_type =3D NULL; g_autofree char *uuid =3D NULL; g_autofree char *name =3D NULL; + bool validate =3D flags & VIR_NODE_DEVICE_DEFINE_XML_VALIDATE; - virCheckFlags(0, NULL); + virCheckFlags(VIR_NODE_DEVICE_DEFINE_XML_VALIDATE, NULL); if (nodeDeviceInitWait() < 0) return NULL; @@ -1406,7 +1408,7 @@ nodeDeviceDefineXML(virConnect *conn, virt_type =3D virConnectGetType(conn); if (!(def =3D virNodeDeviceDefParse(xmlDesc, NULL, CREATE_DEVICE, virt= _type, - &driver->parserCallbacks, NULL, fals= e))) + &driver->parserCallbacks, NULL, vali= date))) return NULL; if (virNodeDeviceDefineXMLEnsureACL(conn, def) < 0) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 9b397e66b1..58c2a02561 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -7688,10 +7688,12 @@ testNodeDeviceCreateXML(virConnectPtr conn, virNodeDeviceDef *objdef; g_autofree char *wwnn =3D NULL; g_autofree char *wwpn =3D NULL; + bool validate =3D flags & VIR_NODE_DEVICE_CREATE_XML_VALIDATE; - virCheckFlags(0, NULL); + virCheckFlags(VIR_NODE_DEVICE_CREATE_XML_VALIDATE, NULL); - if (!(def =3D virNodeDeviceDefParse(xmlDesc, NULL, CREATE_DEVICE, NULL= , NULL, NULL, false))) + if (!(def =3D virNodeDeviceDefParse(xmlDesc, NULL, CREATE_DEVICE, NULL= , NULL, + NULL, validate))) goto cleanup; /* We run this simply for validation - it essentially validates that --=20 2.37.3 From nobody Fri May 3 14:45:32 2024 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=1666276725; cv=none; d=zohomail.com; s=zohoarc; b=VogcxPZNEMfWgOe+VLIiU3beBlqPMeqpVekJ2kgA58zWAjlEWjqgjIU3EWeH3/tTooJY5sAJWLZebAak6Ft72JP2RUXD7QbQytayXCv7krBTWmgiNjDn6rflcliS1OAXfqZRSqDlgRCKBv6qKZCalozEU1nJGacVesuSR4PHGjk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666276725; 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=ycAyE9HeDhqDPwTxgecrTJ088d4AQUxx+NJA2LPUADE=; b=NZXpdyyryiJWQggxyh+WjJ7ceddtSZfV6EZSbwGOBemIYKa/9jNL59EP939fPVAYhpq4xTcdfTDg+bM8MFYTUDm+Qmd7ygLCJ6oTWE1eauroDRfatg7fc1Jeb76FZBwAiUzaa1R0xYq+E9fnzwZFpPB8Zc+qCnVaM5tGEW4YjPY= 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 1666276725676451.163214045117; Thu, 20 Oct 2022 07:38:45 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-590-5SdCJKS5OC6gP1XWrWb-TQ-1; Thu, 20 Oct 2022 10:38:34 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 905238065ED; Thu, 20 Oct 2022 14:38:28 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 583831401CD3; Thu, 20 Oct 2022 14:38:28 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 7E5061946A7E; Thu, 20 Oct 2022 14:38:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 18E5119465B9 for ; Thu, 20 Oct 2022 14:38:07 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 5FE9439D7C; Thu, 20 Oct 2022 14:38:01 +0000 (UTC) Received: from speedmetal.lan (ovpn-208-27.brq.redhat.com [10.40.208.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id C9ED51759E for ; Thu, 20 Oct 2022 14:38:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666276724; 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=ycAyE9HeDhqDPwTxgecrTJ088d4AQUxx+NJA2LPUADE=; b=MuLK3hbB+n/wJIcxB8MTzDHyrGoF4OpNu04K/TcuFdis/BMM5nBiLV2AJh87BsWGJKD8WU N9vtq/iwqzkzw5a4VAB3F2ifk8ODguMNvzff6j9MZSUqZZTF8TC4hAJ+i3H9ZRHNbP4vBq sEr5hVSCCzPDzCe/31nVPFMKtYCfo5E= X-MC-Unique: 5SdCJKS5OC6gP1XWrWb-TQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 4/6] conf: storage: Add support for validating storage vol XML to virStorageVolDefParse Date: Thu, 20 Oct 2022 16:37:53 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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: 1666276727736100005 Content-Type: text/plain; charset="utf-8" Introduce the VIR_VOL_XML_PARSE_VALIDATE parser flag and wire it up into the validator. Signed-off-by: Peter Krempa Reviewed-by: Jonathon Jongsma --- src/conf/storage_conf.c | 3 ++- src/conf/storage_conf.h | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index 0f4fe1451e..72c53872cb 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -1407,9 +1407,10 @@ virStorageVolDefParse(virStoragePoolDef *pool, { g_autoptr(xmlDoc) xml =3D NULL; g_autoptr(xmlXPathContext) ctxt =3D NULL; + bool validate =3D flags & VIR_VOL_XML_PARSE_VALIDATE; if (!(xml =3D virXMLParse(filename, xmlStr, _("(storage_volume_definit= ion)"), - "volume", &ctxt, NULL, false))) + "volume", &ctxt, "storagevol.rng", validate))) return NULL; return virStorageVolDefParseXML(pool, ctxt, flags); diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h index bbfdbc2f2f..fc67957cfe 100644 --- a/src/conf/storage_conf.h +++ b/src/conf/storage_conf.h @@ -284,6 +284,8 @@ typedef enum { VIR_VOL_XML_PARSE_NO_CAPACITY =3D 1 << 0, /* do not require volume capacity if the volume has a backing store */ VIR_VOL_XML_PARSE_OPT_CAPACITY =3D 1 << 1, + /* validate the XML against the RNG schema */ + VIR_VOL_XML_PARSE_VALIDATE =3D 1 << 2, } virStorageVolDefParseFlags; virStorageVolDef * --=20 2.37.3 From nobody Fri May 3 14:45:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1666276724; cv=none; d=zohomail.com; s=zohoarc; b=HECWjUqD4fsHMTeB6JcUtKyssGCLsD5CX0kVX/5zvbgslJ2FtsBC6eUNunffjs0XswxVYnD5z3YhUjGGKerekFTuM7MBEs+zZZz1hKKPRvdxqoRlum88z2MBe/NSxsIRuB6oAmAEmeDjlxZwBBL5cV81tpJ7znapQ2Uozfw1S6w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666276724; 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=I/icNU4RRAXJ8fgd7by8h26gWx1MZ/az9cIv+8pNTbI=; b=GQ9HZ6YbCePNNRdXXYKERb1jAWVspNOnF0xHWnbZKOnPvutVt54Q+23+BjKuiKpu5wbR04iY5tuwVKV8oeKpWtHHbdz3uzXAqFG9iO4enHgUJGd7P1YQuIOJGS8Jz00vmeh834i5SoIja3/vokk/Lf8SrHO7f9dsWNwMP5OI6VY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 1666276724262205.1477612158219; Thu, 20 Oct 2022 07:38:44 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-575-UobVrrhMNpmezgmwSo5nkQ-1; Thu, 20 Oct 2022 10:38:33 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 362AF857D0A; Thu, 20 Oct 2022 14:38:28 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1B6FD4221F; Thu, 20 Oct 2022 14:38:28 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 2FC5E1946A73; Thu, 20 Oct 2022 14:38:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id D7BF11946A72 for ; Thu, 20 Oct 2022 14:38:08 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 5168749AFD; Thu, 20 Oct 2022 14:38:02 +0000 (UTC) Received: from speedmetal.lan (ovpn-208-27.brq.redhat.com [10.40.208.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id B9E141759E for ; Thu, 20 Oct 2022 14:38:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666276723; 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=I/icNU4RRAXJ8fgd7by8h26gWx1MZ/az9cIv+8pNTbI=; b=YDpYbn7yTSCJXBAjFdn0Hj7pthjnWVeqP8t365fLmugbjKasM48eRBWqGyygt83+8fEsMp KBA60uaESHwEIiIJwndGH5+B+trViPOjFmMTWGSEv8waFvoIlcPZ/om6mUwSFEWdlqP5A8 QRWHvuCzD4vjylwECIx7GsxCAGMS1XU= X-MC-Unique: UobVrrhMNpmezgmwSo5nkQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 5/6] storage: Add VIR_STORAGE_VOL_CREATE_VALIDATE flag Date: Thu, 20 Oct 2022 16:37:54 +0200 Message-Id: <2a73e1fd0f211f06ad729470bb0264f2024a0a3f.1666276542.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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: 1666276725774100003 Content-Type: text/plain; charset="utf-8" Allow users to request validation of the storage volume XML. Add new flag and virsh support. Signed-off-by: Peter Krempa Reviewed-by: Jonathon Jongsma --- docs/manpages/virsh.rst | 9 +++++++-- include/libvirt/libvirt-storage.h | 1 + tools/virsh-volume.c | 14 ++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index 532d4e779c..1e85b6ae78 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -6542,7 +6542,7 @@ vol-create :: - vol-create pool-or-uuid FILE [--prealloc-metadata] + vol-create pool-or-uuid FILE [--prealloc-metadata] [--validate] Create a volume from an XML . @@ -6557,6 +6557,9 @@ support full allocation). This option creates a spars= e image file with metadata, resulting in higher performance compared to images with no preallocation a= nd only slightly higher initial disk space usage. +If *--validate* is specified, validates the format of the XML document aga= inst +an internal RNG schema. + **Example:** :: @@ -6574,7 +6577,7 @@ vol-create-from :: vol-create-from pool-or-uuid FILE vol-name-or-key-or-path - [--inputpool pool-or-uuid] [--prealloc-metadata] [--reflink] + [--inputpool pool-or-uuid] [--prealloc-metadata] [--reflink] [--val= idate] Create a volume, using another volume as input. @@ -6596,6 +6599,8 @@ When *--reflink* is specified, perform a COW lightwei= ght copy, where the data blocks are copied only when modified. If this is not possible, the copy fails. +If *--validate* is specified, validates the format of the XML document aga= inst +an internal RNG schema. vol-create-as ------------- diff --git a/include/libvirt/libvirt-storage.h b/include/libvirt/libvirt-st= orage.h index af1c50b9f1..aaad4a3da1 100644 --- a/include/libvirt/libvirt-storage.h +++ b/include/libvirt/libvirt-storage.h @@ -437,6 +437,7 @@ const char* virStorageVolGetKey = (virStorageVolPtr vol); typedef enum { VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA =3D 1 << 0, /* (Since: 1.0.1)= */ VIR_STORAGE_VOL_CREATE_REFLINK =3D 1 << 1, /* perform a btrfs lightwei= ght copy (Since: 1.2.13) */ + VIR_STORAGE_VOL_CREATE_VALIDATE =3D 1 << 2, /* Validate the XML docume= nt against schema (Since: 8.10.0) */ } virStorageVolCreateFlags; virStorageVolPtr virStorageVolCreateXML (virStoragePoolPtr= pool, diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c index 300a0aa8e5..4f23481180 100644 --- a/tools/virsh-volume.c +++ b/tools/virsh-volume.c @@ -380,6 +380,10 @@ static const vshCmdOptDef opts_vol_create[] =3D { .type =3D VSH_OT_BOOL, .help =3D N_("preallocate metadata (for qcow2 instead of full allocat= ion)") }, + {.name =3D "validate", + .type =3D VSH_OT_BOOL, + .help =3D N_("validate the XML against the schema") + }, {.name =3D NULL} }; @@ -395,6 +399,9 @@ cmdVolCreate(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptBool(cmd, "prealloc-metadata")) flags |=3D VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA; + if (vshCommandOptBool(cmd, "validate")) + flags |=3D VIR_STORAGE_VOL_CREATE_VALIDATE; + if (!(pool =3D virshCommandOptPool(ctl, cmd, "pool", NULL))) return false; @@ -446,6 +453,10 @@ static const vshCmdOptDef opts_vol_create_from[] =3D { .type =3D VSH_OT_BOOL, .help =3D N_("use btrfs COW lightweight copy") }, + {.name =3D "validate", + .type =3D VSH_OT_BOOL, + .help =3D N_("validate the XML against the schema") + }, {.name =3D NULL} }; @@ -468,6 +479,9 @@ cmdVolCreateFrom(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptBool(cmd, "reflink")) flags |=3D VIR_STORAGE_VOL_CREATE_REFLINK; + if (vshCommandOptBool(cmd, "validate")) + flags |=3D VIR_STORAGE_VOL_CREATE_VALIDATE; + if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) return false; --=20 2.37.3 From nobody Fri May 3 14:45:32 2024 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=1666276723; cv=none; d=zohomail.com; s=zohoarc; b=A/BDy6+QtxttgSNPXzirKnGt3r7d3VbXLaZFPBKDzOz520S9g7aQ6qc92xNUexcoVl6VMSViHA4iGdLsoVoE8o8eM+QZ5Rxxnz4iaZDg6YPcn60Tz1dGT0iOBMNuuy8N5rQcISpxvSbDsE8Od3CvLVLm7F3gP2vOdpfGGfucykU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666276723; 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=C9ht20rtfcusaBAb9vQhGYPDhYci1ztuwOSZbbvtHJE=; b=Qd3wYLTE1hmetKExLqrb1JKlUQvIFKV4yKvMkG1jV01QKhiTUWw4/RMPvPK5YsqNlNCXFJdfGzMa2C3/fmmdIYauLMz/7HyYJLxAkxcyAW03mIj3O/27dySC3jMaUNhFDZfl/5/2Rx2/qSZaQcmvzlTTZjs96WYnIP56HO0MYE8= 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 1666276723416821.0285771525514; Thu, 20 Oct 2022 07:38:43 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-264-YgXX0_XnM-aoJPhBfQ2tpw-1; Thu, 20 Oct 2022 10:38:35 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E537C100F813; Thu, 20 Oct 2022 14:38:28 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id BA5C21400C3B; Thu, 20 Oct 2022 14:38:28 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id D75751947056; Thu, 20 Oct 2022 14:38:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id B8F481946A72 for ; Thu, 20 Oct 2022 14:38:09 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 397A84C816; Thu, 20 Oct 2022 14:38:03 +0000 (UTC) Received: from speedmetal.lan (ovpn-208-27.brq.redhat.com [10.40.208.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id A7A281759E for ; Thu, 20 Oct 2022 14:38:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666276722; 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=C9ht20rtfcusaBAb9vQhGYPDhYci1ztuwOSZbbvtHJE=; b=N7UD9qviRaIrGlIwPQap0LIo9yjIFrjhbX5YbzW12n7Mwl6ZwJS5JrRmUEa5NlZ6rt8ZxX FWEi57s6IFzscK/pA5z+5I+gIk6tGP6uVf6U9hFsCQ3xbKr4kkjNkfV8XvxchS7NYfs4O9 Zl11HAWc6Rp6kFPn37qSZowNacKDOA8= X-MC-Unique: YgXX0_XnM-aoJPhBfQ2tpw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 6/6] storage|test|vbox: Implement support for validating storage volume XMLs Date: Thu, 20 Oct 2022 16:37:55 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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: 1666276723715100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa Reviewed-by: Jonathon Jongsma --- src/storage/storage_driver.c | 18 ++++++++++++++---- src/test/test_driver.c | 16 ++++++++++++---- src/vbox/vbox_storage.c | 8 ++++++-- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index c25d9ca1ad..d90c1c9ee8 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -1877,8 +1877,13 @@ storageVolCreateXML(virStoragePoolPtr pool, virStorageBackend *backend; virStorageVolPtr vol =3D NULL, newvol =3D NULL; g_autoptr(virStorageVolDef) voldef =3D NULL; + unsigned int parseFlags =3D VIR_VOL_XML_PARSE_OPT_CAPACITY; - virCheckFlags(VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA, NULL); + virCheckFlags(VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA | + VIR_STORAGE_VOL_CREATE_VALIDATE, NULL); + + if (flags & VIR_STORAGE_VOL_CREATE_VALIDATE) + parseFlags |=3D VIR_VOL_XML_PARSE_VALIDATE; if (!(obj =3D virStoragePoolObjFromStoragePool(pool))) return NULL; @@ -1893,7 +1898,7 @@ storageVolCreateXML(virStoragePoolPtr pool, if ((backend =3D virStorageBackendForType(def->type)) =3D=3D NULL) goto cleanup; - voldef =3D virStorageVolDefParse(def, xmldesc, NULL, VIR_VOL_XML_PARSE= _OPT_CAPACITY); + voldef =3D virStorageVolDefParse(def, xmldesc, NULL, parseFlags); if (voldef =3D=3D NULL) goto cleanup; @@ -2012,11 +2017,16 @@ storageVolCreateXMLFrom(virStoragePoolPtr pool, virStorageVolPtr vol =3D NULL; int buildret; g_autoptr(virStorageVolDef) voldef =3D NULL; + unsigned int parseFlags =3D VIR_VOL_XML_PARSE_NO_CAPACITY; virCheckFlags(VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA | - VIR_STORAGE_VOL_CREATE_REFLINK, + VIR_STORAGE_VOL_CREATE_REFLINK | + VIR_STORAGE_VOL_CREATE_VALIDATE, NULL); + if (flags & VIR_STORAGE_VOL_CREATE_VALIDATE) + parseFlags |=3D VIR_VOL_XML_PARSE_VALIDATE; + obj =3D virStoragePoolObjFindByUUID(driver->pools, pool->uuid); if (obj && STRNEQ(pool->name, volsrc->pool)) { virObjectUnlock(obj); @@ -2066,7 +2076,7 @@ storageVolCreateXMLFrom(virStoragePoolPtr pool, goto cleanup; } - voldef =3D virStorageVolDefParse(def, xmldesc, NULL, VIR_VOL_XML_PARSE= _NO_CAPACITY); + voldef =3D virStorageVolDefParse(def, xmldesc, NULL, parseFlags); if (voldef =3D=3D NULL) goto cleanup; diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 58c2a02561..87c7d8cf65 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -7182,14 +7182,18 @@ testStorageVolCreateXML(virStoragePoolPtr pool, virStoragePoolDef *def; virStorageVolPtr ret =3D NULL; g_autoptr(virStorageVolDef) privvol =3D NULL; + unsigned int parseFlags =3D 0; - virCheckFlags(0, NULL); + virCheckFlags(VIR_STORAGE_VOL_CREATE_VALIDATE, NULL); + + if (flags & VIR_STORAGE_VOL_CREATE_VALIDATE) + parseFlags |=3D VIR_VOL_XML_PARSE_VALIDATE; if (!(obj =3D testStoragePoolObjFindActiveByName(privconn, pool->name)= )) return NULL; def =3D virStoragePoolObjGetDef(obj); - privvol =3D virStorageVolDefParse(def, xmldesc, NULL, 0); + privvol =3D virStorageVolDefParse(def, xmldesc, NULL, parseFlags); if (privvol =3D=3D NULL) goto cleanup; @@ -7241,14 +7245,18 @@ testStorageVolCreateXMLFrom(virStoragePoolPtr pool, virStorageVolDef *origvol =3D NULL; virStorageVolPtr ret =3D NULL; g_autoptr(virStorageVolDef) privvol =3D NULL; + unsigned int parseFlags =3D 0; - virCheckFlags(0, NULL); + virCheckFlags(VIR_STORAGE_VOL_CREATE_VALIDATE, NULL); + + if (flags & VIR_STORAGE_VOL_CREATE_VALIDATE) + parseFlags |=3D VIR_VOL_XML_PARSE_VALIDATE; if (!(obj =3D testStoragePoolObjFindActiveByName(privconn, pool->name)= )) return NULL; def =3D virStoragePoolObjGetDef(obj); - privvol =3D virStorageVolDefParse(def, xmldesc, NULL, 0); + privvol =3D virStorageVolDefParse(def, xmldesc, NULL, parseFlags); if (privvol =3D=3D NULL) goto cleanup; diff --git a/src/vbox/vbox_storage.c b/src/vbox/vbox_storage.c index 7d1cee562f..f6ede700f9 100644 --- a/src/vbox/vbox_storage.c +++ b/src/vbox/vbox_storage.c @@ -409,11 +409,15 @@ vboxStorageVolCreateXML(virStoragePoolPtr pool, virStorageVolPtr ret =3D NULL; g_autoptr(virStorageVolDef) def =3D NULL; g_autofree char *homedir =3D NULL; + unsigned int parseFlags =3D 0; if (!data->vboxObj) return ret; - virCheckFlags(0, NULL); + virCheckFlags(VIR_STORAGE_VOL_CREATE_VALIDATE, NULL); + + if (flags & VIR_STORAGE_VOL_CREATE_VALIDATE) + parseFlags |=3D VIR_VOL_XML_PARSE_VALIDATE; /* since there is currently one default pool now * and virStorageVolDefFormat() just checks it type @@ -423,7 +427,7 @@ vboxStorageVolCreateXML(virStoragePoolPtr pool, memset(&poolDef, 0, sizeof(poolDef)); poolDef.type =3D VIR_STORAGE_POOL_DIR; - if ((def =3D virStorageVolDefParse(&poolDef, xml, NULL, 0)) =3D=3D NUL= L) + if ((def =3D virStorageVolDefParse(&poolDef, xml, NULL, parseFlags)) = =3D=3D NULL) goto cleanup; if (!def->name || --=20 2.37.3