From 9bcad69093e3c0f57be4c5fa7d9086f3f49eb6d5 Mon Sep 17 00:00:00 2001 From: Stefan Berger Date: Fri, 26 Mar 2010 17:01:35 +0100 Subject: [PATCH] Use enum of virDomainNetType 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. * src/conf/domain_conf.h: change _virDomainNetDef type from int to virDomainNetType enum * src/conf/domain_conf.c src/lxc/lxc_driver.c src/qemu/qemu_conf.c src/uml/uml_conf.c: make sure all enum cases are properly handled in switches --- src/conf/domain_conf.c | 14 +++++++++++++- src/conf/domain_conf.h | 2 +- src/lxc/lxc_driver.c | 10 ++++++++++ src/qemu/qemu_conf.c | 8 ++++++++ src/uml/uml_conf.c | 8 ++++++++ 5 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index ffbb26fbd4..651dd04630 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -451,6 +451,10 @@ void virDomainNetDefFree(virDomainNetDefPtr def) 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); @@ -1743,7 +1747,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; @@ -1952,6 +1956,10 @@ virDomainNetDefParseXML(virCapsPtr caps, dev = NULL; break; + + case VIR_DOMAIN_NET_TYPE_USER: + case VIR_DOMAIN_NET_TYPE_LAST: + break; } if (ifname != NULL) { @@ -4868,6 +4876,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) diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index efd5db625d..218e0a79d2 100644 --- a/src/conf/domain_conf.h +++ b/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 { diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index e0e60c9a28..532cf8b27a 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -800,6 +800,16 @@ static int lxcSetupInterfaces(virConnectPtr conn, 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); diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 902eecb0d5..b1cc8349ce 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -2686,6 +2686,14 @@ qemuBuildHostNetStr(virDomainNetDefPtr net, 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; diff --git a/src/uml/uml_conf.c b/src/uml/uml_conf.c index 6e7bc59a02..876e16be26 100644 --- a/src/uml/uml_conf.c +++ b/src/uml/uml_conf.c @@ -244,6 +244,14 @@ umlBuildCommandLineNet(virConnectPtr conn, 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", -- GitLab