xen_common: Split per-Vif logic from xenParseVif()

xenParseVif() does a lot of stuff and, in order to make things cleaner,
let's split it in two new functions:
- xenParseVif(): it's a new function that keeps the old name. It's
responsible for the whole per-Vif logic from the old xenParseVif();
- xenParseVifList(): it's basically the old xenParsePCI(), but now it
just iterates over the list of Vifs, calling xenParsePCI() per each Vif.

This patch is basically preparing the ground for the future when
typesafe virConf acessors will be used.

Signed-off-by: Fabiano Fidêncio <fabiano@fidencio.org>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Fabiano Fidêncio 2018-06-14 06:59:52 +02:00 committed by Ján Tomko
parent 43c9c9e429
commit b6445dccc9

View File

@ -846,16 +846,12 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr def, const char *nativeFormat)
}
static int
xenParseVif(virConfPtr conf, virDomainDefPtr def, const char *vif_typename)
static virDomainNetDefPtr
xenParseVif(char *entry, const char *vif_typename)
{
char *script = NULL;
virDomainNetDefPtr net = NULL;
virConfValuePtr list = virConfGetValue(conf, "vif");
if (list && list->type == VIR_CONF_LIST) {
list = list->list;
while (list) {
virDomainNetDefPtr ret = NULL;
char *script = NULL;
char model[10];
char type[10];
char ip[128];
@ -873,16 +869,13 @@ xenParseVif(virConfPtr conf, virDomainDefPtr def, const char *vif_typename)
vifname[0] = '\0';
rate[0] = '\0';
if ((list->type != VIR_CONF_STRING) || (list->str == NULL))
goto skipnic;
key = list->str;
key = entry;
while (key) {
char *data;
char *nextkey = strchr(key, ',');
if (!(data = strchr(key, '=')))
goto skipnic;
return NULL;
data++;
if (STRPREFIX(key, "mac=")) {
@ -891,7 +884,7 @@ xenParseVif(virConfPtr conf, virDomainDefPtr def, const char *vif_typename)
virReportError(VIR_ERR_INTERNAL_ERROR,
_("MAC address %s too big for destination"),
data);
goto skipnic;
return NULL;
}
} else if (STRPREFIX(key, "bridge=")) {
int len = nextkey ? (nextkey - data) : sizeof(bridge) - 1;
@ -899,20 +892,20 @@ xenParseVif(virConfPtr conf, virDomainDefPtr def, const char *vif_typename)
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Bridge %s too big for destination"),
data);
goto skipnic;
return NULL;
}
} else if (STRPREFIX(key, "script=")) {
int len = nextkey ? (nextkey - data) : strlen(data);
VIR_FREE(script);
if (VIR_STRNDUP(script, data, len) < 0)
goto cleanup;
return NULL;
} else if (STRPREFIX(key, "model=")) {
int len = nextkey ? (nextkey - data) : sizeof(model) - 1;
if (virStrncpy(model, data, len, sizeof(model)) == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Model %s too big for destination"),
data);
goto skipnic;
return NULL;
}
} else if (STRPREFIX(key, "type=")) {
int len = nextkey ? (nextkey - data) : sizeof(type) - 1;
@ -920,7 +913,7 @@ xenParseVif(virConfPtr conf, virDomainDefPtr def, const char *vif_typename)
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Type %s too big for destination"),
data);
goto skipnic;
return NULL;
}
} else if (STRPREFIX(key, "vifname=")) {
int len = nextkey ? (nextkey - data) : sizeof(vifname) - 1;
@ -928,21 +921,21 @@ xenParseVif(virConfPtr conf, virDomainDefPtr def, const char *vif_typename)
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Vifname %s too big for destination"),
data);
goto skipnic;
return NULL;
}
} else if (STRPREFIX(key, "ip=")) {
int len = nextkey ? (nextkey - data) : sizeof(ip) - 1;
if (virStrncpy(ip, data, len, sizeof(ip)) == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("IP %s too big for destination"), data);
goto skipnic;
return NULL;
}
} else if (STRPREFIX(key, "rate=")) {
int len = nextkey ? (nextkey - data) : sizeof(rate) - 1;
if (virStrncpy(rate, data, len, sizeof(rate)) == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("rate %s too big for destination"), data);
goto skipnic;
return NULL;
}
}
@ -1016,6 +1009,7 @@ xenParseVif(virConfPtr conf, virDomainDefPtr def, const char *vif_typename)
if (VIR_ALLOC(bandwidth) < 0)
goto cleanup;
if (VIR_ALLOC(bandwidth->out) < 0) {
VIR_FREE(bandwidth);
goto cleanup;
@ -1025,23 +1019,41 @@ xenParseVif(virConfPtr conf, virDomainDefPtr def, const char *vif_typename)
net->bandwidth = bandwidth;
}
if (VIR_APPEND_ELEMENT(def->nets, def->nnets, net) < 0)
goto cleanup;
skipnic:
list = list->next;
virDomainNetDefFree(net);
net = NULL;
VIR_FREE(script);
}
}
return 0;
VIR_STEAL_PTR(ret, net);
cleanup:
virDomainNetDefFree(net);
VIR_FREE(script);
return ret;
}
static int
xenParseVifList(virConfPtr conf, virDomainDefPtr def, const char *vif_typename)
{
virConfValuePtr list = virConfGetValue(conf, "vif");
if (!list || list->type != VIR_CONF_LIST)
return 0;
for (list = list->list; list; list = list->next) {
virDomainNetDefPtr net = NULL;
int rc;
if ((list->type != VIR_CONF_STRING) || (list->str == NULL))
continue;
if (!(net = xenParseVif(list->str, vif_typename)))
return -1;
rc = VIR_APPEND_ELEMENT(def->nets, def->nnets, net);
if (rc < 0) {
virDomainNetDefFree(net);
return -1;
}
}
return 0;
}
@ -1126,10 +1138,10 @@ xenParseConfigCommon(virConfPtr conf,
return -1;
if (STREQ(nativeFormat, XEN_CONFIG_FORMAT_XL)) {
if (xenParseVif(conf, def, "vif") < 0)
if (xenParseVifList(conf, def, "vif") < 0)
return -1;
} else if (STREQ(nativeFormat, XEN_CONFIG_FORMAT_XM)) {
if (xenParseVif(conf, def, "netfront") < 0)
if (xenParseVifList(conf, def, "netfront") < 0)
return -1;
} else {
virReportError(VIR_ERR_INVALID_ARG,