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
This commit is contained in:
Stefan Berger 2010-03-26 17:01:35 +01:00 committed by Daniel Veillard
parent 67203f6780
commit 9bcad69093
5 changed files with 40 additions and 2 deletions

View File

@ -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)

View File

@ -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 {

View File

@ -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);

View File

@ -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;

View File

@ -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",