diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c index 66d2e7f17d..8822f44c81 100644 --- a/src/xen/xend_internal.c +++ b/src/xen/xend_internal.c @@ -1770,11 +1770,12 @@ xenDaemonParseSxprNets(virConnectPtr conn, for (cur = root; cur->kind == SEXPR_CONS; cur = cur->u.s.cdr) { node = cur->u.s.car; if (sexpr_lookup(node, "device/vif")) { - const char *tmp2, *model; + const char *tmp2, *model, *type; char buf[50]; tmp2 = sexpr_node(node, "device/vif/script"); tmp = sexpr_node(node, "device/vif/bridge"); model = sexpr_node(node, "device/vif/model"); + type = sexpr_node(node, "device/vif/type"); if (VIR_ALLOC(net) < 0) goto no_memory; @@ -1841,6 +1842,11 @@ xenDaemonParseSxprNets(virConnectPtr conn, !(net->model = strdup(model))) goto no_memory; + if (!model && type && + STREQ(type, "netfront") && + !(net->model = strdup("netfront"))) + goto no_memory; + if (VIR_REALLOC_N(def->nets, def->nnets + 1) < 0) goto no_memory; @@ -5500,15 +5506,25 @@ xenDaemonFormatSxprNet(virConnectPtr conn, !STRPREFIX(def->ifname, "vif")) virBufferVSprintf(buf, "(vifname '%s')", def->ifname); - if (def->model != NULL) + if (!hvm) { + if (def->model != NULL) + virBufferVSprintf(buf, "(model '%s')", def->model); + } + else if (def->model == NULL) { + /* + * apparently (type ioemu) breaks paravirt drivers on HVM so skip + * this from XEND_CONFIG_MAX_VERS_NET_TYPE_IOEMU + */ + if (xendConfigVersion <= XEND_CONFIG_MAX_VERS_NET_TYPE_IOEMU) + virBufferAddLit(buf, "(type ioemu)"); + } + else if (STREQ(def->model, "netfront")) { + virBufferAddLit(buf, "(type netfront)"); + } + else { virBufferVSprintf(buf, "(model '%s')", def->model); - - /* - * apparently (type ioemu) breaks paravirt drivers on HVM so skip this - * from Xen 3.1.0 - */ - if (hvm && xendConfigVersion <= XEND_CONFIG_MAX_VERS_NET_TYPE_IOEMU) virBufferAddLit(buf, "(type ioemu)"); + } if (!isAttach) virBufferAddLit(buf, ")"); diff --git a/src/xen/xm_internal.c b/src/xen/xm_internal.c index 40c199682e..6c60839e51 100644 --- a/src/xen/xm_internal.c +++ b/src/xen/xm_internal.c @@ -1020,6 +1020,7 @@ xenXMDomainConfigParse(virConnectPtr conn, virConfPtr conf) { while (list) { char script[PATH_MAX]; char model[10]; + char type[10]; char ip[16]; char mac[18]; char bridge[50]; @@ -1031,6 +1032,7 @@ xenXMDomainConfigParse(virConnectPtr conn, virConfPtr conf) { script[0] = '\0'; ip[0] = '\0'; model[0] = '\0'; + type[0] = '\0'; vifname[0] = '\0'; if ((list->type != VIR_CONF_STRING) || (list->str == NULL)) @@ -1076,6 +1078,13 @@ xenXMDomainConfigParse(virConnectPtr conn, virConfPtr conf) { _("Model %s too big for destination"), data); goto skipnic; } + } else if (STRPREFIX(key, "type=")) { + int len = nextkey ? (nextkey - data) : sizeof(type) - 1; + if (virStrncpy(type, data, len, sizeof(type)) == NULL) { + xenXMError(conn, VIR_ERR_INTERNAL_ERROR, + _("Type %s too big for destination"), data); + goto skipnic; + } } else if (STRPREFIX(key, "vifname=")) { int len = nextkey ? (nextkey - data) : sizeof(vifname) - 1; if (virStrncpy(vifname, data, len, sizeof(vifname)) == NULL) { @@ -1145,10 +1154,16 @@ xenXMDomainConfigParse(virConnectPtr conn, virConfPtr conf) { !(net->data.ethernet.ipaddr = strdup(ip))) goto no_memory; } + if (model[0] && !(net->model = strdup(model))) goto no_memory; + if (!model[0] && type[0] && + STREQ(type, "netfront") && + !(net->model = strdup("netfront"))) + goto no_memory; + if (vifname[0] && !(net->ifname = strdup(vifname))) goto no_memory; @@ -2092,12 +2107,25 @@ static int xenXMDomainConfigFormatNet(virConnectPtr conn, goto cleanup; } - if (hvm && priv->xendConfigVersion <= XEND_CONFIG_MAX_VERS_NET_TYPE_IOEMU) + if (!hvm) { + if (net->model != NULL) + virBufferVSprintf(&buf, ",model=%s", net->model); + } + else if (net->model == NULL) { + /* + * apparently type ioemu breaks paravirt drivers on HVM so skip this + * from XEND_CONFIG_MAX_VERS_NET_TYPE_IOEMU + */ + if (priv->xendConfigVersion <= XEND_CONFIG_MAX_VERS_NET_TYPE_IOEMU) + virBufferAddLit(&buf, ",type=ioemu"); + } + else if (STREQ(net->model, "netfront")) { + virBufferAddLit(&buf, ",type=netfront"); + } + else { + virBufferVSprintf(&buf, ",model=%s", net->model); virBufferAddLit(&buf, ",type=ioemu"); - - if (net->model) - virBufferVSprintf(&buf, ",model=%s", - net->model); + } if (net->ifname) virBufferVSprintf(&buf, ",vifname=%s",