]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
conf: Remove <metadata> elements with no namespace
authorPeter Krempa <pkrempa@redhat.com>
Mon, 5 Oct 2015 07:58:30 +0000 (09:58 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 6 Oct 2015 11:36:12 +0000 (13:36 +0200)
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
tests/qemuxml2argvdata/qemuxml2argv-metadata-duplicate.xml

index 29e55f29861956859d55d59fc8d8ec4d48949b43..65e0d8ea90c049f16b18eea2f4251373c134e7cb 100644 (file)
@@ -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;
 }
index 13fb44963a33e87697d16443682c55fd57f004da..2143faac022f0849d531debdfc34d991f16ebb11 100644 (file)
@@ -24,6 +24,9 @@
   </devices>
   <!-- intentional mis-indentation -->
   <metadata>
+      <herp2erp xmlns:foobar="http://foo.bar3/"/>
+      <herp2erp xmlns:foobar="http://foo.bar3/"/>
+      <herp2erp xmlns:foobar="http://foo.bar3/"/>
       <app1:foo xmlns:app1="http://foo.org/">fooish</app1:foo>
       <app3:foo xmlns:app3="http://foo.org/">fooish</app3:foo>
       <app1:foo xmlns:app1="http://foo.org/">fooish</app1:foo>