[libvirt] [PATCH] conf: Remove <metadata> elements with no namespace
Michal Privoznik
mprivozn at redhat.com
Mon Oct 5 14:39:25 UTC 2015
On 05.10.2015 10:56, Peter Krempa wrote:
> Our docs state that subelements of <metadata> shall have a namespace
> and the medatata APIs expect that too. To avoid inaccessible
> <metadata> sub-elements, just remove those that don't conform to the
> documentation.
>
> Apart from adding the new condition this patch renames the function and
> refactors the code flow to allow the changes.
>
> Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1245525
> ---
> src/conf/domain_conf.c | 29 ++++++++++++++++++++++-------
> 1 file changed, 22 insertions(+), 7 deletions(-)
>
> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
> index 29e55f2..65e0d8e 100644
> --- a/src/conf/domain_conf.c
> +++ b/src/conf/domain_conf.c
> @@ -3688,27 +3688,40 @@ virDomainDefRejectDuplicateControllers(virDomainDefPtr def)
>
>
> /**
> - * virDomainDefRemoveDuplicateMetadata:
> - * @def: Remove duplicate metadata for this def
> + * virDomainDefMetadataSanitize:
> + * @def: Sanitize metadata for this def
> *
> * This function removes metadata elements in @def that share the namespace.
> - * The first metadata entry of every duplicate namespace is kept.
> + * The first metadata entry of every duplicate namespace is kept. Additionally
> + * elements with no namespace are deleted.
> */
> static void
> -virDomainDefRemoveDuplicateMetadata(virDomainDefPtr def)
> +virDomainDefMetadataSanitize(virDomainDefPtr def)
> {
> xmlNodePtr child;
> xmlNodePtr next;
> + xmlNodePtr dupl;
>
> if (!def || !def->metadata)
> return;
>
> - for (child = def->metadata->children; child; child = child->next) {
> + child = def->metadata->children;
> + while (child) {
> + /* remove metadata entries that don't have any namespace at all */
> + if (!child->ns || !child->ns->href) {
> + dupl = child;
> + child = child->next;
> +
> + xmlUnlinkNode(dupl);
> + xmlFreeNode(dupl);
> + continue;
> + }
> +
> /* check that every other child of @root doesn't share the namespace of
> * the current one and delete them possibly */
> next = child->next;
> while (next) {
> - xmlNodePtr dupl = NULL;
> + dupl = NULL;
>
> if (child->ns && next->ns &&
> STREQ_NULLABLE((const char *) child->ns->href,
> @@ -3722,6 +3735,8 @@ virDomainDefRemoveDuplicateMetadata(virDomainDefPtr def)
> xmlFreeNode(dupl);
> }
> }
> +
> + child = child->next;
> }
> }
>
> @@ -3956,7 +3971,7 @@ virDomainDefPostParseInternal(virDomainDefPtr def,
> }
>
> /* clean up possibly duplicated metadata entries */
> - virDomainDefRemoveDuplicateMetadata(def);
> + virDomainDefMetadataSanitize(def);
>
> return 0;
> }
>
ACK, but minding adding a simple test case?
Michal
More information about the libvir-list
mailing list