From 03f8bba26e24db9fbce32078f587ed6b8424ce8e Mon Sep 17 00:00:00 2001 From: Chunyan Liu Date: Tue, 17 May 2016 17:34:45 +0800 Subject: [PATCH] xenFormatNet: correct `type=netfront' to 'type=vif' to match libxl According to current xl.cfg docs and xl codes, it uses type=vif instead of type=netfront. Currently after domxml-to-native, libvirt xml model=netfront will be converted to xl type=netfront. This has no problem before, xen codes for a long time just check type=ioemu, if not, set type to _VIF. Since libxl uses parse_nic_config to avoid duplicate codes, it compares 'type=vif' and 'type=ioemu' for valid parameters, others are considered as invalid, thus we have problem with type=netfront in xl config file. #xl create sles12gm-hvm.orig Parsing config from sles12gm-hvm.orig Invalid parameter `type'. Correct the conversion in libvirt, so that it matchs libxl codes and also xl.cfg. Signed-off-by: Chunyan Liu --- src/xenconfig/xen_common.c | 42 +++++++++++++++++++++++++++++--------- src/xenconfig/xen_common.h | 6 ++++-- src/xenconfig/xen_xl.c | 4 ++-- src/xenconfig/xen_xm.c | 4 ++-- 4 files changed, 40 insertions(+), 16 deletions(-) diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c index c753fa8de0..5014bad728 100644 --- a/src/xenconfig/xen_common.c +++ b/src/xenconfig/xen_common.c @@ -807,7 +807,7 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr def) static int -xenParseVif(virConfPtr conf, virDomainDefPtr def) +xenParseVif(virConfPtr conf, virDomainDefPtr def, const char *vif_typename) { char *script = NULL; virDomainNetDefPtr net = NULL; @@ -946,7 +946,7 @@ xenParseVif(virConfPtr conf, virDomainDefPtr def) VIR_STRDUP(net->model, model) < 0) goto cleanup; - if (!model[0] && type[0] && STREQ(type, "netfront") && + if (!model[0] && type[0] && STREQ(type, vif_typename) && VIR_STRDUP(net->model, "netfront") < 0) goto cleanup; @@ -1050,7 +1050,8 @@ xenParseGeneralMeta(virConfPtr conf, virDomainDefPtr def, virCapsPtr caps) int xenParseConfigCommon(virConfPtr conf, virDomainDefPtr def, - virCapsPtr caps) + virCapsPtr caps, + const char *nativeFormat) { if (xenParseGeneralMeta(conf, def, caps) < 0) return -1; @@ -1070,8 +1071,17 @@ xenParseConfigCommon(virConfPtr conf, if (xenConfigCopyStringOpt(conf, "device_model", &def->emulator) < 0) return -1; - if (xenParseVif(conf, def) < 0) + if (STREQ(nativeFormat, XEN_CONFIG_FORMAT_XL)) { + if (xenParseVif(conf, def, "vif") < 0) + return -1; + } else if (STREQ(nativeFormat, XEN_CONFIG_FORMAT_XM)) { + if (xenParseVif(conf, def, "netfront") < 0) + return -1; + } else { + virReportError(VIR_ERR_INVALID_ARG, + _("unsupported config type %s"), nativeFormat); return -1; + } if (xenParsePCI(conf, def) < 0) return -1; @@ -1131,7 +1141,8 @@ static int xenFormatNet(virConnectPtr conn, virConfValuePtr list, virDomainNetDefPtr net, - int hvm) + int hvm, + const char *vif_typename) { virBuffer buf = VIR_BUFFER_INITIALIZER; virConfValuePtr val, tmp; @@ -1203,7 +1214,7 @@ xenFormatNet(virConnectPtr conn, virBufferAsprintf(&buf, ",model=%s", net->model); } else { if (net->model != NULL && STREQ(net->model, "netfront")) { - virBufferAddLit(&buf, ",type=netfront"); + virBufferAsprintf(&buf, ",type=%s", vif_typename); } else { if (net->model != NULL) virBufferAsprintf(&buf, ",model=%s", net->model); @@ -1753,7 +1764,8 @@ xenFormatSound(virConfPtr conf, virDomainDefPtr def) static int xenFormatVif(virConfPtr conf, virConnectPtr conn, - virDomainDefPtr def) + virDomainDefPtr def, + const char *vif_typename) { virConfValuePtr netVal = NULL; size_t i; @@ -1766,7 +1778,7 @@ xenFormatVif(virConfPtr conf, for (i = 0; i < def->nnets; i++) { if (xenFormatNet(conn, netVal, def->nets[i], - hvm) < 0) + hvm, vif_typename) < 0) goto cleanup; } @@ -1792,7 +1804,8 @@ xenFormatVif(virConfPtr conf, int xenFormatConfigCommon(virConfPtr conf, virDomainDefPtr def, - virConnectPtr conn) + virConnectPtr conn, + const char *nativeFormat) { if (xenFormatGeneralMeta(conf, def) < 0) return -1; @@ -1818,8 +1831,17 @@ xenFormatConfigCommon(virConfPtr conf, if (xenFormatVfb(conf, def) < 0) return -1; - if (xenFormatVif(conf, conn, def) < 0) + if (STREQ(nativeFormat, XEN_CONFIG_FORMAT_XL)) { + if (xenFormatVif(conf, conn, def, "vif") < 0) + return -1; + } else if (STREQ(nativeFormat, XEN_CONFIG_FORMAT_XM)) { + if (xenFormatVif(conf, conn, def, "netfront") < 0) + return -1; + } else { + virReportError(VIR_ERR_INVALID_ARG, + _("unsupported config type %s"), nativeFormat); return -1; + } if (xenFormatPCI(conf, def) < 0) return -1; diff --git a/src/xenconfig/xen_common.h b/src/xenconfig/xen_common.h index d8b8478510..1c74bee9a2 100644 --- a/src/xenconfig/xen_common.h +++ b/src/xenconfig/xen_common.h @@ -58,11 +58,13 @@ int xenConfigCopyStringOpt(virConfPtr conf, int xenParseConfigCommon(virConfPtr conf, virDomainDefPtr def, - virCapsPtr caps); + virCapsPtr caps, + const char *nativeFormat); int xenFormatConfigCommon(virConfPtr conf, virDomainDefPtr def, - virConnectPtr conn); + virConnectPtr conn, + const char *nativeFormat); int xenDomainDefAddImplicitInputDevice(virDomainDefPtr def); diff --git a/src/xenconfig/xen_xl.c b/src/xenconfig/xen_xl.c index 7d41e0504e..15350f92bb 100644 --- a/src/xenconfig/xen_xl.c +++ b/src/xenconfig/xen_xl.c @@ -498,7 +498,7 @@ xenParseXL(virConfPtr conf, def->virtType = VIR_DOMAIN_VIRT_XEN; def->id = -1; - if (xenParseConfigCommon(conf, def, caps) < 0) + if (xenParseConfigCommon(conf, def, caps, XEN_CONFIG_FORMAT_XL) < 0) goto cleanup; if (xenParseXLOS(conf, def, caps) < 0) @@ -993,7 +993,7 @@ xenFormatXL(virDomainDefPtr def, virConnectPtr conn) if (!(conf = virConfNew())) goto cleanup; - if (xenFormatConfigCommon(conf, def, conn) < 0) + if (xenFormatConfigCommon(conf, def, conn, XEN_CONFIG_FORMAT_XL) < 0) goto cleanup; if (xenFormatXLOS(conf, def) < 0) diff --git a/src/xenconfig/xen_xm.c b/src/xenconfig/xen_xm.c index e09d97e7b6..34d57de1d0 100644 --- a/src/xenconfig/xen_xm.c +++ b/src/xenconfig/xen_xm.c @@ -443,7 +443,7 @@ xenParseXM(virConfPtr conf, def->virtType = VIR_DOMAIN_VIRT_XEN; def->id = -1; - if (xenParseConfigCommon(conf, def, caps) < 0) + if (xenParseConfigCommon(conf, def, caps, XEN_CONFIG_FORMAT_XM) < 0) goto cleanup; if (xenParseXMOS(conf, def) < 0) @@ -586,7 +586,7 @@ xenFormatXM(virConnectPtr conn, if (!(conf = virConfNew())) goto cleanup; - if (xenFormatConfigCommon(conf, def, conn) < 0) + if (xenFormatConfigCommon(conf, def, conn, XEN_CONFIG_FORMAT_XM) < 0) goto cleanup; if (xenFormatXMOS(conf, def) < 0)