[libvirt] [PATCH] [RFC] Use enum of virDomainNetType

Stefan Berger stefanb at us.ibm.com
Thu Mar 25 18:50:50 UTC 2010


To find out where the net type 'direct' needs to be handled I introduced
the 'enum virDomainNetType' in the virDomainNetDef structure and let the
compiler tell me where the case statement is missing. Then I added the
unhandled device statement to the UML driver.

Signed-off-by; Stefan Berger <stefanb at us.ibm.com>



Index: libvirt-plain/src/conf/domain_conf.h
===================================================================
--- libvirt-plain.orig/src/conf/domain_conf.h
+++ libvirt-plain/src/conf/domain_conf.h
@@ -251,7 +251,7 @@ enum virDomainNetdevMacvtapType {
 typedef struct _virDomainNetDef virDomainNetDef;
 typedef virDomainNetDef *virDomainNetDefPtr;
 struct _virDomainNetDef {
-    int type;
+    enum virDomainNetType type;
     unsigned char mac[VIR_MAC_BUFLEN];
     char *model;
     union {
Index: libvirt-plain/src/lxc/lxc_driver.c
===================================================================
--- libvirt-plain.orig/src/lxc/lxc_driver.c
+++ libvirt-plain/src/lxc/lxc_driver.c
@@ -800,6 +800,16 @@ static int lxcSetupInterfaces(virConnect
         case VIR_DOMAIN_NET_TYPE_BRIDGE:
             bridge = def->nets[i]->data.bridge.brname;
             break;
+
+        case VIR_DOMAIN_NET_TYPE_USER:
+        case VIR_DOMAIN_NET_TYPE_ETHERNET:
+        case VIR_DOMAIN_NET_TYPE_SERVER:
+        case VIR_DOMAIN_NET_TYPE_CLIENT:
+        case VIR_DOMAIN_NET_TYPE_MCAST:
+        case VIR_DOMAIN_NET_TYPE_INTERNAL:
+        case VIR_DOMAIN_NET_TYPE_DIRECT:
+        case VIR_DOMAIN_NET_TYPE_LAST:
+            break;
         }
 
         DEBUG("bridge: %s", bridge);
Index: libvirt-plain/src/qemu/qemu_conf.c
===================================================================
--- libvirt-plain.orig/src/qemu/qemu_conf.c
+++ libvirt-plain/src/qemu/qemu_conf.c
@@ -2686,6 +2686,14 @@ qemuBuildHostNetStr(virDomainNetDefPtr n
                               net->data.socket.address,
                               net->data.socket.port);
             break;
+        case VIR_DOMAIN_NET_TYPE_USER:
+        case VIR_DOMAIN_NET_TYPE_ETHERNET:
+        case VIR_DOMAIN_NET_TYPE_NETWORK:
+        case VIR_DOMAIN_NET_TYPE_BRIDGE:
+        case VIR_DOMAIN_NET_TYPE_INTERNAL:
+        case VIR_DOMAIN_NET_TYPE_DIRECT:
+        case VIR_DOMAIN_NET_TYPE_LAST:
+            break;
         }
         type_sep = ',';
         break;
Index: libvirt-plain/src/uml/uml_conf.c
===================================================================
--- libvirt-plain.orig/src/uml/uml_conf.c
+++ libvirt-plain/src/uml/uml_conf.c
@@ -244,6 +244,14 @@ umlBuildCommandLineNet(virConnectPtr con
         umlReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s",
                        _("internal networking type not supported"));
         goto error;
+
+    case VIR_DOMAIN_NET_TYPE_DIRECT:
+        umlReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("direct networking type not supported"));
+        goto error;
+
+    case VIR_DOMAIN_NET_TYPE_LAST:
+        break;
     }
 
     virBufferVSprintf(&buf, ",%02x:%02x:%02x:%02x:%02x:%02x",
Index: libvirt-plain/src/conf/domain_conf.c
===================================================================
--- libvirt-plain.orig/src/conf/domain_conf.c
+++ libvirt-plain/src/conf/domain_conf.c
@@ -450,6 +450,10 @@ void virDomainNetDefFree(virDomainNetDef
     case VIR_DOMAIN_NET_TYPE_DIRECT:
         VIR_FREE(def->data.direct.linkdev);
         break;
+
+    case VIR_DOMAIN_NET_TYPE_USER:
+    case VIR_DOMAIN_NET_TYPE_LAST:
+        break;
     }
 
     VIR_FREE(def->ifname);
@@ -1740,7 +1744,7 @@ virDomainNetDefParseXML(virCapsPtr caps,
 
     type = virXMLPropString(node, "type");
     if (type != NULL) {
-        if ((def->type = virDomainNetTypeFromString(type)) < 0) {
+        if ((int)(def->type = virDomainNetTypeFromString(type)) < 0) {
             virDomainReportError(VIR_ERR_INTERNAL_ERROR,
                                  _("unknown interface type '%s'"), type);
             goto error;
@@ -1949,6 +1953,10 @@ virDomainNetDefParseXML(virCapsPtr caps,
         dev = NULL;
 
         break;
+
+    case VIR_DOMAIN_NET_TYPE_USER:
+    case VIR_DOMAIN_NET_TYPE_LAST:
+        break;
     }
 
     if (ifname != NULL) {
@@ -4861,6 +4869,10 @@ virDomainNetDefFormat(virBufferPtr buf,
                    virDomainNetdevMacvtapTypeToString(def->data.direct.mode));
         virBufferAddLit(buf, "/>\n");
         break;
+
+    case VIR_DOMAIN_NET_TYPE_USER:
+    case VIR_DOMAIN_NET_TYPE_LAST:
+        break;
     }
 
     if (def->ifname)




More information about the libvir-list mailing list