提交 578391e1 编写于 作者: J Jim Fehlig

Xen: Do not generate net ifname if domain is inactive

V2: Use virAsprintf instead of snprintf/strdup

The xend driver will generate a virDomainNetDef ifname if one is not
specified in xend sexpr, even if domain is inactive.  The result is
network interface XML containing 'vif-1.Y' on dev attribute of target
element, e.g.

  <interface type='bridge'>
    <target dev='vif-1.0'/>
    ...

This patch changes the behavior to only generate the ifname if not
specified in xend sexpr *and* domain is not inactive (id != -1).
上级 a8891666
...@@ -510,7 +510,6 @@ xenParseSxprNets(virDomainDefPtr def, ...@@ -510,7 +510,6 @@ xenParseSxprNets(virDomainDefPtr def,
node = cur->u.s.car; node = cur->u.s.car;
if (sexpr_lookup(node, "device/vif")) { if (sexpr_lookup(node, "device/vif")) {
const char *tmp2, *model, *type; const char *tmp2, *model, *type;
char buf[50];
tmp2 = sexpr_node(node, "device/vif/script"); tmp2 = sexpr_node(node, "device/vif/script");
tmp = sexpr_node(node, "device/vif/bridge"); tmp = sexpr_node(node, "device/vif/bridge");
model = sexpr_node(node, "device/vif/model"); model = sexpr_node(node, "device/vif/model");
...@@ -547,12 +546,16 @@ xenParseSxprNets(virDomainDefPtr def, ...@@ -547,12 +546,16 @@ xenParseSxprNets(virDomainDefPtr def,
} }
tmp = sexpr_node(node, "device/vif/vifname"); tmp = sexpr_node(node, "device/vif/vifname");
if (!tmp) { /* If vifname is specified in xend config, include it in net
snprintf(buf, sizeof(buf), "vif%d.%d", def->id, vif_index); * definition regardless of domain state. If vifname is not
tmp = buf; * specified, only generate one if domain is active (id != -1). */
} if (tmp) {
if (!(net->ifname = strdup(tmp))) if (!(net->ifname = strdup(tmp)))
goto no_memory; goto no_memory;
} else if (def->id != -1) {
if (virAsprintf(&net->ifname, "vif%d.%d", def->id, vif_index) < 0)
goto no_memory;
}
tmp = sexpr_node(node, "device/vif/mac"); tmp = sexpr_node(node, "device/vif/mac");
if (tmp) { if (tmp) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册