[libvirt] [PATCH V2 2/3] xenFormatNet: correct `type=netfront' to 'type=vif' to match libxl

Chunyan Liu cyliu at suse.com
Tue May 17 09:34:45 UTC 2016


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 convertion in libvirt, so that it matchs libxl codes
and also xl.cfg.

Signed-off-by: Chunyan Liu <cyliu at suse.com>
---
 src/xenconfig/xen_common.c | 43 ++++++++++++++++++++++++++++++++-----------
 src/xenconfig/xen_common.h |  6 ++++--
 src/xenconfig/xen_xl.c     |  4 ++--
 src/xenconfig/xen_xm.c     |  4 ++--
 4 files changed, 40 insertions(+), 17 deletions(-)

diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c
index c6aee69..3e57601 100644
--- a/src/xenconfig/xen_common.c
+++ b/src/xenconfig/xen_common.c
@@ -801,9 +801,8 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr def)
     return -1;
 }
 
-
 static int
-xenParseVif(virConfPtr conf, virDomainDefPtr def)
+xenParseVif(virConfPtr conf, virDomainDefPtr def, const char *vif_typename)
 {
     char *script = NULL;
     virDomainNetDefPtr net = NULL;
@@ -942,7 +941,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;
 
@@ -1046,7 +1045,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;
@@ -1066,8 +1066,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;
@@ -1127,7 +1136,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;
@@ -1199,7 +1209,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);
@@ -1749,7 +1759,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;
@@ -1762,7 +1773,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;
     }
 
@@ -1788,7 +1799,8 @@ xenFormatVif(virConfPtr conf,
 int
 xenFormatConfigCommon(virConfPtr conf,
                       virDomainDefPtr def,
-                      virConnectPtr conn)
+                      virConnectPtr conn,
+                      const char * nativeFormat)
 {
     if (xenFormatGeneralMeta(conf, def) < 0)
         return -1;
@@ -1814,8 +1826,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 d96063c..6361aec 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 889dd40..7372f53 100644
--- a/src/xenconfig/xen_xl.c
+++ b/src/xenconfig/xen_xl.c
@@ -499,7 +499,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)
@@ -994,7 +994,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 e09d97e..34d57de 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)
-- 
2.1.4




More information about the libvir-list mailing list