[libvirt] [PATCH] Fix <cpu> element in domain XML schema

The current schema is more permissive than the XML parsing code in libvirt. Precisely, 'match' attribute is optional in schema while in reality its use is bound to <model> element: - <cpu> element without 'match' attribute is allowed only if <topology> element is the only child element of <cpu> - <cpu> element with 'match' attribute requires <model> element to be present; <topology> and <feature> elements are optional Signed-off-by: Jiri Denemark <jdenemar@redhat.com> --- docs/schemas/domain.rng | 109 +++++++++++++++++++++++++++-------------------- 1 files changed, 63 insertions(+), 46 deletions(-) diff --git a/docs/schemas/domain.rng b/docs/schemas/domain.rng index bb6d00d..c913a50 100644 --- a/docs/schemas/domain.rng +++ b/docs/schemas/domain.rng @@ -1313,52 +1313,69 @@ --> <define name="cpu"> <element name="cpu"> - <optional> - <attribute name="match"> - <choice> - <value>minimum</value> - <value>exact</value> - <value>strict</value> - </choice> - </attribute> - </optional> - <interleave> - <optional> - <element name="model"> - <text/> - </element> - </optional> - <optional> - <element name="topology"> - <attribute name="sockets"> - <ref name="positiveInteger"/> - </attribute> - <attribute name="cores"> - <ref name="positiveInteger"/> - </attribute> - <attribute name="threads"> - <ref name="positiveInteger"/> - </attribute> - </element> - </optional> - <zeroOrMore> - <element name="feature"> - <attribute name="policy"> - <choice> - <value>force</value> - <value>require</value> - <value>optional</value> - <value>disable</value> - <value>forbid</value> - </choice> - </attribute> - <attribute name="name"> - <ref name="featureName"/> - </attribute> - <empty/> - </element> - </zeroOrMore> - </interleave> + <choice> + <ref name="cpuTopology"/> + <group> + <ref name="cpuMatch"/> + <interleave> + <ref name="cpuModel"/> + <optional> + <ref name="cpuTopology"/> + </optional> + <zeroOrMore> + <ref name="cpuFeature"/> + </zeroOrMore> + </interleave> + </group> + </choice> + </element> + </define> + + <define name="cpuMatch"> + <attribute name="match"> + <choice> + <value>minimum</value> + <value>exact</value> + <value>strict</value> + </choice> + </attribute> + </define> + + <define name="cpuModel"> + <element name="model"> + <text/> + </element> + </define> + + <define name="cpuFeature"> + <element name="feature"> + <attribute name="policy"> + <choice> + <value>force</value> + <value>require</value> + <value>optional</value> + <value>disable</value> + <value>forbid</value> + </choice> + </attribute> + <attribute name="name"> + <ref name="featureName"/> + </attribute> + <empty/> + </element> + </define> + + <define name="cpuTopology"> + <element name="topology"> + <attribute name="sockets"> + <ref name="positiveInteger"/> + </attribute> + <attribute name="cores"> + <ref name="positiveInteger"/> + </attribute> + <attribute name="threads"> + <ref name="positiveInteger"/> + </attribute> </element> </define> -- 1.6.6.1

On Tue, Feb 09, 2010 at 03:53:03PM +0100, Jiri Denemark wrote:
The current schema is more permissive than the XML parsing code in libvirt. Precisely, 'match' attribute is optional in schema while in reality its use is bound to <model> element:
- <cpu> element without 'match' attribute is allowed only if <topology> element is the only child element of <cpu>
- <cpu> element with 'match' attribute requires <model> element to be present; <topology> and <feature> elements are optional
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
ACK, but there is a limit to this kind of refinements. Basically the schemas will always have to be more permissive than the internals, for example some constructs are allowed only for some values of attribute type on top level element, and except making the schemas unmaintainable, I don't think it's feasible to have the RNG model exactly the actual set accepted. It's really 2 different models of validation. Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/

The current schema is more permissive than the XML parsing code in libvirt. Precisely, 'match' attribute is optional in schema while in reality its use is bound to <model> element:
- <cpu> element without 'match' attribute is allowed only if <topology> element is the only child element of <cpu>
- <cpu> element with 'match' attribute requires <model> element to be present; <topology> and <feature> elements are optional
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
ACK, but there is a limit to this kind of refinements. Basically the schemas will always have to be more permissive than the internals, for example some constructs are allowed only for some values of attribute type on top level element, and except making the schemas unmaintainable, I don't think it's feasible to have the RNG model exactly the actual set accepted. It's really 2 different models of validation.
Sure thing, I considered this was within the limit and I think it also made that part of schema a bit more readable. Thanks, pushed. Jirka
participants (2)
-
Daniel Veillard
-
Jiri Denemark