From 7909300498fc216bbf8fcafb2b770799fb8daf2c Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Tue, 3 Mar 2015 17:50:59 +0100 Subject: [PATCH] conf: Remove duplicate entries in by namespace Since the APIs support just one element per namespace and while modifying an element all duplicates would be removed, let's do this right away in the post parse callback. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1190590 --- src/conf/domain_conf.c | 42 +++++++++++++++++++ .../qemuxml2argv-metadata-duplicate.xml | 34 +++++++++++++++ .../qemuxml2xmlout-metadata-duplicate.xml | 31 ++++++++++++++ tests/qemuxml2xmltest.c | 1 + 4 files changed, 108 insertions(+) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-metadata-duplicate.xml create mode 100644 tests/qemuxml2xmloutdata/qemuxml2xmlout-metadata-duplicate.xml diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 6da02b00ad..5467befe3d 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -3148,6 +3148,45 @@ virDomainDefRejectDuplicateControllers(virDomainDefPtr def) } +/** + * virDomainDefRemoveDuplicateMetadata: + * @def: Remove duplicate 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. + */ +static void +virDomainDefRemoveDuplicateMetadata(virDomainDefPtr def) +{ + xmlNodePtr child; + xmlNodePtr next; + + if (!def || !def->metadata) + return; + + for (child = def->metadata->children; child; child = child->next) { + /* 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; + + if (child->ns && next->ns && + STREQ_NULLABLE((const char *) child->ns->href, + (const char *) next->ns->href)) + dupl = next; + + next = next->next; + + if (dupl) { + xmlUnlinkNode(dupl); + xmlFreeNode(dupl); + } + } + } +} + + static int virDomainDefPostParseInternal(virDomainDefPtr def, virCapsPtr caps ATTRIBUTE_UNUSED) @@ -3316,6 +3355,9 @@ virDomainDefPostParseInternal(virDomainDefPtr def, } } + /* clean up possibly duplicated metadata entries */ + virDomainDefRemoveDuplicateMetadata(def); + return 0; } diff --git a/tests/qemuxml2argvdata/qemuxml2argv-metadata-duplicate.xml b/tests/qemuxml2argvdata/qemuxml2argv-metadata-duplicate.xml new file mode 100644 index 0000000000..13fb44963a --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-metadata-duplicate.xml @@ -0,0 +1,34 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219100 + 219100 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu + + + +
+ + + + + + + fooish + fooish + fooish + barish + fooish + barish + + diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-metadata-duplicate.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-metadata-duplicate.xml new file mode 100644 index 0000000000..e32fb6795a --- /dev/null +++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-metadata-duplicate.xml @@ -0,0 +1,31 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + + fooish + barish + + 219100 + 219100 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu + + + +
+ + + + + + + diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index 58917c33e8..2bec2b2d07 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -367,6 +367,7 @@ mymain(void) DO_TEST_DIFFERENT("usb-ich9-ehci-addr"); DO_TEST_DIFFERENT("metadata"); + DO_TEST_DIFFERENT("metadata-duplicate"); DO_TEST("tpm-passthrough"); DO_TEST("pci-bridge"); -- 2.47.3