mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 19:41:16 +00:00
conf/openvz: eliminate incorrect/undocumented use of <source dev='blah'/>
When support for <interface type='ethernet'> was added in commit
9a4b705f
back in 2010, it erroneously looked at <source dev='blah'/>
for a user-specified guest-side interface name. This was never
documented though. (that attribute already existed at the time in the
data.ethernet union member of virDomainNetDef, but apparently had no
practical use - it was only used as a storage place for a NetDef's
bridge name during qemuDomainXMLToNative(), but even then that was
never used for anything).
When support for similar guest-side device naming was added to the lxc
driver several years later, it was put in a new subelement <guest
dev='blah'/>.
In the intervening years, since there was no validation that
ethernet.dev was NULL in the other drivers that didn't actually use
it, innocent souls who were adding other features assuming they needed
to account for non-NULL ethernet.dev when really they didn't, so
little bits of the usual pointless cargo-cult code showed up.
This patch not only switches the openvz driver to use the documented
<guest dev='blah'/> notation for naming the guest-side device (just in
case anyone is still using the openvz driver), and logs an error if
anyone tries to set <source dev='blah'/> for a type='ethernet'
interface, it also removes the cargo-cult uses of ethernet.dev and
<source dev='blah'/>, and eliminates if from the RNG and from
virDomainNetDef.
NB: I decided on this course of action after mentioning the
inconsistency here:
https://www.redhat.com/archives/libvir-list/2016-May/msg02038.html
and getting encouragement do eliminate it in a later IRC discussion
with danpb.
This commit is contained in:
parent
a71fd239bd
commit
9658e70f7d
@ -2142,9 +2142,6 @@
|
|||||||
<interleave>
|
<interleave>
|
||||||
<optional>
|
<optional>
|
||||||
<element name="source">
|
<element name="source">
|
||||||
<attribute name="dev">
|
|
||||||
<ref name="deviceName"/>
|
|
||||||
</attribute>
|
|
||||||
<empty/>
|
<empty/>
|
||||||
</element>
|
</element>
|
||||||
</optional>
|
</optional>
|
||||||
|
@ -1748,10 +1748,6 @@ virDomainNetDefClear(virDomainNetDefPtr def)
|
|||||||
VIR_FREE(def->model);
|
VIR_FREE(def->model);
|
||||||
|
|
||||||
switch (def->type) {
|
switch (def->type) {
|
||||||
case VIR_DOMAIN_NET_TYPE_ETHERNET:
|
|
||||||
VIR_FREE(def->data.ethernet.dev);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case VIR_DOMAIN_NET_TYPE_VHOSTUSER:
|
case VIR_DOMAIN_NET_TYPE_VHOSTUSER:
|
||||||
virDomainChrSourceDefFree(def->data.vhostuser);
|
virDomainChrSourceDefFree(def->data.vhostuser);
|
||||||
def->data.vhostuser = NULL;
|
def->data.vhostuser = NULL;
|
||||||
@ -1788,6 +1784,7 @@ virDomainNetDefClear(virDomainNetDefPtr def)
|
|||||||
virDomainHostdevDefClear(&def->data.hostdev.def);
|
virDomainHostdevDefClear(&def->data.hostdev.def);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case VIR_DOMAIN_NET_TYPE_ETHERNET:
|
||||||
case VIR_DOMAIN_NET_TYPE_USER:
|
case VIR_DOMAIN_NET_TYPE_USER:
|
||||||
case VIR_DOMAIN_NET_TYPE_LAST:
|
case VIR_DOMAIN_NET_TYPE_LAST:
|
||||||
break;
|
break;
|
||||||
@ -9019,12 +9016,31 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
|
|||||||
def->type == VIR_DOMAIN_NET_TYPE_BRIDGE &&
|
def->type == VIR_DOMAIN_NET_TYPE_BRIDGE &&
|
||||||
xmlStrEqual(cur->name, BAD_CAST "source")) {
|
xmlStrEqual(cur->name, BAD_CAST "source")) {
|
||||||
bridge = virXMLPropString(cur, "bridge");
|
bridge = virXMLPropString(cur, "bridge");
|
||||||
} else if (!dev &&
|
} else if (!dev && def->type == VIR_DOMAIN_NET_TYPE_DIRECT &&
|
||||||
(def->type == VIR_DOMAIN_NET_TYPE_ETHERNET ||
|
|
||||||
def->type == VIR_DOMAIN_NET_TYPE_DIRECT) &&
|
|
||||||
xmlStrEqual(cur->name, BAD_CAST "source")) {
|
xmlStrEqual(cur->name, BAD_CAST "source")) {
|
||||||
dev = virXMLPropString(cur, "dev");
|
dev = virXMLPropString(cur, "dev");
|
||||||
mode = virXMLPropString(cur, "mode");
|
mode = virXMLPropString(cur, "mode");
|
||||||
|
} else if (!dev && def->type == VIR_DOMAIN_NET_TYPE_ETHERNET &&
|
||||||
|
xmlStrEqual(cur->name, BAD_CAST "source")) {
|
||||||
|
/* This clause is only necessary because from 2010 to
|
||||||
|
* 2016 it was possible (but never documented) to
|
||||||
|
* configure the name of the guest-side interface of
|
||||||
|
* an openvz domain with <source dev='blah'/>. That
|
||||||
|
* was blatant misuse of <source>, so was likely
|
||||||
|
* (hopefully) never used, but just in case there was
|
||||||
|
* somebody using it, we need to generate an error. If
|
||||||
|
* the openvz driver is ever deprecated, this clause
|
||||||
|
* can be removed from here.
|
||||||
|
*/
|
||||||
|
if ((dev = virXMLPropString(cur, "dev"))) {
|
||||||
|
virReportError(VIR_ERR_XML_ERROR,
|
||||||
|
_("Invalid attempt to set <interface type='ethernet'> "
|
||||||
|
"device name with <source dev='%s'/>. "
|
||||||
|
"Use <target dev='%s'/> (for host-side) "
|
||||||
|
"or <guest dev='%s'/> (for guest-side) instead."),
|
||||||
|
dev, dev, dev);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
} else if (!vhostuser_path && !vhostuser_mode && !vhostuser_type
|
} else if (!vhostuser_path && !vhostuser_mode && !vhostuser_type
|
||||||
&& def->type == VIR_DOMAIN_NET_TYPE_VHOSTUSER &&
|
&& def->type == VIR_DOMAIN_NET_TYPE_VHOSTUSER &&
|
||||||
xmlStrEqual(cur->name, BAD_CAST "source")) {
|
xmlStrEqual(cur->name, BAD_CAST "source")) {
|
||||||
@ -9274,13 +9290,6 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_DOMAIN_NET_TYPE_ETHERNET:
|
|
||||||
if (dev != NULL) {
|
|
||||||
def->data.ethernet.dev = dev;
|
|
||||||
dev = NULL;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case VIR_DOMAIN_NET_TYPE_BRIDGE:
|
case VIR_DOMAIN_NET_TYPE_BRIDGE:
|
||||||
if (bridge == NULL) {
|
if (bridge == NULL) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
@ -9409,6 +9418,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case VIR_DOMAIN_NET_TYPE_ETHERNET:
|
||||||
case VIR_DOMAIN_NET_TYPE_USER:
|
case VIR_DOMAIN_NET_TYPE_USER:
|
||||||
case VIR_DOMAIN_NET_TYPE_LAST:
|
case VIR_DOMAIN_NET_TYPE_LAST:
|
||||||
break;
|
break;
|
||||||
@ -20802,8 +20812,6 @@ virDomainNetDefFormat(virBufferPtr buf,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_DOMAIN_NET_TYPE_ETHERNET:
|
case VIR_DOMAIN_NET_TYPE_ETHERNET:
|
||||||
virBufferEscapeString(buf, "<source dev='%s'/>\n",
|
|
||||||
def->data.ethernet.dev);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_DOMAIN_NET_TYPE_VHOSTUSER:
|
case VIR_DOMAIN_NET_TYPE_VHOSTUSER:
|
||||||
|
@ -930,9 +930,6 @@ struct _virDomainNetDef {
|
|||||||
char *vhost;
|
char *vhost;
|
||||||
} backend;
|
} backend;
|
||||||
union {
|
union {
|
||||||
struct {
|
|
||||||
char *dev;
|
|
||||||
} ethernet;
|
|
||||||
virDomainChrSourceDefPtr vhostuser;
|
virDomainChrSourceDefPtr vhostuser;
|
||||||
struct {
|
struct {
|
||||||
char *address;
|
char *address;
|
||||||
|
@ -862,9 +862,8 @@ openvzDomainSetNetwork(virConnectPtr conn, const char *vpsid,
|
|||||||
|
|
||||||
/* if net is ethernet and the user has specified guest interface name,
|
/* if net is ethernet and the user has specified guest interface name,
|
||||||
* let's use it; otherwise generate a new one */
|
* let's use it; otherwise generate a new one */
|
||||||
if (net->type == VIR_DOMAIN_NET_TYPE_ETHERNET &&
|
if (net->ifname_guest) {
|
||||||
net->data.ethernet.dev != NULL) {
|
if (VIR_STRDUP(guest_ifname, net->ifname_guest) < 0)
|
||||||
if (VIR_STRDUP(guest_ifname, net->data.ethernet.dev) == -1)
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
} else {
|
} else {
|
||||||
guest_ifname = openvzGenerateContainerVethName(veid);
|
guest_ifname = openvzGenerateContainerVethName(veid);
|
||||||
|
@ -2345,10 +2345,6 @@ qemuDomainChangeNet(virQEMUDriverPtr driver,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_DOMAIN_NET_TYPE_ETHERNET:
|
case VIR_DOMAIN_NET_TYPE_ETHERNET:
|
||||||
if (STRNEQ_NULLABLE(olddev->data.ethernet.dev,
|
|
||||||
newdev->data.ethernet.dev)) {
|
|
||||||
needReconnect = true;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_DOMAIN_NET_TYPE_SERVER:
|
case VIR_DOMAIN_NET_TYPE_SERVER:
|
||||||
|
@ -20,7 +20,6 @@
|
|||||||
<interface type="ethernet">
|
<interface type="ethernet">
|
||||||
<mac address="00:11:22:33:44:55"/>
|
<mac address="00:11:22:33:44:55"/>
|
||||||
<ip address="172.14.5.6"/>
|
<ip address="172.14.5.6"/>
|
||||||
<source dev="eth3"/>
|
|
||||||
<script path="vif-routed"/>
|
<script path="vif-routed"/>
|
||||||
<target dev="vif4.0"/>
|
<target dev="vif4.0"/>
|
||||||
</interface>
|
</interface>
|
||||||
|
Loading…
Reference in New Issue
Block a user