From nobody Thu Apr 25 03:31:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1538567995719169.0970352948798; Wed, 3 Oct 2018 04:59:55 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B207A308330B; Wed, 3 Oct 2018 11:59:53 +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 1F3906606E; Wed, 3 Oct 2018 11:59:53 +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 551C04CA95; Wed, 3 Oct 2018 11:59:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w93Bxpam011174 for ; Wed, 3 Oct 2018 07:59:51 -0400 Received: by smtp.corp.redhat.com (Postfix) id 750F02010D69; Wed, 3 Oct 2018 11:59:51 +0000 (UTC) Received: from dahmer.brq.redhat.com (unknown [10.43.2.94]) by smtp.corp.redhat.com (Postfix) with ESMTP id BF05C2010D59; Wed, 3 Oct 2018 11:59:50 +0000 (UTC) From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= To: libvir-list@redhat.com Date: Wed, 3 Oct 2018 13:59:38 +0200 Message-Id: <20181003115939.24738-2-fidencio@redhat.com> In-Reply-To: <20181003115939.24738-1-fidencio@redhat.com> References: <20181003115939.24738-1-fidencio@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Subject: [libvirt] [glib PATCH 1/2] object: Also add the ns to the node's children 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: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 03 Oct 2018 11:59:54 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 With the current code, we can only create a custom XML that looks like: installed http://centos.org/centos/7.0:0 /home/fidencio/Downloads/CentOS-7-x86_64-DVD-1804.iso Although it works well for some use cases, there are use cases where we'd like to have something a bit more complex libosinfo or nova examples: 512 10 And for the latter case we'd have to go through the node's children and also set the namespace for each children. Signed-off-by: Fabiano Fid=C3=AAncio --- libvirt-gconfig/libvirt-gconfig-domain.c | 2 +- .../libvirt-gconfig-object-private.h | 3 +- libvirt-gconfig/libvirt-gconfig-object.c | 51 +++++++++++++++---- 3 files changed, 44 insertions(+), 12 deletions(-) diff --git a/libvirt-gconfig/libvirt-gconfig-domain.c b/libvirt-gconfig/lib= virt-gconfig-domain.c index 4fbbe67..a99f9ef 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain.c +++ b/libvirt-gconfig/libvirt-gconfig-domain.c @@ -806,7 +806,7 @@ gboolean gvir_config_domain_set_custom_xml(GVirConfigDo= main *domain, return FALSE; } =20 - gvir_config_object_set_namespace(custom_xml, ns, ns_uri); + gvir_config_object_set_namespace(custom_xml, ns, ns_uri, FALSE); =20 gvir_config_object_delete_children(metadata, NULL, ns_uri); gvir_config_object_attach_add(metadata, custom_xml); diff --git a/libvirt-gconfig/libvirt-gconfig-object-private.h b/libvirt-gco= nfig/libvirt-gconfig-object-private.h index 7a0d21f..02c704e 100644 --- a/libvirt-gconfig/libvirt-gconfig-object-private.h +++ b/libvirt-gconfig/libvirt-gconfig-object-private.h @@ -111,7 +111,8 @@ void gvir_config_object_foreach_child(GVirConfigObject = *object, gpointer opaque); gboolean gvir_config_object_set_namespace(GVirConfigObject *object, const char *ns, - const char *ns_uri); + const char *ns_uri, + gboolean ns_children); GVirConfigObject *gvir_config_object_get_child(GVirConfigObject *object, const gchar *child_name); GVirConfigObject *gvir_config_object_get_child_with_type(GVirConfigObject = *object, diff --git a/libvirt-gconfig/libvirt-gconfig-object.c b/libvirt-gconfig/lib= virt-gconfig-object.c index fffbd21..eb8763e 100644 --- a/libvirt-gconfig/libvirt-gconfig-object.c +++ b/libvirt-gconfig/libvirt-gconfig-object.c @@ -928,26 +928,57 @@ gvir_config_object_remove_attribute(GVirConfigObject = *object, } while (status =3D=3D 0); } =20 -G_GNUC_INTERNAL gboolean -gvir_config_object_set_namespace(GVirConfigObject *object, const char *ns, - const char *ns_uri) +static gboolean +gvir_config_object_set_xmlnode_namespace(xmlNodePtr node, const char *ns, + const char *ns_uri) { xmlNsPtr namespace; =20 - g_return_val_if_fail(GVIR_CONFIG_IS_OBJECT(object), FALSE); - g_return_val_if_fail(ns !=3D NULL, FALSE); - g_return_val_if_fail(ns_uri !=3D NULL, FALSE); - - namespace =3D xmlNewNs(object->priv->node, - (xmlChar *)ns_uri, (xmlChar *)ns); + namespace =3D xmlNewNs(node, (xmlChar *)ns_uri, (xmlChar *)ns); if (namespace =3D=3D NULL) return FALSE; =20 - xmlSetNs(object->priv->node, namespace); + xmlSetNs(node, namespace); + return TRUE; +} + +static gboolean +gvir_config_object_set_namespace_recursively(xmlNodePtr node, + const char *ns, + const char *ns_uri) +{ + xmlNodePtr n; + + for (n =3D node; n !=3D NULL; n =3D n->next) { + if (n->type =3D=3D XML_ELEMENT_NODE) { + if (!gvir_config_object_set_xmlnode_namespace(n, ns, ns_uri)) + return FALSE; + } + + if (!gvir_config_object_set_namespace_recursively(n->children, ns,= NULL)) + return FALSE; + } =20 return TRUE; } =20 +G_GNUC_INTERNAL gboolean +gvir_config_object_set_namespace(GVirConfigObject *object, const char *ns, + const char *ns_uri, gboolean ns_children) +{ + g_return_val_if_fail(GVIR_CONFIG_IS_OBJECT(object), FALSE); + g_return_val_if_fail(ns !=3D NULL, FALSE); + g_return_val_if_fail(ns_uri !=3D NULL, FALSE); + + if (!ns_children) { + return gvir_config_object_set_xmlnode_namespace(object->priv->node, + ns, ns_uri); + } + + return gvir_config_object_set_namespace_recursively(object->priv->node, + ns, ns_uri); +} + G_GNUC_INTERNAL GVirConfigObject * gvir_config_object_get_child_with_type(GVirConfigObject *object, const gchar *child_name, --=20 2.19.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 03:31:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1538567996455988.0177490532249; Wed, 3 Oct 2018 04:59:56 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6477A811A4; Wed, 3 Oct 2018 11:59:54 +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 2131D308BDAA; Wed, 3 Oct 2018 11:59:54 +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 98C6C180B5B7; Wed, 3 Oct 2018 11:59:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w93Bxqwr011181 for ; Wed, 3 Oct 2018 07:59:52 -0400 Received: by smtp.corp.redhat.com (Postfix) id 78FF72010D11; Wed, 3 Oct 2018 11:59:52 +0000 (UTC) Received: from dahmer.brq.redhat.com (unknown [10.43.2.94]) by smtp.corp.redhat.com (Postfix) with ESMTP id C32F52010D59; Wed, 3 Oct 2018 11:59:51 +0000 (UTC) From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= To: libvir-list@redhat.com Date: Wed, 3 Oct 2018 13:59:39 +0200 Message-Id: <20181003115939.24738-3-fidencio@redhat.com> In-Reply-To: <20181003115939.24738-1-fidencio@redhat.com> References: <20181003115939.24738-1-fidencio@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Subject: [libvirt] [glib PATCH 2/2] domain: Introduce gvir_config_domain_set_custom_xml_ns_children() 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: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 03 Oct 2018 11:59:55 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 gvir_config_domain_set_custom_xml_ns_children() basically has the same functionallity as gvir_config_domain_set_custom_xml() but also sets the namespace to the nodes' children. Signed-off-by: Fabiano Fid=C3=AAncio --- libvirt-gconfig/libvirt-gconfig-domain.c | 41 ++++++++++++++++++++---- libvirt-gconfig/libvirt-gconfig-domain.h | 5 +++ libvirt-gconfig/libvirt-gconfig.sym | 5 +++ tests/test-gconfig.c | 3 ++ tests/xml/gconfig-domain.xml | 12 +++++++ 5 files changed, 60 insertions(+), 6 deletions(-) diff --git a/libvirt-gconfig/libvirt-gconfig-domain.c b/libvirt-gconfig/lib= virt-gconfig-domain.c index a99f9ef..ff5352a 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain.c +++ b/libvirt-gconfig/libvirt-gconfig-domain.c @@ -782,11 +782,12 @@ GList *gvir_config_domain_get_devices(GVirConfigDomai= n *domain) return data.devices; } =20 -gboolean gvir_config_domain_set_custom_xml(GVirConfigDomain *domain, - const gchar *xml, - const gchar *ns, - const gchar *ns_uri, - GError **error) +static gboolean gvir_config_domain_set_custom_xml_helper(GVirConfigDomain = *domain, + const gchar *xml, + const gchar *ns, + const gchar *ns_u= ri, + gboolean ns_child= ren, + GError **error) { GVirConfigObject *metadata; GVirConfigObject *custom_xml; @@ -806,7 +807,7 @@ gboolean gvir_config_domain_set_custom_xml(GVirConfigDo= main *domain, return FALSE; } =20 - gvir_config_object_set_namespace(custom_xml, ns, ns_uri, FALSE); + gvir_config_object_set_namespace(custom_xml, ns, ns_uri, ns_children); =20 gvir_config_object_delete_children(metadata, NULL, ns_uri); gvir_config_object_attach_add(metadata, custom_xml); @@ -816,6 +817,34 @@ gboolean gvir_config_domain_set_custom_xml(GVirConfigD= omain *domain, return TRUE; } =20 +gboolean gvir_config_domain_set_custom_xml(GVirConfigDomain *domain, + const gchar *xml, + const gchar *ns, + const gchar *ns_uri, + GError **error) +{ + return gvir_config_domain_set_custom_xml_helper(domain, + xml, + ns, + ns_uri, + FALSE, + error); +} + +gboolean gvir_config_domain_set_custom_xml_ns_children(GVirConfigDomain *d= omain, + const gchar *xml, + const gchar *ns, + const gchar *ns_uri, + GError **error) +{ + return gvir_config_domain_set_custom_xml_helper(domain, + xml, + ns, + ns_uri, + TRUE, + error); +} + struct LookupNamespacedNodeData { const char *ns_uri; xmlNodePtr node; diff --git a/libvirt-gconfig/libvirt-gconfig-domain.h b/libvirt-gconfig/lib= virt-gconfig-domain.h index ed9be6b..822f500 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain.h +++ b/libvirt-gconfig/libvirt-gconfig-domain.h @@ -137,6 +137,11 @@ GList *gvir_config_domain_get_devices(GVirConfigDomain= *domain); void gvir_config_domain_set_lifecycle(GVirConfigDomain *domain, GVirConfigDomainLifecycleEvent event, GVirConfigDomainLifecycleAction acti= on); +gboolean gvir_config_domain_set_custom_xml_ns_children(GVirConfigDomain *d= omain, + const gchar *xml, + const gchar *ns, + const gchar *ns_uri, + GError **error); gboolean gvir_config_domain_set_custom_xml(GVirConfigDomain *domain, const gchar *xml, const gchar *ns, diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-= gconfig.sym index 4ef4bf7..db69cba 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -766,4 +766,9 @@ global: gvir_config_domain_video_set_accel3d; } LIBVIRT_GCONFIG_0.2.2; =20 +LIBVIRT_GCONFIG_1.0.1 { +global: + gvir_config_domain_set_custom_xml_ns_children; +} LIBVIRT_GCONFIG_0.2.4; + # .... define new API here using predicted next version number .... diff --git a/tests/test-gconfig.c b/tests/test-gconfig.c index 2c98c25..a64da26 100644 --- a/tests/test-gconfig.c +++ b/tests/test-gconfig.c @@ -114,6 +114,9 @@ static void test_domain(void) GVIR_CONFIG_DOMAIN_LIFECYCLE_ON_POWER= OFF, GVIR_CONFIG_DOMAIN_LIFECYCLE_RESTART); =20 + gvir_config_domain_set_custom_xml_ns_children(domain, "", "libosinfo", "http://li= bosinfo.org/xmlns/libvirt/domain/1.0", NULL); + gvir_config_domain_set_custom_xml_ns_children(domain, "51210", "nova", "http://openstack.org/nova/instance/1", NULL); + gvir_config_domain_set_custom_xml(domain, "inst= alled", "boxes", "https://wiki.gnome.org/Apps/Boxe= s", NULL); gvir_config_domain_set_custom_xml(domain, "", "ns", "http://foo"= , NULL); gvir_config_domain_set_custom_xml(domain, "", "nsbar", "http://b= ar", NULL); gvir_config_domain_set_custom_xml(domain, "", "ns", "http://bar"= , NULL); diff --git a/tests/xml/gconfig-domain.xml b/tests/xml/gconfig-domain.xml index 4118487..bfe0f53 100644 --- a/tests/xml/gconfig-domain.xml +++ b/tests/xml/gconfig-domain.xml @@ -9,6 +9,18 @@ restart + + + + + + 512 + 10 + + + + installed + --=20 2.19.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list