From 1734cdb9951690cc9f13e371e301c3747c7b8777 Mon Sep 17 00:00:00 2001 From: Laine Stump Date: Fri, 6 Jan 2012 12:59:47 -0500 Subject: [PATCH] config: report error when script given for inappropriate interface type This fixes https://bugzilla.redhat.com/show_bug.cgi?id=638633 Although scripts are not used by interfaces of type other than "ethernet" in qemu, due to the fact that the parser stores the script name in a union that is only valid when type is ethernet or bridge, there is no way for anyone except the parser itself to catch the problem of specifying an interface script for an inappropriate interface type (by the time the parsed data gets back to the code that called the parser, all evidence that a script was specified is forgotten). Since the parser itself should be agnostic to which type of interface allows scripts (an example of why: a script specified for an interface of type bridge is valid for xen domains, but not for qemu domains), the solution here is to move the script out of the union(s) in the DomainNetDef, always populate it when specified (regardless of interface type), and let the driver decide whether or not it is appropriate. Currently the qemu, xen, libxml, and uml drivers recognize the script parameter and do something with it (the uml driver only to report that it isn't supported). Those drivers have been updated to log a CONFIG_UNSUPPORTED error when a script is specified for an interface type that's inappropriate for that particular hypervisor. (NB: There was earlier discussion of solving this problem by adding a VALIDATE flag to all libvirt APIs that accept XML, which would cause the XML to be validated against the RNG files. One statement during that discussion was that the RNG shouldn't contain hypervisor-specific things, though, and a proper solution to this problem would require that (again, because a script for an interface of type "bridge" is accepted by xen, but not by qemu). --- src/conf/domain_conf.c | 25 +++++++------------------ src/conf/domain_conf.h | 3 +-- src/libxl/libxl_conf.c | 11 +++++++++-- src/qemu/qemu_command.c | 18 +++++++++++++----- src/qemu/qemu_domain.c | 10 ++++++---- src/qemu/qemu_driver.c | 10 +++++----- src/qemu/qemu_hotplug.c | 2 +- src/uml/uml_conf.c | 11 ++++++----- src/vbox/vbox_tmpl.c | 2 +- src/xenxs/xen_sxpr.c | 20 ++++++++++++++------ src/xenxs/xen_xm.c | 14 ++++++-------- 11 files changed, 69 insertions(+), 57 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 7327667bda..0190a816a3 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -956,7 +956,6 @@ void virDomainNetDefFree(virDomainNetDefPtr def) switch (def->type) { case VIR_DOMAIN_NET_TYPE_ETHERNET: VIR_FREE(def->data.ethernet.dev); - VIR_FREE(def->data.ethernet.script); VIR_FREE(def->data.ethernet.ipaddr); break; @@ -975,7 +974,6 @@ void virDomainNetDefFree(virDomainNetDefPtr def) case VIR_DOMAIN_NET_TYPE_BRIDGE: VIR_FREE(def->data.bridge.brname); - VIR_FREE(def->data.bridge.script); VIR_FREE(def->data.bridge.ipaddr); break; @@ -993,6 +991,7 @@ void virDomainNetDefFree(virDomainNetDefPtr def) break; } + VIR_FREE(def->script); VIR_FREE(def->ifname); virDomainDeviceInfoClear(&def->info); @@ -3764,8 +3763,6 @@ virDomainNetDefParseXML(virCapsPtr caps, xmlStrEqual(cur->name, BAD_CAST "link")) { linkstate = virXMLPropString(cur, "state"); } else if ((script == NULL) && - (def->type == VIR_DOMAIN_NET_TYPE_ETHERNET || - def->type == VIR_DOMAIN_NET_TYPE_BRIDGE) && xmlStrEqual(cur->name, BAD_CAST "script")) { script = virXMLPropString(cur, "path"); } else if (xmlStrEqual (cur->name, BAD_CAST "model")) { @@ -3854,11 +3851,6 @@ virDomainNetDefParseXML(virCapsPtr caps, break; case VIR_DOMAIN_NET_TYPE_ETHERNET: - - if (script != NULL) { - def->data.ethernet.script = script; - script = NULL; - } if (dev != NULL) { def->data.ethernet.dev = dev; dev = NULL; @@ -3877,10 +3869,6 @@ virDomainNetDefParseXML(virCapsPtr caps, } def->data.bridge.brname = bridge; bridge = NULL; - if (script != NULL) { - def->data.bridge.script = script; - script = NULL; - } if (address != NULL) { def->data.bridge.ipaddr = address; address = NULL; @@ -3957,6 +3945,10 @@ virDomainNetDefParseXML(virCapsPtr caps, break; } + if (script != NULL) { + def->script = script; + script = NULL; + } if (ifname != NULL) { def->ifname = ifname; ifname = NULL; @@ -10340,8 +10332,6 @@ virDomainNetDefFormat(virBufferPtr buf, if (def->data.ethernet.ipaddr) virBufferAsprintf(buf, " \n", def->data.ethernet.ipaddr); - virBufferEscapeString(buf, "